]> git.proxmox.com Git - rustc.git/blame - src/libstd/build.rs
Imported Upstream version 1.9.0+dfsg1
[rustc.git] / src / libstd / build.rs
CommitLineData
7453a54e
SL
1// Copyright 2015 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
11extern crate gcc;
12extern crate build_helper;
13
14use std::env;
15use std::fs;
16use std::path::PathBuf;
17use std::process::Command;
18
19use build_helper::run;
20
21fn main() {
22 println!("cargo:rustc-cfg=cargobuild");
23
24 let target = env::var("TARGET").unwrap();
25 let host = env::var("HOST").unwrap();
54a0048b 26 if !target.contains("apple") && !target.contains("msvc") && !target.contains("emscripten"){
7453a54e
SL
27 build_libbacktrace(&host, &target);
28 }
29
54a0048b
SL
30 if target.contains("linux") {
31 if target.contains("musl") && (target.contains("x86_64") || target.contains("i686")) {
7453a54e 32 println!("cargo:rustc-link-lib=static=unwind");
54a0048b
SL
33 } else if target.contains("android") {
34 println!("cargo:rustc-link-lib=dl");
35 println!("cargo:rustc-link-lib=log");
36 println!("cargo:rustc-link-lib=gcc");
7453a54e
SL
37 } else {
38 println!("cargo:rustc-link-lib=dl");
39 println!("cargo:rustc-link-lib=rt");
40 println!("cargo:rustc-link-lib=pthread");
41 println!("cargo:rustc-link-lib=gcc_s");
42 }
7453a54e
SL
43 } else if target.contains("freebsd") {
44 println!("cargo:rustc-link-lib=execinfo");
45 println!("cargo:rustc-link-lib=pthread");
46 println!("cargo:rustc-link-lib=gcc_s");
47 } else if target.contains("dragonfly") || target.contains("bitrig") ||
48 target.contains("netbsd") || target.contains("openbsd") {
49 println!("cargo:rustc-link-lib=pthread");
50
51 if target.contains("rumprun") {
52 println!("cargo:rustc-link-lib=unwind");
54a0048b
SL
53 } else if target.contains("netbsd") {
54 println!("cargo:rustc-link-lib=gcc_s");
55 } else if target.contains("openbsd") {
7453a54e
SL
56 println!("cargo:rustc-link-lib=gcc");
57 } else if target.contains("bitrig") {
58 println!("cargo:rustc-link-lib=c++abi");
59 } else if target.contains("dragonfly") {
60 println!("cargo:rustc-link-lib=gcc_pic");
61 }
62 } else if target.contains("apple-darwin") {
63 println!("cargo:rustc-link-lib=System");
64 } else if target.contains("apple-ios") {
65 println!("cargo:rustc-link-lib=System");
66 println!("cargo:rustc-link-lib=objc");
67 println!("cargo:rustc-link-lib=framework=Security");
68 println!("cargo:rustc-link-lib=framework=Foundation");
69 } else if target.contains("windows") {
70 if target.contains("windows-gnu") {
71 println!("cargo:rustc-link-lib=gcc_eh");
72 }
73 println!("cargo:rustc-link-lib=advapi32");
74 println!("cargo:rustc-link-lib=ws2_32");
75 println!("cargo:rustc-link-lib=userenv");
76 println!("cargo:rustc-link-lib=shell32");
77 }
78}
79
80fn build_libbacktrace(host: &str, target: &str) {
81 let src_dir = env::current_dir().unwrap().join("../libbacktrace");
82 let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
83
84 println!("cargo:rustc-link-lib=static=backtrace");
85 println!("cargo:rustc-link-search=native={}/.libs", build_dir.display());
86
87 if fs::metadata(&build_dir.join(".libs/libbacktrace.a")).is_ok() {
88 return
89 }
90
91 let compiler = gcc::Config::new().get_compiler();
92 let ar = build_helper::cc2ar(compiler.path(), target);
93 let cflags = compiler.args().iter().map(|s| s.to_str().unwrap())
94 .collect::<Vec<_>>().join(" ");
95 run(Command::new("sh")
96 .current_dir(&build_dir)
97 .arg(src_dir.join("configure").to_str().unwrap()
98 .replace("C:\\", "/c/")
99 .replace("\\", "/"))
100 .arg("--with-pic")
101 .arg("--disable-multilib")
102 .arg("--disable-shared")
103 .arg("--disable-host-shared")
104 .arg(format!("--host={}", build_helper::gnu_target(target)))
105 .arg(format!("--build={}", build_helper::gnu_target(host)))
106 .env("CC", compiler.path())
107 .env("AR", &ar)
108 .env("RANLIB", format!("{} s", ar.display()))
109 .env("CFLAGS", cflags));
110 run(Command::new("make")
111 .current_dir(&build_dir)
112 .arg(format!("INCDIR={}", src_dir.display()))
113 .arg("-j").arg(env::var("NUM_JOBS").unwrap()));
114}