forked from BluRosie/hg-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
414 lines (317 loc) · 12.3 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
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
# Makefile
MAC = $(shell uname -s | grep -i -q 'darwin'; echo $$?)
ifneq ($(MAC), 0)
# see if on msys2, but only if not on mac because /proc/version doesn't exist there
MSYS2 = $(shell grep -i -q 'msys' /proc/version; echo $$?)
else
MSYS2 = 1
endif
# environment setting
# get rid of devkitpro: if devkitpro is installed, can still use it. otherwise, default to arm-none-eabi tools
ifeq ($(shell echo $$DEVKITARM),)
ifeq ($(MSYS2), 0)
PREFIX = /mingw64/bin/arm-none-eabi-
AS = $(PREFIX)as
CC = $(PREFIX)gcc
LD = $(PREFIX)ld
OBJCOPY = $(PREFIX)objcopy
else
PREFIX = arm-none-eabi-
AS = $(PREFIX)as
CC = $(PREFIX)gcc
LD = $(PREFIX)ld
OBJCOPY = $(PREFIX)objcopy
endif
else
# support legacy devkitpro instructions
PREFIX = bin/arm-none-eabi-
AS = $(DEVKITARM)/$(PREFIX)as
CC = $(DEVKITARM)/$(PREFIX)gcc
LD = $(DEVKITARM)/$(PREFIX)ld
OBJCOPY = $(DEVKITARM)/$(PREFIX)objcopy
endif
PYTHON = python3
.PHONY: clean all
ifeq ($(MSYS2), 0)
CSC := csc
else
CSC := mcs -pkg:dotnet
endif
default: all
ROMNAME = rom.nds
BUILDROM = test.nds
####################### Tools #######################
ADPCMXQ := tools/adpcm-xq
ARMIPS := tools/armips
BLZ := tools/blz
BTX_EXE := tools/pngtobtx0.exe
BTX := mono $(BTX_EXE)
ENCODEPWIMG := tools/ENCODE_IMG
GFX := tools/nitrogfx
MSGENC := tools/msgenc
NARCHIVE := $(PYTHON) tools/narcpy.py
NDSTOOL := tools/ndstool
NTRWAVTOOL := $(PYTHON) tools/ntrWavTool.py
O2NARC := tools/o2narc
SDATTOOL := $(PYTHON) tools/SDATTool.py
SWAV2SWAR_EXE := tools/swav2swar.exe
SWAV2SWAR := mono $(SWAV2SWAR_EXE)
# Compiler/Assembler/Linker settings
LDFLAGS = rom.ld -T linker.ld
ASFLAGS = -mthumb -I ./data
CFLAGS = -mthumb -mno-thumb-interwork -mcpu=arm7tdmi -mtune=arm7tdmi -mno-long-calls -march=armv4t -Wall -Wextra -Wno-builtin-declaration-mismatch -Wno-sequence-point -Wno-address-of-packed-member -Os -fira-loop-pressure -fipa-pta
####################### Output #######################
C_SUBDIR = src
ASM_SUBDIR = asm
INCLUDE_SUBDIR = include
BUILD := build
BUILD_NARC := $(BUILD)/narc
BASE := base
FILESYS := $(BASE)/root
LINK = $(BUILD)/linked.o
OUTPUT = $(BUILD)/output.bin
INCLUDE_SRCS := $(wildcard $(INCLUDE_SUBDIR)/*.h)
C_SRCS := $(wildcard $(C_SUBDIR)/*.c)
C_OBJS := $(patsubst $(C_SUBDIR)/%.c,$(BUILD)/%.o,$(C_SRCS))
ASM_SRCS := $(wildcard $(ASM_SUBDIR)/*.s)
ASM_OBJS := $(patsubst $(ASM_SUBDIR)/%.s,$(BUILD)/%.d,$(ASM_SRCS))
OBJS := $(C_OBJS) $(ASM_OBJS)
## includes
include data/graphics/pokegra.mk
include data/itemdata/itemdata.mk
include data/codetables.mk
include narcs.mk
include overlays.mk
####################### Build Tools #######################
MSGENC_SOURCES := $(wildcard tools/source/msgenc/*.cpp) $(wildcard tools/source/msgenc/*.h)
$(MSGENC): tools/source/msgenc/*
cd tools/source/msgenc ; $(MAKE)
mv tools/source/msgenc/msgenc tools/msgenc
TOOLS += $(MSGENC)
BTX_SOURCES := $(wildcard tools/source/BTXEditor/*.cs)
$(BTX_EXE): $(BTX_SOURCES)
cd tools ; $(CSC) /target:exe /out:pngtobtx0.exe "source/BTXEditor/Program-P.cs" "source/BTXEditor/pngtobtx0.cs" "source/BTXEditor/BTX0.cs"
TOOLS += $(BTX_EXE)
$(SWAV2SWAR_EXE): tools/source/swav2swar/Principal.cs
cd tools ; $(CSC) /target:exe /out:swav2swar.exe "source/swav2swar/Principal.cs"
TOOLS += $(SWAV2SWAR_EXE)
$(NDSTOOL):
ifeq (,$(wildcard $(NDSTOOL)))
ifeq ($(MSYS2), 0)
wget -O $(NDSTOOL) https://github.com/AdAstra-LD/DS-Pokemon-Rom-Editor/raw/main/DS_Map/Tools/ndstool.exe
else
rm -r -f tools/source/ndstool
cd tools/source ; git clone https://github.com/devkitPro/ndstool.git
cd tools/source/ndstool ; git checkout fa6b6d01881363eb2cd6e31d794f51440791f336
cd tools/source/ndstool ; find . -name '*.sh' -execdir chmod +x {} \;
cd tools/source/ndstool ; ./autogen.sh
cd tools/source/ndstool ; ./configure && $(MAKE)
mv tools/source/ndstool/ndstool tools/ndstool
rm -r -f tools/source/ndstool
endif
endif
TOOLS += $(NDSTOOL)
$(ARMIPS):
ifeq (,$(wildcard $(ARMIPS)))
ifeq ($(MSYS2), 0)
wget -O $(ARMIPS).7z https://github.com/Kingcom/armips/releases/download/v0.11.0/armips-v0.11.0-windows-x86.7z
cd tools; p7zip -d armips.7z; rm -f Readme.md
else
rm -r -f tools/source/armips
cd tools/source ; git clone --recursive https://github.com/Kingcom/armips.git
cd tools/source/armips ; mkdir build
cd tools/source/armips/build ; cmake -DCMAKE_BUILD_TYPE=Release ..
cd tools/source/armips/build ; cmake --build .
mv tools/source/armips/build/armips tools/armips
rm -r -f tools/source/armips
endif
endif
TOOLS += $(ARMIPS)
$(ADPCMXQ):
ifeq (,$(wildcard $(ARMIPS)))
rm -r -f tools/source/adpcm-xq
cd tools/source ; git clone https://github.com/dbry/adpcm-xq.git
cd tools/source/adpcm-xq ; gcc -O2 *.c -o adpcm-xq
mv tools/source/adpcm-xq/adpcm-xq $(ADPCMXQ)
rm -r -f tools/source/adpcm-xq
endif
TOOLS += $(ADPCMXQ)
tools/ntrWavTool.py:
ifeq (,$(wildcard tools/ntrWavTool.py))
rm -r -f tools/source/ntrWavTool
cd tools/source ; git clone https://github.com/turtleisaac/ntrWavTool.git
mv tools/source/ntrWavTool/ntrWavTool.py tools/ntrWavTool.py
rm -r -f tools/source/ntrWavTool
endif
TOOLS += tools/ntrWavTool.py
NITROGFX_SOURCES := $(wildcard tools/source/nitrogfx/*.c) $(wildcard tools/source/nitrogfx/*.h)
$(GFX): $(NITROGFX_SOURCES)
cd tools/source/nitrogfx ; $(MAKE)
mv tools/source/nitrogfx/nitrogfx $(GFX)
TOOLS += $(GFX)
$(O2NARC): $(wildcard tools/source/o2narc/*.cpp) $(wildcard tools/source/o2narc/*.h)
cd tools/source/o2narc ; $(MAKE)
mv tools/source/o2narc/o2narc $(O2NARC)
TOOLS += $(O2NARC)
$(ENCODEPWIMG):
cd tools/source/DECODEIMG ; $(MAKE)
mv tools/source/DECODEIMG/ENCODE_IMG $(ENCODEPWIMG)
TOOLS += $(ENCODEPWIMG)
####################### Build #######################
rom_gen.ld:$(LINK) $(OUTPUT) rom.ld
cp rom.ld rom_gen.ld
$(PYTHON) scripts/generate_ld.py
$(BUILD)/%.d:asm/%.s
$(AS) $(ASFLAGS) -c $< -o $@
$(BUILD)/%.o:src/%.c
@mkdir -p $(BUILD) $(BUILD)/field $(BUILD)/battle $(BUILD)/pokedex $(BUILD)/individual
@echo -e "Compiling"
$(CC) $(CFLAGS) -c $< -o $@
$(LINK):$(OBJS)
$(LD) $(LDFLAGS) -o $@ $(OBJS)
$(OUTPUT):$(LINK)
$(OBJCOPY) -O binary $< $@
all: $(TOOLS) $(OUTPUT) $(OVERLAY_OUTPUTS)
rm -rf $(BASE)
mkdir -p $(BASE)
mkdir -p $(BUILD)
mkdir -p $(BUILD)/pokemonow $(BUILD)/pokemonicon $(BUILD)/pokemonpic $(BUILD)/a018 $(BUILD)/narc $(BUILD)/text $(BUILD)/move $(BUILD)/a011 $(BUILD)/rawtext
mkdir -p $(BUILD)/move/battle_sub_seq $(BUILD)/move/battle_eff_seq $(BUILD)/move/battle_move_seq $(BUILD)/move/move_anim $(BUILD)/move/move_sub_anim $(BUILD)/move/move_anim $(BUILD)/pw_pokegra $(BUILD)/pw_pokeicon $(BUILD)/pw_pokegra_int $(BUILD)/pw_pokeicon_int
###The line below is because of junk files that macOS can create which will interrupt the build process###
find . -name '*.DS_Store' -execdir rm -f {} \;
$(NDSTOOL) -x $(ROMNAME) -9 $(BASE)/arm9.bin -7 $(BASE)/arm7.bin -y9 $(BASE)/overarm9.bin -y7 $(BASE)/overarm7.bin -d $(FILESYS) -y $(BASE)/overlay -t $(BASE)/banner.bin -h $(BASE)/header.bin
@echo "$(ROMNAME) Decompression successful!!"
$(NARCHIVE) extract $(FILESYS)/a/0/2/8 -o $(BUILD)/a028/ -nf
$(PYTHON) scripts/make.py
$(MAKE) move_narc
$(ARMIPS) armips/global.s
$(NARCHIVE) create $(FILESYS)/a/0/2/8 $(BUILD)/a028/ -nf
@echo "Making ROM.."
$(NDSTOOL) -c $(BUILDROM) -9 $(BASE)/arm9.bin -7 $(BASE)/arm7.bin -y9 $(BASE)/overarm9.bin -y7 $(BASE)/overarm7.bin -d $(FILESYS) -y $(BASE)/overlay -t $(BASE)/banner.bin -h $(BASE)/header.bin
@echo "Done."
####################### Clean #######################
clean:
rm -rf $(BUILD)
rm -rf $(BASE)
clean_tools:
rm -f $(TOOLS)
clean_code:
rm -f $(OBJS) $(FIELD_OBJS) $(BATTLE_OBJS) $(POKEDEX_OBJS) $(LINK) $(OUTPUT) rom_gen.ld
####################### Debug #######################
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
####################### Final ROM Build #######################
CODE_ADDON_ARTIFACTS := $(wildcard build/a028/9_*) $(wildcard build/a028/8_1*) $(wildcard build/a028/8_2*) build/a028/8_07 build/a028/8_08 build/a028/8_09
CODE_ADDON_ARTIFACTS := $(filter-out build/a028/8_1 build/a028/8_2 build/a028/8_3 build/a028/8_4 build/a028/8_5 build/a028/8_6, $(CODE_ADDON_ARTIFACTS))
move_narc: $(NARC_FILES)
@echo "battle hud layout:"
cp $(BATTLEHUD_NARC) $(BATTLEHUD_TARGET)
@echo "move data:"
cp $(MOVEDATA_NARC) $(MOVEDATA_TARGET)
@echo "move particles:"
cp $(MOVEPARTICLES_NARC) $(MOVEPARTICLES_TARGET)
@echo "item data files:"
cp $(ITEMDATA_NARC) $(ITEMDATA_TARGET)
@echo "mon sprite data:"
cp $(POKEGRA_NARC) $(POKEGRA_TARGET)
cp $(POKEGRA_NARC) $(PBR_POKEGRA_TARGET)
@echo "opening demo files:"
cp $(OPENDEMO_NARC) $(OPENDEMO_TARGET)
@echo "mon data properties:"
cp $(MONDATA_NARC) $(MONDATA_TARGET)
@echo "sprite offsets:"
cp $(SPRITEOFFSETS_NARC) $(SPRITEOFFSETS_TARGET)
@echo "mon height offsets (a005):"
cp $(HEIGHT_NARC) $(HEIGHT_TARGET)
@echo "dex area data:"
cp $(DEXAREA_NARC) $(DEXAREA_TARGET)
@echo "pokedex sort lists:"
cp $(DEXSORT_NARC) $(DEXSORT_TARGET)
@echo "egg moves:"
cp $(EGGMOVES_NARC) $(EGGMOVES_TARGET)
cp $(EGGMOVES_NARC) $(EGGMOVES_TARGET_2)
@echo "evolution data:"
cp $(EVOS_NARC) $(EVOS_TARGET)
@echo "mon learnset data:"
cp $(LEARNSET_NARC) $(LEARNSET_TARGET)
@echo "regional dex order:"
cp $(REGIONALDEX_NARC) $(REGIONALDEX_TARGET)
@echo "trainer data:"
cp $(TRAINERDATA_NARC) $(TRAINERDATA_TARGET)
cp $(TRAINERDATA_NARC_2) $(TRAINERDATA_TARGET_2)
@echo "trainer text:"
cp $(TRAINERTEXT_NARC) $(TRAINERTEXT_TARGET)
cp $(TRAINERTEXT_NARC_2) $(TRAINERTEXT_TARGET_2)
@echo "footprints:"
cp $(FOOTPRINTS_NARC) $(FOOTPRINTS_TARGET)
@echo "move anims:"
cp $(MOVEANIM_NARC) $(MOVEANIM_TARGET)
@echo "move sub animations:"
cp $(MOVESUBANIM_NARC) $(MOVESUBANIM_TARGET)
@echo "move battle scripts:"
cp $(MOVE_SEQ_NARC) $(MOVE_SEQ_TARGET)
@echo "move battle scripts:"
cp $(BATTLE_EFF_NARC) $(BATTLE_EFF_TARGET)
@echo "battle sub effects:"
cp $(BATTLE_SUB_NARC) $(BATTLE_SUB_TARGET)
@echo "item gfx:"
cp $(ITEMGFX_NARC) $(ITEMGFX_TARGET)
@echo "dex gfx for fairy:"
cp $(DEXGFX_NARC) $(DEXGFX_TARGET)
@echo "battle gfx for fairy:"
cp $(BATTLEGFX_NARC) $(BATTLEGFX_TARGET)
@echo "otherpoke gfx for fairy:"
cp $(OTHERPOKE_NARC) $(OTHERPOKE_TARGET)
@echo "pokemon icons:"
$(ARMIPS) armips/data/iconpalettetable.s
cp $(ICONGFX_NARC) $(ICONGFX_TARGET)
@echo "wild encounters:"
cp $(ENCOUNTER_NARC) $(ENCOUNTER_TARGET)
@echo "pokemon overworlds:"
cp $(OVERWORLDS_NARC) $(OVERWORLDS_TARGET)
@echo "pokemon overworld data:"
cp $(OVERWORLD_DATA_NARC) $(OVERWORLD_DATA_TARGET)
@echo "move an updated gs_sound_data.sdat:"
cp $(SDAT_BUILD) $(SDAT_TARGET)
@echo "text data:"
cp $(MSGDATA_NARC) $(MSGDATA_TARGET)
@echo "ball spa files:"
cp $(BALL_SPA_NARC) $(BALL_SPA_TARGET)
@echo "pokewalker sprites:"
cp $(PW_POKEGRA_NARC) $(PW_POKEGRA_TARGET)
@echo "pokewalker icons:"
cp $(PW_POKEICON_NARC) $(PW_POKEICON_TARGET)
@echo "font:"
if [ $$(grep -i -c "//#define IMPLEMENT_TRANSPARENT_TEXTBOXES" include/config.h) -eq 0 ]; then cp $(FONT_NARC) $(FONT_TARGET); fi
@echo "textbox:"
if [ $$(grep -i -c "//#define IMPLEMENT_TRANSPARENT_TEXTBOXES" include/config.h) -eq 0 ]; then cp $(TEXTBOX_NARC) $(TEXTBOX_TARGET); fi
@echo "scripts:"
cp $(SCR_SEQ_NARC) $(SCR_SEQ_TARGET)
@echo "headbutt trees:"
cp $(HEADBUTT_NARC) $(HEADBUTT_TARGET)
@echo "baby mons:"
$(ARMIPS) armips/data/babymons.s
@echo "tutor moves and tm moves:"
$(PYTHON) scripts/tm_learnset.py --writetmlist armips/data/tmlearnset.txt
$(PYTHON) scripts/tutor_learnset.py --writemovecostlist armips/data/tutordata.txt
$(PYTHON) scripts/tutor_learnset.py armips/data/tutordata.txt
@if test -s build/a028/8_00; then \
rm -rf build/a028/8_0 build/a028/8_1 build/a028/8_2 build/a028/8_3 build/a028/8_4 build/a028/8_5 build/a028/8_6 build/a028/8_7 build/a028/8_8 build/a028/8_9; \
fi
@if test -s build/a028/8_7; then \
rm -rf build/a028/8_7 build/a028/8_8 build/a028/8_9; \
fi
@rm -rf $(CODE_ADDON_ARTIFACTS)
@echo "hidden ability table:"
cp $(HIDDEN_ABILITY_TABLE_BIN) $(HIDDEN_ABILITY_TABLE_TARGET)
@echo "base experience table:"
cp $(BASE_EXPERIENCE_TABLE_BIN) $(BASE_EXPERIENCE_TABLE_TARGET)
@echo "mon overworld data:"
$(ARMIPS) $(OVERWORLD_DATA_DEPENDENCIES)
@echo "species to ow gfx table:"
cp $(SPECIES_TO_OW_GFX_BIN) $(SPECIES_TO_OW_GFX_TARGET)
@echo "form data table:"
cp $(POKEFORMDATATBL_BIN) $(POKEFORMDATATBL_TARGET)
# needed to keep the $(SDAT_OBJ_DIR)/WAVE_ARC_PV%/00.swav from being detected as an intermediate file
.SECONDARY:
# debug makefile print
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true