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 5.8KB

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