blob: 74e271c76c36e7a0849b984d3a1b807bb3562fb5 [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");
David Browndc1964c2017-01-10 16:45:05 -070016 conf.include("../boot/zephyr/include");
David Brownde7729e2017-01-09 10:41:35 -070017 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();
David Brown1a44316c2017-01-10 11:54:42 -070021}
22
23// Output the names of all files within a directory so that Cargo knows when to rebuild.
24fn walk_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
25 for ent in fs::read_dir(path.as_ref())? {
26 let ent = ent?;
27 let p = ent.path();
28 if p.is_dir() {
29 walk_dir(p)?;
30 } else {
31 // Note that non-utf8 names will fail.
32 let name = p.to_str().unwrap();
33 if name.ends_with(".c") || name.ends_with(".h") {
34 println!("cargo:rerun-if-changed={}", name);
35 }
36 }
37 }
38
39 Ok(())
David Brownde7729e2017-01-09 10:41:35 -070040}