説明なし

makefile 7.5KB

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