use std::env;
use std::path::PathBuf;
use std::path::Path;
fn main() {
println!("cargo:rerun-if-changed=wrapper.h");
let mut files = vec![];
scan(&[
Path::new("it2play/audiodrivers/sdl"),
Path::new("it2play/loaders/mmcmp"),
Path::new("it2play/loaders"),
Path::new("it2play/it2drivers"),
Path::new("it2play"),
], &mut files);
if let Some(pos) = files.iter().position(|x| x.ends_with("sdldriver.c")) {
files.swap_remove(pos);
}
cc::Build::new()
.warnings(false)
.define("AUDIODRIVER_SDL", None)
.include(Path::new("it2play/audiodrivers"))
.include(Path::new("it2play/audiodrivers/sdl"))
.include(Path::new("it2play/loaders/mmcmp"))
.include(Path::new("it2play/loaders"))
.include(Path::new("it2play/it2drivers"))
.include(Path::new("it2play"))
.files(&files)
.file("dummydriver.c")
.compile("it2play");
let bindings = bindgen::Builder::default()
.header("wrapper.h")
.parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
.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!");
}
fn scan(folders: &[&Path], files: &mut Vec<PathBuf>) {
folders.iter().for_each(|folder| {
std::fs::read_dir(folder).unwrap().filter(|x| {
x.as_ref().unwrap().path().extension().is_some_and(|y| y == "c")
}).for_each(|x| {
let path = x.unwrap().path();
files.push(path);
});
});
}