blob: d341e24e27ab7593bb4127823797f62df94ebd40 [file] [log] [blame]
David Brownde7729e2017-01-09 10:41:35 -07001// Build the library.
2
3extern crate gcc;
4
David Brown1a44316c2017-01-10 11:54:42 -07005use std::fs;
6use std::io;
7use std::path::Path;
8
David Brownde7729e2017-01-09 10:41:35 -07009fn main() {
10 let mut conf = gcc::Config::new();
11
12 conf.file("../boot/bootutil/src/loader.c");
13 conf.file("../boot/bootutil/src/bootutil_misc.c");
14 conf.file("csupport/run.c");
15 conf.include("../boot/bootutil/include");
16 conf.include("../zephyr/include");
17 conf.debug(true);
18 conf.compile("libbootutil.a");
David Brown1a44316c2017-01-10 11:54:42 -070019 walk_dir("../boot").unwrap();
20 walk_dir("csupport").unwrap();
21 walk_dir("../zephyr").unwrap();
22}
23
24// Output the names of all files within a directory so that Cargo knows when to rebuild.
25fn walk_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
26 for ent in fs::read_dir(path.as_ref())? {
27 let ent = ent?;
28 let p = ent.path();
29 if p.is_dir() {
30 walk_dir(p)?;
31 } else {
32 // Note that non-utf8 names will fail.
33 let name = p.to_str().unwrap();
34 if name.ends_with(".c") || name.ends_with(".h") {
35 println!("cargo:rerun-if-changed={}", name);
36 }
37 }
38 }
39
40 Ok(())
David Brownde7729e2017-01-09 10:41:35 -070041}