]> git.lizzy.rs Git - rust.git/blob - src/etc/mklldeps.py
auto merge of #16345 : EduardoBautista/rust/fix-error-message-in-guide, r=steveklabnik
[rust.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
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.
26 //
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.
32
33 // WARNING: THIS IS A GENERATED FILE, DO NOT MODIFY
34 //          take a look at src/etc/mklldeps.py if you're interested
35 """)
36
37 def run(args):
38     proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
39     out, err = proc.communicate()
40
41     if err:
42         print("failed to run llconfig: args = `{}`".format(args))
43         print(err)
44         sys.exit(1)
45     return out
46
47 for llconfig in sys.argv[4:]:
48     f.write("\n")
49
50     out = run([llconfig, '--host-target'])
51     arch, os = out.split('-', 1)
52     arch = 'x86' if arch == 'i686' or arch == 'i386' else arch
53     if 'darwin' in os:
54         os = 'macos'
55     elif 'linux' in os:
56         os = 'linux'
57     elif 'freebsd' in os:
58         os = 'freebsd'
59     elif 'dragonfly' in os:
60         os = 'dragonfly'
61     elif 'android' in os:
62         os = 'android'
63     elif 'win' in os or 'mingw' in os:
64         os = 'windows'
65     cfg = [
66         "target_arch = \"" + arch + "\"",
67         "target_os = \"" + os + "\"",
68     ]
69
70     f.write("#[cfg(" + ', '.join(cfg) + ")]\n")
71     if os == "windows": # NOTE: Remove after snapshot
72         f.write("#[cfg(stage0, target_arch = \"%s\", target_os = \"win32\")]\n" % (arch,))
73
74     version = run([llconfig, '--version']).strip()
75
76     # LLVM libs
77     if version < '3.5':
78       args = [llconfig, '--libs']
79     else:
80       args = [llconfig, '--libs', '--system-libs']
81     args.extend(components)
82     out = run(args)
83     for lib in out.strip().replace("\n", ' ').split(' '):
84         lib = lib.strip()[2:] # chop of the leading '-l'
85         f.write("#[link(name = \"" + lib + "\"")
86         # LLVM libraries are all static libraries
87         if 'LLVM' in lib:
88             f.write(", kind = \"static\"")
89         f.write(")]\n")
90
91     # llvm-config before 3.5 didn't have a system-libs flag
92     if version < '3.5':
93       if os == 'win32':
94         f.write("#[link(name = \"imagehlp\")]")
95
96     # LLVM ldflags
97     out = run([llconfig, '--ldflags'])
98     for lib in out.strip().split(' '):
99         if lib[:2] == "-l":
100             f.write("#[link(name = \"" + lib[2:] + "\")]\n")
101
102     # C++ runtime library
103     out = run([llconfig, '--cxxflags'])
104     if enable_static == '1':
105       assert('stdlib=libc++' not in out)
106       f.write("#[link(name = \"stdc++\", kind = \"static\")]\n")
107     else:
108       if 'stdlib=libc++' in out:
109         f.write("#[link(name = \"c++\")]\n")
110       else:
111         f.write("#[link(name = \"stdc++\")]\n")
112
113     # Attach everything to an extern block
114     f.write("extern {}\n")