extern crate gcc;
extern crate pkg_config;
use std::ascii::AsciiExt;
use std::process::Command;
use gcc::Config;
use std::env;
use std::path::Path;
const MIN_MAJOR: u16 = 3;
const MIN_MINOR: u16 = 4;
const MINOR_STEP: u16 = 2;
fn main() {
let lib = pkg_config::find_library("gtk+-3.0")
.unwrap_or_else(|e| panic!("{}", e));
let mut parts = lib.version.splitn(3, '.')
.map(|s| s.parse())
.take_while(|r| r.is_ok())
.map(|r| r.unwrap());
let version: (u16, u16) = (parts.next().unwrap_or(0), parts.next().unwrap_or(0));
let mut cfgs = Vec::new();
if version.0 == MIN_MAJOR && version.1 > MIN_MINOR {
let major = version.0;
let mut minor = MIN_MINOR;
while minor <= version.1 {
cfgs.push(format!("gtk_{}_{}", major, minor));
minor += MINOR_STEP;
}
}
for cfg in &cfgs {
println!("cargo:rustc-cfg={}", cfg);
}
println!("cargo:cfg={}", cfgs.connect(" "));
env::set_var("PKG_CONFIG_ALLOW_CROSS", "1");
let cmd = Command::new("pkg-config").arg("--cflags").arg("gtk+-3.0")
.output().unwrap();
if !cmd.status.success() {
panic!("{}", String::from_utf8_lossy(&cmd.stderr));
}
let output = String::from_utf8(cmd.stdout).unwrap();
let mut gcc_conf = Config::new();
for s in output.split(' ') {
if s.starts_with("-I") {
let path: &Path = s[2..].as_ref();
gcc_conf.include(path);
}
}
gcc_conf.file("src/gtk_glue.c");
for cfg in &cfgs {
gcc_conf.flag(&format!("-D{}", cfg.to_ascii_uppercase()));
}
gcc_conf.compile("librgtk_glue.a");
}