aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Voss <mail@thomasvoss.com> 2023-12-30 18:04:04 +0100
committerThomas Voss <mail@thomasvoss.com> 2023-12-30 18:04:04 +0100
commit0b282796b76eb54406d44d1bd3f55c9c0ad624ce (patch)
tree87098a133f0fd7c1c72f4c48ae9acccf5b8ae4ce
parentb31c642e7177cb718579d4f88ed840ba58f7778d (diff)
Add foutdated() and foutdatedv()
-rw-r--r--cbs.h21
1 files changed, 21 insertions, 0 deletions
diff --git a/cbs.h b/cbs.h
index f47d237..d5f1a1f 100644
--- a/cbs.h
+++ b/cbs.h
@@ -202,6 +202,15 @@ static int fmdcmp(const char *, const char *);
static bool fmdolder(const char *, const char *);
static bool fmdnewer(const char *, const char *);
+/* Report if any of n files specified by p render the file base outdated. If
+ the file base does not exist, this function returns true. You will typically
+ call this with a compiled program as base, and C source files as p. The
+ macro foutdated() is a wrapper around foutdatedv() that allows you to specify
+ the sources to base as variadic arguments instead of as an array. */
+static bool foutdatedv(const char *base, const char **p, size_t n);
+#define foutdated(s, ...) \
+ foutdatedv(s, _vtoa(__VA_ARGS__), lengthof(_vtoa(__VA_ARGS__)))
+
/* Rebuild the build script if either it, or this header file have been
modified, and execute the newly built script. You should call the rebuild()
macro at the very beginning of main(), but right after cbsinit(). You
@@ -550,6 +559,18 @@ fmdolder(const char *lhs, const char *rhs)
return fmdcmp(lhs, rhs) < 0;
}
+bool
+foutdatedv(const char *src, const char **deps, size_t n)
+{
+ if (!fexists(src))
+ return true;
+ for (size_t i = 0; i < n; i++) {
+ if (fmdolder(src, deps[i]))
+ return true;
+ }
+ return false;
+}
+
void
_rebuild(char *src)
{