2014-02-02 04:47:02 -06:00
|
|
|
# Copyright 2013-2014 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
# file at the top-level directory of this distribution and at
|
|
|
|
# http://rust-lang.org/COPYRIGHT.
|
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
# <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
# option. This file may not be copied, modified, or distributed
|
|
|
|
# except according to those terms.
|
2013-11-30 22:52:21 -06:00
|
|
|
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import subprocess
|
|
|
|
|
2013-12-16 23:35:22 -06:00
|
|
|
f = open(sys.argv[1], 'wb')
|
2013-11-30 22:52:21 -06:00
|
|
|
|
2015-05-29 11:36:02 -05:00
|
|
|
components = sys.argv[2].split() # splits on whitespace
|
2014-04-16 12:45:04 -05:00
|
|
|
enable_static = sys.argv[3]
|
2015-05-29 11:36:13 -05:00
|
|
|
llvm_config = sys.argv[4]
|
2015-09-18 09:30:45 -05:00
|
|
|
stdcpp_name = sys.argv[5]
|
2015-08-21 23:43:56 -05:00
|
|
|
use_libcpp = sys.argv[6]
|
2013-12-16 23:35:22 -06:00
|
|
|
|
|
|
|
f.write("""// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
2013-11-30 22:52:21 -06:00
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
// WARNING: THIS IS A GENERATED FILE, DO NOT MODIFY
|
|
|
|
// take a look at src/etc/mklldeps.py if you're interested
|
2013-12-16 23:35:22 -06:00
|
|
|
""")
|
2013-11-30 22:52:21 -06:00
|
|
|
|
2015-01-27 02:22:24 -06:00
|
|
|
|
2014-04-14 14:30:52 -05:00
|
|
|
def run(args):
|
|
|
|
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
out, err = proc.communicate()
|
|
|
|
|
|
|
|
if err:
|
2015-05-29 11:36:13 -05:00
|
|
|
print("failed to run llvm_config: args = `{}`".format(args))
|
2014-04-14 14:30:52 -05:00
|
|
|
print(err)
|
|
|
|
sys.exit(1)
|
|
|
|
return out
|
|
|
|
|
2015-08-21 23:43:56 -05:00
|
|
|
def runErr(args):
|
|
|
|
proc = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
|
|
|
out, err = proc.communicate()
|
|
|
|
|
|
|
|
if err:
|
|
|
|
return False, out
|
|
|
|
else:
|
|
|
|
return True, out
|
|
|
|
|
2014-11-25 17:53:05 -06:00
|
|
|
f.write("\n")
|
|
|
|
|
2015-08-21 23:43:56 -05:00
|
|
|
args = [llvm_config, '--shared-mode']
|
|
|
|
args.extend(components)
|
|
|
|
llvm_shared, out = runErr(args)
|
|
|
|
if llvm_shared:
|
|
|
|
llvm_shared = 'shared' in out
|
|
|
|
|
2014-11-25 17:53:05 -06:00
|
|
|
# LLVM libs
|
2015-05-29 11:36:13 -05:00
|
|
|
args = [llvm_config, '--libs', '--system-libs']
|
2014-11-25 17:53:05 -06:00
|
|
|
args.extend(components)
|
|
|
|
out = run(args)
|
|
|
|
for lib in out.strip().replace("\n", ' ').split(' '):
|
2015-01-17 01:51:04 -06:00
|
|
|
if len(lib) == 0:
|
|
|
|
continue
|
|
|
|
# in some cases we get extra spaces in between libs so ignore those
|
|
|
|
if len(lib) == 1 and lib == ' ':
|
|
|
|
continue
|
|
|
|
# not all libs strictly follow -lfoo, on Bitrig, there is -pthread
|
|
|
|
if lib[0:2] == '-l':
|
|
|
|
lib = lib.strip()[2:]
|
|
|
|
elif lib[0] == '-':
|
|
|
|
lib = lib.strip()[1:]
|
2016-07-25 17:37:12 -05:00
|
|
|
# If this actually points at a literal file then we're on MSVC which now
|
|
|
|
# prints full paths, so get just the name of the library and strip off the
|
|
|
|
# trailing ".lib"
|
|
|
|
elif os.path.exists(lib):
|
|
|
|
lib = os.path.basename(lib)[:-4]
|
|
|
|
elif lib[-4:] == '.lib':
|
|
|
|
lib = lib[:-4]
|
2014-11-25 17:53:05 -06:00
|
|
|
f.write("#[link(name = \"" + lib + "\"")
|
2015-08-21 23:43:56 -05:00
|
|
|
if not llvm_shared and 'LLVM' in lib:
|
2014-11-25 17:53:05 -06:00
|
|
|
f.write(", kind = \"static\"")
|
|
|
|
f.write(")]\n")
|
|
|
|
|
|
|
|
# LLVM ldflags
|
2015-05-29 11:36:13 -05:00
|
|
|
out = run([llvm_config, '--ldflags'])
|
2014-11-25 17:53:05 -06:00
|
|
|
for lib in out.strip().split(' '):
|
|
|
|
if lib[:2] == "-l":
|
|
|
|
f.write("#[link(name = \"" + lib[2:] + "\")]\n")
|
|
|
|
|
|
|
|
# C++ runtime library
|
2015-05-29 11:36:13 -05:00
|
|
|
out = run([llvm_config, '--cxxflags'])
|
2014-11-25 17:53:05 -06:00
|
|
|
if enable_static == '1':
|
|
|
|
assert('stdlib=libc++' not in out)
|
2015-09-18 09:30:45 -05:00
|
|
|
f.write("#[link(name = \"" + stdcpp_name + "\", kind = \"static\")]\n")
|
2014-11-25 17:53:05 -06:00
|
|
|
else:
|
2015-05-11 16:47:04 -05:00
|
|
|
# Note that we use `cfg_attr` here because on MSVC the C++ standard library
|
|
|
|
# is not c++ or stdc++, but rather the linker takes care of linking the
|
|
|
|
# right standard library.
|
2015-08-21 23:43:56 -05:00
|
|
|
if use_libcpp != "0" or 'stdlib=libc++' in out:
|
2015-05-11 16:47:04 -05:00
|
|
|
f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"c++\"))]\n")
|
2014-11-25 17:53:05 -06:00
|
|
|
else:
|
2015-09-18 09:30:45 -05:00
|
|
|
f.write("#[cfg_attr(not(target_env = \"msvc\"), link(name = \"" + stdcpp_name + "\"))]\n")
|
2014-04-14 11:49:34 -05:00
|
|
|
|
2014-11-25 17:53:05 -06:00
|
|
|
# Attach everything to an extern block
|
|
|
|
f.write("extern {}\n")
|