|
31 | 31 | // take a look at src/etc/mklldeps.py if you're interested
|
32 | 32 | """)
|
33 | 33 |
|
| 34 | +def run(args): |
| 35 | + proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
| 36 | + out, err = proc.communicate() |
| 37 | + |
| 38 | + if err: |
| 39 | + print("failed to run llconfig: args = `{}`".format(args)) |
| 40 | + print(err) |
| 41 | + sys.exit(1) |
| 42 | + return out |
| 43 | + |
34 | 44 | for llconfig in sys.argv[3:]:
|
35 | 45 | f.write("\n")
|
36 | 46 |
|
37 |
| - proc = subprocess.Popen([llconfig, '--host-target'], stdout = subprocess.PIPE) |
38 |
| - out, err = proc.communicate() |
| 47 | + out = run([llconfig, '--host-target']) |
39 | 48 | arch, os = out.split('-', 1)
|
40 | 49 | arch = 'x86' if arch == 'i686' or arch == 'i386' else arch
|
41 | 50 | if 'darwin' in os:
|
|
55 | 64 |
|
56 | 65 | f.write("#[cfg(" + ', '.join(cfg) + ")]\n")
|
57 | 66 |
|
| 67 | + version = run([llconfig, '--version']).strip() |
| 68 | + |
58 | 69 | # LLVM libs
|
59 |
| - args = [llconfig, '--libs', '--system-libs'] |
| 70 | + if version < '3.5': |
| 71 | + args = [llconfig, '--libs'] |
| 72 | + else: |
| 73 | + args = [llconfig, '--libs', '--system-libs'] |
60 | 74 | args.extend(components)
|
61 |
| - proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
62 |
| - out, err = proc.communicate() |
63 |
| - |
64 |
| - if err: |
65 |
| - print("failed to run llconfig: args = `{}`".format(args)) |
66 |
| - sys.exit(1) |
67 |
| - |
| 75 | + out = run(args) |
68 | 76 | for lib in out.strip().replace("\n", ' ').split(' '):
|
69 | 77 | lib = lib.strip()[2:] # chop of the leading '-l'
|
70 | 78 | f.write("#[link(name = \"" + lib + "\"")
|
|
73 | 81 | f.write(", kind = \"static\"")
|
74 | 82 | f.write(")]\n")
|
75 | 83 |
|
76 |
| - # LLVM ldflags |
77 |
| - args = [llconfig, '--ldflags'] |
78 |
| - proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
79 |
| - out, err = proc.communicate() |
80 |
| - |
81 |
| - if err: |
82 |
| - print("failed to run llconfig: args = `{}`".format(args)) |
83 |
| - sys.exit(1) |
| 84 | + # llvm-config before 3.5 didn't have a system-libs flag |
| 85 | + if version < '3.5': |
| 86 | + if os == 'win32': |
| 87 | + f.write("#[link(name = \"imagehlp\")]") |
84 | 88 |
|
| 89 | + # LLVM ldflags |
| 90 | + out = run([llconfig, '--ldflags']) |
85 | 91 | for lib in out.strip().split(' '):
|
86 | 92 | if lib[:2] == "-l":
|
87 | 93 | f.write("#[link(name = \"" + lib[2:] + "\")]\n")
|
88 | 94 |
|
89 | 95 | # C++ runtime library
|
90 |
| - args = [llconfig, '--cxxflags'] |
91 |
| - proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE) |
92 |
| - out, err = proc.communicate() |
93 |
| - |
94 |
| - if err: |
95 |
| - print("failed to run llconfig: args = `{}`".format(args)) |
96 |
| - sys.exit(1) |
97 |
| - |
| 96 | + out = run([llconfig, '--cxxflags']) |
98 | 97 | if 'stdlib=libc++' in out:
|
99 | 98 | f.write("#[link(name = \"c++\")]\n")
|
100 | 99 | else:
|
|
0 commit comments