GameBoy (Color) port of the GTA San Andreas arcade game Duality
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Makefile 6.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. GIT := $(BUILD_DIR)/$(DATA_DIR)/git.c
  27. SRCS += $(GIT)
  28. SRCS += $(BUILD_DIR)/$(DATA_DIR)/speed_table.c
  29. OBJS := $(SRCS:%.c=$(BUILD_DIR)/%.o)
  30. IMAGES := $(wildcard $(DATA_DIR)/*.png)
  31. SPRITES := $(IMAGES:%.png=$(BUILD_DIR)/%.c)
  32. OBJS += $(SPRITES:%.c=%.o)
  33. WAVES := $(wildcard $(DATA_DIR)/*.wav)
  34. SOUNDS := $(WAVES:%.wav=$(BUILD_DIR)/%.c)
  35. OBJS += $(SOUNDS:%.c=%.o)
  36. ASSETS := $(SPRITES)
  37. ASSETS += $(SOUNDS)
  38. LCC := $(GBDK_HOME)/bin/lcc
  39. PNGA := $(GBDK_HOME)/bin/png2asset
  40. ROMU := $(GBDK_HOME)/bin/romusage
  41. GB_EMU := gearboy
  42. SGB_EMU := sameboy
  43. BGB_EMU := ~/bin/bgb/bgb.exe
  44. GBE_EMU := ~/bin/gbe/gbe_plus_qt.exe
  45. FLASHER := flashgbx
  46. LCCFLAGS := -Wa-l -Wl-m -Wp-MMD -Wf--opt-code-speed
  47. LCCFLAGS += -I$(SRC_DIR) -I$(BUILD_DIR)/$(DATA_DIR)
  48. LCCFLAGS += -Wm"-yn Duality" -Wm-yt0x1B -Wm-yoA -Wm-ya1 -Wm-yc -Wm-ys
  49. LCCFLAGS += -autobank -Wb-ext=.rel -Wb-v -Wf-bo255
  50. GB_EMUFLAGS := $(BUILD_DIR)/$(BIN)
  51. SGB_EMUFLAGS := $(BUILD_DIR)/$(BIN)
  52. BGB_EMUFLAGS := $(BUILD_DIR)/$(BIN)
  53. GBE_EMUFLAGS := $(BUILD_DIR)/$(BIN)
  54. ifndef GBDK_RELEASE
  55. LCCFLAGS += -debug -DDEBUG -Wa-j -Wa-y -Wa-s -Wl-j -Wl-y -Wl-u -Wm-yS
  56. GB_EMUFLAGS += $(BUILD_DIR)/$(BIN:.gb=.sym)
  57. BUILD_TYPE = Debug
  58. else
  59. BUILD_TYPE = Release
  60. endif
  61. FLASHCART := "DIY cart with MX29LV640 @ WR"
  62. FLASHFLAGS := --mode dmg --action flash-rom --flashcart-type $(FLASHCART)
  63. $(info BUILD_TYPE is $(BUILD_TYPE))
  64. DEPS=$(OBJS:%.o=%.d)
  65. -include $(DEPS)
  66. .PHONY: all run cloc sgb_run bgb_run gbe_run flash clean compile_commands.json usage
  67. .PHONY: $(GIT) $(BUILD_DIR)/$(DATA_DIR)/speed_table.c $(BUILD_DIR)/$(DATA_DIR)/speed_table.h
  68. .PRECIOUS: $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h
  69. all: $(BIN)
  70. cloc:
  71. @cloc . --exclude-dir=$(BUILD_DIR)
  72. compile_commands.json:
  73. @echo "Cleaning old build"
  74. @make clean
  75. @echo "Preparing bear.cfg"
  76. @echo '{"compilation":{"compilers_to_recognize":[{"executable":"$(GBDK_HOME)/bin/sdcc","flags_to_add":["-D__PORT_sm83", "-D__TARGET_gb" ],"flags_to_remove":[""]}]}}' > bear.cfg
  77. @echo "Running full build within bear"
  78. @bear --config bear.cfg -- make -j4
  79. @rm -rf bear.cfg
  80. $(GIT): $(DATA_DIR)/git.c
  81. @mkdir -p $(@D)
  82. @echo Generating $@ from $<
  83. @sed 's|GIT_VERSION|$(shell git describe --abbrev=7 --dirty --always --tags)|g' $< > $@
  84. $(BUILD_DIR)/$(DATA_DIR)/speed_table.c:
  85. @mkdir -p $(@D)
  86. @echo Generating $@
  87. @util/gen_angles.py -n speed_table -d $(BUILD_DIR)/$(DATA_DIR) -s 16 -w 2 -f 0 -m 42 -t int8_t
  88. usage: $(BUILD_DIR)/$(BIN)
  89. @echo Analyzing $<
  90. @$(ROMU) $(BUILD_DIR)/$(BIN:%.gb=%.map)
  91. run: $(BUILD_DIR)/$(BIN)
  92. @echo Emulating $<
  93. @$(GB_EMU) $(GB_EMUFLAGS)
  94. sgb_run: $(BUILD_DIR)/$(BIN)
  95. @echo Emulating $<
  96. @$(SGB_EMU) $(SGB_EMUFLAGS)
  97. bgb_run: $(BUILD_DIR)/$(BIN)
  98. @echo Emulating $<
  99. @$(BGB_EMU) $(BGB_EMUFLAGS)
  100. gbe_run: $(BUILD_DIR)/$(BIN)
  101. @echo Emulating $<
  102. @$(GBE_EMU) $(GBE_EMUFLAGS)
  103. flash: $(BIN)
  104. @echo Flashing $<
  105. @$(FLASHER) $(FLASHFLAGS) $<
  106. $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.wav
  107. @mkdir -p $(@D)
  108. @echo Converting sound $<
  109. @util/cvtsample.py $< "(None)" GBDK $(BUILD_DIR)/$(DATA_DIR)
  110. $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.png
  111. @mkdir -p $(@D)
  112. $(eval SPRFLAG = $(shell echo "$<" | sed -n 's/.*_spr\([0-9]\+\).*/\-sw \1 \-sh \1/p'))
  113. $(eval FNTFLAG = $(shell echo "$<" | sed -n 's/.*_fnt\([0-9]\+\).*/\-sw \1 \-sh \1/p'))
  114. $(if $(findstring _map,$<), \
  115. @echo "Converting map $<" && \
  116. $(PNGA) $< -o $@ -spr8x8 -map -noflip \
  117. ,$(if $(findstring _fnt,$<), \
  118. @echo "Converting font $<" && \
  119. $(PNGA) $< -o $@ -spr8x8 $(FNTFLAG) -map -noflip \
  120. ,$(if $(findstring _spr,$<), \
  121. @echo "Converting 8x8 sprite $<" && \
  122. $(PNGA) $< -o $@ -spr8x8 $(SPRFLAG) -noflip \
  123. ,$(if $(findstring pause,$<), \
  124. @echo "Converting 40x16 sprite $<" && \
  125. $(PNGA) $< -o $@ -spr8x8 -sw 40 -sh 16 -noflip \
  126. ,$(if $(findstring _sgb,$<), \
  127. @echo "Converting sgb border $<" && \
  128. $(PNGA) $< -o $@ -map -bpp 4 -max_palettes 4 -pack_mode sgb -use_map_attributes \
  129. , \
  130. @echo "Converting tile $<" && \
  131. $(PNGA) $< -o $@ -spr8x8 \
  132. )))))
  133. $(BUILD_DIR)/%.o: %.c $(ASSETS) $(SRCS)
  134. @mkdir -p $(@D)
  135. @echo Compiling Code $<
  136. $(eval BAFLAG = $(shell echo "$<" | sed -n 's/.*\.ba\([0-9]\+\).*/\-Wf-ba\1/p'))
  137. @$(LCC) $(LCCFLAGS) $(BAFLAG) -c -o $@ $<
  138. $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c $(ASSETS) $(SRCS)
  139. @mkdir -p $(@D)
  140. @echo Compiling Asset $<
  141. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  142. $(BUILD_DIR)/%.o: %.s $(ASSETS) $(SRCS)
  143. @mkdir -p $(@D)
  144. @echo Assembling $<
  145. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  146. $(BUILD_DIR)/$(BIN): $(OBJS) $(SRCS)
  147. @echo Linking $@
  148. @$(LCC) $(LCCFLAGS) -o $@ $(OBJS)
  149. $(BIN): $(BUILD_DIR)/$(BIN) usage
  150. @cp $< $@
  151. clean:
  152. rm -rf $(BUILD_DIR) $(BIN)