summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2017-12-06 00:09:21 -0500
committerGitHub <noreply@github.com>2017-12-06 00:09:21 -0500
commit89b9292db0898f8ad2b6ea8513a3190762eb58c8 (patch)
treef01d917412f5a50ce36fa377982c99645305092e
parentcf7eec3bdeeaa9ace0bba7db87c0c71bd48915ba (diff)
parent346a6f8dcb6e0d1a9540eeae481cca33021439ec (diff)
Merge pull request #405 from yenatch/fix-no-rule-error
fix cryptic 'no rule' error when a prerequisite is missing
-rw-r--r--Makefile32
1 files changed, 21 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index da984c41b..6cbc1e1df 100644
--- a/Makefile
+++ b/Makefile
@@ -41,11 +41,6 @@ all: crystal
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 @@ compare: $(roms)
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)