2015-03-03 14:51:45 +08:00
|
|
|
#![feature(old_io, old_path)]
|
2015-02-03 03:17:23 +08:00
|
|
|
use std::old_io::Command;
|
|
|
|
use std::old_io::fs::PathExtensions;
|
|
|
|
use std::old_io::fs;
|
2015-03-03 14:51:45 +08:00
|
|
|
use std::env;
|
2014-12-23 11:24:40 +08:00
|
|
|
|
|
|
|
fn main() {
|
2015-03-03 14:51:45 +08:00
|
|
|
let out_dir = env::var("OUT_DIR").unwrap();
|
2014-12-23 11:24:40 +08:00
|
|
|
let mut objects = Vec::new();
|
|
|
|
|
|
|
|
let files = fs::readdir(&Path::new("src")).unwrap();
|
|
|
|
let mut files = files.iter().filter(|p| p.is_file());
|
|
|
|
|
|
|
|
for file in files {
|
|
|
|
if let Some(filename) = file.filename_str() {
|
|
|
|
let filepath = format!("src/{}", filename);
|
|
|
|
let outpath;
|
|
|
|
|
|
|
|
if let Some(basename) = eat_extension(filename, ".c") {
|
|
|
|
outpath = format!("{}/{}.o", out_dir, basename);
|
|
|
|
|
2015-01-14 18:15:52 +08:00
|
|
|
Command::new("cc").args(&[&*filepath, "-c", "-fPIC", "-o"])
|
2014-12-23 11:24:40 +08:00
|
|
|
.arg(outpath.clone())
|
|
|
|
.status().unwrap();
|
|
|
|
}
|
|
|
|
else { continue }
|
|
|
|
|
|
|
|
objects.push(outpath);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
Command::new("ar").args(&["crus", "libcontext.a"])
|
2015-02-03 03:17:23 +08:00
|
|
|
.args(&*objects)
|
2014-12-23 11:24:40 +08:00
|
|
|
.cwd(&Path::new(&out_dir))
|
|
|
|
.status().unwrap();
|
|
|
|
|
|
|
|
println!("cargo:rustc-flags=-L {} -l context:static", out_dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn eat_extension<'a>(s: &'a str, ext: &str) -> Option<&'a str> {
|
|
|
|
if s.ends_with(ext) {
|
2015-01-14 18:15:52 +08:00
|
|
|
Some(&s[..s.len() - ext.len()])
|
2014-12-23 11:24:40 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
}
|