ref: 89b9292db0898f8ad2b6ea8513a3190762eb58c8
parent: cf7eec3bdeeaa9ace0bba7db87c0c71bd48915ba
parent: 346a6f8dcb6e0d1a9540eeae481cca33021439ec
author: yenatch <[email protected]>
date: Tue Dec 5 19:09:21 EST 2017
Merge pull request #405 from yenatch/fix-no-rule-error fix cryptic 'no rule' error when a prerequisite is missing
--- a/Makefile
+++ b/Makefile
@@ -41,11 +41,6 @@
crystal: pokecrystal.gbc
crystal11: pokecrystal11.gbc
-# Build tools when building the rom
-ifeq (,$(filter clean tools,$(MAKECMDGOALS)))
-Makefile: tools ;
-endif
-
clean:
rm -f $(roms) $(crystal_obj) $(crystal11_obj) $(roms:.gbc=.map) $(roms:.gbc=.sym)
$(MAKE) clean -C tools/
@@ -56,13 +51,28 @@
tools:
$(MAKE) -C tools/
-%11.o: dep = $(shell tools/scan_includes $(@D)/$*.asm)
-%11.o: %.asm $$(dep)
- $(RGBASM) -D CRYSTAL11 -o $@ $<
-%.o: dep = $(shell tools/scan_includes $(@D)/$*.asm)
-%.o: %.asm $$(dep)
- $(RGBASM) -o $@ $<
+$(crystal11_obj): RGBASMFLAGS = -D CRYSTAL11
+
+# The dep rules have to be explicit or else missing files won't be reported.
+# As a side effect, they're evaluated immediately instead of when the rule is invoked.
+# It doesn't look like $(shell) can be deferred so there might not be a better way.
+define DEP
+$1: $2 $$(shell tools/scan_includes $2)
+ $$(RGBASM) $$(RGBASMFLAGS) -o $$@ $$<
+endef
+
+# Build tools when building the rom.
+# This has to happen before the rules are processed, since that's when scan_includes is run.
+ifeq (,$(filter clean tools,$(MAKECMDGOALS)))
+
+$(info $(shell $(MAKE) -C tools))
+
+$(foreach obj, $(crystal11_obj), $(eval $(call DEP,$(obj),$(obj:11.o=.asm))))
+$(foreach obj, $(crystal_obj), $(eval $(call DEP,$(obj),$(obj:.o=.asm))))
+
+endif
+
pokecrystal11.gbc: $(crystal11_obj) pokecrystal.link
$(RGBLINK) -n pokecrystal11.sym -m pokecrystal11.map -l pokecrystal.link -o $@ $(crystal11_obj)