GameBoy (Color) port of the GTA San Andreas arcade game Duality
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Makefile 6.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. # Adapted from GBDK-2020 examples
  2. #
  3. # Copyright (C) 2025 Thomas Buck <thomas@xythobuz.de>
  4. #
  5. # https://gbdk.org/docs/api/docs_toolchain_settings.html
  6. #
  7. # This program is free software: you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation, either version 3 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # See <http://www.gnu.org/licenses/>.
  18. ifndef GBDK_HOME
  19. GBDK_HOME = ../../../
  20. endif
  21. BIN := duality.gb
  22. SRC_DIR := src
  23. BUILD_DIR := build
  24. DATA_DIR := data
  25. SRCS := $(wildcard $(SRC_DIR)/*.c)
  26. OBJS := $(SRCS:%.c=$(BUILD_DIR)/%.o)
  27. GIT := $(BUILD_DIR)/$(DATA_DIR)/git.c
  28. OBJS += $(GIT:%.c=%.o)
  29. GEN_SRCS := $(BUILD_DIR)/$(DATA_DIR)/table_speed_shot.c
  30. GEN_SRCS += $(BUILD_DIR)/$(DATA_DIR)/table_speed_move.c
  31. OBJS += $(GEN_SRCS:%.c=%.o)
  32. IMAGES := $(wildcard $(DATA_DIR)/*.png)
  33. SPRITES := $(IMAGES:%.png=$(BUILD_DIR)/%.c)
  34. OBJS += $(SPRITES:%.c=%.o)
  35. WAVES := $(wildcard $(DATA_DIR)/*.wav)
  36. SOUNDS := $(WAVES:%.wav=$(BUILD_DIR)/%.c)
  37. OBJS += $(SOUNDS:%.c=%.o)
  38. ASSETS := $(SPRITES)
  39. ASSETS += $(SOUNDS)
  40. ASSETS += $(GEN_SRCS)
  41. LCC := $(GBDK_HOME)/bin/lcc
  42. PNGA := $(GBDK_HOME)/bin/png2asset
  43. ROMU := $(GBDK_HOME)/bin/romusage
  44. GB_EMU := gearboy
  45. SGB_EMU := sameboy
  46. BGB_EMU := ~/bin/bgb/bgb.exe
  47. GBE_EMU := ~/bin/gbe/gbe_plus_qt.exe
  48. FLASHER := flashgbx
  49. LCCFLAGS := -Wa-l -Wl-m -Wp-MMD -Wf--opt-code-speed
  50. LCCFLAGS += -I$(SRC_DIR) -I$(BUILD_DIR)/$(DATA_DIR)
  51. LCCFLAGS += -Wm"-yn Duality" -Wm-yt0x1B -Wm-yoA -Wm-ya1 -Wm-yc -Wm-ys
  52. LCCFLAGS += -autobank -Wb-ext=.rel -Wb-v -Wf-bo255
  53. GB_EMUFLAGS := $(BUILD_DIR)/$(BIN)
  54. SGB_EMUFLAGS := $(BUILD_DIR)/$(BIN)
  55. BGB_EMUFLAGS := $(BUILD_DIR)/$(BIN)
  56. GBE_EMUFLAGS := $(BUILD_DIR)/$(BIN)
  57. ifndef GBDK_RELEASE
  58. LCCFLAGS += -debug -DDEBUG -Wa-j -Wa-y -Wa-s -Wl-j -Wl-y -Wl-u -Wm-yS
  59. GB_EMUFLAGS += $(BUILD_DIR)/$(BIN:.gb=.sym)
  60. BUILD_TYPE = Debug
  61. else
  62. BUILD_TYPE = Release
  63. endif
  64. FLASHCART := "DIY cart with MX29LV640 @ WR"
  65. FLASHFLAGS := --mode dmg --action flash-rom --flashcart-type $(FLASHCART)
  66. $(info BUILD_TYPE is $(BUILD_TYPE))
  67. DEPS=$(OBJS:%.o=%.d)
  68. -include $(DEPS)
  69. .PHONY: all run cloc sgb_run bgb_run gbe_run flash clean compile_commands.json usage $(GIT)
  70. .PRECIOUS: $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h
  71. all: $(BIN)
  72. cloc:
  73. @cloc . --exclude-dir=$(BUILD_DIR)
  74. compile_commands.json:
  75. @echo "Cleaning old build"
  76. @make clean
  77. @echo "Preparing bear.cfg"
  78. @echo '{"compilation":{"compilers_to_recognize":[{"executable":"$(GBDK_HOME)/bin/sdcc","flags_to_add":["-D__PORT_sm83", "-D__TARGET_gb" ],"flags_to_remove":[""]}]}}' > bear.cfg
  79. @echo "Running full build within bear"
  80. @bear --config bear.cfg -- make -j4
  81. @rm -rf bear.cfg
  82. $(GIT): $(DATA_DIR)/git.c
  83. @mkdir -p $(@D)
  84. @echo Generating $@ from $<
  85. @sed 's|GIT_VERSION|$(shell git describe --abbrev=7 --dirty --always --tags)|g' $< > $@
  86. $(BUILD_DIR)/$(DATA_DIR)/table_speed_shot.c $(BUILD_DIR)/$(DATA_DIR)/table_speed_shot.h: util/gen_angles.py Makefile
  87. @mkdir -p $(@D)
  88. @echo Generating $@
  89. @util/gen_angles.py -n table_speed_shot -d $(BUILD_DIR)/$(DATA_DIR) -s 16 -w 2 -f 0 -m 42 -t int8_t
  90. $(BUILD_DIR)/$(DATA_DIR)/table_speed_move.c $(BUILD_DIR)/$(DATA_DIR)/table_speed_move.h: util/gen_angles.py Makefile
  91. @mkdir -p $(@D)
  92. @echo Generating $@
  93. @util/gen_angles.py -n table_speed_move -d $(BUILD_DIR)/$(DATA_DIR) -s 16 -w 2 -f 0 -m 23 -t int8_t
  94. usage: $(BUILD_DIR)/$(BIN)
  95. @echo Analyzing $<
  96. @$(ROMU) $(BUILD_DIR)/$(BIN:%.gb=%.map)
  97. run: $(BIN)
  98. @echo Emulating $<
  99. @$(GB_EMU) $(GB_EMUFLAGS)
  100. sgb_run: $(BIN)
  101. @echo Emulating $<
  102. @$(SGB_EMU) $(SGB_EMUFLAGS)
  103. bgb_run: $(BIN)
  104. @echo Emulating $<
  105. @$(BGB_EMU) $(BGB_EMUFLAGS)
  106. gbe_run: $(BIN)
  107. @echo Emulating $<
  108. @$(GBE_EMU) $(GBE_EMUFLAGS)
  109. flash: $(BIN)
  110. @echo Flashing $<
  111. @$(FLASHER) $(FLASHFLAGS) $<
  112. $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.wav util/cvtsample.py Makefile
  113. @mkdir -p $(@D)
  114. @echo Converting sound $<
  115. @util/cvtsample.py $< "(None)" GBDK $(BUILD_DIR)/$(DATA_DIR)
  116. $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.png Makefile
  117. @mkdir -p $(@D)
  118. $(eval SPRFLAG = $(shell echo "$<" | sed -n 's/.*_spr\([0-9]\+\).*/\-sw \1 \-sh \1/p'))
  119. $(eval FNTFLAG = $(shell echo "$<" | sed -n 's/.*_fnt\([0-9]\+\).*/\-sw \1 \-sh \1/p'))
  120. $(if $(findstring _map,$<), \
  121. @echo "Converting map $<" && \
  122. $(PNGA) $< -o $@ -spr8x8 -map -noflip \
  123. ,$(if $(findstring _fnt,$<), \
  124. @echo "Converting font $<" && \
  125. $(PNGA) $< -o $@ -spr8x8 $(FNTFLAG) -map -noflip \
  126. ,$(if $(findstring _spr,$<), \
  127. @echo "Converting 8x8 sprite $<" && \
  128. $(PNGA) $< -o $@ -spr8x8 $(SPRFLAG) -noflip \
  129. ,$(if $(findstring pause,$<), \
  130. @echo "Converting 40x16 sprite $<" && \
  131. $(PNGA) $< -o $@ -spr8x8 -sw 40 -sh 16 -noflip \
  132. ,$(if $(findstring _sgb,$<), \
  133. @echo "Converting sgb border $<" && \
  134. $(PNGA) $< -o $@ -map -bpp 4 -max_palettes 4 -pack_mode sgb -use_map_attributes \
  135. , \
  136. @echo "Converting tile $<" && \
  137. $(PNGA) $< -o $@ -spr8x8 \
  138. )))))
  139. $(BUILD_DIR)/%.o: %.c $(ASSETS) Makefile
  140. @mkdir -p $(@D)
  141. @echo Compiling Code $<
  142. $(eval BAFLAG = $(shell echo "$<" | sed -n 's/.*\.ba\([0-9]\+\).*/\-Wf-ba\1/p'))
  143. @$(LCC) $(LCCFLAGS) $(BAFLAG) -c -o $@ $<
  144. $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c $(ASSETS) Makefile
  145. @mkdir -p $(@D)
  146. @echo Compiling Asset $<
  147. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  148. $(BUILD_DIR)/%.o: %.s $(ASSETS) Makefile
  149. @mkdir -p $(@D)
  150. @echo Assembling $<
  151. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  152. $(BUILD_DIR)/$(BIN): $(OBJS) $(GIT) Makefile
  153. @echo Linking $@
  154. @$(LCC) $(LCCFLAGS) -o $@ $(OBJS)
  155. $(BIN): $(BUILD_DIR)/$(BIN) usage
  156. @cp $< $@
  157. clean:
  158. rm -rf $(BUILD_DIR) $(BIN)