forked from metroidret/mzm
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
293 lines (246 loc) · 6.37 KB
/
Makefile
File metadata and controls
293 lines (246 loc) · 6.37 KB
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
# Disable built-in rules
.SUFFIXES:
REGION ?= us
PAD_TO = 0x08800000
ifeq ($(REGION),us)
TARGET = mzm_us
GAME_TITLE = ZEROMISSIONE
GAME_CODE = BMXE
CPPFLAGS += -DREGION_US
ASFLAGS += --defsym REGION_US=1
endif
ifeq ($(REGION),us_beta)
TARGET = mzm_us_beta
GAME_TITLE = ZEROMISSIONE
GAME_CODE = BMXE
CPPFLAGS += -DREGION_US -DREGION_US_BETA -DDEBUG
ASFLAGS += --defsym REGION_US=1 --defsym REGION_US_BETA=1 --defsym DEBUG=1
PAD_TO = 0x09000000
endif
ifeq ($(REGION),eu)
TARGET = mzm_eu
GAME_TITLE = ZEROMISSIONP
GAME_CODE = BMXP
CPPFLAGS += -DREGION_EU
ASFLAGS += --defsym REGION_EU=1
endif
ifeq ($(REGION),eu_beta)
TARGET = mzm_eu_beta
GAME_TITLE = ZEROMISSIONP
GAME_CODE = BMXP
CPPFLAGS += -DREGION_EU -DREGION_EU_BETA -DDEBUG
ASFLAGS += --defsym REGION_EU=1 --defsym REGION_EU_BETA=1 --defsym DEBUG=1
PAD_TO = 0x09000000
endif
ifeq ($(REGION),jp)
TARGET = mzm_jp
GAME_TITLE = ZEROMISSIONJ
GAME_CODE = BMXJ
CPPFLAGS += -DREGION_JP
ASFLAGS += --defsym REGION_JP=1
endif
# ifeq ($(REGION),cn)
# TARGET = mzm_cn
# GAME_TITLE = ZEROMISSIONC
# GAME_CODE = BMXC
# CPPFLAGS += -DREGION_CN
# ASFLAGS += --defsym REGION_CN=1
# endif
ifeq ($(RANDOMIZER),1)
CPPFLAGS += -DRANDOMIZER
ASFLAGS += --defsym RANDOMIZER=1
TARGET := $(TARGET)_rando
endif
ifeq ($(DEBUG),1)
CPPFLAGS += -DDEBUG
ASFLAGS += --defsym DEBUG=1
TARGET := $(TARGET)_debug
endif
BASEROM := $(TARGET)_baserom.gba
TARGET := $(TARGET).gba
# Default target
.PHONY: all
all: $(TARGET)
ELF = $(TARGET:.gba=.elf)
MAP = $(TARGET:.gba=.map)
SHA1FILE = $(TARGET:.gba=.sha1)
DUMPS = $(BASEROM:.gba=.dump) $(TARGET:.gba=.dump)
LD_SCRIPT = linker.ld.pp
# ROM header
MAKER_CODE = 01
GAME_REVISION = 00
# Binaries
CPP = cpp
TOOLCHAIN ?= arm-none-eabi-
AS = $(TOOLCHAIN)as
LD = $(TOOLCHAIN)ld
OBJCOPY = $(TOOLCHAIN)objcopy
OBJDUMP = $(TOOLCHAIN)objdump
CC = agbcc
DIFF = diff -u
HOSTCC = cc
MKDIR = mkdir -p
RM = rm -f
SHA1SUM = sha1sum
TAIL = tail
# Tools
include make_tools.mk
GBAFIX = $(TOOLS_DIR)/gbafix/gbafix
PYTHON = python3
EXTRACTOR = $(PYTHON) $(TOOLS_DIR)/extractor.py
PREPROC = $(TOOLS_DIR)/preproc/preproc
# Flags
ASFLAGS += -mcpu=arm7tdmi
CFLAGS = -Werror -O2 -mthumb-interwork -fhex-asm -f2003-patch
CPPFLAGS += -nostdinc -Iinclude/
PREPROCFLAGS = charmap.txt
# Objects
CSRC = $(wildcard src/**.c) $(wildcard src/**/**.c) $(wildcard src/**/**/**.c) $(wildcard src/**/**/**/**.c)
.PRECIOUS: $(CSRC:.c=.s)
ASMSRC = $(CSRC:.c=.s) $(wildcard asm/*.s) $(wildcard sound/*.s) $(wildcard sound/**/*.s) $(wildcard sound/**/**/*.s)
OBJ = $(ASMSRC:.s=.o)
# Detect if agbcc was installed into the project
ifneq (,$(wildcard tools/agbcc))
AGBCC_BIN := tools/agbcc/bin/agbcc
AGBCC_LIB := tools/agbcc/lib
CC = $(AGBCC_BIN)
else
# Dynamically find agbcc path and its lib folder
AGBCC_BIN := $(shell which agbcc)
AGBCC_DIR := $(dir $(AGBCC_BIN))/
AGBCC_LIB := $(abspath $(AGBCC_DIR))
endif
LIBS := $(AGBCC_LIB)/libgcc.a $(AGBCC_LIB)/libc.a
# Enable verbose output
ifeq ($(V),1)
Q =
MSG = @:
else
Q = @
MSG = @echo " "
endif
# Rules that do not require scanning for dependencies
RULES_NO_SCAN += dump diff extract clean tidy
# Generate tools before building anything
SETUP_PREREQS ?= 1
# Disable generating tools for rules that do not build anything
ifneq (,$(MAKECMDGOALS))
ifeq (,$(filter-out $(RULES_NO_SCAN),$(MAKECMDGOALS)))
SETUP_PREREQS := 0
endif
endif
.SHELLSTATUS ?= 0
ifeq ($(SETUP_PREREQS),1)
$(foreach line, $(shell $(MAKE) -f make_tools.mk | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
ifneq ($(.SHELLSTATUS),0)
$(error Errors occurred while building tools. See error messages above for more details)
endif
endif
.PHONY: check
check: all
$(MSG) SHA1SUM $(SHA1FILE)
$Q$(SHA1SUM) -c $(SHA1FILE)
.PHONY: dump
dump: $(DUMPS)
.PHONY: diff
diff: $(DUMPS)
$(MSG) DIFF $^
$Q$(DIFF) $^
.PHONY: extract
extract:
$(MSG) Extracting
$Q$(EXTRACTOR) -r $(REGION)
.PHONY: clean
clean: clean-tools tidy
.PHONY: tidy
tidy:
$(MSG) RM roms
# Delete every gba file that doesn't end with baserom
$Qfind -type f -name "*.gba" -a ! -name "*baserom.gba" -delete
$(MSG) RM elf
$Q$(RM) *.elf
$(MSG) RM map
$Q$(RM) *.map
$(MSG) RM \*.dump
$Q$(RM) $(DUMPS)
$(MSG) RM \*.o
$Q$(RM) $(OBJ)
$(MSG) RM data/*.s
$(MSG) RM src/\*\*/\*.s
$Q$(RM) $(CSRC:.c=.s)
$(MSG) RM $(GBAFIX)
$Q$(RM) $(GBAFIX)
ifeq ($(DATA),1)
$(MSG) RM data/
$Q$(RM) -r data
$(MSG) RM sound/direct_sound_samples
$Q$(RM) -r sound/direct_sound_samples
endif
$(MSG) RM linker.ld.pp
$Q$(RM) linker.ld.pp
.PHONY: help
help:
@echo 'Targets:'
@echo ' all: build the ROM'
@echo ' check: checksum the ROM'
@echo ' dump: dump the ROMs'
@echo ' diff: compare the ROM with the original'
@echo ' clean: remove the ROM and intermediate files'
@echo ' DATA=1: removes the data folder generated by the extractor'
@echo ' help: show this message'
@echo ''
@echo 'Flags:'
@echo ' V=1: enable verbose output'
@echo ' REGION=<region>: selects the region of the ROM, possible values are "us", "eu", "jp", "cn", "us_beta", and "eu_beta"'
@echo ' DEBUG=1: enables the debug code'
$(TARGET): $(ELF)
$(MSG) OBJCOPY $@
$Q$(OBJCOPY) -O binary --gap-fill 0xff --pad-to $(PAD_TO) $< $@
$(MSG) GBAFIX $@
$Q$(GBAFIX) $@ -t$(GAME_TITLE) -c$(GAME_CODE) -m$(MAKER_CODE) -r$(GAME_REVISION)
$(ELF) $(MAP): $(OBJ) $(LD_SCRIPT)
$(MSG) LD $@
$Q$(LD) $(LDFLAGS) -n -T $(LD_SCRIPT) -Map=$(MAP) $(LIBS) -o $@
$(LD_SCRIPT): linker.ld
$(MSG) CPP $@
$Q$(CPP) $(CPPFLAGS) $< -o $@
%.dump: %.gba
$(MSG) OBJDUMP $@
$Q$(OBJDUMP) -D -bbinary -marm7tdmi -Mforce-thumb $< | $(TAIL) -n+3 >$@
#--stop-address 0x8c71c
%.o: %.s
$(MSG) AS $@
$Q$(AS) $(ASFLAGS) $< -o $@
%.s: %.c
$(MSG) CC $@
$Q$(PREPROC) $< $(PREPROCFLAGS) | $(CPP) $(CPPFLAGS) | $(CC) -o $@ $(CFLAGS) && printf '\t.align 2, 0 @ dont insert nops\n' >> $@
src/dma.s: CFLAGS = -Werror -O1 -mthumb-interwork -fhex-asm -f2003-patch
src/dma.s: src/dma.c
src/sram/%.s: CFLAGS = -Werror -O1 -mthumb-interwork -fhex-asm -f2003-patch
src/sram/%.s: src/sram/%.c
.PHONY: rando rando_debug us us_debug us_beta eu eu_debug eu_beta jp jp_debug
# cn cn_debug
rando:
$(MAKE) RANDOMIZER=1
rando_debug:
$(MAKE) RANDOMIZER=1 DEBUG=1
us:
$(MAKE) REGION=us
us_debug:
$(MAKE) REGION=us DEBUG=1
us_beta:
$(MAKE) REGION=us_beta
eu:
$(MAKE) REGION=eu
eu_debug:
$(MAKE) REGION=eu DEBUG=1
eu_beta:
$(MAKE) REGION=eu_beta
jp:
$(MAKE) REGION=jp
jp_debug:
$(MAKE) REGION=jp DEBUG=1
# cn:
# $(MAKE) REGION=cn
# cn_debug:
# $(MAKE) REGION=cn DEBUG=1