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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  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. ASSETS := $(wildcard $(DATA_DIR)/*.png)
  28. SPRITES := $(ASSETS:%.png=$(BUILD_DIR)/%.c)
  29. OBJS += $(SPRITES:%.c=%.o)
  30. LCC := $(GBDK_HOME)/bin/lcc
  31. PNGA := $(GBDK_HOME)/bin/png2asset
  32. ROMU := $(GBDK_HOME)/bin/romusage
  33. GB_EMU := gearboy
  34. SGB_EMU := sameboy
  35. FLASHER := flashgbx
  36. LCCFLAGS := -Wa-l -Wl-m -Wp-MMD -Wf--opt-code-speed
  37. LCCFLAGS += -I$(BUILD_DIR)/$(DATA_DIR)
  38. LCCFLAGS += -Wm"-yn Duality" -Wm-yt0x1B -Wm-yoA -Wm-ya16 -Wm-yc -Wm-ys
  39. LCCFLAGS += -autobank -Wb-ext=.rel -Wb-v -Wf-bo255
  40. EMUFLAGS := $(BIN)
  41. ifndef GBDK_RELEASE
  42. LCCFLAGS += -debug -DDEBUG -Wa-j -Wa-y -Wa-s -Wl-j -Wl-y -Wl-u -Wm-yS
  43. EMUFLAGS += $(BUILD_DIR)/$(BIN:.gb=.sym)
  44. BUILD_TYPE = Debug
  45. else
  46. BUILD_TYPE = Release
  47. endif
  48. FLASHFLAGS := --mode dmg --action flash-rom
  49. $(info BUILD_TYPE is $(BUILD_TYPE))
  50. # TODO this is not working. why?!
  51. #DEPS=$(OBJS:%.o=%.d)
  52. #-include $(DEPS)
  53. .PHONY: all run sgb_run flash clean compile_commands.json usage
  54. .PRECIOUS: $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h
  55. all: $(BIN)
  56. compile_commands.json:
  57. @echo "Cleaning old build"
  58. @make clean
  59. @echo "Preparing bear.cfg"
  60. @echo '{"compilation":{"compilers_to_recognize":[{"executable":"$(GBDK_HOME)/bin/sdcc","flags_to_add":[""],"flags_to_remove":[""]}]}}' > bear.cfg
  61. @echo "Running full build within bear"
  62. @bear --config bear.cfg -- make -j4
  63. @rm -rf bear.cfg
  64. usage: $(BUILD_DIR)/$(BIN)
  65. @echo Analyzing $<
  66. @$(ROMU) $(BUILD_DIR)/$(BIN:%.gb=%.map)
  67. run: $(BIN)
  68. @echo Emulating $<
  69. @$(GB_EMU) $(EMUFLAGS)
  70. sgb_run: $(BIN)
  71. @echo Emulating $<
  72. @$(SGB_EMU) $(BIN)
  73. flash: $(BIN)
  74. @echo Flasing $<
  75. $(FLASHER) $(FLASHFLAGS) $<
  76. $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.png
  77. @mkdir -p $(@D)
  78. $(if $(findstring _map,$<), \
  79. @echo "Converting map $<" && \
  80. $(PNGA) $< -o $@ -spr8x8 -map -use_map_attributes -noflip \
  81. ,$(if $(findstring _fnt,$<), \
  82. @echo "Converting font $<" && \
  83. $(PNGA) $< -o $@ -spr8x8 -sw 16 -sh 16 -map -noflip \
  84. ,$(if $(findstring _spr8,$<), \
  85. @echo "Converting 8x8 sprite $<" && \
  86. $(PNGA) $< -o $@ -spr8x8 -sw 8 -sh 8 -noflip \
  87. ,$(if $(findstring _spr16,$<), \
  88. @echo "Converting 16x16 sprite $<" && \
  89. $(PNGA) $< -o $@ -spr8x8 -sw 16 -sh 16 -noflip \
  90. ,$(if $(findstring _spr24,$<), \
  91. @echo "Converting 24x24 sprite $<" && \
  92. $(PNGA) $< -o $@ -spr8x8 -sw 24 -sh 24 -noflip \
  93. ,$(if $(findstring _sgb,$<), \
  94. @echo "Converting sgb border $<" && \
  95. $(PNGA) $< -o $@ -map -bpp 4 -max_palettes 4 -pack_mode sgb -use_map_attributes \
  96. , \
  97. @echo "Converting tile $<" && \
  98. $(PNGA) $< -o $@ -spr8x8 \
  99. ))))))
  100. $(BUILD_DIR)/%.o: %.c $(SPRITES)
  101. @mkdir -p $(@D)
  102. @echo Compiling Code $<
  103. $(eval BAFLAG = $(shell echo "$<" | sed -n 's/.*\.ba\([0-9]\+\).*/\-Wf-ba\1/p'))
  104. @$(LCC) $(LCCFLAGS) $(BAFLAG) -c -o $@ $<
  105. $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c $(SPRITES)
  106. @mkdir -p $(@D)
  107. @echo Compiling Asset $<
  108. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  109. $(BUILD_DIR)/%.o: %.s $(SPRITES)
  110. @mkdir -p $(@D)
  111. @echo Assembling $<
  112. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  113. $(BUILD_DIR)/$(BIN): $(OBJS)
  114. @echo Linking $@
  115. @$(LCC) $(LCCFLAGS) -o $@ $(OBJS)
  116. $(BIN): $(BUILD_DIR)/$(BIN)
  117. @cp $< $@
  118. @make usage
  119. clean:
  120. rm -rf $(BUILD_DIR) $(BIN)