-
Notifications
You must be signed in to change notification settings - Fork 144
/
Makefile
361 lines (290 loc) · 13.5 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
roms := \
pokegold.gbc \
pokesilver.gbc \
pokegold_debug.gbc \
pokesilver_debug.gbc
patches := \
pokegold.patch \
pokesilver.patch
rom_obj := \
audio.o \
home.o \
main.o \
ram.o \
data/text/common.o \
data/maps/map_data.o \
data/pokemon/egg_moves.o \
data/pokemon/evos_attacks.o \
engine/movie/credits.o \
engine/overworld/events.o \
gfx/misc.o \
gfx/sprites.o \
gfx/tilesets.o
# Distinguish asm files which are game-exclusive for building (*_[gold|silver].asm)
gs_excl_asm := \
data/pokemon/dex_entries \
gfx/pics
gold_excl_obj := $(addsuffix _gold.o,$(gs_excl_asm))
silver_excl_obj := $(addsuffix _silver.o,$(gs_excl_asm))
gold_debug_excl_obj := $(addsuffix _gold_debug.o,$(gs_excl_asm))
silver_debug_excl_obj := $(addsuffix _silver_debug.o,$(gs_excl_asm))
gold_vc_excl_obj := $(addsuffix _gold_vc.o,$(gs_excl_asm))
silver_vc_excl_obj := $(addsuffix _silver_vc.o,$(gs_excl_asm))
pokegold_obj := $(rom_obj:.o=_gold.o) $(gold_excl_obj)
pokesilver_obj := $(rom_obj:.o=_silver.o) $(silver_excl_obj)
pokegold_debug_obj := $(rom_obj:.o=_gold_debug.o) $(gold_debug_excl_obj)
pokesilver_debug_obj := $(rom_obj:.o=_silver_debug.o) $(silver_debug_excl_obj)
pokegold_vc_obj := $(rom_obj:.o=_gold_vc.o) $(gold_vc_excl_obj)
pokesilver_vc_obj := $(rom_obj:.o=_silver_vc.o) $(silver_vc_excl_obj)
### 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
### Build targets
.SUFFIXES:
.PHONY: all gold silver gold_debug silver_debug clean tidy compare tools
.SECONDEXPANSION:
.PRECIOUS:
.SECONDARY:
all: $(roms)
gold: pokegold.gbc
silver: pokesilver.gbc
gold_debug: pokegold_debug.gbc
silver_debug: pokesilver_debug.gbc
gold_vc: pokegold.patch
silver_vc: pokesilver.patch
clean: tidy
find gfx \
\( -name "*.[12]bpp" \
-o -name "*.lz" \
-o -name "*.gbcpal" \
-o -name "*.dimensions" \
-o -name "*.sgb.tilemap" \) \
-delete
tidy:
$(RM) $(roms) \
$(roms:.gbc=.sym) \
$(roms:.gbc=.map) \
$(patches) \
$(patches:.patch=_vc.gbc) \
$(patches:.patch=_vc.sym) \
$(patches:.patch=_vc.map) \
$(patches:%.patch=vc/%.constants.sym) \
$(pokegold_obj) \
$(pokesilver_obj) \
$(pokegold_vc_obj) \
$(pokesilver_vc_obj) \
$(pokegold_debug_obj) \
$(pokesilver_debug_obj) \
rgbdscheck.o
$(MAKE) clean -C tools/
compare: $(roms) $(patches)
@$(SHA1) -c roms.sha1
tools:
$(MAKE) -C tools/
RGBASMFLAGS = -Q8 -P includes.asm -Weverything -Wnumeric-string=2 -Wtruncation=1
# Create a sym/map for debug purposes if `make` run with `DEBUG=1`
ifeq ($(DEBUG),1)
RGBASMFLAGS += -E
endif
$(pokegold_obj): RGBASMFLAGS += -D _GOLD
$(pokesilver_obj): RGBASMFLAGS += -D _SILVER
$(pokegold_debug_obj): RGBASMFLAGS += -D _GOLD -D _DEBUG
$(pokesilver_debug_obj): RGBASMFLAGS += -D _SILVER -D _DEBUG
$(pokegold_vc_obj): RGBASMFLAGS += -D _GOLD -D _GOLD_VC
$(pokesilver_vc_obj): RGBASMFLAGS += -D _SILVER -D _GOLD_VC
%.patch: vc/%.constants.sym %_vc.gbc %.gbc vc/%.patch.template
tools/make_patch $*_vc.sym $^ $@
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 := includes.asm $(shell tools/scan_includes includes.asm)
define DEP
$1: $2 $$(shell tools/scan_includes $2) $(preinclude_deps) | rgbdscheck.o
$$(RGBASM) $$(RGBASMFLAGS) -o $$@ $$<
endef
# Dependencies for shared objects (drop _gold and _silver from asm file basenames)
$(foreach obj, $(filter-out $(gold_excl_obj), $(pokegold_obj)), \
$(eval $(call DEP,$(obj),$(obj:_gold.o=.asm))))
$(foreach obj, $(filter-out $(silver_excl_obj), $(pokesilver_obj)), \
$(eval $(call DEP,$(obj),$(obj:_silver.o=.asm))))
$(foreach obj, $(filter-out $(gold_debug_excl_obj), $(pokegold_debug_obj)), \
$(eval $(call DEP,$(obj),$(obj:_gold_debug.o=.asm))))
$(foreach obj, $(filter-out $(silver_debug_excl_obj), $(pokesilver_debug_obj)), \
$(eval $(call DEP,$(obj),$(obj:_silver_debug.o=.asm))))
$(foreach obj, $(filter-out $(gold_vc_excl_obj), $(pokegold_vc_obj)), \
$(eval $(call DEP,$(obj),$(obj:_gold_vc.o=.asm))))
$(foreach obj, $(filter-out $(silver_vc_excl_obj), $(pokesilver_vc_obj)), \
$(eval $(call DEP,$(obj),$(obj:_silver_vc.o=.asm))))
# Dependencies for game-exclusive objects (keep _gold and _silver in asm file basenames)
$(foreach obj, $(gold_excl_obj) $(silver_excl_obj), \
$(eval $(call DEP,$(obj),$(obj:.o=.asm))))
$(foreach obj, $(gold_debug_excl_obj), \
$(eval $(call DEP,$(obj),$(obj:_gold_debug.o=_gold.asm))))
$(foreach obj, $(silver_debug_excl_obj), \
$(eval $(call DEP,$(obj),$(obj:_silver_debug.o=_silver.asm))))
$(foreach obj, $(gold_vc_excl_obj), \
$(eval $(call DEP,$(obj),$(obj:_gold_vc.o=_gold.asm))))
$(foreach obj, $(silver_vc_excl_obj), \
$(eval $(call DEP,$(obj),$(obj:_silver_vc.o=_silver.asm))))
# Dependencies for VC files that need to run scan_includes
%.constants.sym: %.constants.asm $(shell tools/scan_includes %.constants.asm) $(preinclude_deps) | rgbdscheck.o
$(RGBASM) $(RGBASMFLAGS) $< > $@
endif
pokegold_opt = -cjsv -t POKEMON_GLD -i AAUE -k 01 -l 0x33 -m 0x10 -r 3 -p 0
pokesilver_opt = -cjsv -t POKEMON_SLV -i AAXE -k 01 -l 0x33 -m 0x10 -r 3 -p 0
pokegold_debug_opt = -cjsv -t POKEMON_GLD -i AAUE -k 01 -l 0x33 -m 0x10 -r 3 -p 0
pokesilver_debug_opt = -cjsv -t POKEMON_SLV -i AAXE -k 01 -l 0x33 -m 0x10 -r 3 -p 0
pokegold_vc_opt = -cjsv -t POKEMON_GLD -i AAUE -k 01 -l 0x33 -m 0x10 -r 3 -p 0
pokesilver_vc_opt = -cjsv -t POKEMON_SLV -i AAXE -k 01 -l 0x33 -m 0x10 -r 3 -p 0
%.gbc: $$(%_obj) layout.link
$(RGBLINK) -n $*.sym -m $*.map -l layout.link -o $@ $(filter %.o,$^)
$(RGBFIX) $($*_opt) $@
tools/stadium $@
### LZ compression rules
# Delete this line if you don't care about matching and just want optimal compression.
include gfx/lz.mk
%.lz: %
tools/lzcomp $(LZFLAGS) -- $< $@
### Pokemon and trainer sprite rules
define PIC
$1/back.2bpp: rgbgfx += --columns
$1/back.2bpp: $1/back.png $1/normal.gbcpal
$$(RGBGFX) $$(rgbgfx) --colors gbc:$$(word 2,$$^) -o $$@ $$<
$1/front.2bpp: rgbgfx += --columns
$1/front.2bpp: $1/front.png $1/normal.gbcpal
$$(RGBGFX) $$(rgbgfx) --colors gbc:$$(word 2,$$^) -o $$@ $$<
$1/normal.gbcpal: $1/front.gbcpal $1/back.gbcpal
tools/gbcpal $$(tools/gbcpal) $$@ $$^
endef
$(foreach pic, $(wildcard gfx/pokemon/*/front.png),\
$(eval $(call PIC,$(pic:/front.png=))))
define PIC_GS
$1/back.2bpp: rgbgfx += --columns
$1/back.2bpp: $1/back.png $1/normal.gbcpal
$$(RGBGFX) $$(rgbgfx) --colors gbc:$$(word 2,$$^) -o $$@ $$<
$1/front_gold.2bpp: rgbgfx += --columns
$1/front_gold.2bpp: $1/front_gold.png $1/normal.gbcpal
$$(RGBGFX) $$(rgbgfx) --colors gbc:$$(word 2,$$^) -o $$@ $$<
$1/front_silver.2bpp: rgbgfx += --columns
$1/front_silver.2bpp: $1/front_silver.png $1/normal.gbcpal
$$(RGBGFX) $$(rgbgfx) --colors gbc:$$(word 2,$$^) -o $$@ $$<
$1/normal.gbcpal: $1/front_gold.gbcpal $1/front_silver.gbcpal $1/back.gbcpal
tools/gbcpal $$(tools/gbcpal) $$@ $$^
endef
$(foreach pic, $(wildcard gfx/pokemon/*/front_gold.png),\
$(eval $(call PIC_GS,$(pic:/front_gold.png=))))
gfx/trainers/%.2bpp: rgbgfx += --columns
gfx/trainers/%.2bpp: gfx/trainers/%.png gfx/trainers/%.gbcpal
$(RGBGFX) $(rgbgfx) --colors gbc:$(word 2,$^) -o $@ $<
# A few back sprites have different compression settings for Gold and Silver
gfx/pokemon/%/back_gold.2bpp: gfx/pokemon/%/back.2bpp ; cp -f $^ $@
gfx/pokemon/%/back_silver.2bpp: gfx/pokemon/%/back.2bpp ; cp -f $^ $@
# Egg does not have a back sprite, so it only uses egg.gbcpal
gfx/pokemon/egg/egg.2bpp: gfx/pokemon/egg/egg.png gfx/pokemon/egg/egg.gbcpal
gfx/pokemon/egg/egg.2bpp: rgbgfx += --columns --colors gbc:$(word 2,$^)
# Unown letters share one normal.gbcpal
unown_pngs := $(wildcard gfx/pokemon/unown_*/front.png) $(wildcard gfx/pokemon/unown_*/back.png)
$(foreach png, $(unown_pngs),\
$(eval $(png:.png=.2bpp): $(png) gfx/pokemon/unown/normal.gbcpal))
gfx/pokemon/unown_%/back.2bpp: rgbgfx += --colors gbc:$(word 2,$^)
gfx/pokemon/unown_%/front.2bpp: rgbgfx += --colors gbc:$(word 2,$^)
gfx/pokemon/unown/normal.gbcpal: $(subst .png,.gbcpal,$(unown_pngs))
tools/gbcpal $(tools/gbcpal) $@ $^
### Misc file-specific graphics rules
gfx/pokemon/squirtle/normal.gbcpal: tools/gbcpal += --reverse
gfx/pokemon/wartortle/normal.gbcpal: tools/gbcpal += --reverse
gfx/pokemon/caterpie/normal.gbcpal: tools/gbcpal += --reverse
gfx/pokemon/farfetch_d/normal.gbcpal: tools/gbcpal += --reverse
gfx/pokemon/hitmonlee/normal.gbcpal: tools/gbcpal += --reverse
gfx/pokemon/scyther/normal.gbcpal: tools/gbcpal += --reverse
gfx/pokemon/bellossom/normal.gbcpal: tools/gbcpal += --reverse
gfx/pokemon/porygon2/normal.gbcpal: tools/gbcpal += --reverse
gfx/trainers/swimmer_m.gbcpal: tools/gbcpal += --reverse
gfx/intro/fire.2bpp: tools/gfx += --remove-whitespace
gfx/intro/fire1.2bpp: gfx/intro/charizard1.2bpp gfx/intro/charizard2_top.2bpp gfx/intro/space.2bpp ; cat $^ > $@
gfx/intro/fire2.2bpp: gfx/intro/charizard2_bottom.2bpp gfx/intro/charizard3.2bpp ; cat $^ > $@
gfx/intro/fire3.2bpp: gfx/intro/fire.2bpp gfx/intro/unused_blastoise_venusaur.2bpp ; cat $^ > $@
gfx/new_game/shrink1.2bpp: rgbgfx += --columns
gfx/new_game/shrink2.2bpp: rgbgfx += --columns
gfx/mail/dragonite.1bpp: tools/gfx += --remove-whitespace
gfx/mail/large_note.1bpp: tools/gfx += --remove-whitespace
gfx/mail/surf_mail_border.1bpp: tools/gfx += --remove-whitespace
gfx/mail/flower_mail_border.1bpp: tools/gfx += --remove-whitespace
gfx/mail/litebluemail_border.1bpp: tools/gfx += --remove-whitespace
gfx/pokedex/pokedex.2bpp: tools/gfx += --trim-whitespace
gfx/pokedex/pokedex_sgb.2bpp: tools/gfx += --trim-whitespace
gfx/pokedex/question_mark.2bpp: rgbgfx += --columns
gfx/pokedex/slowpoke.2bpp: tools/gfx += --trim-whitespace
gfx/pokegear/pokegear.2bpp: rgbgfx += --trim-end 2
gfx/pokegear/pokegear_sprites.2bpp: tools/gfx += --trim-whitespace
gfx/mystery_gift/mystery_gift.2bpp: tools/gfx += --remove-whitespace
gfx/mystery_gift/mystery_gift_2.2bpp: tools/gfx += --trim-whitespace
gfx/mystery_gift/question_mark.1bpp: tools/gfx += --remove-whitespace
gfx/title/logo_bottom_gold.2bpp: tools/gfx += --trim-whitespace
gfx/title/logo_bottom_silver.2bpp: tools/gfx += --trim-whitespace
gfx/title/hooh_gold.2bpp: tools/gfx += --interleave --png=$<
gfx/title/lugia_silver.2bpp: tools/gfx += --interleave --png=$<
gfx/trade/ball.2bpp: tools/gfx += --remove-whitespace
gfx/trade/game_boy.2bpp: tools/gfx += --remove-duplicates --preserve=0x23,0x27
gfx/trade/game_boy_cable.2bpp: gfx/trade/game_boy.2bpp gfx/trade/link_cable.2bpp ; cat $^ > $@
gfx/slots/slots_1.2bpp: tools/gfx += --trim-whitespace
gfx/slots/slots_2.2bpp: tools/gfx += --interleave --png=$<
gfx/slots/slots_3.2bpp: tools/gfx += --interleave --png=$< --remove-duplicates --keep-whitespace --remove-xflip
gfx/card_flip/card_flip_1.2bpp: tools/gfx += --trim-whitespace
gfx/card_flip/card_flip_2.2bpp: tools/gfx += --remove-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/player/chris.2bpp: rgbgfx += --columns
gfx/player/chris_back.2bpp: rgbgfx += --columns
gfx/trainer_card/leaders.2bpp: tools/gfx += --trim-whitespace
gfx/overworld/chris_fish.2bpp: tools/gfx += --trim-whitespace
gfx/sprites/big_onix.2bpp: tools/gfx += --remove-whitespace --remove-xflip
gfx/battle/dude.2bpp: rgbgfx += --columns
gfx/font/unused_bold_font.1bpp: tools/gfx += --trim-whitespace
gfx/sgb/gold_border.2bpp: tools/gfx += --trim-whitespace
gfx/sgb/silver_border.2bpp: tools/gfx += --trim-whitespace
gfx/sgb/gold_border.sgb.tilemap: gfx/sgb/gold_border.bin ; tr < $< -d '\000' > $@
gfx/sgb/silver_border.sgb.tilemap: gfx/sgb/silver_border.bin ; tr < $< -d '\000' > $@
### Catch-all graphics rules
%.2bpp: %.png
$(RGBGFX) $(rgbgfx) -o $@ $<
$(if $(tools/gfx),\
tools/gfx $(tools/gfx) -o $@ $@ || $$($(RM) $@ && false))
%.1bpp: %.png
$(RGBGFX) $(rgbgfx) --depth 1 -o $@ $<
$(if $(tools/gfx),\
tools/gfx $(tools/gfx) --depth 1 -o $@ $@ || $$($(RM) $@ && false))
%.gbcpal: %.png
$(RGBGFX) -p $@ $<
tools/gbcpal $(tools/gbcpal) $@ $@ || $$($(RM) $@ && false)
%.dimensions: %.png
tools/png_dimensions $< $@