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

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