summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2017-12-03 20:46:11 -0500
committeryenatch <yenatch@gmail.com>2017-12-03 20:46:11 -0500
commitea8aaeb8e3a85fa2303fe52493d840de9222f3a2 (patch)
tree3beeca4d1f9a93badebf5a3ba7ec3cf5c4d35832
parent7a2a20528136b9a2452a313cd50c46a45f9a5cb0 (diff)
fix cryptic 'no rule' error when a prerequisite is missing
at the cost of scan_includes running before the rules are actually evaluated
-rw-r--r--Makefile36
1 files changed, 27 insertions, 9 deletions
diff --git a/Makefile b/Makefile
index da984c41b..a252e25ea 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,14 +51,37 @@ compare: $(roms)
tools:
$(MAKE) -C tools/
-%11.o: dep = $(shell tools/scan_includes $(@D)/$*.asm)
-%11.o: %.asm $$(dep)
+
+# Prevents $(shell) from filtering out newlines.
+define shell2 =
+$(foreach line,\
+$(shell $1 | sed "s/ /{space}/g"),\
+$(info $(shell echo $(line) | sed "s/{space}/ /g")))
+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)))
+$(call shell2, $(MAKE) -C tools/)
+endif
+
+
+# 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: $$(shell tools/scan_includes $2)
+endef
+$(foreach obj, $(crystal11_obj), $(eval $(call DEP,$(obj),$(obj:11.o=.asm))))
+$(foreach obj, $(crystal_obj), $(eval $(call DEP,$(obj),$(obj:.o=.asm))))
+
+%11.o: %.asm
$(RGBASM) -D CRYSTAL11 -o $@ $<
-%.o: dep = $(shell tools/scan_includes $(@D)/$*.asm)
-%.o: %.asm $$(dep)
+%.o: %.asm
$(RGBASM) -o $@ $<
+
pokecrystal11.gbc: $(crystal11_obj) pokecrystal.link
$(RGBLINK) -n pokecrystal11.sym -m pokecrystal11.map -l pokecrystal.link -o $@ $(crystal11_obj)
$(RGBFIX) -Cjv -i BYTE -k 01 -l 0x33 -m 0x10 -n 1 -p 0 -r 3 -t PM_CRYSTAL $@