aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruce Hill <bruce@bruce-hill.com>2025-03-21 21:30:37 -0400
committerBruce Hill <bruce@bruce-hill.com>2025-03-21 21:30:37 -0400
commit9acea1807f5945c55445a16259386e4979203a1e (patch)
tree0196e6ededb7beb8d3b4dd6068b75da088567353
parenteaa0fe42668a78592f6a36de9a7889dcde41695e (diff)
Recompile files older than the compiler's executable
-rw-r--r--tomo.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/tomo.c b/tomo.c
index 12767ad4..e99f42d9 100644
--- a/tomo.c
+++ b/tomo.c
@@ -31,6 +31,8 @@
#define run_cmd(...) ({ const char *_cmd = heap_strf(__VA_ARGS__); if (verbose) printf("\033[34;1m%s\033[m\n", _cmd); popen(_cmd, "w"); })
#define array_str(arr) Text$as_c_string(Text$join(Text(" "), arr))
+static struct stat compiler_stat;
+
static const char *paths_str(Array_t paths) {
Text_t result = EMPTY_TEXT;
for (int64_t i = 0; i < paths.length; i++) {
@@ -83,6 +85,11 @@ typedef struct {
#pragma GCC diagnostic ignored "-Wstack-protector"
int main(int argc, char *argv[])
{
+ // Get the file modification time of the compiler, so we
+ // can recompile files after changing the compiler:
+ if (stat(argv[0], &compiler_stat) != 0)
+ err(1, "Could not find age of compiler");
+
if (register_printf_specifier('T', printf_type, printf_pointer_size))
errx(1, "Couldn't set printf specifier");
if (register_printf_specifier('W', printf_ast, printf_pointer_size))
@@ -583,6 +590,11 @@ bool is_stale(Path_t path, Path_t relative_to)
struct stat target_stat;
if (stat(Path$as_c_string(path), &target_stat) != 0)
return true;
+
+ // Any file older than the compiler is stale:
+ if (target_stat.st_mtime < compiler_stat.st_mtime)
+ return true;
+
struct stat relative_to_stat;
if (stat(Path$as_c_string(relative_to), &relative_to_stat) != 0)
errx(1, "File doesn't exist: %s", Path$as_c_string(relative_to));