pokegold-spaceworld/Makefile
2026-07-05 22:29:56 -04:00

227 lines
7.1 KiB
Makefile

ROMS := pokegold-spaceworld.gb \
pokesilver-spaceworld.gb \
pokegold-spaceworld-debug.gb \
pokesilver-spaceworld-debug.gb
CORRECTEDROMS := $(ROMS:%.gb=%-correctheader.gb)
ROM_OBJ := \
audio.o \
home.o \
main.o \
maps.o \
ram.o \
garbage/garbage.o \
gfx/misc.o \
gfx/pics.o \
gfx/sprites.o \
gfx/tilesets.o
pokegold-spaceworld_obj := $(ROM_OBJ:.o=_gold.o)
pokegold-spaceworld-debug_obj := $(ROM_OBJ:.o=_gold_debug.o)
pokesilver-spaceworld_obj := $(ROM_OBJ:.o=_silver.o)
pokesilver-spaceworld-debug_obj := $(ROM_OBJ:.o=_silver_debug.o)
### Build tools
ifeq (,$(shell which sha1sum))
SHA1 := shasum
else
SHA1 := sha1sum
endif
RGBDS ?=
RGBASM ?= $(RGBDS)rgbasm
RGBFIX ?= $(RGBDS)rgbfix
RGBGFX ?= $(RGBDS)rgbgfx
RGBLINK ?= $(RGBDS)rgblink
RGBASMFLAGS ?= -Weverything -Wtruncation=1
RGBLINKFLAGS ?= -Weverything -Wtruncation=1
RGBFIXFLAGS ?= -Weverything
RGBGFXFLAGS ?= -Weverything
tools/gfx :=
### Build targets
.SUFFIXES:
.SECONDEXPANSION:
.PRECIOUS:
.SECONDARY:
.PHONY: \
all \
gold \
silver \
gold_debug \
silver_debug \
tools \
clean \
tidy \
compare
all: $(ROMS) $(CORRECTEDROMS) compare
gold: pokegold-spaceworld.gb pokegold-spaceworld-correctheader.gb
silver: pokesilver-spaceworld.gb pokesilver-spaceworld-correctheader.gb
gold_debug: pokegold-spaceworld-debug.gb pokegold-spaceworld-debug-correctheader.gb
silver_debug: pokesilver-spaceworld-debug.gb pokesilver-spaceworld-debug-correctheader.gb
compare: $(ROMS) $(CORRECTEDROMS)
@$(SHA1) -c roms.sha1
tools:
$(MAKE) -C tools/
# Remove files generated by the build process.
clean: tidy
find gfx garbage \
\( -iname "*.[12]bpp" \
-o -iname "*.pic" \
-o -iname "*.sgb.tilemap" \) \
-delete
# Remove generated files except for graphics.
tidy:
$(RM) $(ROMS) $(CORRECTEDROMS) \
$(ROMS:.gb=.sym) $(CORRECTEDROMS:.gb=.sym) \
$(ROMS:.gb=.map) $(CORRECTEDROMS:.gb=.map) \
$(pokegold-spaceworld_obj) \
$(pokesilver-spaceworld_obj) \
$(pokegold-spaceworld-debug_obj) \
$(pokesilver-spaceworld-debug_obj) \
rgbdscheck.o
$(MAKE) clean -C tools/
RGBASMFLAGS += -Q8 -P constants.asm
# Create a sym/map for debug purposes if `make` run with `DEBUG=1`
ifeq ($(DEBUG),1)
RGBASMFLAGS += -E
endif
$(pokegold-spaceworld_obj): RGBASMFLAGS += -D _GOLD
$(pokesilver-spaceworld_obj): RGBASMFLAGS += -D _SILVER
$(pokegold-spaceworld-debug_obj): RGBASMFLAGS += -D _GOLD -D _DEBUG
$(pokesilver-spaceworld-debug_obj): RGBASMFLAGS += -D _SILVER -D _DEBUG
rgbdscheck.o: rgbdscheck.asm
$(RGBASM) -o $@ $<
# 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 tidy tools,$(MAKECMDGOALS)))
$(info $(shell $(MAKE) -C tools))
# 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.
preinclude_deps := constants.asm $(shell tools/scan_includes constants.asm)
define DEP
$1: $2 $$(shell tools/scan_includes $2) $(preinclude_deps) | rgbdscheck.o
$$(RGBASM) $$(RGBASMFLAGS) -o $$@ $$<
endef
# Dependencies for objects (drop _gold and _silver from asm file basenames)
$(foreach obj, $(pokegold-spaceworld_obj), $(eval $(call DEP,$(obj),$(obj:_gold.o=.asm))))
$(foreach obj, $(pokesilver-spaceworld_obj), $(eval $(call DEP,$(obj),$(obj:_silver.o=.asm))))
$(foreach obj, $(pokegold-spaceworld-debug_obj), $(eval $(call DEP,$(obj),$(obj:_gold_debug.o=.asm))))
$(foreach obj, $(pokesilver-spaceworld-debug_obj), $(eval $(call DEP,$(obj),$(obj:_silver_debug.o=.asm))))
endif
### Build products
%-correctheader.gb: RGBFIXCFLAGS = -f hg -m MBC3+TIMER+RAM+BATTERY -Wno-overwrite
%-correctheader.gb: %.gb
cp $< $@
cp $(<:.gb=.sym) $(@:.gb=.sym)
$(RGBFIX) $(RGBFIXFLAGS) $(RGBFIXCFLAGS) $@
RGBLINKFLAGS += -d
RGBFIXFLAGS += -sf lh -k 01 -l 0x33 -m MBC1+RAM+BATTERY -r 3 -p 0xff
pokegold%.gb: RGBFIXFLAGS += -t POKEMON2GOLD
pokesilver%.gb: RGBFIXFLAGS += -t POKEMON2SILVER
%.gb: $$(%_obj) layout.link
$(RGBLINK) $(RGBLINKFLAGS) -l layout.link -m $*.map -n $*.sym -o $@ $(filter %.o,$^)
$(RGBFIX) $(RGBFIXFLAGS) $@
### Misc file-specific graphics rules
gfx/trainer_card/leaders.2bpp: tools/gfx += --trim-whitespace
gfx/minigames/slots_1.2bpp: tools/gfx += --trim-whitespace
gfx/minigames/slots_2.2bpp: tools/gfx += --interleave --png=$<
gfx/minigames/slots_3.2bpp: tools/gfx += --interleave --png=$< --remove-duplicates --keep-whitespace --remove-xflip
gfx/minigames/slots_4.2bpp: tools/gfx += --interleave --png=$<
gfx/minigames/poker.2bpp: tools/gfx += --trim-whitespace
gfx/minigames/picross_numbers.2bpp: tools/gfx += --trim-whitespace
gfx/intro/jigglypuff_pikachu.2bpp: tools/gfx += --trim-whitespace
gfx/battle_anims/attack_animations_1.2bpp: tools/gfx += --trim-whitespace
gfx/battle_anims/attack_animations_2.2bpp: tools/gfx += --trim-whitespace
gfx/title/title_logo.2bpp: tools/gfx += --trim-whitespace
gfx/battle_anims/angels.2bpp: tools/gfx += --trim-whitespace
gfx/battle_anims/beam.2bpp: tools/gfx += --remove-xflip --remove-yflip --remove-whitespace
gfx/battle_anims/bubble.2bpp: tools/gfx += --trim-whitespace
gfx/battle_anims/charge.2bpp: tools/gfx += --trim-whitespace
gfx/battle_anims/egg.2bpp: tools/gfx += --remove-whitespace
gfx/battle_anims/explosion.2bpp: tools/gfx += --remove-whitespace
gfx/battle_anims/hit.2bpp: tools/gfx += --remove-whitespace
gfx/battle_anims/horn.2bpp: tools/gfx += --remove-whitespace
gfx/battle_anims/lightning.2bpp: tools/gfx += --remove-whitespace
gfx/battle_anims/misc.2bpp: tools/gfx += --remove-duplicates --remove-xflip
gfx/battle_anims/noise.2bpp: tools/gfx += --remove-whitespace
gfx/battle_anims/objects.2bpp: tools/gfx += --remove-whitespace --remove-xflip
gfx/battle_anims/pokeball.2bpp: tools/gfx += --remove-xflip --keep-whitespace
gfx/battle_anims/reflect.2bpp: tools/gfx += --remove-whitespace
gfx/battle_anims/rocks.2bpp: tools/gfx += --remove-whitespace
gfx/battle_anims/skyattack.2bpp: tools/gfx += --remove-whitespace
gfx/battle_anims/status.2bpp: tools/gfx += --remove-whitespace
gfx/evo/bubbles.2bpp: tools/gfx += --remove-xflip --remove-yflip --remove-whitespace
gfx/trade/game_boy.2bpp: tools/gfx += --remove-duplicates --preserve=0x23,0x27
gfx/sgb/sgb_border_alt.2bpp: tools/gfx += --trim-whitespace
gfx/sgb/sgb_border_gold.2bpp: tools/gfx += --trim-whitespace
gfx/sgb/sgb_border_silver.2bpp: tools/gfx += --trim-whitespace
gfx/sgb/sgb_border_silver.2bpp: tools/gfx += --trim-whitespace
gfx/sgb/%.sgb.tilemap: gfx/sgb/%.bin ; LC_ALL=C tr < $< -d '\000' > $@
### Catch-all graphics rules
%.2bpp: %.png
$(RGBGFX) --colors dmg $(RGBGFXFLAGS) -o $@ $<
$(if $(tools/gfx),\
tools/gfx $(tools/gfx) -o $@ $@ || $$($(RM) $@ && false))
%.1bpp: %.png
$(RGBGFX) --colors dmg $(RGBGFXFLAGS) --depth 1 -o $@ $<
$(if $(tools/gfx),\
tools/gfx $(tools/gfx) --depth 1 -o $@ $@ || $$($(RM) $@ && false))
%.pic: %.2bpp
tools/pkmncompress $< $@
### File extensions that are never generated and should be manually created
%.asm: ;
%.inc: ;
%.png: ;
%.pal: ;
%.bin: ;
%.blk: ;
%.rle: ;