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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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. LCCFLAGS := -Wa-l -Wl-m -Wp-MMD
  35. LCCFLAGS += -I$(BUILD_DIR)/$(DATA_DIR)
  36. LCCFLAGS += -Wm"-yn Duality" -Wm-yc
  37. EMUFLAGS := $(BIN)
  38. ifndef GBDK_RELEASE
  39. LCCFLAGS += -debug -DDEBUG -Wa-j -Wa-y -Wa-s -Wl-j -Wl-y -Wl-u -Wm-yS
  40. EMUFLAGS += $(BUILD_DIR)/$(BIN:.gb=.sym)
  41. BUILD_TYPE = Debug
  42. else
  43. BUILD_TYPE = Release
  44. endif
  45. $(info BUILD_TYPE is $(BUILD_TYPE))
  46. # TODO this is not working. why?!
  47. #DEPS=$(OBJS:%.o=%.d)
  48. #-include $(DEPS)
  49. .PHONY: all run clean compile_commands.json usage
  50. .PRECIOUS: $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h
  51. all: $(BIN)
  52. compile_commands.json:
  53. @echo "Cleaning old build"
  54. @make clean
  55. @echo "Preparing bear.cfg"
  56. @echo '{"compilation":{"compilers_to_recognize":[{"executable":"$(GBDK_HOME)/bin/sdcc","flags_to_add":[""],"flags_to_remove":[""]}]}}' > bear.cfg
  57. @echo "Running full build within bear"
  58. @bear --config bear.cfg -- make -j4
  59. @rm -rf bear.cfg
  60. usage: $(BUILD_DIR)/$(BIN)
  61. @echo Analyzing $<
  62. @$(ROMU) $(BUILD_DIR)/$(BIN:%.gb=%.map)
  63. run: $(BIN)
  64. @echo Emulating $<
  65. @$(GB_EMU) $(EMUFLAGS)
  66. $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.png
  67. @mkdir -p $(@D)
  68. $(if $(findstring _map,$<), \
  69. @echo "Converting map $<" && \
  70. $(PNGA) $< -o $@ -spr8x8 -map -use_map_attributes -noflip \
  71. ,$(if $(findstring numbers,$<), \
  72. @echo "Converting font $<" && \
  73. $(PNGA) $< -o $@ -spr8x8 -sw 16 -sh 16 -map -no_palettes \
  74. , \
  75. @echo "Converting tile $<" && \
  76. $(PNGA) $< -o $@ -spr8x8 \
  77. ))
  78. $(BUILD_DIR)/%.o: %.c $(SPRITES)
  79. @mkdir -p $(@D)
  80. @echo Compiling $<
  81. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  82. $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c $(SPRITES)
  83. @mkdir -p $(@D)
  84. @echo Compiling $<
  85. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  86. $(BUILD_DIR)/%.o: %.s $(SPRITES)
  87. @mkdir -p $(@D)
  88. @echo Assembling $<
  89. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  90. $(BUILD_DIR)/$(BIN): $(OBJS)
  91. @echo Linking $@
  92. @$(LCC) $(LCCFLAGS) -o $@ $(OBJS)
  93. $(BIN): $(BUILD_DIR)/$(BIN)
  94. @cp $< $@
  95. @make usage
  96. clean:
  97. rm -rf $(BUILD_DIR) $(BIN)