sim: Add dependency output

Output the names of source files used to build the C library so that
Cargo knows to rerun the compilation if these have changed.
diff --git a/sim/build.rs b/sim/build.rs
index c69c09a..d341e24 100644
--- a/sim/build.rs
+++ b/sim/build.rs
@@ -2,6 +2,10 @@
 
 extern crate gcc;
 
+use std::fs;
+use std::io;
+use std::path::Path;
+
 fn main() {
     let mut conf = gcc::Config::new();
 
@@ -12,4 +16,26 @@
     conf.include("../zephyr/include");
     conf.debug(true);
     conf.compile("libbootutil.a");
+    walk_dir("../boot").unwrap();
+    walk_dir("csupport").unwrap();
+    walk_dir("../zephyr").unwrap();
+}
+
+// Output the names of all files within a directory so that Cargo knows when to rebuild.
+fn walk_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
+    for ent in fs::read_dir(path.as_ref())? {
+        let ent = ent?;
+        let p = ent.path();
+        if p.is_dir() {
+            walk_dir(p)?;
+        } else {
+            // Note that non-utf8 names will fail.
+            let name = p.to_str().unwrap();
+            if name.ends_with(".c") || name.ends_with(".h") {
+                println!("cargo:rerun-if-changed={}", name);
+            }
+        }
+    }
+
+    Ok(())
 }