From 689751ffe69b4555b057b46d9ea34c7fa299a9e6 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Tue, 22 Sep 2026 22:25:53 +0200 Subject: [PATCH] build: rebuild objects when the compiler flags change The .d files track headers, so adding or removing a flag on a tree that was already built leaves every object that did not change for some other reason compiled with the old flags, and the image ends up a mix of the two. How that shows depends on the flag. DIAG=1 fails the link on undefined symbols, which at least stops the build. An opt-in whose hooks expand to empty macros loses the calls instead, so the link succeeds and the feature quietly measures nothing. Objects now depend on a stamp holding CC_FLAGS, rewritten only when the flags differ, so an unchanged flag set still does not force a rebuild. --- Makefile | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 0b5628be..a47df340 100644 --- a/Makefile +++ b/Makefile @@ -130,10 +130,20 @@ distclean: $(SUBDIRSCLEAN) $(SUBDIRSCLEAN): $(MAKE) -C $(@:clean=) clean -$(BUILDDIR)/%.rel: %.c | create_build_dir html_data.h +# Objects depend on the flags they were built with, through a stamp file that +# is rewritten only when CC_FLAGS actually changes. +CCFLAGS_STAMP := $(BUILDDIR)/.ccflags + +.PHONY: FORCE +FORCE: + +$(CCFLAGS_STAMP): FORCE | create_build_dir + @echo '$(CC_FLAGS)' | cmp -s - $@ 2>/dev/null || echo '$(CC_FLAGS)' > $@ + +$(BUILDDIR)/%.rel: %.c $(CCFLAGS_STAMP) | create_build_dir html_data.h $(CC) -MMD $(CC_FLAGS) -o $@ -c $< -$(BUILDDIR)/%.rel: %.asm | create_build_dir +$(BUILDDIR)/%.rel: %.asm $(CCFLAGS_STAMP) | create_build_dir ${ASM} ${AFLAGS} -o $@ $< # mv -f $(addprefix $(basename $^), .lst .rel .sym) .