include ../makeflags
-include ../localconf
+# 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)
+
LIBS = -lcrucible -lpthread -latomic
BEES_LDFLAGS = -L../lib $(LDFLAGS)
(echo 'const char *BEES_USAGE = '; sed -r 's/^(.*)$$/"\1\\n"/' < bees-usage.txt; echo ';') > bees-usage.new.c
mv -f bees-usage.new.c bees-usage.c
-%.dep: %.cc 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 Makefile $(BUILD_CONF)
$(CXX) $(BEES_CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $<
include $(ALL_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 $<
$(BEES): $(BEES_OBJS) bees-version.o bees-usage.o ../lib/libcrucible.a
include ../makeflags
-include ../localconf
+# 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)
+
LIBS = -lcrucible -lpthread -latomic
BEES_LDFLAGS = -L../lib $(LDFLAGS)
-%.dep: %.cc tests.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 tests.h Makefile $(BUILD_CONF)
$(CXX) $(BEES_CXXFLAGS) -M -MF $@ -MT $(<:.cc=.o) $<
include $(PROGRAMS:%=%.dep)
-$(PROGRAMS:%=%.o): %.o: %.cc ../makeflags Makefile
+$(PROGRAMS:%=%.o): %.o: %.cc $(BUILD_CONF) Makefile
$(CXX) $(BEES_CXXFLAGS) -o $@ -c $<
-$(NORMAL_PROGRAMS): %: %.o ../makeflags Makefile ../lib/libcrucible.a
+$(NORMAL_PROGRAMS): %: %.o $(BUILD_CONF) Makefile ../lib/libcrucible.a
$(CXX) $(BEES_CXXFLAGS) $(BEES_LDFLAGS) -o $@ $< $(LIBS)
-config-parse: config-parse.o ../src/bees-config.cc ../src/bees-trace.cc ../src/bees-log.cc ../src/bees-lib.cc ../makeflags Makefile ../lib/libcrucible.a
+config-parse: config-parse.o ../src/bees-config.cc ../src/bees-trace.cc ../src/bees-log.cc ../src/bees-lib.cc $(BUILD_CONF) Makefile ../lib/libcrucible.a
$(CXX) $(BEES_CXXFLAGS) -ffunction-sections -fdata-sections $(BEES_LDFLAGS) -Wl,--gc-sections -o $@ config-parse.o ../src/bees-config.cc ../src/bees-trace.cc ../src/bees-log.cc ../src/bees-lib.cc $(LIBS)
%.txt: % Makefile FORCE