]> git.hungrycats.org Git - bees/commitdiff
crucible: rebuild when localconf changes
authorZygo Blaxell <bees@furryterror.org>
Mon, 24 Aug 2026 19:20:33 +0000 (15:20 -0400)
committerZygo Blaxell <bees@furryterror.org>
Sat, 5 Sep 2026 04:03:58 +0000 (00:03 -0400)
The object and dependency rules named ../makeflags as a prerequisite but
not ../localconf, even though localconf is -include'd right after it and
overrides the same variables -- CC, CXX and CCFLAGS.  Editing localconf
therefore recompiled nothing.

Objects record nothing about the compiler that produced them, so a
toolchain switch made in localconf leaves the tree holding a mix of two
compilers' output.  Under -flto that surfaces at link time as "plugin
needed to handle lto object", which names neither localconf nor the
compilers, and is a poor clue to what actually happened.

Add localconf to the prerequisites via BUILD_CONF.  It is optional and
has no rule to create it, so $(wildcard) names it only when it exists; an
unconditional prerequisite would make its absence an error on a clean
checkout, which is presumably why it was left out to begin with.

Include the .dep rules, which previously depended on neither file.
Generated dependencies name the compiler's own header paths, and they are
pulled in with `include' rather than `-include', so a dep left pointing
at a header the new toolchain does not ship does not merely miss a
rebuild: it stops the build with "No rule to make target".

Assisted-by: Claude-Code:claude-opus-5
Signed-off-by: Zygo Blaxell <bees@furryterror.org>
lib/Makefile

index 91b340c7b798cf441d1841d883567ac213676d8b..929794d5b8cd4ada9935250a7d7f9ea5c5f3c5a5 100644 (file)
@@ -31,23 +31,37 @@ include ../makeflags
 -include ../localconf
 include ../Defines.mk
 
+# Files that decide which compiler runs and with which flags.  Anything built
+# by that compiler is stale when they change, so they belong in prerequisite
+# lists -- objects record nothing about the toolchain that produced them, and
+# mixing two toolchains in one tree fails in ways that never mention compilers
+# (under -flto, "plugin needed to handle lto object").
+#
+# localconf is optional and has no rule to create it, so name it only when it
+# exists: an unconditional prerequisite would make it an error not to have one.
+BUILD_CONF = ../makeflags $(wildcard ../localconf)
+
 BEES_LDFLAGS = $(LDFLAGS)
 
 configure.h: configure.h.in
        $(TEMPLATE_COMPILER)
 
-%.dep: %.cc configure.h Makefile
+# The generated dependencies name the compiler's own header paths, so they are
+# stale after a toolchain switch too.  These files are `include'd, not
+# `-include'd: a dep left pointing at headers the new compiler does not ship
+# would stop the build with "No rule to make target", not just miss a rebuild.
+%.dep: %.cc configure.h Makefile $(BUILD_CONF)
        $(CXX) $(BEES_CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $<
 
-%.dep: %.c Makefile
+%.dep: %.c Makefile $(BUILD_CONF)
        $(CC) $(BEES_CFLAGS) -M -MF $@ -MT $(<:.c=.o) $<
 
 include $(CRUCIBLE_OBJS:%.o=%.dep)
 
-%.o: %.c ../makeflags
+%.o: %.c $(BUILD_CONF)
        $(CC) $(BEES_CFLAGS) -o $@ -c $<
 
-%.o: %.cc ../makeflags
+%.o: %.cc $(BUILD_CONF)
        $(CXX) $(BEES_CXXFLAGS) -o $@ -c $<
 
 libcrucible.a: $(CRUCIBLE_OBJS)