use std::{env, path::PathBuf};
#[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
}
}
fn main() {
let bindings = bindgen::Builder::default()
.header("include/wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks))
.allowlist_function("pal.*")
.generate()
.expect("Unable to generate bindings");
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings!");
let pal_lib = std::env::var("PAL_LIB").unwrap_or(String::from("/usr/local/lib"));
println!("cargo:rustc-link-search=native={}", pal_lib);
#[cfg(not(feature = "static"))]
{
println!("cargo:rustc-link-lib=pal");
if infer_static("PAL") {
println!("cargo:rustc-link-lib=static=pal");
}
}
#[cfg(feature = "static")]
{
println!("cargo:rustc-link-lib=static=pal");
}
let erfa_lib = std::env::var("ERFA_LIB").unwrap_or(String::from("/usr/lib/x86_64-linux-gnu"));
println!("cargo:rustc-link-search=native={}", erfa_lib);
println!("cargo:rustc-link-lib=erfa");
}