暂无描述

makefile 6.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. AS := @arm-none-eabi-as
  2. LD := @arm-none-eabi-ld
  3. OBJCOPY := @arm-none-eabi-objcopy
  4. GRIT := @grit
  5. CC := @arm-none-eabi-gcc
  6. ARS := @armips
  7. MAKE := make
  8. NM := @arm-none-eabi-nm
  9. PREPROC := @preproc
  10. VBA := vba
  11. LAN := de
  12. STRAGB := string2agb
  13. PYPROJS := @python ../tools/v_tools/pyproj2s.py
  14. PYMAPS := @python ../tools/v_tools/pymap2s.py
  15. PYSETS := @python ../tools/v_tools/pyset2s.py
  16. export PATH := $(realpath ../tools):$(PATH)
  17. PAGB_MAIN := g3headers
  18. PAGB_INCLUDE := $(PAGB_MAIN)/build/include/
  19. PAGB_LINK := $(PAGB_MAIN)/build/linker/BPRE.ld
  20. AUTO_ASSET_ROOT := sots-private/assets/images
  21. CHARMAP := charmap.txt
  22. DEFINES := -DBPRE -DSOFTWARE_VERSION=0 -DLAN_DE
  23. ASFLAGS := -mthumb
  24. CFLAGS := -mthumb -mthumb-interwork -g -mcpu=arm7tdmi -fno-inline -fdiagnostics-show-option -fdiagnostics-color -mlong-calls -march=armv4t -Og -std=c11 -Wall -Wextra -Wunreachable-code -I$(PAGB_INCLUDE) -Isrc/include -Igenerated_image -fdiagnostics-color $(DEFINES)
  25. GRITFLAGS := -ftc -fa
  26. LDFLAGS := -z muldefs
  27. BLDPATH := object
  28. OUTPATH := build
  29. SOURCEDIR := src
  30. STRINGDIR := string
  31. MAPROOT := sots-private/map
  32. MAPMAPS := $(MAPROOT)/maps
  33. MAPTS := $(MAPROOT)/tileset
  34. MAP_PROJ := $(MAPROOT)/sots.json
  35. MAIN_OBJ := $(BLDPATH)/linked.o
  36. B_ENGINE := battle_engine/build/linked.o
  37. SPRITES := $(BLDPATH)/pkmn_sprites.o
  38. ICONS_AR := $(BLDPATH)/pkmn_icons.a
  39. DYN_OVER := built/dynamic_overworld.o
  40. TMP_LD := tmp.ld
  41. SND_ROOT := sots-private/sound
  42. MUSIC_AR := $(SND_ROOT)/Music/music.a
  43. SMPL_AR := $(SND_ROOT)/Samples/sample.a
  44. VOICE_AR := $(SND_ROOT)/Voicegroup/voice.a
  45. LIST_AR := $(SND_ROOT)/Songtable/songlist.a
  46. CRY_AR := $(SND_ROOT)/Crys/cry.a
  47. rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
  48. IMAGES=$(call rwildcard,$(AUTO_ASSET_ROOT),*.png)
  49. TSPNG=$(call rwildcard,$(MAPTS)/,*.png)
  50. TS_GEN_SRC := $(TSPNG:%.png=%.s)
  51. TS_GEN_O := $(TSPNG:%.png=$(BLDPATH)/%.o)
  52. GEN_SRC := $(IMAGES:$(AUTO_ASSET_ROOT)/%.png=generated_image/%.c)
  53. ASM_SRC := $(call rwildcard,src/,*.s)
  54. C_SRC := $(call rwildcard,src/,*.c)
  55. DATA_SRC := $(call rwildcard,data/,*.s)
  56. STRING := $(call rwildcard,string/$(LAN)/,*.txt)
  57. STRING_SRC := $(STRING:%.txt=%.s)
  58. SCRIPT_SRC := $(call rwildcard,$(MAPMAPS)/,*.s)
  59. MAP_PROJ_S := $(MAP_PROJ:%.json=%.s)
  60. MAP_PROJ_O := $(MAP_PROJ:%.json=$(BLDPATH)/%.o)
  61. MAP_FILES := $(call rwildcard,$(MAPMAPS)/,*.pmh)
  62. MAP_FILES_S := $(MAP_FILES:%.pmh=%.s)
  63. MAP_FILES_O := $(MAP_FILES:%.pmh=$(BLDPATH)/%.o)
  64. TS_FILES := $(call rwildcard,$(MAPTS)/,*.pts)
  65. TS_FILES_S := $(TS_FILES:%.pts=%.s)
  66. TS_FILES_O := $(TS_FILES:%.pts=$(BLDPATH)/%.o)
  67. GEN_OBJ := $(GEN_SRC:%.c=$(BLDPATH)/%.o)
  68. STRING_OBJ := $(STRING_SRC:%.s=$(BLDPATH)/%.o)
  69. ASM_OBJ := $(ASM_SRC:%.s=$(BLDPATH)/%.o)
  70. C_OBJ := $(C_SRC:%.c=$(BLDPATH)/%.o)
  71. DATA_OBJ := $(DATA_SRC:%.s=$(BLDPATH)/%.o)
  72. SCRIPT_OBJ := $(SCRIPT_SRC:%.s=$(BLDPATH)/%.o)
  73. 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)
  74. $(MAPMAPS)/%.s: $(MAPMAPS)/%.pmh
  75. @echo -e "\e[96mGenerating map $<\e[0m"
  76. $(PYMAPS) -o $@ $<
  77. $(MAPTS)/%.s: $(MAPTS)/%.pts
  78. @echo -e "\e[94mGenerating tileset $<\e[0m"
  79. $(PYSETS) -o $@ $<
  80. $(STRINGDIR)/%.s: $(STRINGDIR)/%.txt
  81. @echo -e "\e[93mGenerating strings $<\e[0m"
  82. $(STRAGB) -o $@ -i $< -t string/table.tbl -e 0xFF
  83. $(BLDPATH)/%.o: %.c $(ASSETS)
  84. @echo -e "\e[32mCompiling $<\e[0m"
  85. $(shell mkdir -p $(dir $@))
  86. $(CC) $(CFLAGS) -c $< -o $@
  87. $(BLDPATH)/%.o: %.s
  88. @echo -e "\e[32mAssembling $<\e[0m"
  89. $(shell mkdir -p $(dir $@))
  90. $(PREPROC) $< $(CHARMAP) > $*.i
  91. $(CC) $(CFLAGS) -c -x assembler-with-cpp $*.i -o $@
  92. @rm -f $*.i
  93. $(MAPTS)/%.s: $(MAPTS)/%.png
  94. @echo -e "\e[34mProcessing image (tileset) $<\e[0m"
  95. $(GRIT) $< -o $@ -fts -gzl -pz! -pu16 -gB4 -m! -mR!
  96. generated_image/%.c: $(AUTO_ASSET_ROOT)/%.png $(AUTO_ASSET_ROOT)/%.grit
  97. @echo -e "\e[34mProcessing image $<\e[0m"
  98. $(shell mkdir -p $(dir $@))
  99. $(GRIT) $< -o $@ -ftc -ff $(<:%.png=%.grit)
  100. generated_image/%.c: $(AUTO_ASSET_ROOT)/%.png
  101. @echo -e "\e[34mProcessing image $< (using directory grit file)\e[0m"
  102. $(shell mkdir -p $(dir $@))
  103. $(GRIT) $< -o $@ -ftc -ff $(<D)/$(notdir $(<D)).grit
  104. all: rom
  105. .PHONY: rom
  106. rom: main.asm $(MAIN_OBJ)
  107. @echo -e "\e[1;32mCreating ROM\e[0m"
  108. $(ARS) $<
  109. $(NM) $(BLDPATH)/linked.o -n -g --defined-only | \
  110. sed -e '{s/^/0x/g};{/.*\sA\s.*/d};{s/\sT\s/ /g}' > $(OUTPATH)/__symbols.sym
  111. @echo "*** SUCCESSFULLY BUILT PROJECT ***"
  112. @echo "*** REMOVING INTERMEDIATE FILES ***"
  113. $(MAIN_OBJ): $(ALL_OBJ) $(ICONS_AR) $(SPRITES) $(MUSIC_AR) $(SMPL_AR) $(VOICE_AR) $(LIST_AR) $(CRY_AR) $()#$(B_ENGINE)
  114. $(MAKE) -f assets.makefile
  115. @echo -e "\e[1;32mLinking ELF binary $@\e[0m"
  116. @echo "INPUT($^)" > $(TMP_LD)
  117. $(LD) $(LDFLAGS) -T $(PAGB_LINK) -T linker.ld -T bpre.sym --whole-archive -r -o $@ --start-group -T $(TMP_LD) --end-group
  118. @rm -f $(TMP_LD)
  119. $(MAP_PROJ_S): $(MAP_PROJ)
  120. @echo -e "\e[91mGenerating map project $<\e[0m"
  121. $(PYPROJS) -b sovereign_banks -f sovereign_footer -o $@ $<
  122. .PHONY: $(B_ENGINE)
  123. $(B_ENGINE):
  124. $(MAKE) -C battle_engine build/linked.o
  125. .PHONY: clean
  126. clean:
  127. rm -f $(OUTPATH)/__symbols.sym $(OUTPATH)/pkmn_sots.gba
  128. rm -rf generated_image/*
  129. rm -R -f object/*
  130. $(MAKE) -C $(dir $(MUSIC_AR)) clean
  131. $(MAKE) -C $(dir $(SMPL_AR)) clean
  132. $(MAKE) -C $(dir $(VOICE_AR)) clean
  133. $(MAKE) -C $(dir $(LIST_AR)) clean
  134. $(MAKE) -C $(dir $(CRY_AR)) clean
  135. $(MAKE) -f sprites.makefile clean
  136. $(MAKE) -f icons.makefile clean
  137. .PHONY: $(ASSETS)
  138. $(ASSETS):
  139. @echo -e "\e[95mMaking Assets\e[0m"
  140. $(MAKE) -f assets.makefile
  141. .PHONY: $(SPRITES)
  142. $(SPRITES):
  143. @echo -e "\e[95mMaking Sprites\e[0m"
  144. $(MAKE) -f sprites.makefile
  145. .PHONY: $(ICONS_AR)
  146. $(ICONS_AR):
  147. @echo -e "\e[95mMaking Icons\e[0m"
  148. $(MAKE) -f icons.makefile
  149. .PHONY: $(MUSIC_AR)
  150. $(MUSIC_AR):
  151. @echo -e "\e[95mMaking Music\e[0m"
  152. $(MAKE) -C $(dir $@) all
  153. .PHONY: $(SMPL_AR)
  154. $(SMPL_AR):
  155. @echo -e "\e[95mMaking Sampler\e[0m"
  156. $(MAKE) -C $(dir $@) all
  157. .PHONY: $(VOICE_AR)
  158. $(VOICE_AR):
  159. @echo -e "\e[95mMaking Voice\e[0m"
  160. $(MAKE) -C $(dir $@) all
  161. .PHONY: $(LIST_AR)
  162. $(LIST_AR):
  163. @echo -e "\e[95mMaking Songlist\e[0m"
  164. $(MAKE) -C $(dir $@) all
  165. .PHONY: $(CRY_AR)
  166. $(CRY_AR):
  167. @echo -e "\e[95mMaking Cries\e[0m"
  168. $(MAKE) -C $(dir $@) all
  169. run: rom
  170. $(VBA) "build/pkmn_sots.gba"