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.
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.
17 f = open(sys.argv[1], 'wb')
19 components = sys.argv[2].split(' ')
20 components = [i for i in components if i] # ignore extra whitespaces
21 enable_static = sys.argv[3]
23 f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
24 // file at the top-level directory of this distribution and at
25 // http://rust-lang.org/COPYRIGHT.
27 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
28 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
29 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
30 // option. This file may not be copied, modified, or distributed
31 // except according to those terms.
33 // WARNING: THIS IS A GENERATED FILE, DO NOT MODIFY
34 // take a look at src/etc/mklldeps.py if you're interested
38 proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
39 out, err = proc.communicate()
42 print("failed to run llconfig: args = `{}`".format(args))
47 for llconfig in sys.argv[4:]:
50 out = run([llconfig, '--host-target'])
51 arch, os = out.split('-', 1)
52 arch = 'x86' if arch == 'i686' or arch == 'i386' else arch
61 elif 'win' in os or 'mingw' in os:
64 "target_arch = \"" + arch + "\"",
65 "target_os = \"" + os + "\"",
68 f.write("#[cfg(" + ', '.join(cfg) + ")]\n")
70 version = run([llconfig, '--version']).strip()
74 args = [llconfig, '--libs']
76 args = [llconfig, '--libs', '--system-libs']
77 args.extend(components)
79 for lib in out.strip().replace("\n", ' ').split(' '):
80 lib = lib.strip()[2:] # chop of the leading '-l'
81 f.write("#[link(name = \"" + lib + "\"")
82 # LLVM libraries are all static libraries
84 f.write(", kind = \"static\"")
87 # llvm-config before 3.5 didn't have a system-libs flag
90 f.write("#[link(name = \"imagehlp\")]")
93 out = run([llconfig, '--ldflags'])
94 for lib in out.strip().split(' '):
96 f.write("#[link(name = \"" + lib[2:] + "\")]\n")
99 out = run([llconfig, '--cxxflags'])
100 if enable_static == '1':
101 assert('stdlib=libc++' not in out)
102 f.write("#[link(name = \"stdc++\", kind = \"static\")]\n")
104 if 'stdlib=libc++' in out:
105 f.write("#[link(name = \"c++\")]\n")
107 f.write("#[link(name = \"stdc++\")]\n")
109 # Attach everything to an extern block
110 f.write("extern {}\n")