-
Notifications
You must be signed in to change notification settings - Fork 1
/
makefile
242 lines (197 loc) · 7.54 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
AS := @arm-none-eabi-as
LD := @arm-none-eabi-ld
OBJCOPY := @arm-none-eabi-objcopy
GRIT := @grit
CC := @arm-none-eabi-gcc
ARS := @armips
MAKE := make
NM := @arm-none-eabi-nm
PREPROC := @preproc
VBA := vba
LAN := de
STRAGB := string2agb
PYTHON_BIN := $(shell ./python_version.sh)
PYPROJS := pyproj2s.py
PYMAPS := pymap2s.py
PYSETS := pyset2s.py
# we don't need those anymore I think
# export PATH := $(realpath ../tools):$(PATH)
export GCC_COLORS := error=01;31:warning=01;35:note=01;36:range1=32:range2=34:locus=01:quote=01:fixit-insert=32:fixit-delete=31:diff-filename=01:diff-hunk=32:diff-delete=31:diff-insert=32
PAGB_MAIN := g3headers
PAGB_INCLUDE := $(PAGB_MAIN)/build/include
PAGB_LINK := $(PAGB_MAIN)/build/linker/BPRE.ld
AUTO_ASSET_ROOT := sots-private/assets/images
CHARMAP := charmap.txt
DEFINES := -DBPRE -DSOFTWARE_VERSION=0 -DLAN_DE
ASFLAGS := -mthumb
CFLAGS := -mthumb -mthumb-interwork -g -mcpu=arm7tdmi -fdiagnostics-show-option -mlong-calls -march=armv4t -Og -std=c11 -Wall -Wextra -Wunreachable-code -I$(PAGB_INCLUDE) -Isrc/include -Igenerated_image -fdiagnostics-color=always $(DEFINES)
GRITFLAGS := -ftc -fa
LDFLAGS := -z muldefs
BLDPATH := object
OUTPATH := build
SOURCEDIR := src
STRINGDIR := string
MAPROOT := sots-private/map
MAPMAPS := $(MAPROOT)/maps
MAPTS := $(MAPROOT)/tileset
MAP_PROJ := $(MAPROOT)/sots.json
SCRIPTROOT := $(MAPROOT)/script
PDATAROOT := sots-private/data
MAIN_OBJ := $(BLDPATH)/linked.o
B_ENGINE := battle_engine/build/linked.o
SPRITES := $(BLDPATH)/pkmn_sprites.o
DYN_OVER := built/dynamic_overworld.o
TMP_LD := tmp.ld
SND_ROOT := assets/sound
MUSIC_AR := $(SND_ROOT)/Music/music.a
SMPL_AR := $(SND_ROOT)/Samples/sample.a
VOICE_AR := $(SND_ROOT)/Voicegroup/voice.a
LIST_AR := $(SND_ROOT)/Songtable/songlist.a
CRY_AR := $(SND_ROOT)/Crys/cry.a
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
IMAGES=$(call rwildcard,$(AUTO_ASSET_ROOT),*.png)
TSPNG=$(call rwildcard,$(MAPTS)/,*.png)
TS_GEN_SRC := $(TSPNG:%.png=%.s)
TS_GEN_O := $(TSPNG:%.png=$(BLDPATH)/%.o)
GEN_SRC := $(IMAGES:$(AUTO_ASSET_ROOT)/%.png=generated_image/%.c)
GEN_H := $(IMAGES:$(AUTO_ASSET_ROOT)/%.png=generated_image/%.h)
ASM_SRC := $(call rwildcard,src/,*.s)
C_SRC := $(call rwildcard,src/,*.c)
DATA_SRC := $(call rwildcard,data/,*.s)
STRING := $(call rwildcard,string/$(LAN)/,*.txt)
STRING_SRC := $(STRING:%.txt=%.s)
SCRIPT_SRC := $(call rwildcard,$(SCRIPTROOT)/,*.s)
PDATA_SRC := $(call rwildcard,$(PDATAROOT)/,*.c)
MAP_PROJ_S := $(MAP_PROJ:%.json=%.s)
MAP_PROJ_O := $(MAP_PROJ:%.json=$(BLDPATH)/%.o)
MAP_FILES := $(call rwildcard,$(MAPMAPS)/,*.pmh)
MAP_FILES_S := $(MAP_FILES:%.pmh=%.s)
MAP_FILES_O := $(MAP_FILES:%.pmh=$(BLDPATH)/%.o)
TS_FILES := $(call rwildcard,$(MAPTS)/,*.pts)
TS_FILES_S := $(TS_FILES:%.pts=%.s)
TS_FILES_O := $(TS_FILES:%.pts=$(BLDPATH)/%.o)
GEN_OBJ := $(GEN_SRC:%.c=$(BLDPATH)/%.o)
STRING_OBJ := $(STRING_SRC:%.s=$(BLDPATH)/%.o)
ASM_OBJ := $(ASM_SRC:%.s=$(BLDPATH)/%.o)
C_OBJ := $(C_SRC:%.c=$(BLDPATH)/%.o)
DATA_OBJ := $(DATA_SRC:%.s=$(BLDPATH)/%.o)
SCRIPT_OBJ := $(SCRIPT_SRC:%.s=$(BLDPATH)/%.o)
PDATA_OBJ := $(PDATA_SRC:%.c=$(BLDPATH)/%.o)
ALL_OBJ := $(GEN_OBJ) $(C_OBJ) $(ASM_OBJ) $(DATA_OBJ) $(STRING_OBJ) $(SCRIPT_OBJ) $(MAP_PROJ_O) $(MAP_FILES_O) $(TS_FILES_O) $(TS_GEN_O) $(PDATA_OBJ)
$(MAPMAPS)/%.s: $(MAPMAPS)/%.pmh
@printf "\e[1;33mGenerating map\e[0m $<\n"
$(PYMAPS) -o $@ $< $(MAP_PROJ)
$(MAPTS)/%.s: $(MAPTS)/%.pts
@printf "\e[1;33mGenerating tileset\e[0m $<\n"
$(PYSETS) -o $@ $<
$(BLDPATH)/sots-private/data/%.o: $(PDATAROOT)/%.c
@printf "\e[1;31mCompiling\e[0m $<\n"
$(shell mkdir -p $(dir $@))
$(CC) $(CFLAGS) -E -x c $< -o $(PDATAROOT)/$*.i
$(PREPROC) $(PDATAROOT)/$*.i $(CHARMAP) > $(PDATAROOT)/$*.ci
$(CC) $(CFLAGS) -c -x c $(PDATAROOT)/$*.ci -o $@
@rm -f $(PDATAROOT)/$*.ci $(PDATAROOT)/$*.i
$(BLDPATH)/%.o: %.c $(ASSETS) $(PAGB_INCLUDE)/pokeagb/pokeagb.h
@printf "\e[1;31mCompiling\e[0m $<\n"
$(shell mkdir -p $(dir $@))
$(CC) $(CFLAGS) -c $< -o $@
$(BLDPATH)/%.o: %.s $(PAGB_INCLUDE)/pokeagb/pokeagb.h
@printf "\e[1;31mAssembling\e[0m $<\n"
$(shell mkdir -p $(dir $@))
$(PREPROC) $< $(CHARMAP) > $*.i
$(CC) $(CFLAGS) -c -x assembler-with-cpp $*.i -o $@
@rm -f $*.i
$(MAPTS)/%.s: $(MAPTS)/%.png
@printf "\e[1;33mProcessing image (tileset)\e[0m $<\n"
$(GRIT) $< -o $@ -fts -gzl -pz! -pu16 -gB4 -m! -mR!
generated_image/%.c generated_image/%.h: $(AUTO_ASSET_ROOT)/%.png $(AUTO_ASSET_ROOT)/%.grit
@printf "\e[1;33mProcessing image\e[0m $<\n"
$(shell mkdir -p $(dir $@))
$(GRIT) $< -o $@ -ftc -ff $(<:%.png=%.grit)
generated_image/%.c generated_image/%.h: $(AUTO_ASSET_ROOT)/%.png
@printf "\e[1;33mProcessing image (using directory grit file)\e[0m $<\n"
$(shell mkdir -p $(dir $@))
$(GRIT) $< -o $@ -ftc -ff $(<D)/$(notdir $(<D)).grit
all: src/include/pymap_constants.h $(GEN_H) rom
.PHONY: rom
rom: main.asm $(MAIN_OBJ)
@printf "\e[1;30;41mCreating ROM\e[0m\n"
$(ARS) $<
$(NM) $(BLDPATH)/linked.o -n -g --defined-only | \
sed -e '{s/^/0x/g};{/.*\sA\s.*/d};{s/\sT\s/ /g}' > $(OUTPATH)/__symbols.sym
@echo "*** SUCCESSFULLY BUILT PROJECT ***"
@echo "*** REMOVING INTERMEDIATE FILES ***"
$(MAIN_OBJ): $(ALL_OBJ) $(SPRITES) $(MUSIC_AR) $(SMPL_AR) $(VOICE_AR) $(LIST_AR) $(CRY_AR) #$(B_ENGINE)
$(MAKE) -f assets.makefile
@printf "\e[1;30;41mLinking ELF binary\e[0m $@\n"
@echo "INPUT($^)" > $(TMP_LD)
$(LD) $(LDFLAGS) -T $(PAGB_LINK) -T linker.ld -T bpre.sym --whole-archive -r -o $@ --start-group -T $(TMP_LD) --end-group
$(LD) $(LDFLAGS) -T $(PAGB_LINK) -T linker.ld -T bpre.sym --whole-archive -o [email protected] --start-group -T $(TMP_LD) --end-group
@rm -f $(TMP_LD)
$(MAP_PROJ_S): $(MAP_PROJ)
@printf "\e[1;33mGenerating map project\e[0m $<\n"
$(PYPROJS) -b sovereign_banks -f sovereign_footer -o $@ $<
.PHONY: $(B_ENGINE)
$(B_ENGINE):
$(MAKE) -C battle_engine build/linked.o PAGB_INCLUDE=../$(PAGB_MAIN)/build
.PHONY: cleansrcdatascript
cleansrcdatascript:
rm -rf object/src/*
rm -rf object/data/*
rm -rf object/sots-private/map/script/*
.PHONY: clean
clean: cleansnd
rm -f $(OUTPATH)/__symbols.sym $(OUTPATH)/pkmn_sots.gba
rm -rf generated_image/*
rm -R -f object/*
$(MAKE) -f sprites.makefile clean
.PHONY: cleansnd
cleansnd:
$(MAKE) -C $(dir $(MUSIC_AR)) clean
$(MAKE) -C $(dir $(SMPL_AR)) clean
$(MAKE) -C $(dir $(VOICE_AR)) clean
$(MAKE) -C $(dir $(LIST_AR)) clean
$(MAKE) -C $(dir $(CRY_AR)) clean
.PHONY: cleannogfx
cleannogfx:
rm -f $(OUTPATH)/__symbols.sym $(OUTPATH)/pkmn_sots.gba
rm -rf generated_image/*
rm -R -f object/*
$(MAKE) -C $(dir $(MUSIC_AR)) clean
$(MAKE) -C $(dir $(SMPL_AR)) clean
$(MAKE) -C $(dir $(VOICE_AR)) clean
$(MAKE) -C $(dir $(LIST_AR)) clean
$(MAKE) -C $(dir $(CRY_AR)) clean
.PHONY: $(ASSETS)
$(ASSETS):
@printf "\e[1;33mMaking Assets\e[0m\n"
$(MAKE) -f assets.makefile
.PHONY: $(SPRITES)
$(SPRITES):
@printf "\e[1,33mMaking Sprites\e[0m\n"
$(MAKE) -f sprites.makefile
.PHONY: $(MUSIC_AR)
$(MUSIC_AR):
@printf "\e[1,32mMaking Music\e[0m\n"
$(MAKE) -C $(dir $@) all
.PHONY: $(SMPL_AR)
$(SMPL_AR):
@printf "\e[1,32mMaking Sampler\e[0m\n"
$(MAKE) -C $(dir $@) all
.PHONY: $(VOICE_AR)
$(VOICE_AR):
@printf "\e[1,32mMaking Voice\e[0m\n"
$(MAKE) -C $(dir $@) all
.PHONY: $(LIST_AR)
$(LIST_AR):
@printf "\e[1,32mMaking Songlist\e[0m\n"
$(MAKE) -C $(dir $@) all
.PHONY: $(CRY_AR)
$(CRY_AR):
@printf "\e[1,32mMaking Cries\e[0m\n"
$(MAKE) -C $(dir $@) all
run: rom
$(VBA) "build/pkmn_sots.gba"
src/include/pymap_constants.h: sots-private/map/sots.json.constants sots-private/map/sots.json.config
pymapconstex.py sots-private/map/sots.json
$(shell ./generate_pymap_header.sh)