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.5KB

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