use std::env;
use std::path::PathBuf;
fn main() {
let target = env::var("TARGET").unwrap();
let manifest_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
eprintln!("Building for target: {}", target);
eprintln!("Project directory: {}", manifest_dir);
if target.contains("msvc") {
let lib_dir = PathBuf::from(&manifest_dir).join("libraw").join("msvc").join("lib");
eprintln!("Using MSVC toolchain");
eprintln!("Library directory: {}", lib_dir.display());
println!("cargo:rustc-link-search=native={}", lib_dir.display());
println!("cargo:rustc-link-lib=static=libraw_static");
println!("cargo:rerun-if-changed=libraw/msvc/lib/libraw_static.lib");
println!("cargo:rerun-if-changed=libraw/msvc/libraw/libraw.h");
}
else if target.contains("windows-gnu") {
let lib_dir = PathBuf::from(&manifest_dir).join("libraw").join("gnu").join("lib");
eprintln!("Using MinGW toolchain");
eprintln!("Library directory: {}", lib_dir.display());
println!("cargo:rustc-link-search=native={}", lib_dir.display());
if lib_dir.join("libraw.a").exists() {
eprintln!("Using static libraw library");
println!("cargo:rustc-link-lib=static=raw");
println!("cargo:rerun-if-changed=libraw/gnu/lib/libraw.a");
} else {
eprintln!("Static libraw not found, using dynamic library");
println!("cargo:rustc-link-lib=dylib=raw");
}
println!("cargo:rustc-link-lib=dylib=stdc++");
println!("cargo:rerun-if-changed=libraw/gnu/libraw/libraw.h");
}
else {
if std::process::Command::new("pkg-config").arg("--exists").arg("libraw").status().is_ok() {
eprintln!("Using system libraw via pkg-config");
println!("cargo:rustc-link-lib=dylib=raw");
println!("cargo:rustc-link-lib=dylib=stdc++");
}
else if std::path::Path::new("/usr/lib64/libraw.so").exists() {
eprintln!("Using system libraw from /usr/lib64");
println!("cargo:rustc-link-search=native=/usr/lib64");
println!("cargo:rustc-link-lib=dylib=raw");
println!("cargo:rustc-link-lib=dylib=stdc++");
}
else {
let lib_dir = PathBuf::from(&manifest_dir).join("libraw").join("gnu").join("lib");
eprintln!("System libraw not found, using bundled GNU libraries");
eprintln!("Library directory: {}", lib_dir.display());
println!("cargo:rustc-link-search=native={}", lib_dir.display());
if lib_dir.join("libraw.a").exists() {
eprintln!("Using static libraw library from bundle");
println!("cargo:rustc-link-lib=static=raw");
println!("cargo:rerun-if-changed=libraw/gnu/lib/libraw.a");
} else {
eprintln!("Static library not found in bundle, expecting system dynamic library");
println!("cargo:rustc-link-lib=dylib=raw");
}
println!("cargo:rustc-link-lib=dylib=stdc++");
}
println!("cargo:rerun-if-changed=libraw/gnu/libraw/libraw.h");
}
println!("cargo:rerun-if-changed=build.rs");
}