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
|
2014-04-16 12:45:04 -05:00
|
|
|
import itertools
|
|
|
|
from os import path
|
2013-11-30 22:52:21 -06:00
|
|
|
|
2013-12-16 23:35:22 -06:00
|
|
|
f = open(sys.argv[1], 'wb')
|
2013-11-30 22:52:21 -06:00
|
|
|
|
2013-12-16 23:35:22 -06:00
|
|
|
components = sys.argv[2].split(' ')
|
2013-12-19 09:50:36 -06:00
|
|
|
components = [i for i in components if i] # ignore extra whitespaces
|
2014-04-16 12:45:04 -05:00
|
|
|
enable_static = sys.argv[3]
|
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
|
|
|
|
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:
|
|
|
|
print("failed to run llconfig: args = `{}`".format(args))
|
|
|
|
print(err)
|
|
|
|
sys.exit(1)
|
|
|
|
return out
|
|
|
|
|
2014-04-16 12:45:04 -05:00
|
|
|
for llconfig in sys.argv[4:]:
|
2013-12-16 23:35:22 -06:00
|
|
|
f.write("\n")
|
2013-11-30 22:52:21 -06:00
|
|
|
|
2014-04-14 14:30:52 -05:00
|
|
|
out = run([llconfig, '--host-target'])
|
2013-11-30 22:52:21 -06:00
|
|
|
arch, os = out.split('-', 1)
|
|
|
|
arch = 'x86' if arch == 'i686' or arch == 'i386' else arch
|
|
|
|
if 'darwin' in os:
|
|
|
|
os = 'macos'
|
|
|
|
elif 'linux' in os:
|
|
|
|
os = 'linux'
|
|
|
|
elif 'freebsd' in os:
|
|
|
|
os = 'freebsd'
|
2014-07-29 09:44:39 -05:00
|
|
|
elif 'dragonfly' in os:
|
|
|
|
os = 'dragonfly'
|
2013-11-30 22:52:21 -06:00
|
|
|
elif 'android' in os:
|
|
|
|
os = 'android'
|
|
|
|
elif 'win' in os or 'mingw' in os:
|
2014-08-10 23:26:45 -05:00
|
|
|
os = 'windows'
|
2013-11-30 22:52:21 -06:00
|
|
|
cfg = [
|
|
|
|
"target_arch = \"" + arch + "\"",
|
|
|
|
"target_os = \"" + os + "\"",
|
|
|
|
]
|
|
|
|
|
2013-12-16 23:35:22 -06:00
|
|
|
f.write("#[cfg(" + ', '.join(cfg) + ")]\n")
|
2013-11-30 22:52:21 -06:00
|
|
|
|
2014-04-14 14:30:52 -05:00
|
|
|
version = run([llconfig, '--version']).strip()
|
|
|
|
|
2014-03-02 10:29:54 -06:00
|
|
|
# LLVM libs
|
2014-04-14 14:30:52 -05:00
|
|
|
if version < '3.5':
|
|
|
|
args = [llconfig, '--libs']
|
|
|
|
else:
|
|
|
|
args = [llconfig, '--libs', '--system-libs']
|
2013-11-30 22:52:21 -06:00
|
|
|
args.extend(components)
|
2014-04-14 14:30:52 -05:00
|
|
|
out = run(args)
|
2014-04-14 11:49:34 -05:00
|
|
|
for lib in out.strip().replace("\n", ' ').split(' '):
|
|
|
|
lib = lib.strip()[2:] # chop of the leading '-l'
|
|
|
|
f.write("#[link(name = \"" + lib + "\"")
|
|
|
|
# LLVM libraries are all static libraries
|
|
|
|
if 'LLVM' in lib:
|
|
|
|
f.write(", kind = \"static\"")
|
|
|
|
f.write(")]\n")
|
2014-03-02 10:29:54 -06:00
|
|
|
|
2014-04-14 14:30:52 -05:00
|
|
|
# llvm-config before 3.5 didn't have a system-libs flag
|
|
|
|
if version < '3.5':
|
|
|
|
if os == 'win32':
|
|
|
|
f.write("#[link(name = \"imagehlp\")]")
|
2014-03-02 10:29:54 -06:00
|
|
|
|
2014-04-14 14:30:52 -05:00
|
|
|
# LLVM ldflags
|
|
|
|
out = run([llconfig, '--ldflags'])
|
2014-03-02 10:29:54 -06:00
|
|
|
for lib in out.strip().split(' '):
|
|
|
|
if lib[:2] == "-l":
|
|
|
|
f.write("#[link(name = \"" + lib[2:] + "\")]\n")
|
|
|
|
|
2014-04-14 11:49:34 -05:00
|
|
|
# C++ runtime library
|
2014-04-14 14:30:52 -05:00
|
|
|
out = run([llconfig, '--cxxflags'])
|
2014-04-16 12:45:04 -05:00
|
|
|
if enable_static == '1':
|
|
|
|
assert('stdlib=libc++' not in out)
|
|
|
|
f.write("#[link(name = \"stdc++\", kind = \"static\")]\n")
|
2014-04-14 11:49:34 -05:00
|
|
|
else:
|
2014-04-16 12:45:04 -05:00
|
|
|
if 'stdlib=libc++' in out:
|
|
|
|
f.write("#[link(name = \"c++\")]\n")
|
|
|
|
else:
|
2014-04-14 11:49:34 -05:00
|
|
|
f.write("#[link(name = \"stdc++\")]\n")
|
|
|
|
|
|
|
|
# Attach everything to an extern block
|
2013-12-16 23:35:22 -06:00
|
|
|
f.write("extern {}\n")
|