2017-12-09 02:50:18 +00:00
|
|
|
extern crate cc;
|
|
|
|
extern crate glob;
|
|
|
|
|
|
|
|
use std::env;
|
2017-10-09 22:09:24 +00:00
|
|
|
use std::process::Command;
|
|
|
|
|
2017-12-09 02:50:18 +00:00
|
|
|
use glob::glob;
|
|
|
|
|
2017-12-08 03:40:55 +00:00
|
|
|
#[path = "../../mkmain.rs"]
|
|
|
|
mod mkmain;
|
|
|
|
|
2017-12-09 02:50:18 +00:00
|
|
|
#[cfg(target_os = "macos")]
|
|
|
|
mod platform {
|
|
|
|
pub const DYLIB_EXT: &'static str = "dylib";
|
|
|
|
pub const DYLIB_FLAGS: [&'static str; 3] = ["-dynamiclib", "-undefined", "dynamic_lookup"];
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(target_os = "linux")]
|
|
|
|
mod platform {
|
|
|
|
pub const DYLIB_EXT: &'static str = "so";
|
|
|
|
pub const DYLIB_FLAGS: [&'static str; 1] = ["-shared"];
|
|
|
|
}
|
|
|
|
|
|
|
|
// FIXME: this entire thing is pretty fragile
|
2017-10-09 22:09:24 +00:00
|
|
|
fn main() {
|
2017-12-08 03:40:55 +00:00
|
|
|
mkmain::main();
|
|
|
|
|
2017-12-09 02:50:18 +00:00
|
|
|
let cc = env::var("CC").unwrap_or("gcc".to_string());
|
|
|
|
|
|
|
|
let out_dir = env::var("OUT_DIR").unwrap();
|
|
|
|
|
|
|
|
let entry = glob(&format!("{}/../../../deps/liblibstdbuf-*.a", out_dir)).unwrap()
|
|
|
|
.next()
|
|
|
|
.unwrap()
|
|
|
|
.unwrap();
|
|
|
|
|
|
|
|
cc::Build::new()
|
|
|
|
.flag("-Wall")
|
|
|
|
.flag("-Werror")
|
|
|
|
.pic(true)
|
|
|
|
.file("libstdbuf.c")
|
|
|
|
.compile("libstdbuf.a");
|
|
|
|
|
|
|
|
// XXX: we have to link manually because apparently cc-rs does not support shared libraries
|
|
|
|
let mut link = Command::new(cc);
|
|
|
|
for flag in platform::DYLIB_FLAGS.iter() {
|
|
|
|
link.arg(flag);
|
|
|
|
}
|
|
|
|
link.arg("-o")
|
|
|
|
.arg(format!("{}/libstdbuf.{}", out_dir, platform::DYLIB_EXT))
|
2017-12-11 08:21:15 +00:00
|
|
|
.arg(format!("{}/libstdbuf.a", out_dir))
|
|
|
|
.arg(entry);
|
2017-12-09 02:50:18 +00:00
|
|
|
if !link.spawn().unwrap().wait().unwrap().success() {
|
|
|
|
panic!("linking failed");
|
|
|
|
}
|
2017-10-09 22:09:24 +00:00
|
|
|
}
|