]>
Commit | Line | Data |
---|---|---|
1a4d82fc JJ |
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 | |
1a4d82fc JJ |
14 | |
15 | f = open(sys.argv[1], 'wb') | |
16 | ||
c1a9b12d | 17 | components = sys.argv[2].split() # splits on whitespace |
1a4d82fc | 18 | enable_static = sys.argv[3] |
c1a9b12d | 19 | llvm_config = sys.argv[4] |
1a4d82fc JJ |
20 | |
21 | f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT | |
22 | // file at the top-level directory of this distribution and at | |
23 | // http://rust-lang.org/COPYRIGHT. | |
24 | // | |
25 | // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | |
26 | // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | |
27 | // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | |
28 | // option. This file may not be copied, modified, or distributed | |
29 | // except according to those terms. | |
30 | ||
31 | // WARNING: THIS IS A GENERATED FILE, DO NOT MODIFY | |
32 | // take a look at src/etc/mklldeps.py if you're interested | |
33 | """) | |
34 | ||
85aaf69f | 35 | |
1a4d82fc JJ |
36 | def run(args): |
37 | proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) | |
38 | out, err = proc.communicate() | |
39 | ||
40 | if err: | |
c1a9b12d | 41 | print("failed to run llvm_config: args = `{}`".format(args)) |
1a4d82fc JJ |
42 | print(err) |
43 | sys.exit(1) | |
44 | return out | |
45 | ||
46 | f.write("\n") | |
47 | ||
1a4d82fc | 48 | # LLVM libs |
c1a9b12d | 49 | args = [llvm_config, '--libs', '--system-libs'] |
1a4d82fc JJ |
50 | |
51 | args.extend(components) | |
52 | out = run(args) | |
53 | for lib in out.strip().replace("\n", ' ').split(' '): | |
c34b1796 AL |
54 | if len(lib) == 0: |
55 | continue | |
56 | # in some cases we get extra spaces in between libs so ignore those | |
57 | if len(lib) == 1 and lib == ' ': | |
58 | continue | |
59 | # not all libs strictly follow -lfoo, on Bitrig, there is -pthread | |
60 | if lib[0:2] == '-l': | |
61 | lib = lib.strip()[2:] | |
62 | elif lib[0] == '-': | |
63 | lib = lib.strip()[1:] | |
1a4d82fc JJ |
64 | f.write("#[link(name = \"" + lib + "\"") |
65 | # LLVM libraries are all static libraries | |
66 | if 'LLVM' in lib: | |
67 | f.write(", kind = \"static\"") | |
68 | f.write(")]\n") | |
69 | ||
1a4d82fc | 70 | # LLVM ldflags |
c1a9b12d | 71 | out = run([llvm_config, '--ldflags']) |
1a4d82fc JJ |
72 | for lib in out.strip().split(' '): |
73 | if lib[:2] == "-l": | |
74 | f.write("#[link(name = \"" + lib[2:] + "\")]\n") | |
75 | ||
76 | # C++ runtime library | |
c1a9b12d | 77 | out = run([llvm_config, '--cxxflags']) |
1a4d82fc JJ |
78 | if enable_static == '1': |
79 | assert('stdlib=libc++' not in out) | |
80 | f.write("#[link(name = \"stdc++\", kind = \"static\")]\n") | |
81 | else: | |
62682a34 SL |
82 | # Note that we use `cfg_attr` here because on MSVC the C++ standard library |
83 | # is not c++ or stdc++, but rather the linker takes care of linking the | |
84 | # right standard library. | |
1a4d82fc | 85 | if 'stdlib=libc++' in out: |
62682a34 | 86 | f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"c++\"))]\n") |
1a4d82fc | 87 | else: |
62682a34 | 88 | f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"stdc++\"))]\n") |
1a4d82fc JJ |
89 | |
90 | # Attach everything to an extern block | |
91 | f.write("extern {}\n") |