Update cook tool to not rebuild files unless it needs to.
(shell "rmdir " path " /s")
(shell "rm -rf " path)))
+(defn- older-than
+ [f1 f2]
+ "Check if f1 is newer than f2. Used for checking if a file should be updated."
+ (if is-win true
+ (zero? (os/shell (string "[ " f1 " -ot " f2 " ]")))))
+
+(defn- older-than-some
+ [f others]
+ (some (partial older-than f) others))
+
(defn- embed-name
"Rename a janet symbol for embedding."
[path]
[opts src dest]
(def cc (or opts:compiler CC))
(def cflags (or opts:cflags CFLAGS))
+ (if (older-than dest src)
(if is-win
(shell cc " /nologo /c " cflags " /Fo" dest " " src)
- (shell cc " " cflags " -o " dest " -c " src)))
+ (shell cc " " cflags " -o " dest " -c " src))))
(defn- link-c
"Link a number of object files together."
(def ld (or opts:linker LD))
(def cflags (or opts:cflags CFLAGS))
(def olist (string/join objects " "))
+ (if (older-than-some target objects)
(if is-win
(shell ld "/out:" target " " olist)
- (shell ld " " cflags " -o " target " " olist)))
+ (shell ld " " cflags " -o " target " " olist))))
(defn- create-buffer-c
"Inline raw byte file as a c file."
[source dest name]
+ (when (older-than dest source)
(def f (file/open source :r))
(if (not f) (error (string "file " f " not found")))
(def out (file/open dest :w))
"const unsigned char *" name "_embed = bytes;\n"
"size_t " name "_embed_size = sizeof(bytes);\n")
(file/close out)
- (file/close f))
+ (file/close f)))
# Public
