From 4f686b76145fef7e23f0dde7d6e9715ea806a8a1 Mon Sep 17 00:00:00 2001 From: Manu Evans Date: Wed, 12 Aug 2026 01:12:43 +1000 Subject: [PATCH] build: rebuild when the compile command changes Record COMPILE_CMD in the object directory and make the target depend on it. Flag-only changes now invalidate an existing binary without forcing every invocation to rebuild. --- Makefile | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 6a0b31c6..b1557faf 100644 --- a/Makefile +++ b/Makefile @@ -269,6 +269,15 @@ endif # Note: LDC's -deps format is its own (D module deps), not Make-compatible -- # so we don't `-include $(DEPFILE)`; full rebuild on file changes. +# Recompile when flags or other compile-command inputs change. +FLAGS_STAMP := $(OBJDIR)/build-flags + +# Parse-time refresh preserves normal timestamp behaviour under -n and -q. +$(shell mkdir -p $(OBJDIR); \ + printf '%s\n' '$(COMPILE_CMD)' > $(FLAGS_STAMP).new; \ + cmp -s $(FLAGS_STAMP).new $(FLAGS_STAMP) || mv -f $(FLAGS_STAMP).new $(FLAGS_STAMP); \ + rm -f $(FLAGS_STAMP).new) + # ======================================================================= # Build rules # ======================================================================= @@ -290,7 +299,7 @@ endif # -- Main target ------------------------------------------------------- -$(TARGET): $(SOURCES) $(BAREMETAL_OBJS) $(VENDOR_OBJS) $(BK_BEKEN_LIB) +$(TARGET): $(SOURCES) $(BAREMETAL_OBJS) $(VENDOR_OBJS) $(BK_BEKEN_LIB) $(FLAGS_STAMP) # -- BK7231 FreeRTOS build (must come after $(TARGET) so it doesn't become default goal)