-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)