#[cfg(not(feature = "static"))]
#[allow(clippy::if_same_then_else, clippy::needless_bool)]
fn infer_static(name: &str) -> bool {
if std::env::var(format!("{}_STATIC", name.to_uppercase())).is_ok() {
true
} else if std::env::var(format!("{}_DYNAMIC", name.to_uppercase())).is_ok() {
false
} else if std::env::var("PKG_CONFIG_ALL_STATIC").is_ok() {
true
} else if std::env::var("PKG_CONFIG_ALL_DYNAMIC").is_ok() {
false
} else {
false
}
}
#[cfg(not(feature = "static"))]
fn bind_erfa() {
match std::env::var("ERFA_LIB") {
Ok(lib) => {
println!("cargo:rustc-link-search=native={}", lib);
println!("cargo:rustc-link-lib=erfa");
}
Err(_) => {
pkg_config::probe_library("erfa")
.unwrap_or_else(|_| panic!("Couldn't find the ERFA library via pkg-config"));
}
}
if infer_static("ERFA") {
println!("cargo:rustc-link-lib=static=erfa");
}
}
fn main() {
#[cfg(not(feature = "static"))]
bind_erfa();
#[cfg(feature = "static")]
{
let erfa_project_dir = std::path::PathBuf::from("ext/erfa");
if !erfa_project_dir.exists() {
panic!(
"Expected to find ERFA source directory {}",
erfa_project_dir.display()
);
}
match std::fs::read_dir(&erfa_project_dir) {
Ok(mut d) => {
if let None = d.next() {
panic!("ERFA source directory ext/erfa is empty!");
}
}
_ => panic!("Could not read from ERFA source directory ext/erfa !"),
}
let opt_level: String = match std::env::var("OPT_LEVEL").as_ref().map(|o| o.as_str()) {
Err(_) => panic!("Something wrong with OPT_LEVEL"),
Ok("z") => "s",
Ok(o) => o,
}
.to_string();
std::process::Command::new("./bootstrap.sh")
.current_dir(&erfa_project_dir)
.output()
.expect("failed to execute autoconf");
let dst = autotools::Config::new(erfa_project_dir)
.disable_shared()
.cflag("-Wall")
.cflag(format!("-O{}", opt_level))
.cflag("-fPIE")
.build();
println!("cargo:rustc-link-search=native={}/lib", dst.display());
println!("cargo:rustc-link-lib=static=erfa");
}
}