Brak opisu

makefile 6.9KB

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