Bez popisu

makefile 4.4KB

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