David Brown | de7729e | 2017-01-09 10:41:35 -0700 | [diff] [blame] | 1 | // Build the library. |
| 2 | |
| 3 | extern crate gcc; |
| 4 | |
David Brown | 1a44316c | 2017-01-10 11:54:42 -0700 | [diff] [blame^] | 5 | use std::fs; |
| 6 | use std::io; |
| 7 | use std::path::Path; |
| 8 | |
David Brown | de7729e | 2017-01-09 10:41:35 -0700 | [diff] [blame] | 9 | fn 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 Brown | 1a44316c | 2017-01-10 11:54:42 -0700 | [diff] [blame^] | 19 | 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. |
| 25 | fn 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 Brown | de7729e | 2017-01-09 10:41:35 -0700 | [diff] [blame] | 41 | } |