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

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