]> git.proxmox.com Git - rustc.git/blob - src/etc/mklldeps.py
Merge tag 'upstream-tar/1.0.0_0alpha'
[rustc.git] / src / etc / mklldeps.py
1 # Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
2 # file at the top-level directory of this distribution and at
3 # http://rust-lang.org/COPYRIGHT.
4 #
5 # Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 # http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 # <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 # option. This file may not be copied, modified, or distributed
9 # except according to those terms.
10
11 import os
12 import sys
13 import subprocess
14 import itertools
15 from os import path
16
17 f = open(sys.argv[1], 'wb')
18
19 components = sys.argv[2].split(' ')
20 components = [i for i in components if i] # ignore extra whitespaces
21 enable_static = sys.argv[3]
22 llconfig = sys.argv[4]
23
24 f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
25 // file at the top-level directory of this distribution and at
26 // http://rust-lang.org/COPYRIGHT.
27 //
28 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
29 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
30 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
31 // option. This file may not be copied, modified, or distributed
32 // except according to those terms.
33
34 // WARNING: THIS IS A GENERATED FILE, DO NOT MODIFY
35 // take a look at src/etc/mklldeps.py if you're interested
36 """)
37
38 def run(args):
39 proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
40 out, err = proc.communicate()
41
42 if err:
43 print("failed to run llconfig: args = `{}`".format(args))
44 print(err)
45 sys.exit(1)
46 return out
47
48 f.write("\n")
49
50 version = run([llconfig, '--version']).strip()
51
52 # LLVM libs
53 if version < '3.5':
54 args = [llconfig, '--libs']
55 else:
56 args = [llconfig, '--libs', '--system-libs']
57
58 args.extend(components)
59 out = run(args)
60 for lib in out.strip().replace("\n", ' ').split(' '):
61 lib = lib.strip()[2:] # chop of the leading '-l'
62 f.write("#[link(name = \"" + lib + "\"")
63 # LLVM libraries are all static libraries
64 if 'LLVM' in lib:
65 f.write(", kind = \"static\"")
66 f.write(")]\n")
67
68 # llvm-config before 3.5 didn't have a system-libs flag
69 if version < '3.5':
70 if os == 'win32':
71 f.write("#[link(name = \"imagehlp\")]")
72
73 # LLVM ldflags
74 out = run([llconfig, '--ldflags'])
75 for lib in out.strip().split(' '):
76 if lib[:2] == "-l":
77 f.write("#[link(name = \"" + lib[2:] + "\")]\n")
78
79 # C++ runtime library
80 out = run([llconfig, '--cxxflags'])
81 if enable_static == '1':
82 assert('stdlib=libc++' not in out)
83 f.write("#[link(name = \"stdc++\", kind = \"static\")]\n")
84 else:
85 if 'stdlib=libc++' in out:
86 f.write("#[link(name = \"c++\")]\n")
87 else:
88 f.write("#[link(name = \"stdc++\")]\n")
89
90 # Attach everything to an extern block
91 f.write("extern {}\n")