-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathMakefile
262 lines (203 loc) · 6.96 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
#### Tools ####
ifeq ($(OS),Windows_NT)
EXE := .exe
else
EXE :=
endif
UNAME := $(shell uname)
TOOLCHAIN ?= $(DEVKITARM)
PREFIX ?= arm-none-eabi-
export PATH := $(TOOLCHAIN)/bin:$(PATH)
ifeq ($(UNAME),Darwin)
SHELL := env PATH=$(PATH) /bin/bash
endif
CPP ?= $(PREFIX)cpp$(EXE)
AS := $(PREFIX)as$(EXE)
LD := $(PREFIX)ld$(EXE)
OBJCOPY := $(PREFIX)objcopy$(EXE)
STRIP := $(PREFIX)strip$(EXE)
CC1 := tools/agbcc/bin/agbcc$(EXE)
CC1_OLD := tools/agbcc/bin/old_agbcc$(EXE)
BIN2C := tools/bin2c/bin2c$(EXE)
GBAGFX := tools/gbagfx/gbagfx$(EXE)
SCANINC := tools/scaninc/scaninc$(EXE)
AIF2PCM := tools/aif2pcm/aif2pcm$(EXE)
MID2AGB := tools/mid2agb/mid2agb$(EXE)
TEXTENCODE := tools/textencode/textencode$(EXE)
JSONPROC := tools/jsonproc/jsonproc$(EXE)
FETSATOOL := scripts/gfxtools/tsa_generator.py
ifeq ($(UNAME),Darwin)
SED := sed -i ''
else
SED := sed -i
endif
ifeq ($(UNAME),Darwin)
SHASUM := shasum
else
SHASUM := sha1sum
endif
CC1FLAGS := -mthumb-interwork -Wimplicit -Wparentheses -Werror -O2 -fhex-asm -ffix-debug-line -g
CPPFLAGS := -I tools/agbcc/include -iquote include -iquote . -nostdinc -undef
ASFLAGS := -mcpu=arm7tdmi -mthumb-interwork -I include
#### Files ####
C_SUBDIR = src
ASM_SUBDIR = asm
DATA_SUBDIR = data
DATA_SRC_SUBDIR = src/data
SAMPLE_SUBDIR = sound/direct_sound_samples
MID_SUBDIR = sound/songs/midi
ROM := fireemblem8.gba
ELF := $(ROM:.gba=.elf)
MAP := $(ROM:.gba=.map)
LDSCRIPT := ldscript.txt
SYM_FILES := sym_iwram.txt
CFILES_GENERATED := $(C_SUBDIR)/msg_data.c
CFILES := $(wildcard $(C_SUBDIR)/*.c)
ifeq (,$(findstring $(CFILES_GENERATED),$(CFILES)))
CFILES += $(CFILES_GENERATED)
endif
ASM_S_FILES := $(wildcard $(ASM_SUBDIR)/*.s)
SRC_S_FILES := src/rom_header.s src/crt0.s src/m4a_1.s src/libagbsyscall.s
DATA_S_FILES := $(wildcard $(DATA_SUBDIR)/*.s)
SOUND_S_FILES := $(wildcard sound/*.s sound/songs/*.s sound/songs/mml/*.s sound/voicegroups/*.s)
SFILES := $(ASM_S_FILES) $(SRC_S_FILES) $(DATA_S_FILES) $(SOUND_S_FILES)
SFILES_COMPILED := $(CFILES:.c=.s)
C_OBJECTS := $(CFILES:.c=.o)
ASM_OBJECTS := $(SFILES:.s=.o)
BANIM_OBJECT := data/banim/data_banim.o
MID_FILES := $(wildcard $(MID_SUBDIR)/*.mid)
MID_OBJECTS := $(MID_FILES:.mid=.o)
ALL_OBJECTS := $(C_OBJECTS) $(ASM_OBJECTS) $(BANIM_OBJECT) $(MID_OBJECTS)
OBJECTS_LST := objects.lst
DEPS_DIR := .dep
AUTO_GEN_TARGETS :=
# Use the older compiler to build library code
src/agb_sram.o: CC1FLAGS := -mthumb-interwork -Wimplicit -Wparentheses -Werror -O1 -ffix-debug-line -g
src/m4a.o: CC1 := $(CC1_OLD)
# TODO: find a more elegant solution to the inlining issue
src/bmitem.o: CC1FLAGS += -Wno-error
#### Main Targets ####
compare: $(ROM)
$(SHASUM) -c checksum.sha1
.PHONY: compare
clean:
$(RM) $(ROM) $(ELF) $(MAP) $(ALL_OBJECTS) $(OBJECTS_LST) $(SFILES_COMPILED) graphics/*.h $(CFILES_GENERATED)
$(RM) -rf $(DEPS_DIR)
# Remove battle animation binaries
$(RM) -f data/banim/*.bin data/banim/*.o data/banim/*.lz data/banim/*.bak
# Remove converted sound samples
$(RM) -f $(SAMPLE_SUBDIR)/*.bin
# Remove converted songs
$(RM) -f $(MID_SUBDIR)/*.s
$(RM) -f $(AUTO_GEN_TARGETS)
@find . \( -iname '*.o' -o -iname '*.obj' -o -iname '*.feimg1.bin' -o -iname '*.fetsa1.bin' -o -iname '*.1bpp' -o -iname '*.4bpp' -o -iname '*.8bpp' -o -iname '*.gbapal' -o -iname '*.lz' -o -iname '*.fk' -o -iname '*.latfont' -o -iname '*.hwjpnfont' -o -iname '*.fwjpnfont' \) -exec rm {} +
.PHONY: clean
tag:
gtags
ctags -R
cscope -Rbkq
.PHONY: tag
#### Recipes ####
# Comprssed Texts Recipes
# =========
# = Texts =
# =========
TEXT_DIR := texts
TEXT_TOOLS := scripts/texttools
TEXT_DECODER := $(PYTHON) $(TEXT_TOOLS)/textdecoder.py
TEXT_DPARSER := $(PYTHON) $(TEXT_TOOLS)/textdeparser.py
TEXT_PROCESS := $(PYTHON) $(TEXT_TOOLS)/textprocess.py
TEXT_MAIN := $(TEXT_DIR)/texts.txt
TEXT_DEFS := $(TEXT_DIR)/textdefs.txt
TEXT_SRC := $(TEXT_MAIN) $(shell find $(TEXT_DIR) -type f -name "*.txt")
TEXT_HEADER := include/constants/msg.h
MSG_LIST := src/msg_data.c
src/msg_data.c: $(TEXT_SRC) $(TEXT_DEFS)
@$(TEXT_PROCESS) $(TEXT_MAIN) $(TEXT_DEFS) $@ $(TEXT_HEADER) utf8
# Graphics Recipes
include graphics_file_rules.mk
include songs.mk
include json_data_rules.mk
%.s: ;
%.png: ;
%.pal: ;
%.aif: ;
%.1bpp: %.png ; $(GBAGFX) $< $@
%.4bpp: %.png ; $(GBAGFX) $< $@
%.8bpp: %.png ; $(GBAGFX) $< $@
%.gbapal: %.pal ; $(GBAGFX) $< $@
%.gbapal: %.png ; $(GBAGFX) $< $@
%.lz: % ; $(GBAGFX) $< $@
%.rl: % ; $(GBAGFX) $< $@
%.fk: % ; ./scripts/compressor.py $< fk
sound/%.bin: sound/%.aif ; $(AIF2PCM) $< $@
%.4bpp.h: %.4bpp
$(BIN2C) $< $(subst .,_,$(notdir $<)) | sed 's/^const //' > $@
%.feimg1.bin %.fetsa1.bin: %.png
$(FETSATOOL) $< $*.feimg1.bin $*.fetsa1.bin
# Battle Animation Recipes
$(BANIM_OBJECT): $(shell ./scripts/arm_compressing_linker.py -t linker_script_banim.txt -m)
./scripts/arm_compressing_linker.py -o $@ -t linker_script_banim.txt -b 0x8c02000 -l $(LD) --objcopy $(OBJCOPY) -c ./scripts/compressor.py
%_modes.bin: %_motion.o
$(OBJCOPY) -O binary -j .data.modes $< $@
%_oam_l.bin: %_motion.o
$(OBJCOPY) -O binary -j .data.oam_l $< $@
%_oam_r.bin: %_motion.o
$(OBJCOPY) -O binary -j .data.oam_r $< $@
# Automatic dependency generation
MAKEDEP = mkdir -p $(DEPS_DIR)/$(dir $*) && $(CPP) $(CPPFLAGS) $< -MM -MG -MT $*.o > $(DEPS_DIR)/$*.d
MAKECMDGOALS_NODEP := clean tag
ifeq (,$(filter $(MAKECMDGOALS),$(MAKECMDGOALS_NODEP)))
-include $(addprefix $(DEPS_DIR)/,$(CFILES:.c=.d))
endif
$(DEPS_DIR)/%.d: %.c
@$(MAKEDEP)
$(OBJECTS_LST): $(ALL_OBJECTS)
@echo $(ALL_OBJECTS) > $@
$(ELF): $(ALL_OBJECTS) $(OBJECTS_LST) $(LDSCRIPT) $(SYM_FILES)
$(LD) -T $(LDSCRIPT) -Map $(MAP) @$(OBJECTS_LST) -R $(BANIM_OBJECT).sym.o -L tools/agbcc/lib -o $@ -lc -lgcc
$(STRIP) -N .gcc2_compiled. $@
%.gba: %.elf
$(OBJCOPY) --strip-debug -O binary --pad-to 0x9000000 --gap-fill=0xff $< $@
$(C_OBJECTS): %.o: %.c $(DEPS_DIR)/%.d
@$(MAKEDEP)
$(CPP) $(CPPFLAGS) $< | iconv -f UTF-8 -t CP932 | $(CC1) $(CC1FLAGS) -o $*.s
echo '.ALIGN 2, 0' >> $*.s
ifeq ($(UNAME),Darwin)
$(SED) -f scripts/align_2_before_debug_section_for_osx.sed $*.s
else
$(SED) '/.section .debug_line/i\.align 2, 0' $*.s
endif
$(AS) $(ASFLAGS) $*.s -o $@
ifeq ($(NODEP),1)
asm/%.o: data_dep :=
else
asm/%.o: data_dep = $(shell $(SCANINC) -I include -I "" $*.s)
endif
ifeq ($(NODEP),1)
src/%.o: data_dep :=
else
src/%.o: data_dep = $(shell $(SCANINC) -I include -I "" $*.s)
endif
ifeq ($(NODEP),1)
data/%.o: data_dep :=
else
data/%.o: data_dep = $(shell $(SCANINC) -I include -I "" $*.s)
endif
ifeq ($(NODEP),1)
banim/%.o: data_dep :=
else
banim/%.o: data_dep = $(shell $(SCANINC) -I include -I "" $*.s)
endif
ifeq ($(NODEP),1)
sound/%.o: data_dep :=
else
sound/%.o: data_dep = $(shell $(SCANINC) -I include -I "" $*.s)
endif
.SECONDEXPANSION:
$(ASM_OBJECTS): %.o: %.s $$(data_dep)
$(AS) $(ASFLAGS) -g $< -o $@
# Don't delete intermediate files
.SECONDARY:
# debug print, to use, call "make print-(your label here)"
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true