No Description

makefile 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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. export PATH := $(realpath ../tools):$(PATH)
  14. PAGB_MAIN := g3headers
  15. PAGB_INCLUDE := $(PAGB_MAIN)/build/include/
  16. PAGB_LINK := $(PAGB_MAIN)/build/linker/BPRE.ld
  17. AUTO_ASSET_ROOT := sots-private/assets/images
  18. CHARMAP := charmap.txt
  19. DEFINES := -DBPRE -DSOFTWARE_VERSION=0
  20. ASFLAGS := -mthumb
  21. 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)
  22. GRITFLAGS := -ftc -fa
  23. LDFLAGS := -z muldefs
  24. BLDPATH := object
  25. OUTPATH := build
  26. SOURCEDIR := src
  27. STRINGDIR := string
  28. MAPROOT := sots-private/map
  29. MAPMAPS := $(MAPROOT)/maps
  30. MAPTS := $(MAPROOT)/tilesets
  31. MAIN_OBJ := $(BLDPATH)/linked.o
  32. B_ENGINE := battle_engine/build/linked.o
  33. SPRITES := $(BLDPATH)/pkmn_sprites.o
  34. ICONS_AR := $(BLDPATH)/pkmn_icons.a
  35. DYN_OVER := built/dynamic_overworld.o
  36. TMP_LD := tmp.ld
  37. SND_ROOT := sots-private/sound
  38. MUSIC_AR := $(SND_ROOT)/Music/music.a
  39. SMPL_AR := $(SND_ROOT)/Samples/sample.a
  40. VOICE_AR := $(SND_ROOT)/Voicegroup/voice.a
  41. LIST_AR := $(SND_ROOT)/Songtable/songlist.a
  42. CRY_AR := $(SND_ROOT)/Crys/cry.a
  43. rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
  44. IMAGES=$(call rwildcard,$(AUTO_ASSET_ROOT),*.png)
  45. GEN_SRC := $(IMAGES:$(AUTO_ASSET_ROOT)/%.png=generated_image/%.c)
  46. ASM_SRC := $(call rwildcard,src/,*.s)
  47. C_SRC := $(call rwildcard,src/,*.c)
  48. DATA_SRC := $(call rwildcard,data/,*.s)
  49. STRING := $(call rwildcard,string/$(LAN)/,*.txt)
  50. STRING_SRC := $(STRING:%.txt=%.s)
  51. SCRIPT_SRC := $(call rwildcard,$(MAPMAPS)/,*.s)
  52. GEN_OBJ := $(GEN_SRC:%.c=$(BLDPATH)/%.o)
  53. STRING_OBJ := $(STRING_SRC:%.s=$(BLDPATH)/%.o)
  54. ASM_OBJ := $(ASM_SRC:%.s=$(BLDPATH)/%.o)
  55. C_OBJ := $(C_SRC:%.c=$(BLDPATH)/%.o)
  56. DATA_OBJ := $(DATA_SRC:%.s=$(BLDPATH)/%.o)
  57. SCRIPT_OBJ := $(SCRIPT_SRC:%.s=$(BLDPATH)/%.o)
  58. ALL_OBJ := $(GEN_OBJ) $(C_OBJ) $(ASM_OBJ) $(DATA_OBJ) $(STRING_OBJ) $(SCRIPT_OBJ)
  59. $(STRINGDIR)/%.s: $(STRINGDIR)/%.txt
  60. @echo -e "\e[93mGenerating strings $<\e[0m"
  61. $(STRAGB) -o $@ -i $< -t string/table.tbl -e 0xFF
  62. $(BLDPATH)/%.o: %.c $(ASSETS)
  63. @echo -e "\e[32mCompiling $<\e[0m"
  64. $(shell mkdir -p $(dir $@))
  65. $(CC) $(CFLAGS) -c $< -o $@
  66. $(BLDPATH)/%.o: %.s
  67. @echo -e "\e[32mAssembling $<\e[0m"
  68. $(shell mkdir -p $(dir $@))
  69. $(PREPROC) $< $(CHARMAP) > $*.i
  70. $(CC) $(CFLAGS) -c -x assembler-with-cpp $*.i -o $@
  71. @rm -f $*.i
  72. generated_image/%.c: $(AUTO_ASSET_ROOT)/%.png $(AUTO_ASSET_ROOT)/%.grit
  73. @echo -e "\e[34mProcessing image $<\e[0m"
  74. $(shell mkdir -p $(dir $@))
  75. $(GRIT) $< -o $@ -ftc -ff $(<:%.png=%.grit)
  76. generated_image/%.c: $(AUTO_ASSET_ROOT)/%.png
  77. @echo -e "\e[34mProcessing image $< (using directory grit file)\e[0m"
  78. $(shell mkdir -p $(dir $@))
  79. $(GRIT) $< -o $@ -ftc -ff $(<D)/$(notdir $(<D)).grit
  80. all: rom
  81. .PHONY: rom
  82. rom: main.asm $(MAIN_OBJ)
  83. @echo -e "\e[1;32mCreating ROM\e[0m"
  84. $(ARS) $<
  85. $(NM) $(BLDPATH)/linked.o -n -g --defined-only | \
  86. sed -e '{s/^/0x/g};{/.*\sA\s.*/d};{s/\sT\s/ /g}' > $(OUTPATH)/__symbols.sym
  87. @echo "*** SUCCESSFULLY BUILT PROJECT ***"
  88. $(MAIN_OBJ): $(ALL_OBJ) $(ICONS_AR) $(SPRITES) $(MUSIC_AR) $(SMPL_AR) $(VOICE_AR) $(LIST_AR) $(CRY_AR) $()#$(B_ENGINE)
  89. $(MAKE) -f assets.makefile
  90. @echo -e "\e[1;32mLinking ELF binary $@\e[0m"
  91. @echo "INPUT($^)" > $(TMP_LD)
  92. $(LD) $(LDFLAGS) -T $(PAGB_LINK) -T linker.ld -T bpre.sym --whole-archive -r -o $@ --start-group -T $(TMP_LD) --end-group
  93. @rm -f $(TMP_LD)
  94. .PHONY: $(B_ENGINE)
  95. $(B_ENGINE):
  96. $(MAKE) -C battle_engine build/linked.o
  97. .PHONY: clean
  98. clean:
  99. rm -f $(OUTPATH)/__symbols.sym $(OUTPATH)/pkmn_sots.gba
  100. rm -rf generated_image/*
  101. rm -R -f object/*
  102. $(MAKE) -C $(dir $(MUSIC_AR)) clean
  103. $(MAKE) -C $(dir $(SMPL_AR)) clean
  104. $(MAKE) -C $(dir $(VOICE_AR)) clean
  105. $(MAKE) -C $(dir $(LIST_AR)) clean
  106. $(MAKE) -C $(dir $(CRY_AR)) clean
  107. $(MAKE) -f sprites.makefile clean
  108. $(MAKE) -f icons.makefile clean
  109. .PHONY: $(ASSETS)
  110. $(ASSETS):
  111. $(MAKE) -f assets.makefile
  112. .PHONY: $(SPRITES)
  113. $(SPRITES):
  114. $(MAKE) -f sprites.makefile
  115. .PHONY: $(ICONS_AR)
  116. $(ICONS_AR):
  117. $(MAKE) -f icons.makefile
  118. .PHONY: $(MUSIC_AR)
  119. $(MUSIC_AR):
  120. $(MAKE) -C $(dir $@) all
  121. .PHONY: $(SMPL_AR)
  122. $(SMPL_AR):
  123. $(MAKE) -C $(dir $@) all
  124. .PHONY: $(VOICE_AR)
  125. $(VOICE_AR):
  126. $(MAKE) -C $(dir $@) all
  127. .PHONY: $(LIST_AR)
  128. $(LIST_AR):
  129. $(MAKE) -C $(dir $@) all
  130. .PHONY: $(CRY_AR)
  131. $(CRY_AR):
  132. $(MAKE) -C $(dir $@) all
  133. run: rom
  134. $(VBA) "build/pkmn_sots.gba"