extern crate pkg_config; use std::env; use std::fs::{self, File}; use std::path::PathBuf; use std::process::Command; fn main() { match pkg_config::find_library("libsodium") { Ok(_) => {}, Err(_) => { let src = PathBuf::from(&env::var_os("CARGO_MANIFEST_DIR").unwrap()) .join("libsodium"); let dst = PathBuf::from(&env::var_os("OUT_DIR").unwrap()).join("build"); let _ = fs::create_dir(&dst); match File::open(src.join("configure")) { Ok(_) => {}, Err(_) => { run(Command::new("./autogen.sh").current_dir(&src)); }, } run(Command::new("./configure").current_dir(&src)); run(Command::new("make").current_dir(&src)); let shlib = src.join("src/libsodium/.libs"); let _ = fs::copy(&shlib.join("libsodium.a"), &dst.join("libsodium.a")); println!("cargo:rustc-flags=-l static=sodium"); println!("cargo:rustc-flags=-L {}", dst.display()); //if let Ok(lib_dir) = env::var("SODIUM_LIB_DIR") { // println!("cargo:rustc-flags=-L native={}", lib_dir); //} //let mode = match env::var_os("SODIUM_STATIC") { // Some(_) => "static", // None => "dylib" //}; //println!("cargo:rustc-flags=-l {0}=sodium", mode); // }, // } }, } } fn run(cmd: &mut Command) { match cmd.status() { Ok(status) => assert!(status.success()), Err(e) => panic!("Unable to execute {:?}! {}", cmd, e), } }