]> git.proxmox.com Git - rustc.git/blame - src/etc/mklldeps.py
Imported Upstream version 1.1.0+dfsg1
[rustc.git] / src / etc / mklldeps.py
CommitLineData
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
11import os
12import sys
13import subprocess
1a4d82fc
JJ
14
15f = open(sys.argv[1], 'wb')
16
17components = sys.argv[2].split(' ')
18components = [i for i in components if i] # ignore extra whitespaces
19enable_static = sys.argv[3]
20llconfig = sys.argv[4]
21
22f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
23// file at the top-level directory of this distribution and at
24// http://rust-lang.org/COPYRIGHT.
25//
26// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
27// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
28// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
29// option. This file may not be copied, modified, or distributed
30// except according to those terms.
31
32// WARNING: THIS IS A GENERATED FILE, DO NOT MODIFY
33// take a look at src/etc/mklldeps.py if you're interested
34""")
35
85aaf69f 36
1a4d82fc
JJ
37def 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
47f.write("\n")
48
1a4d82fc 49# LLVM libs
d9579d0f 50args = [llconfig, '--libs', '--system-libs']
1a4d82fc
JJ
51
52args.extend(components)
53out = run(args)
54for lib in out.strip().replace("\n", ' ').split(' '):
c34b1796
AL
55 if len(lib) == 0:
56 continue
57 # in some cases we get extra spaces in between libs so ignore those
58 if len(lib) == 1 and lib == ' ':
59 continue
60 # not all libs strictly follow -lfoo, on Bitrig, there is -pthread
61 if lib[0:2] == '-l':
62 lib = lib.strip()[2:]
63 elif lib[0] == '-':
64 lib = lib.strip()[1:]
1a4d82fc
JJ
65 f.write("#[link(name = \"" + lib + "\"")
66 # LLVM libraries are all static libraries
67 if 'LLVM' in lib:
68 f.write(", kind = \"static\"")
69 f.write(")]\n")
70
1a4d82fc
JJ
71# LLVM ldflags
72out = run([llconfig, '--ldflags'])
73for lib in out.strip().split(' '):
74 if lib[:2] == "-l":
75 f.write("#[link(name = \"" + lib[2:] + "\")]\n")
76
77# C++ runtime library
78out = run([llconfig, '--cxxflags'])
79if enable_static == '1':
80 assert('stdlib=libc++' not in out)
81 f.write("#[link(name = \"stdc++\", kind = \"static\")]\n")
82else:
83 if 'stdlib=libc++' in out:
84 f.write("#[link(name = \"c++\")]\n")
85 else:
86 f.write("#[link(name = \"stdc++\")]\n")
87
88# Attach everything to an extern block
89f.write("extern {}\n")