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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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-ya1 -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. DEPS=$(OBJS:%.o=%.d)
  53. -include $(DEPS)
  54. .PHONY: all run sgb_run flash clean compile_commands.json usage $(GIT)
  55. .PRECIOUS: $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h
  56. all: $(BIN)
  57. compile_commands.json:
  58. @echo "Cleaning old build"
  59. @make clean
  60. @echo "Preparing bear.cfg"
  61. @echo '{"compilation":{"compilers_to_recognize":[{"executable":"$(GBDK_HOME)/bin/sdcc","flags_to_add":[""],"flags_to_remove":[""]}]}}' > bear.cfg
  62. @echo "Running full build within bear"
  63. @bear --config bear.cfg -- make -j4
  64. @rm -rf bear.cfg
  65. $(GIT): $(DATA_DIR)/git.c
  66. @echo Generating $@ from $<
  67. @sed 's|GIT_VERSION|$(shell git describe --abbrev=7 --dirty --always --tags)|g' $< > $@
  68. usage: $(BUILD_DIR)/$(BIN)
  69. @echo Analyzing $<
  70. @$(ROMU) $(BUILD_DIR)/$(BIN:%.gb=%.map)
  71. run: $(BIN)
  72. @echo Emulating $<
  73. @$(GB_EMU) $(EMUFLAGS)
  74. sgb_run: $(BIN)
  75. @echo Emulating $<
  76. @$(SGB_EMU) $(BIN)
  77. flash: $(BIN)
  78. @echo Flasing $<
  79. $(FLASHER) $(FLASHFLAGS) $<
  80. $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.png
  81. @mkdir -p $(@D)
  82. $(if $(findstring _map,$<), \
  83. @echo "Converting map $<" && \
  84. $(PNGA) $< -o $@ -spr8x8 -map -use_map_attributes -noflip \
  85. ,$(if $(findstring _fnt,$<), \
  86. @echo "Converting font $<" && \
  87. $(PNGA) $< -o $@ -spr8x8 -sw 16 -sh 16 -map -noflip \
  88. ,$(if $(findstring _spr8,$<), \
  89. @echo "Converting 8x8 sprite $<" && \
  90. $(PNGA) $< -o $@ -spr8x8 -sw 8 -sh 8 -noflip \
  91. ,$(if $(findstring _spr16,$<), \
  92. @echo "Converting 16x16 sprite $<" && \
  93. $(PNGA) $< -o $@ -spr8x8 -sw 16 -sh 16 -noflip \
  94. ,$(if $(findstring _spr24,$<), \
  95. @echo "Converting 24x24 sprite $<" && \
  96. $(PNGA) $< -o $@ -spr8x8 -sw 24 -sh 24 -noflip \
  97. ,$(if $(findstring pause,$<), \
  98. @echo "Converting 40x16 sprite $<" && \
  99. $(PNGA) $< -o $@ -spr8x8 -sw 40 -sh 16 -noflip \
  100. ,$(if $(findstring _sgb,$<), \
  101. @echo "Converting sgb border $<" && \
  102. $(PNGA) $< -o $@ -map -bpp 4 -max_palettes 4 -pack_mode sgb -use_map_attributes \
  103. , \
  104. @echo "Converting tile $<" && \
  105. $(PNGA) $< -o $@ -spr8x8 \
  106. )))))))
  107. $(BUILD_DIR)/%.o: %.c $(SPRITES)
  108. @mkdir -p $(@D)
  109. @echo Compiling Code $<
  110. $(eval BAFLAG = $(shell echo "$<" | sed -n 's/.*\.ba\([0-9]\+\).*/\-Wf-ba\1/p'))
  111. @$(LCC) $(LCCFLAGS) $(BAFLAG) -c -o $@ $<
  112. $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c $(SPRITES)
  113. @mkdir -p $(@D)
  114. @echo Compiling Asset $<
  115. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  116. $(BUILD_DIR)/%.o: %.s $(SPRITES)
  117. @mkdir -p $(@D)
  118. @echo Assembling $<
  119. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  120. $(BUILD_DIR)/$(BIN): $(OBJS)
  121. @echo Linking $@
  122. @$(LCC) $(LCCFLAGS) -o $@ $(OBJS)
  123. $(BIN): $(BUILD_DIR)/$(BIN) usage
  124. @cp $< $@
  125. clean:
  126. rm -rf $(BUILD_DIR) $(BIN)