-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
209 lines (165 loc) · 6.88 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
include $(DEVKITARM)/base_tools
include config.mk
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
#### Tools ####
SHELL := /bin/bash -o pipefail
AS := $(PREFIX)as
CC1 := tools/agbcc/bin/agbcc$(EXE)
CPP := $(PREFIX)cpp
LD := $(PREFIX)ld
OBJCOPY := $(PREFIX)objcopy
SHA1SUM := sha1sum -c
GBAGFX := tools/gbagfx/gbagfx$(EXE)
RSFONT := tools/rsfont/rsfont$(EXE)
AIF2PCM := tools/aif2pcm/aif2pcm$(EXE)
MID2AGB := tools/mid2agb/mid2agb$(EXE)
PREPROC := tools/preproc/preproc$(EXE)
SCANINC := tools/scaninc/scaninc$(EXE)
RAMSCRGEN := tools/ramscrgen/ramscrgen$(EXE)
GBAFIX := tools/gbafix/gbafix$(EXE)
MAPJSON := tools/mapjson/mapjson$(EXE)
ASFLAGS := -mcpu=arm7tdmi -I include --defsym $(GAME_VERSION)=1 --defsym REVISION=$(GAME_REVISION) --defsym $(GAME_LANGUAGE)=1 --defsym DEBUG=$(DEBUG)
CC1FLAGS := -mthumb-interwork -Wimplicit -Wparentheses -Wunused -Werror -O2 -fhex-asm
CPPFLAGS := -I tools/agbcc/include -iquote include -nostdinc -undef -Werror -Wno-trigraphs -D $(GAME_VERSION) -D REVISION=$(GAME_REVISION) -D $(GAME_LANGUAGE) -D DEBUG=$(DEBUG)
#### Files ####
ROM := poke$(BUILD_NAME).gba
MAP := $(ROM:%.gba=%.map)
BUILD_DIR := build/$(BUILD_NAME)
C_SOURCES := $(wildcard src/*.c src/*/*.c src/*/*/*.c)
ASM_SOURCES := $(wildcard src/*.s src/*/*.s asm/*.s data/*.s sound/*.s sound/*/*.s)
C_OBJECTS := $(addprefix $(BUILD_DIR)/, $(C_SOURCES:%.c=%.o))
ASM_OBJECTS := $(addprefix $(BUILD_DIR)/, $(ASM_SOURCES:%.s=%.o))
ALL_OBJECTS := $(C_OBJECTS) $(ASM_OBJECTS)
SUBDIRS := $(sort $(dir $(ALL_OBJECTS)))
LIBC := tools/agbcc/lib/libc.a
LIBGCC := tools/agbcc/lib/libgcc.a
LDFLAGS := -L ../../tools/agbcc/lib -lgcc -lc
LD_SCRIPT := $(BUILD_DIR)/ld_script.ld
# Special configurations required for lib files
%src/libs/siirtc.o: CC1FLAGS := -mthumb-interwork
%src/libs/agb_flash.o: CC1FLAGS := -O1 -mthumb-interwork
%src/libs/agb_flash_1m.o: CC1FLAGS := -O1 -mthumb-interwork
%src/libs/agb_flash_mx.o: CC1FLAGS := -O1 -mthumb-interwork
%src/libs/m4a.o: CC1 := tools/agbcc/bin/old_agbcc$(EXE)
%src/libs/libisagbprn.o: CC1 := tools/agbcc/bin/old_agbcc$(EXE)
%src/libs/libisagbprn.o: CC1FLAGS := -mthumb-interwork
#### Main Rules ####
ALL_BUILDS := ruby ruby_rev1 ruby_rev2 sapphire sapphire_rev1 sapphire_rev2 ruby_de sapphire_de ruby_de_debug
# Available targets
.PHONY: all clean tidy tools $(ALL_BUILDS)
infoshell = $(foreach line, $(shell $1 | sed "s/ /__SPACE__/g"), $(info $(subst __SPACE__, ,$(line))))
# Build tools when building the rom
# Disable dependency scanning for clean/tidy/tools
ifeq (,$(filter-out all,$(MAKECMDGOALS)))
$(call infoshell, $(MAKE) tools)
else
NODEP := 1
endif
# Disable dependency scanning when NODEP is used for quick building
ifeq ($(NODEP),)
$(BUILD_DIR)/src/%.o: C_FILE = $(*D)/$(*F).c
$(BUILD_DIR)/src/%.o: C_DEP = $(shell $(SCANINC) -I include $(C_FILE:$(BUILD_DIR)/=))
$(BUILD_DIR)/asm/%.o: ASM_DEP = $(shell $(SCANINC) asm/$(*F).s)
$(BUILD_DIR)/data/%.o: ASM_DEP = $(shell $(SCANINC) data/$(*F).s)
endif
MAKEFLAGS += --no-print-directory
# Secondary expansion is required for dependency variables in object rules.
.SECONDEXPANSION:
# Clear the default suffixes
.SUFFIXES:
# Don't delete intermediate files
.SECONDARY:
# Delete files that weren't built properly
.DELETE_ON_ERROR:
# Create build subdirectories
$(shell mkdir -p $(SUBDIRS))
all: $(ROM)
ifeq ($(COMPARE),1)
# @$(SHA1SUM) $(BUILD_NAME).sha1
endif
clean: tidy
find sound/direct_sound_samples \( -iname '*.bin' \) -exec rm {} +
$(RM) $(ALL_OBJECTS)
find . \( -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.rl' \) -exec rm {} +
rm -f data/layouts/layouts.inc data/layouts/layouts_table.inc
rm -f data/maps/connections.inc data/maps/events.inc data/maps/groups.inc data/maps/headers.inc
find data/maps \( -iname 'connections.inc' -o -iname 'events.inc' -o -iname 'header.inc' \) -exec rm {} +
$(MAKE) clean -C tools/gbagfx
$(MAKE) clean -C tools/scaninc
$(MAKE) clean -C tools/preproc
$(MAKE) clean -C tools/bin2c
$(MAKE) clean -C tools/rsfont
$(MAKE) clean -C tools/aif2pcm
$(MAKE) clean -C tools/ramscrgen
$(MAKE) clean -C tools/gbafix
$(MAKE) clean -C tools/mapjson
tools:
@$(MAKE) -C tools/gbagfx
@$(MAKE) -C tools/scaninc
@$(MAKE) -C tools/preproc
@$(MAKE) -C tools/bin2c
@$(MAKE) -C tools/rsfont
@$(MAKE) -C tools/aif2pcm
@$(MAKE) -C tools/ramscrgen
@$(MAKE) -C tools/mid2agb
@$(MAKE) -C tools/gbafix
@$(MAKE) -C tools/mapjson
tidy:
$(RM) $(ALL_BUILDS:%=poke%{.gba,.elf,.map})
$(RM) -r build
$(ROM): %.gba: %.elf
$(OBJCOPY) -O binary --gap-fill 0xFF --pad-to 0x9000000 $< $@
$(GBAFIX) $@ -p -t"$(TITLE)" -c$(GAME_CODE) -m$(MAKER_CODE) -r$(GAME_REVISION) --silent
%.elf: $(LD_SCRIPT) $(ALL_OBJECTS)
cd $(BUILD_DIR) && $(LD) -T ld_script.ld -Map ../../$(MAP) -o ../../$@ $(LDFLAGS)
$(LD_SCRIPT): ld_script.txt $(BUILD_DIR)/sym_common.ld $(BUILD_DIR)/sym_ewram.ld $(BUILD_DIR)/sym_bss.ld
cd $(BUILD_DIR) && sed -e "s#tools/#../../tools/#g" ../../ld_script.txt >ld_script.ld
$(BUILD_DIR)/sym_%.ld: sym_%.txt
$(CPP) -P $(CPPFLAGS) $< | sed -e "s#tools/#../../tools/#g" > $@
$(C_OBJECTS): $(BUILD_DIR)/%.o: %.c $$(C_DEP)
$(CPP) $(CPPFLAGS) $< -o $(BUILD_DIR)/$*.i
$(PREPROC) $(BUILD_DIR)/$*.i charmap.txt | $(CC1) $(CC1FLAGS) -o $(BUILD_DIR)/$*.s
@printf ".text\n\t.align\t2, 0\n" >> $(BUILD_DIR)/$*.s
@$(AS) $(ASFLAGS) -W -o $@ $(BUILD_DIR)/$*.s
# Only .s files in data need preproc
$(BUILD_DIR)/data/%.o: data/%.s $$(ASM_DEP)
$(PREPROC) $< charmap.txt | $(CPP) -I include | $(AS) $(ASFLAGS) -o $@
$(BUILD_DIR)/%.o: %.s $$(ASM_DEP)
$(AS) $(ASFLAGS) $< -o $@
# "friendly" target names for convenience sake
ruby: ; @$(MAKE) GAME_VERSION=RUBY
ruby_rev1: ; @$(MAKE) GAME_VERSION=RUBY GAME_REVISION=1
ruby_rev2: ; @$(MAKE) GAME_VERSION=RUBY GAME_REVISION=2
sapphire: ; @$(MAKE) GAME_VERSION=SAPPHIRE
sapphire_rev1: ; @$(MAKE) GAME_VERSION=SAPPHIRE GAME_REVISION=1
sapphire_rev2: ; @$(MAKE) GAME_VERSION=SAPPHIRE GAME_REVISION=2
ruby_de: ; @$(MAKE) GAME_VERSION=RUBY GAME_LANGUAGE=GERMAN
sapphire_de: ; @$(MAKE) GAME_VERSION=SAPPHIRE GAME_LANGUAGE=GERMAN
ruby_de_debug: ; @$(MAKE) GAME_VERSION=RUBY GAME_LANGUAGE=GERMAN DEBUG=1
#### Graphics Rules ####
GFX_OPTS :=
include castform.mk
include tilesets.mk
include fonts.mk
include misc.mk
include spritesheet_rules.mk
include override.mk
include map_data_rules.mk
%.1bpp: %.png ; $(GBAGFX) $< $@ $(GFX_OPTS)
%.4bpp: %.png ; $(GBAGFX) $< $@ $(GFX_OPTS)
%.8bpp: %.png ; $(GBAGFX) $< $@ $(GFX_OPTS)
%.gbapal: %.pal ; $(GBAGFX) $< $@ $(GFX_OPTS)
%.gbapal: %.png ; $(GBAGFX) $< $@ $(GFX_OPTS)
%.lz: % ; $(GBAGFX) $< $@ $(GFX_OPTS)
%.rl: % ; $(GBAGFX) $< $@ $(GFX_OPTS)
#### Sound Rules ####
sound/direct_sound_samples/cries/cry_%.bin: sound/direct_sound_samples/cries/cry_%.aif
$(AIF2PCM) $< $@ --compress
sound/%.bin: sound/%.aif
$(AIF2PCM) $< $@
sound/songs/%.s: sound/songs/%.mid
cd $(@D) && ../../$(MID2AGB) $(<F)