forked from zladx/LADX-Disassembly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
215 lines (170 loc) · 6.11 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
.POSIX:
.SUFFIXES:
.PRECIOUS: %.2bpp oam_%.2bpp
.PHONY: default build build-all test test-all all clean tidy
# Recursive `wildcard` function.
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
#
# Dev tools binaries and options
#
RGBDS :=
2BPP := $(RGBDS)rgbgfx
ASM := $(RGBDS)rgbasm
ASFLAGS := \
--export-all
LD := $(RGBDS)rgblink
LDFLAGS :=
FX := $(RGBDS)rgbfix
FXFLAGS := \
--color-compatible \
--sgb-compatible \
--ram-size 0x03 \
--old-licensee 0x33 \
--new-licensee "01" \
--mbc-type 0x1B \
--pad-value 0xFF \
--validate
# Default target: build and test only the US 1.0 revision.
# (Use `make all` to build and test all targets.)
default: build test
#
# Generic rules
#
# Dependencies for the base version (English 1.0)
asm_files := $(call rwildcard,src,*.asm)
# this is the only .inc file in the repo
asm_files += src/constants/hardware.inc
gfx_files := $(call rwildcard,src/gfx,*.png)
bin_files := $(wildcard src/data/backgrounds/*.tilemap.encoded)
bin_files += $(wildcard src/data/backgrounds/*.attrmap.encoded)
# Compile an PNG file for OAM memory to a 2BPP file
# (inverting the palette and de-interleaving the tiles).
oam_%.2bpp: oam_%.png
tools/gfx/gfx.py --invert --interleave --out $@ 2bpp $<
# Compile a PNG file to a 2BPP file, without any special conversion.
# (This typically uses `rgbgfx`, which is much faster than the
# Python-based `gfx.py`.)
%.2bpp: %.png
$(2BPP) -o $@ $<
# Compile all dependencies (ASM, 2BPP) into an single object file.
# (This means all the source code is always fully recompiled: for now,
# we don't compile the different ASM files separately.)
# Locale-specific rules below (e.g. `src/main.azlj.o`) will add their own
# pre-requisites to the ones defined by this rule.
src/main.%.o: src/main.asm $(asm_files) $(gfx_files:.png=.2bpp) $(bin_files)
$(ASM) $(ASFLAGS) $($*_ASFLAGS) -I src/ -o $@ $<
# Link object files into a GBC executable rom
# The arguments used are both the global options (e.g. `LDFLAGS`) and the
# locale-specific options (e.g. `azlg-r1_LDFLAGS`).
%.gbc: src/main.%.o
$(LD) $(LDFLAGS) $($*_LDFLAGS) -n $*.sym -o $@ $^
$(FX) $(FXFLAGS) $($*_FXFLAGS) $@
# Make may attempt to re-generate the Makefile; prevent this.
Makefile: ;
#
# Japanese
#
azlj_asm := $(call rwildcard,revisions/J0/src,*.asm)
azlj_gfx := $(call rwildcard,revisions/J0/src/gfx,*.png)
azlj_bin := $(wildcard revisions/J0/src/data/backgrounds/*.tilemap.encoded)
azlj_bin += $(wildcard revisions/J0/src/data/backgrounds/*.attrmap.encoded)
games += azlj.gbc
src/main.azlj.o: $(azlj_asm) $(azlj_gfx:.png=.2bpp) $(azlj_bin)
azlj_ASFLAGS = -DLANG=JP -DVERSION=0 -I revisions/J0/src/
azlj_FXFLAGS = --rom-version 0 --title "ZELDA"
games += azlj-r1.gbc
src/main.azlj-r1.o: $(azlj_asm) $(azlj_gfx:.png=.2bpp) $(azlj_bin)
azlj-r1_ASFLAGS = -DLANG=JP -DVERSION=1 -I revisions/J0/src/
azlj-r1_FXFLAGS = --rom-version 1 --title "ZELDA"
games += azlj-r2.gbc
src/main.azlj-r2.o: $(azlj_asm) $(azlj_gfx:.png=.2bpp) $(azlj_bin)
azlj-r2_ASFLAGS = -DLANG=JP -DVERSION=2 -I revisions/J0/src/
azlj-r2_FXFLAGS = --rom-version 2 --title "ZELDA" --game-id "AZLJ"
#
# German
#
azlg_asm := $(call rwildcard,revisions/G0/src,*.asm)
azlg_gfx := $(call rwildcard,revisions/G0/src/gfx,*.png)
azlg_bin := $(wildcard revisions/G0/src/data/backgrounds/*.tilemap.encoded)
azlg_bin += $(wildcard revisions/G0/src/data/backgrounds/*.attrmap.encoded)
games += azlg.gbc
src/main.azlg.o: $(azlg_asm) $(azlg_gfx:.png=.2bpp) $(azlg_bin)
azlg_ASFLAGS = -DLANG=DE -DVERSION=0 -I revisions/G0/src/
azlg_FXFLAGS = --rom-version 0 --non-japanese --title "ZELDA"
games += azlg-r1.gbc
src/main.azlg-r1.o: $(azlg_asm) $(azlg_gfx:.png=.2bpp) $(azlg_bin) azlj-r2.gbc
azlg-r1_ASFLAGS = -DLANG=DE -DVERSION=1 -I revisions/G0/src/
azlg-r1_LDFLAGS = -O azlj-r2.gbc
azlg-r1_FXFLAGS = --rom-version 1 --non-japanese --title "ZELDA" --game-id "AZLD"
#
# French
#
azlf_asm := $(call rwildcard,revisions/F0/src,*.asm)
azlf_gfx := $(call rwildcard,revisions/F0/src/gfx,*.png)
azlf_bin := $(wildcard revisions/F0/src/data/backgrounds/*.tilemap.encoded)
azlf_bin += $(wildcard revisions/F0/src/data/backgrounds/*.attrmap.encoded)
games += azlf.gbc
src/main.azlf.o: $(azlf_asm) $(azlf_gfx:.png=.2bpp) $(azlf_bin)
azlf_ASFLAGS = -DLANG=FR -DVERSION=0 -I revisions/F0/src/
azlf_FXFLAGS = --rom-version 0 --non-japanese --title "ZELDA"
games += azlf-r1.gbc
src/main.azlf-r1.o: $(azlf_asm) $(azlf_gfx:.png=.2bpp) $(azlf_bin) azlg-r1.gbc
azlf-r1_ASFLAGS = -DLANG=FR -DVERSION=1 -I revisions/F0/src/
azlf-r1_LDFLAGS = -O azlg-r1.gbc
azlf-r1_FXFLAGS = --rom-version 1 --non-japanese --title "ZELDA" --game-id "AZLF"
#
# English
#
games += azle.gbc
src/main.azle.o:
azle_ASFLAGS = -DLANG=EN -DVERSION=0
azle_FXFLAGS = --rom-version 0 --non-japanese --title "ZELDA"
games += azle-r1.gbc
src/main.azle-r1.o:
azle-r1_ASFLAGS = -DLANG=EN -DVERSION=1
azle-r1_FXFLAGS = --rom-version 1 --non-japanese --title "ZELDA"
redux += azle-r2.gbc
src/main.azle-r2.o: azlf-r1.gbc
azle-r2_ASFLAGS = -DLANG=EN -DVERSION=2
azle-r2_LDFLAGS = -O azlf-r1.gbc
azle-r2_FXFLAGS = --rom-version 2 --non-japanese --title "ZELDA" --game-id "AZLE"
#
# Redux
#
redux += redux.gbc
src/main.redux.o: azlf-r1.gbc
redux_ASFLAGS = -DLANG=RX -DVERSION=2
redux_LDFLAGS = -O azlf-r1.gbc
redux_FXFLAGS = --rom-version 2 --non-japanese --title "ZELDA" --game-id "AZLE"
#
# Main targets
#
# By default, build the US 1.0 revision.
build: azle.gbc
# Build all revisions.
build-all: $(games)
# Build Redux version
redux: $(redux)
rm -f $(games) azle-r2.gbc
rm -f $(games:%.gbc=src/main.%.o) src/main.azle-r2.o
rm -f $(games:.gbc=.map) azle-r2.map
rm -f $(games:.gbc=.sym) azle-r2.sym
# Test the default revision.
test: build
@tools/compare.sh ladx.md5 azle.gbc
# Test all revisions.
test-all: build-all
@tools/compare.sh ladx.md5 $(games)
all: build-all test-all
tidy:
rm -f $(games)
rm -f $(games:%.gbc=src/main.%.o)
rm -f $(games:.gbc=.map)
rm -f $(games:.gbc=.sym)
clean: tidy
rm -f $(gfx_files:.png=.2bpp)
rm -f $(azlj_gfx:.png=.2bpp)
rm -f $(azlg_gfx:.png=.2bpp)
rm -f $(azlf_gfx:.png=.2bpp)
### Debug Print ###
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true