extern crate bindgen;
use std::{env, fs};
use std::fs::File;
use std::path::PathBuf;
use std::io::Write;
fn main() {
let wrapper_file_path = format!("{}/{}", env::var("OUT_DIR").expect("env var should be set"), "wrapper.h");
let mut wrapper_file = File::create(&wrapper_file_path).unwrap();
let header_files_apache: Vec<String> = fs::read_dir("/usr/include/apache2").unwrap().map(|r| r.unwrap().file_name().to_str().unwrap().into()).collect();
let header_files_apr: Vec<String> = fs::read_dir("/usr/include/apr-1.0").unwrap().map(|r| r.unwrap().file_name().to_str().unwrap().into()).collect();
let mut header_files: Vec<String> = [header_files_apache, header_files_apr].concat();
header_files.retain(|header_file| !header_file.eq("mod_xml2enc.h"));
header_files.sort();
for header_file in header_files {
writeln!(&mut wrapper_file, "#include \"{}\"", header_file).unwrap();
}
println!("cargo:rerun-if-changed={}", &wrapper_file_path);
let bindings = bindgen::Builder::default()
.default_macro_constant_type(bindgen::MacroTypeVariation::Signed)
.blocklist_function("qecvt")
.blocklist_function("qecvt_r")
.blocklist_function("qfcvt")
.blocklist_function("qfcvt_r")
.blocklist_function("qgcvt")
.blocklist_function("strfromf64x")
.blocklist_function("strfroml")
.blocklist_function("strtof64x")
.blocklist_function("strtold")
.header(&wrapper_file_path)
.clang_arg("-I/usr/include/apache2")
.clang_arg("-I/usr/include/apr-1.0")
.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!");
}