]> git.earman.xyz Git - sensor-watch.git/commitdiff
Make submodule and directory rules order-only prerequisites on objects
authorGeorge Hahn <george.hahn.vhs@gmail.com>
Thu, 19 May 2022 06:33:31 +0000 (00:33 -0600)
committerGeorge Hahn <george.hahn.vhs@gmail.com>
Thu, 19 May 2022 06:33:31 +0000 (00:33 -0600)
This instructs make to run the tinyusb and directory rules before
building any objects. Docs: [1].

After this change, `make clean` started running
the tinyusb submodule rule before cleaning. This appears to have been
caused by one of the `build/*.d` files overlapping with the `tinyusb`
name, triggering that rule. I didn't trace this all the way down to a
root cause, but switching the include to something less broad solved the
issue. Roughly guided by [2].

1: https://www.gnu.org/software/make/manual/html_node/Prerequisite-Types.html

2: http://make.mad-scientist.net/papers/advanced-auto-dependency-generation/

rules.mk

index 2f2f39225c09acba0150ededb3f4227f58788c64..8de3fc1e46700b0457f5d09582001f07c0175d85 100644 (file)
--- a/rules.mk
+++ b/rules.mk
@@ -7,9 +7,9 @@ SUBMODULES = tinyusb
 COBRA = cobra -f
 
 ifndef EMSCRIPTEN
-all: directory $(SUBMODULES) $(BUILD)/$(BIN).elf $(BUILD)/$(BIN).hex $(BUILD)/$(BIN).bin $(BUILD)/$(BIN).uf2 size
+all: $(BUILD)/$(BIN).elf $(BUILD)/$(BIN).hex $(BUILD)/$(BIN).bin $(BUILD)/$(BIN).uf2 size
 else
-all: directory $(SUBMODULES) $(BUILD)/$(BIN).html
+all: $(BUILD)/$(BIN).html
 endif
 
 $(BUILD)/$(BIN).html: $(OBJS)
@@ -35,13 +35,14 @@ $(BUILD)/$(BIN).uf2: $(BUILD)/$(BIN).bin
        @echo UF2CONV $@
        @$(UF2) $^ -co $@
 
+.phony: $(SUBMODULES)
 $(SUBMODULES):
        git submodule update --init
 
 install:
        @$(UF2) -D $(BUILD)/$(BIN).uf2
 
-%.o:
+$(BUILD)/%.o: | $(SUBMODULES) directory
        @echo CC $@
        @$(CC) $(CFLAGS) $(filter %/$(subst .o,.c,$(notdir $@)), $(SRCS)) -c -o $@
 
@@ -59,4 +60,6 @@ clean:
 analyze:
        @$(COBRA) basic $(INCLUDES) $(DEFINES) $(SRCS)
 
--include $(wildcard $(BUILD)/*.d)
+DEPFILES := $(SRCS:%.c=$(BUILD)/%.d)
+
+-include $(wildcard $(DEPFILES))