extern crate cc;
use std::env;
use std::ffi::OsString;
use std::fs;
use std::path::PathBuf;
use std::process::Command;
fn main() {
let cfg = cc::Build::new();
let compiler = cfg.get_compiler();
let src = PathBuf::from(env::var_os("CARGO_MANIFEST_DIR").unwrap());
let dst = PathBuf::from(env::var_os("OUT_DIR").unwrap());
info(&format!("src dir: {}", src.display()));
info(&format!("dst dir: {}", dst.display()));
println!("cargo:rustc-link-lib=static=fuzzy");
println!("cargo:rustc-link-search={}/.libs", dst.display());
let _ = fs::create_dir(&dst);
let mut cflags = OsString::new();
for arg in compiler.args() {
cflags.push(arg);
cflags.push(" ");
}
cflags.push("-fPIC");
run(Command::new(&src.join("libfuzzy/configure"))
.arg("--enable-shared=no")
.arg("--enable-static=yes")
.env("CFLAGS", cflags)
.current_dir(&dst));
run(Command::new("make")
.arg(&format!("-j{}", env::var("NUM_JOBS").unwrap()))
.arg("AUTOCONF=:")
.arg("AUTOHEADER=:")
.arg("AUTOMAKE=: ")
.arg("ACLOCAL=:")
.current_dir(&dst));
}
fn run(cmd: &mut Command) {
info(&format!("running command: {:?}", cmd));
let status = match cmd.status() {
Ok(status) => status,
Err(e) => fail(&format!("failed to execute command: {}", e)),
};
if !status.success() {
fail(&format!("command did not execute successfully: {}", status));
}
info(&format!("command finished: {}", status));
}
fn info(msg: &str) {
println!("INFO: {}", msg);
}
fn fail(reason: &str) -> ! {
panic!("FAIL: {}\n\nbuild script failed", reason)
}