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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. # Adapted from GBDK-2020 examples
  2. #
  3. # Copyright (C) 2025 Thomas Buck <thomas@xythobuz.de>
  4. #
  5. # This program is free software: you can redistribute it and/or modify
  6. # it under the terms of the GNU General Public License as published by
  7. # the Free Software Foundation, either version 3 of the License, or
  8. # (at your option) any later version.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # See <http://www.gnu.org/licenses/>.
  16. ifndef GBDK_HOME
  17. GBDK_HOME = ../../../
  18. endif
  19. BIN := duality.gb
  20. SRC_DIR := src
  21. BUILD_DIR := build
  22. DATA_DIR := data
  23. SRCS := $(wildcard $(SRC_DIR)/*.c)
  24. OBJS := $(SRCS:%.c=$(BUILD_DIR)/%.o)
  25. ASSETS := $(wildcard $(DATA_DIR)/*.png)
  26. SPRITES := $(ASSETS:%.png=$(BUILD_DIR)/%.c)
  27. OBJS += $(SPRITES:%.c=%.o)
  28. LCC := $(GBDK_HOME)/bin/lcc
  29. PNGA := $(GBDK_HOME)/bin/png2asset
  30. ROMU := $(GBDK_HOME)/bin/romusage
  31. GB_EMU := gearboy
  32. LCCFLAGS := -Wa-l -Wl-m -Wm"-yn Duality" -I$(BUILD_DIR)/$(DATA_DIR) -Wm-yc
  33. EMUFLAGS := $(BIN)
  34. ifndef GBDK_RELEASE
  35. LCCFLAGS += -debug -DDEBUG -Wa-j -Wa-y -Wa-s -Wl-j -Wl-y -Wl-u -Wm-yS
  36. EMUFLAGS += $(BUILD_DIR)/$(BIN:.gb=.sym)
  37. BUILD_TYPE = Debug
  38. else
  39. BUILD_TYPE = Release
  40. endif
  41. $(info BUILD_TYPE is $(BUILD_TYPE))
  42. .PHONY: all run $(BIN) clean compile_commands.json usage
  43. all: $(BIN)
  44. compile_commands.json:
  45. @echo "Cleaning old build"
  46. @make clean
  47. @echo "Preparing bear.cfg"
  48. @echo '{"compilation":{"compilers_to_recognize":[{"executable":"$(GBDK_HOME)/bin/sdcc","flags_to_add":[""],"flags_to_remove":[""]}]}}' > bear.cfg
  49. @echo "Running full build within bear"
  50. @bear --config bear.cfg -- make -j4
  51. @rm -rf bear.cfg
  52. usage: $(BUILD_DIR)/$(BIN)
  53. @echo Analyzing $<
  54. @$(ROMU) $(BUILD_DIR)/$(BIN:%.gb=%.map)
  55. run: $(BIN)
  56. @echo Emulating $<
  57. @$(GB_EMU) $(EMUFLAGS)
  58. .PRECIOUS: $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h
  59. $(BUILD_DIR)/$(DATA_DIR)/%.c $(BUILD_DIR)/$(DATA_DIR)/%.h: $(DATA_DIR)/%.png
  60. @mkdir -p $(@D)
  61. $(if $(findstring _map,$<), \
  62. @echo "Converting map $<" && \
  63. $(PNGA) $< -o $@ -spr8x8 -map -use_map_attributes -noflip \
  64. , \
  65. @echo "Converting tile $<" && \
  66. $(PNGA) $< -o $@ -spr8x8 \
  67. )
  68. $(BUILD_DIR)/%.o: %.c $(SPRITES)
  69. @mkdir -p $(@D)
  70. @echo Compiling $<
  71. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  72. $(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c
  73. @mkdir -p $(@D)
  74. @echo Compiling $<
  75. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  76. $(BUILD_DIR)/%.o: %.s
  77. @mkdir -p $(@D)
  78. @echo Assembling $<
  79. @$(LCC) $(LCCFLAGS) -c -o $@ $<
  80. $(BUILD_DIR)/$(BIN): $(OBJS)
  81. @echo Linking $@
  82. @$(LCC) $(LCCFLAGS) -o $@ $(OBJS)
  83. $(BIN): $(BUILD_DIR)/$(BIN) usage
  84. @cp $< $@
  85. clean:
  86. rm -rf $(BUILD_DIR) $(BIN)