forked from pret/pokeemerald
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMakefile
More file actions
699 lines (595 loc) · 22.1 KB
/
Copy pathMakefile
File metadata and controls
699 lines (595 loc) · 22.1 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
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
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
# GBA rom header
TITLE := POKEMON EMER
GAME_CODE := BPEE
MAKER_CODE := 01
REVISION := 0
MODERN ?= 0
KEEP_TEMPS ?= 0
# `File name`.gba ('_modern' will be appended to the modern builds)
FILE_NAME := pokeemerald
BUILD_DIR := build
# Web UI opponent build flag — lets an mGBA Lua driver + browser UI control
# the AI opponent's decisions via an EWRAM mailbox. Usage: `make WEBUI_OPPONENT=1`.
WEBUI_OPPONENT ?= 0
# Builds the ROM using a modern compiler
MODERN ?= 0
# Compares the ROM to a checksum of the original - only makes sense using when non-modern
COMPARE ?= 0
ifeq (modern,$(MAKECMDGOALS))
MODERN := 1
endif
ifeq (compare,$(MAKECMDGOALS))
COMPARE := 1
endif
# Default make rule
all: rom
# Toolchain selection
TOOLCHAIN := $(DEVKITARM)
# don't use dkP's base_tools anymore
# because the redefinition of $(CC) conflicts
# with when we want to use $(CC) to preprocess files
# thus, manually create the variables for the bin
# files, or use arm-none-eabi binaries on the system
# if dkP is not installed on this system
ifneq (,$(TOOLCHAIN))
ifneq ($(wildcard $(TOOLCHAIN)/bin),)
export PATH := $(TOOLCHAIN)/bin:$(PATH)
endif
endif
PREFIX := arm-none-eabi-
OBJCOPY := $(PREFIX)objcopy
OBJDUMP := $(PREFIX)objdump
AS := $(PREFIX)as
LD := $(PREFIX)ld
EXE :=
ifeq ($(OS),Windows_NT)
EXE := .exe
endif
# use arm-none-eabi-cpp for macOS
# as macOS's default compiler is clang
# and clang's preprocessor will warn on \u
# when preprocessing asm files, expecting a unicode literal
# we can't unconditionally use arm-none-eabi-cpp
# as installations which install binutils-arm-none-eabi
# don't come with it
ifneq ($(MODERN),1)
ifeq ($(shell uname -s),Darwin)
CPP := $(PREFIX)cpp
else
CPP := $(CC) -E
endif
else
CPP := $(PREFIX)cpp
endif
# Output ROM name:
# - Default: uses FILE_NAME (override with e.g. `make FILE_NAME=myhack`)
# - Or override directly: `make ROM_NAME_OVERRIDE=myrom.gba`
ROM_NAME_OVERRIDE ?=
MODERN_ROM_NAME_OVERRIDE ?=
ifneq ($(ROM_NAME_OVERRIDE),)
ROM_NAME := $(ROM_NAME_OVERRIDE)
else
ROM_NAME := $(FILE_NAME).gba
endif
ifneq ($(MODERN_ROM_NAME_OVERRIDE),)
MODERN_ROM_NAME := $(MODERN_ROM_NAME_OVERRIDE)
else
MODERN_ROM_NAME := $(FILE_NAME)_modern.gba
endif
# Object directories.
ifeq ($(WEBUI_OPPONENT),1)
OBJ_DIR_NAME := $(BUILD_DIR)/emerald_webui
MODERN_OBJ_DIR_NAME := $(BUILD_DIR)/modern_webui
else
OBJ_DIR_NAME := $(BUILD_DIR)/emerald
MODERN_OBJ_DIR_NAME := $(BUILD_DIR)/modern
endif
ELF_NAME := $(ROM_NAME:.gba=.elf)
MAP_NAME := $(ROM_NAME:.gba=.map)
MODERN_ELF_NAME := $(MODERN_ROM_NAME:.gba=.elf)
MODERN_MAP_NAME := $(MODERN_ROM_NAME:.gba=.map)
# Pick our active variables
ifeq ($(MODERN),0)
ROM := $(ROM_NAME)
OBJ_DIR := $(OBJ_DIR_NAME)
else
ROM := $(MODERN_ROM_NAME)
OBJ_DIR := $(MODERN_OBJ_DIR_NAME)
endif
ELF := $(ROM:.gba=.elf)
MAP := $(ROM:.gba=.map)
SYM := $(ROM:.gba=.sym)
# Commonly used directories
C_SUBDIR = src
ASM_SUBDIR = asm
DATA_SRC_SUBDIR = src/data
DATA_ASM_SUBDIR = data
SONG_SUBDIR = sound/songs
MID_SUBDIR = sound/songs/midi
C_BUILDDIR = $(OBJ_DIR)/$(C_SUBDIR)
ASM_BUILDDIR = $(OBJ_DIR)/$(ASM_SUBDIR)
DATA_ASM_BUILDDIR = $(OBJ_DIR)/$(DATA_ASM_SUBDIR)
SONG_BUILDDIR = $(OBJ_DIR)/$(SONG_SUBDIR)
MID_BUILDDIR = $(OBJ_DIR)/$(MID_SUBDIR)
SHELL := bash -o pipefail
# Set flags for tools
ASFLAGS := -mcpu=arm7tdmi --defsym MODERN=$(MODERN)
INCLUDE_DIRS := include
INCLUDE_CPP_ARGS := $(INCLUDE_DIRS:%=-iquote %)
INCLUDE_SCANINC_ARGS := $(INCLUDE_DIRS:%=-I %)
O_LEVEL ?= 2
CPPFLAGS := $(INCLUDE_CPP_ARGS) -Wno-trigraphs -DMODERN=$(MODERN)
ifeq ($(WEBUI_OPPONENT),1)
CPPFLAGS += -DWEBUI_OPPONENT
ifeq ($(COMPARE),1)
$(error compare is not supported with WEBUI_OPPONENT=1)
endif
endif
# Optional feature flags (enable with e.g. `make RANDOM_EVOLUTIONS=1`)
RANDOM_EVOLUTIONS ?= 0
ifeq ($(RANDOM_EVOLUTIONS),1)
CPPFLAGS += -DRANDOM_EVOLUTIONS
endif
HARDCODED_RANDOM_EVOLUTIONS ?= 0
ifeq ($(HARDCODED_RANDOM_EVOLUTIONS),1)
CPPFLAGS += -DHARDCODED_RANDOM_EVOLUTIONS
endif
# Compile-time toggle: run the evolution scene update loop N times per frame,
# making the evolution animation/cutscene much faster. Usage: make FAST_EVOLUTION_ANIM=1
FAST_EVOLUTION_ANIM ?= 0
ifeq ($(FAST_EVOLUTION_ANIM),1)
CPPFLAGS += -DFAST_EVOLUTION_ANIM=4
endif
# Compile-time toggle: prevent B from cancelling evolution scenes.
# Usage: make PREVENT_EVOLUTION_CANCEL=1
PREVENT_EVOLUTION_CANCEL ?= 0
ifeq ($(PREVENT_EVOLUTION_CANCEL),1)
CPPFLAGS += -DPREVENT_EVOLUTION_CANCEL
endif
WALK_FAST ?= 0
ifeq ($(WALK_FAST),1)
CPPFLAGS += -DWALK_FAST
endif
FAST_SWIM ?= 0
ifeq ($(FAST_SWIM),1)
CPPFLAGS += -DFAST_SWIM
endif
REPEL_ANY_LEVEL ?= 0
ifeq ($(REPEL_ANY_LEVEL),1)
CPPFLAGS += -DREPEL_ANY_LEVEL
endif
NO_WILD_ENCOUNTERS ?= 0
ifeq ($(NO_WILD_ENCOUNTERS),1)
CPPFLAGS += -DNO_WILD_ENCOUNTERS
endif
RELOAD_SAVE_ON_WHITEOUT ?= 0
ifeq ($(RELOAD_SAVE_ON_WHITEOUT),1)
CPPFLAGS += -DRELOAD_SAVE_ON_WHITEOUT
endif
SKIP_WALLY_CAPTURE_TUTORIAL ?= 0
ifeq ($(SKIP_WALLY_CAPTURE_TUTORIAL),1)
CPPFLAGS += -DSKIP_WALLY_CAPTURE_TUTORIAL
endif
OPEN_WORLD_MODE ?= 0
ifeq ($(OPEN_WORLD_MODE),1)
CPPFLAGS += -DOPEN_WORLD_MODE
endif
FREE_HM_MODE ?= 0
ifeq ($(FREE_HM_MODE),1)
CPPFLAGS += -DFREE_HM_MODE
endif
LEVEL_CAP ?= 0
ifeq ($(LEVEL_CAP),1)
CPPFLAGS += -DLEVEL_CAP
endif
WALK_THROUGH_WALLS ?= 0
ifeq ($(WALK_THROUGH_WALLS),1)
CPPFLAGS += -DWALK_THROUGH_WALLS
endif
NUZLOCKE_DELETE_FAINTED ?= 0
ifeq ($(NUZLOCKE_DELETE_FAINTED),1)
CPPFLAGS += -DNUZLOCKE_DELETE_FAINTED
endif
WAIT_TIME_DIVISOR ?= 1
CPPFLAGS += -DWAIT_TIME_DIVISOR=$(WAIT_TIME_DIVISOR)
# Numeric modifier applied to opponent initial stat stages at battle start.
# Positive values boost; negative values nerf. Clamped to MIN_STAT_STAGE..MAX_STAT_STAGE.
# Usage: make OPPONENT_STAT_STAGE_MOD=1
OPPONENT_STAT_STAGE_MOD ?= 0
CPPFLAGS += -DOPPONENT_STAT_STAGE_MOD=$(OPPONENT_STAT_STAGE_MOD)
# Numeric modifier applied to player's initial stat stages at battle start.
# Positive values boost; negative values nerf. Clamped to MIN_STAT_STAGE..MAX_STAT_STAGE.
# Usage: make PLAYER_STAT_STAGE_MOD=1
PLAYER_STAT_STAGE_MOD ?= 0
CPPFLAGS += -DPLAYER_STAT_STAGE_MOD=$(PLAYER_STAT_STAGE_MOD)
# Which gym leader roster is used for the first badge battle.
# 0 = base team, 1..4 = first through fourth rematch team.
# Usage: make GYM_LEADER_FIRST_ROSTER=4
GYM_LEADER_FIRST_ROSTER ?= 0
CPPFLAGS += -DGYM_LEADER_FIRST_ROSTER=$(GYM_LEADER_FIRST_ROSTER)
# Level of the starter received from Professor Birch. Usage: make STARTER_LEVEL=10
STARTER_LEVEL ?= 5
CPPFLAGS += -DSTARTER_LEVEL=$(STARTER_LEVEL)
INSTANT_TEXT ?= 0
ifeq ($(INSTANT_TEXT),1)
CPPFLAGS += -DINSTANT_TEXT
endif
FORCE_DOUBLE_BATTLES ?= 0
ifeq ($(FORCE_DOUBLE_BATTLES),1)
CPPFLAGS += -DFORCE_DOUBLE_BATTLES
endif
STEAL_TRAINER_TEAM ?= 0
ifeq ($(STEAL_TRAINER_TEAM),1)
CPPFLAGS += -DSTEAL_TRAINER_TEAM
endif
# Compile-time toggle: add the selected trainer Pokemon when the player's
# party has space, while retaining replacement selection for full parties.
# Requires SWAP_TRAINER_POKEMON=1.
ADD_TRAINER_POKEMON_IF_SPACE ?= 0
SWAP_TRAINER_POKEMON ?= 0
ifeq ($(SWAP_TRAINER_POKEMON),1)
CPPFLAGS += -DSWAP_TRAINER_POKEMON
ifeq ($(ADD_TRAINER_POKEMON_IF_SPACE),1)
CPPFLAGS += -DADD_TRAINER_POKEMON_IF_SPACE
endif
endif
# Compile-time toggle: prevent Pokémon from gaining experience.
# Usage: make NO_EXP=1
NO_EXP ?= 0
ifeq ($(NO_EXP),1)
CPPFLAGS += -DNO_EXP
endif
# Compile-time toggle: wild Pokémon give no experience (trainer battles still do).
# Usage: make NO_EXP_WILD=1
NO_EXP_WILD ?= 0
ifeq ($(NO_EXP_WILD),1)
CPPFLAGS += -DNO_EXP_WILD
endif
# Compile-time toggle: trainer Pokémon give no experience (wild battles still do).
# Usage: make NO_EXP_TRAINER=1
NO_EXP_TRAINER ?= 0
ifeq ($(NO_EXP_TRAINER),1)
CPPFLAGS += -DNO_EXP_TRAINER
endif
# Compile-time toggle: start the game with the Super Rare Candy key item.
# Usage: make START_WITH_SUPER_RARE_CANDY=1
START_WITH_SUPER_RARE_CANDY ?= 0
ifeq ($(START_WITH_SUPER_RARE_CANDY),1)
CPPFLAGS += -DSTART_WITH_SUPER_RARE_CANDY
endif
# Compile-time toggle: start the game with the Cap Candy key item, which raises
# a Pokemon's level to the current level cap (see LEVEL_CAP). Usage: make START_WITH_CAP_CANDY=1
START_WITH_CAP_CANDY ?= 0
ifeq ($(START_WITH_CAP_CANDY),1)
CPPFLAGS += -DSTART_WITH_CAP_CANDY
endif
# Compile-time toggle: EXP is subtracted instead of added.
# Usage: make NEGATIVE_EXP=1
NEGATIVE_EXP ?= 0
ifeq ($(NEGATIVE_EXP),1)
CPPFLAGS += -DNEGATIVE_EXP
endif
# Compile-time setting: multiply EXP gained on faint, expressed in tenths
# (10 = 1.0x, 30 = 3.0x). Default 10 keeps vanilla EXP. Usage: make EXP_MULTIPLIER=25
EXP_MULTIPLIER ?= 10
CPPFLAGS += -DEXP_MULTIPLIER=$(EXP_MULTIPLIER)
# Compile-time toggle: prevent using Poké Balls.
# Usage: make NO_POKEBALLS=1
NO_POKEBALLS ?= 0
ifeq ($(NO_POKEBALLS),1)
CPPFLAGS += -DNO_POKEBALLS
endif
# Compile-time toggle: prevent using bag items and berries in battle.
# Poké Balls (and escape items) are still allowed.
# Usage: make NO_BATTLE_ITEMS=1
NO_BATTLE_ITEMS ?= 0
ifeq ($(NO_BATTLE_ITEMS),1)
CPPFLAGS += -DNO_BATTLE_ITEMS
endif
# Compile-time toggle: stock Poké Balls in Oldale Mart before the first rival fight.
# Usage: make FIRST_SHOP_POKEBALLS=1
FIRST_SHOP_POKEBALLS ?= 0
ifeq ($(FIRST_SHOP_POKEBALLS),1)
CPPFLAGS += -DFIRST_SHOP_POKEBALLS
endif
# Compile-time toggle: use money instead of PP for moves.
# Usage: make MONEY_FOR_MOVES=1
MONEY_FOR_MOVES ?= 0
ifeq ($(MONEY_FOR_MOVES),1)
CPPFLAGS += -DMONEY_FOR_MOVES
endif
# Compile-time toggle: remove Nurse Joy NPCs from Pokemon Center 1F maps.
# Usage: make REMOVE_POKEMON_CENTER_JOY=1
REMOVE_POKEMON_CENTER_JOY ?= 0
ifeq ($(REMOVE_POKEMON_CENTER_JOY),1)
CPPFLAGS += -DREMOVE_POKEMON_CENTER_JOY
endif
# Compile-time toggle: disable field interactions with PCs.
# Usage: make DISABLE_PCS=1
DISABLE_PCS ?= 0
ifeq ($(DISABLE_PCS),1)
CPPFLAGS += -DDISABLE_PCS
endif
# Compile-time toggle: skip/instant-complete visual fade in/out animations.
# Usage: make SKIP_FADE_ANIMS=1
SKIP_FADE_ANIMS ?= 0
ifeq ($(SKIP_FADE_ANIMS),1)
CPPFLAGS += -DSKIP_FADE_ANIMS
endif
# Compile-time toggle: shorten the normal start-menu save flow without
# changing or skipping any flash writes or verification.
# Usage: make FAST_SAVE=1
FAST_SAVE ?= 0
ifeq ($(FAST_SAVE),1)
CPPFLAGS += -DFAST_SAVE
endif
# Compile-time toggle: require A-press to advance every battle message.
# Usage: make MANUAL_BATTLE_TEXT=1
MANUAL_BATTLE_TEXT ?= 0
ifeq ($(MANUAL_BATTLE_TEXT),1)
CPPFLAGS += -DMANUAL_BATTLE_TEXT
endif
# Compile-time toggle: skip the intro cutscene and go straight to title screen.
# Usage: make SKIP_INTRO_CUTSCENE=1
SKIP_INTRO_CUTSCENE ?= 0
ifeq ($(SKIP_INTRO_CUTSCENE),1)
CPPFLAGS += -DSKIP_INTRO_CUTSCENE
endif
# Compile-time toggle: skip the new-game moving/truck intro after gender/name.
# Usage: make FAST_INTRO=1
FAST_INTRO ?= 0
ifeq ($(FAST_INTRO),1)
CPPFLAGS += -DFAST_INTRO
endif
SKIP_BATTLE_TRANSITION ?= 0
ifeq ($(SKIP_BATTLE_TRANSITION),1)
CPPFLAGS += -DSKIP_BATTLE_TRANSITION
endif
# Compile-time toggle: speed up battle intro/sendout/healthbox animations without
# skipping the battle transition itself. SKIP_BATTLE_TRANSITION also enables these
# speedups for compatibility with older presets.
# Usage: make FAST_BATTLE_ANIMS=1
FAST_BATTLE_ANIMS ?= 0
ifeq ($(FAST_BATTLE_ANIMS),1)
CPPFLAGS += -DFAST_BATTLE_ANIMS
endif
BATTLE_ANIM_SPEED_MULTIPLIER ?= 1
CPPFLAGS += -DBATTLE_ANIM_SPEED_MULTIPLIER=$(BATTLE_ANIM_SPEED_MULTIPLIER)
ifeq ($(MODERN),0)
CPPFLAGS += -I tools/agbcc/include -I tools/agbcc -nostdinc -undef -std=gnu89
CC1 := tools/agbcc/bin/agbcc$(EXE)
override CFLAGS += -mthumb-interwork -Wimplicit -Wparentheses -Werror -O$(O_LEVEL) -fhex-asm -g
LIBPATH := -L ../../tools/agbcc/lib
LIB := $(LIBPATH) -lgcc -lc -L../../libagbsyscall -lagbsyscall
else
# Note: The makefile must be set up to not call these if modern == 0
MODERNCC := $(PREFIX)gcc
PATH_MODERNCC := PATH="$(PATH)" $(MODERNCC)
CC1 := $(shell $(PATH_MODERNCC) --print-prog-name=cc1) -quiet
override CFLAGS += -mthumb -mthumb-interwork -O$(O_LEVEL) -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast
LIBPATH := -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libgcc.a))" -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libnosys.a))" -L "$(dir $(shell $(PATH_MODERNCC) -mthumb -print-file-name=libc.a))"
LIB := $(LIBPATH) -lc -lnosys -lgcc -L../../libagbsyscall -lagbsyscall
endif
# Rebuild objects when build flags change.
# (Make does not automatically consider changes to command-line variables like SKIP_BATTLE_TRANSITION.)
CONFIG_FLAGS_FILE := $(OBJ_DIR)/.config_flags
.PHONY: FORCE
FORCE:
$(CONFIG_FLAGS_FILE): FORCE
@mkdir -p $(dir $@)
@tmp=$@.tmp; \
{ \
echo "CPPFLAGS=$(CPPFLAGS)"; \
echo "CFLAGS=$(CFLAGS)"; \
echo "ASFLAGS=$(ASFLAGS)"; \
} > $$tmp; \
if [ -f $@ ] && cmp -s $$tmp $@; then rm -f $$tmp; else mv -f $$tmp $@; fi
# Enable debug info if set
ifeq ($(DINFO),1)
override CFLAGS += -g
endif
# Variable filled out in other make files
AUTO_GEN_TARGETS :=
include make_tools.mk
# Tool executables
GFX := $(TOOLS_DIR)/gbagfx/gbagfx$(EXE)
WAV2AGB := $(TOOLS_DIR)/wav2agb/wav2agb$(EXE)
MID := $(TOOLS_DIR)/mid2agb/mid2agb$(EXE)
SCANINC := $(TOOLS_DIR)/scaninc/scaninc$(EXE)
PREPROC := $(TOOLS_DIR)/preproc/preproc$(EXE)
RAMSCRGEN := $(TOOLS_DIR)/ramscrgen/ramscrgen$(EXE)
FIX := $(TOOLS_DIR)/gbafix/gbafix$(EXE)
MAPJSON := $(TOOLS_DIR)/mapjson/mapjson$(EXE)
JSONPROC := $(TOOLS_DIR)/jsonproc/jsonproc$(EXE)
PERL := perl
SHA1 := $(shell { command -v sha1sum || command -v shasum; } 2>/dev/null) -c
MAKEFLAGS += --no-print-directory
# Clear the default suffixes
.SUFFIXES:
# Don't delete intermediate files
.SECONDARY:
# Delete files that weren't built properly
.DELETE_ON_ERROR:
RULES_NO_SCAN += libagbsyscall clean clean-assets tidy tidymodern tidynonmodern generated clean-generated
.PHONY: all rom modern compare
.PHONY: $(RULES_NO_SCAN)
infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
# Check if we need to scan dependencies based on the chosen rule OR user preference
NODEP ?= 0
# Check if we need to pre-build tools and generate assets based on the chosen rule.
SETUP_PREREQS ?= 1
# Disable dependency scanning for rules that don't need it.
ifneq (,$(MAKECMDGOALS))
ifeq (,$(filter-out $(RULES_NO_SCAN),$(MAKECMDGOALS)))
NODEP := 1
SETUP_PREREQS := 0
endif
endif
.SHELLSTATUS ?= 0
ifeq ($(SETUP_PREREQS),1)
# If set on: Default target or a rule requiring a scan
# Forcibly execute `make tools` since we need them for what we are doing.
$(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
# Oh and also generate mapjson sources before we use `SCANINC`.
$(foreach line, $(shell $(MAKE) generated | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
ifneq ($(.SHELLSTATUS),0)
$(error Errors occurred while generating map-related sources. See error messages above for more details)
endif
endif
# Collect sources
C_SRCS_IN := $(wildcard $(C_SUBDIR)/*.c $(C_SUBDIR)/*/*.c $(C_SUBDIR)/*/*/*.c)
C_SRCS := $(foreach src,$(C_SRCS_IN),$(if $(findstring .inc.c,$(src)),,$(src)))
C_OBJS := $(patsubst $(C_SUBDIR)/%.c,$(C_BUILDDIR)/%.o,$(C_SRCS))
C_ASM_SRCS := $(wildcard $(C_SUBDIR)/*.s $(C_SUBDIR)/*/*.s $(C_SUBDIR)/*/*/*.s)
C_ASM_OBJS := $(patsubst $(C_SUBDIR)/%.s,$(C_BUILDDIR)/%.o,$(C_ASM_SRCS))
ASM_SRCS := $(wildcard $(ASM_SUBDIR)/*.s)
ASM_OBJS := $(patsubst $(ASM_SUBDIR)/%.s,$(ASM_BUILDDIR)/%.o,$(ASM_SRCS))
# get all the data/*.s files EXCEPT the ones with specific rules
REGULAR_DATA_ASM_SRCS := $(filter-out $(DATA_ASM_SUBDIR)/maps.s $(DATA_ASM_SUBDIR)/map_events.s, $(wildcard $(DATA_ASM_SUBDIR)/*.s))
DATA_ASM_SRCS := $(wildcard $(DATA_ASM_SUBDIR)/*.s)
DATA_ASM_OBJS := $(patsubst $(DATA_ASM_SUBDIR)/%.s,$(DATA_ASM_BUILDDIR)/%.o,$(DATA_ASM_SRCS))
SONG_SRCS := $(wildcard $(SONG_SUBDIR)/*.s)
SONG_OBJS := $(patsubst $(SONG_SUBDIR)/%.s,$(SONG_BUILDDIR)/%.o,$(SONG_SRCS))
MID_SRCS := $(wildcard $(MID_SUBDIR)/*.mid)
MID_OBJS := $(patsubst $(MID_SUBDIR)/%.mid,$(MID_BUILDDIR)/%.o,$(MID_SRCS))
OBJS := $(C_OBJS) $(C_ASM_OBJS) $(ASM_OBJS) $(DATA_ASM_OBJS) $(SONG_OBJS) $(MID_OBJS)
OBJS_REL := $(patsubst $(OBJ_DIR)/%,%,$(OBJS))
SUBDIRS := $(sort $(dir $(OBJS)))
$(shell mkdir -p $(SUBDIRS))
# Pretend rules that are actually flags defer to `make all`
modern: all
compare: all
# Other rules
rom: $(ROM)
ifeq ($(COMPARE),1)
@$(SHA1) rom.sha1
endif
syms: $(SYM)
clean: tidy clean-tools clean-generated clean-assets
@$(MAKE) clean -C libagbsyscall
clean-assets:
rm -f $(MID_SUBDIR)/*.s
rm -f $(DATA_ASM_SUBDIR)/layouts/layouts.inc $(DATA_ASM_SUBDIR)/layouts/layouts_table.inc
rm -f $(DATA_ASM_SUBDIR)/maps/connections.inc $(DATA_ASM_SUBDIR)/maps/events.inc $(DATA_ASM_SUBDIR)/maps/groups.inc $(DATA_ASM_SUBDIR)/maps/headers.inc
find sound -iname '*.bin' -exec rm {} +
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.rl' -o -iname '*.latfont' -o -iname '*.hwjpnfont' -o -iname '*.fwjpnfont' \) -exec rm {} +
find $(DATA_ASM_SUBDIR)/maps \( -iname 'connections.inc' -o -iname 'events.inc' -o -iname 'header.inc' \) -exec rm {} +
tidy: tidynonmodern tidymodern
tidynonmodern:
rm -f $(ROM_NAME) $(ELF_NAME) $(MAP_NAME)
rm -rf $(OBJ_DIR_NAME)
tidymodern:
rm -f $(MODERN_ROM_NAME) $(MODERN_ELF_NAME) $(MODERN_MAP_NAME)
rm -rf $(MODERN_OBJ_DIR_NAME)
# Other rules
include graphics_file_rules.mk
include map_data_rules.mk
include spritesheet_rules.mk
include json_data_rules.mk
include audio_rules.mk
# NOTE: Tools must have been built prior (FIXME)
# so you can't really call this rule directly
generated: $(AUTO_GEN_TARGETS)
@: # Silence the "Nothing to be done for `generated'" message, which some people were confusing for an error.
%.s: ;
%.png: ;
%.pal: ;
%.wav: ;
%.1bpp: %.png ; $(GFX) $< $@
%.4bpp: %.png ; $(GFX) $< $@
%.8bpp: %.png ; $(GFX) $< $@
%.gbapal: %.pal ; $(GFX) $< $@
%.gbapal: %.png ; $(GFX) $< $@
%.lz: % ; $(GFX) $< $@
%.rl: % ; $(GFX) $< $@
clean-generated:
@rm -f $(AUTO_GEN_TARGETS)
@echo "rm -f <AUTO_GEN_TARGETS>"
ifeq ($(MODERN),0)
$(C_BUILDDIR)/libc.o: CC1 := $(TOOLS_DIR)/agbcc/bin/old_agbcc$(EXE)
$(C_BUILDDIR)/libc.o: CFLAGS := -O2
$(C_BUILDDIR)/siirtc.o: CFLAGS := -mthumb-interwork
$(C_BUILDDIR)/agb_flash.o: CFLAGS := -O -mthumb-interwork
$(C_BUILDDIR)/agb_flash_1m.o: CFLAGS := -O -mthumb-interwork
$(C_BUILDDIR)/agb_flash_mx.o: CFLAGS := -O -mthumb-interwork
$(C_BUILDDIR)/m4a.o: CC1 := tools/agbcc/bin/old_agbcc$(EXE)
$(C_BUILDDIR)/record_mixing.o: CFLAGS += -ffreestanding
$(C_BUILDDIR)/librfu_intr.o: CC1 := $(TOOLS_DIR)/agbcc/bin/agbcc_arm$(EXE)
$(C_BUILDDIR)/librfu_intr.o: CFLAGS := -O2 -mthumb-interwork -quiet
else
$(C_BUILDDIR)/librfu_intr.o: CFLAGS := -mthumb-interwork -O2 -mabi=apcs-gnu -mtune=arm7tdmi -march=armv4t -fno-toplevel-reorder -Wno-pointer-to-int-cast
$(C_BUILDDIR)/berry_crush.o: override CFLAGS += -Wno-address-of-packed-member
endif
# Dependency rules (for the *.c & *.s sources to .o files)
# 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 (Icedude_907: there is soon).
$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.c $(CONFIG_FLAGS_FILE)
ifneq ($(KEEP_TEMPS),1)
@echo "$(CC1) <flags> -o $@ $<"
@$(CPP) $(CPPFLAGS) $< | $(PREPROC) -i $< charmap.txt | $(CC1) $(CFLAGS) -o - - | cat - <(echo -e ".text\n\t.align\t2, 0") | $(AS) $(ASFLAGS) -o $@ -
else
@$(CPP) $(CPPFLAGS) $< -o $(C_BUILDDIR)/$*.i
@$(PREPROC) $(C_BUILDDIR)/$*.i charmap.txt | $(CC1) $(CFLAGS) -o $(C_BUILDDIR)/$*.s
@echo -e ".text\n\t.align\t2, 0\n" >> $(C_BUILDDIR)/$*.s
$(AS) $(ASFLAGS) -o $@ $(C_BUILDDIR)/$*.s
endif
$(C_BUILDDIR)/%.d: $(C_SUBDIR)/%.c
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I tools/agbcc/include $<
ifneq ($(NODEP),1)
-include $(addprefix $(OBJ_DIR)/,$(C_SRCS:.c=.d))
endif
$(ASM_BUILDDIR)/%.o: $(ASM_SUBDIR)/%.s $(CONFIG_FLAGS_FILE)
$(AS) $(ASFLAGS) -o $@ $<
$(ASM_BUILDDIR)/%.d: $(ASM_SUBDIR)/%.s
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I "" $<
ifneq ($(NODEP),1)
-include $(addprefix $(OBJ_DIR)/,$(ASM_SRCS:.s=.d))
endif
$(C_BUILDDIR)/%.o: $(C_SUBDIR)/%.s $(CONFIG_FLAGS_FILE)
$(PREPROC) $< charmap.txt | $(CPP) $(CPPFLAGS) $(INCLUDE_SCANINC_ARGS) - | $(PREPROC) -ie $< charmap.txt | $(AS) $(ASFLAGS) -o $@
$(C_BUILDDIR)/%.d: $(C_SUBDIR)/%.s
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I "" $<
ifneq ($(NODEP),1)
-include $(addprefix $(OBJ_DIR)/,$(C_ASM_SRCS:.s=.d))
endif
$(DATA_ASM_BUILDDIR)/%.o: $(DATA_ASM_SUBDIR)/%.s $(CONFIG_FLAGS_FILE)
$(PREPROC) $< charmap.txt | $(CPP) $(CPPFLAGS) $(INCLUDE_SCANINC_ARGS) - | $(PREPROC) -ie $< charmap.txt | $(AS) $(ASFLAGS) -o $@
$(DATA_ASM_BUILDDIR)/%.d: $(DATA_ASM_SUBDIR)/%.s
$(SCANINC) -M $@ $(INCLUDE_SCANINC_ARGS) -I "" $<
ifneq ($(NODEP),1)
-include $(addprefix $(OBJ_DIR)/,$(REGULAR_DATA_ASM_SRCS:.s=.d))
endif
$(OBJ_DIR)/sym_bss.ld: sym_bss.txt
$(RAMSCRGEN) .bss $< ENGLISH > $@
$(OBJ_DIR)/sym_common.ld: sym_common.txt $(C_OBJS) $(wildcard common_syms/*.txt)
$(RAMSCRGEN) COMMON $< ENGLISH -c $(C_BUILDDIR),common_syms > $@
$(OBJ_DIR)/sym_ewram.ld: sym_ewram.txt
$(RAMSCRGEN) ewram_data $< ENGLISH > $@
# Linker script
ifeq ($(MODERN),0)
LD_SCRIPT := ld_script.ld
LD_SCRIPT_DEPS := $(OBJ_DIR)/sym_bss.ld $(OBJ_DIR)/sym_common.ld $(OBJ_DIR)/sym_ewram.ld
else
LD_SCRIPT := ld_script_modern.ld
LD_SCRIPT_DEPS :=
endif
# Final rules
libagbsyscall:
@$(MAKE) -C libagbsyscall TOOLCHAIN=$(TOOLCHAIN) MODERN=$(MODERN)
# Elf from object files
LDFLAGS = -Map ../../$(MAP)
$(ELF): $(LD_SCRIPT) $(LD_SCRIPT_DEPS) $(OBJS) libagbsyscall
@cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ../../$< --print-memory-usage -o ../../$@ $(OBJS_REL) $(LIB) | cat
@echo "cd $(OBJ_DIR) && $(LD) $(LDFLAGS) -T ../../$< --print-memory-usage -o ../../$@ <objs> <libs> | cat"
$(FIX) $@ -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(REVISION) --silent
# Builds the rom from the elf file
$(ROM): $(ELF)
$(OBJCOPY) -O binary $< $@
$(FIX) $@ -p --silent
# Symbol file (`make syms`)
$(SYM): $(ELF)
$(OBJDUMP) -t $< | sort -u | grep -E "^0[2389]" | $(PERL) -p -e 's/^(\w{8}) (\w).{6} \S+\t(\w{8}) (\S+)$$/\1 \2 \3 \4/g' > $@