2018-10-19 00:45:50 +02:00
|
|
|
|
2023-11-05 11:53:46 +01:00
|
|
|
.SUFFIXES: # Suppress a lot of useless default rules, which also provides a nice speedup.
|
|
|
|
|
|
|
|
|
|
# Recursive `wildcard` function.
|
|
|
|
|
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
|
|
|
|
|
|
|
|
|
|
# Program constants.
|
|
|
|
|
# POSIX OSes (the sane default).
|
|
|
|
|
RM_RF := rm -rf
|
|
|
|
|
MKDIR_P := mkdir -p
|
|
|
|
|
ifeq ($(strip $(shell which rm)),)
|
|
|
|
|
# Windows *really* tries its hardest to be Special™!
|
2023-11-24 12:23:42 +01:00
|
|
|
RM_RF := -rmdir /s /q
|
2023-11-05 11:53:46 +01:00
|
|
|
MKDIR_P := -mkdir
|
2021-03-03 02:52:00 +01:00
|
|
|
endif
|
|
|
|
|
|
2023-11-05 11:53:46 +01:00
|
|
|
RGBDS ?= # Shortcut if you want to use a local copy of RGBDS.
|
|
|
|
|
RGBASM := ${RGBDS}rgbasm
|
|
|
|
|
RGBLINK := ${RGBDS}rgblink
|
|
|
|
|
RGBFIX := ${RGBDS}rgbfix
|
|
|
|
|
RGBGFX := ${RGBDS}rgbgfx
|
2019-04-28 19:36:07 +02:00
|
|
|
|
2023-11-05 11:53:46 +01:00
|
|
|
ROM = bin/${ROMNAME}.${ROMEXT}
|
2019-04-28 19:36:07 +02:00
|
|
|
|
2018-10-19 00:45:50 +02:00
|
|
|
# Argument constants
|
2023-11-05 17:18:40 +01:00
|
|
|
INCDIRS = src/ include/
|
2020-04-25 19:13:38 +02:00
|
|
|
WARNINGS = all extra
|
2023-11-05 11:53:46 +01:00
|
|
|
ASFLAGS = -p ${PADVALUE} $(addprefix -I,${INCDIRS}) $(addprefix -W,${WARNINGS})
|
|
|
|
|
LDFLAGS = -p ${PADVALUE}
|
|
|
|
|
FIXFLAGS = -p ${PADVALUE} -i "${GAMEID}" -k "${LICENSEE}" -l ${OLDLIC} -m ${MBC} -n ${VERSION} -r ${SRAMSIZE} -t ${TITLE}
|
2018-10-19 00:45:50 +02:00
|
|
|
|
2023-11-05 11:53:46 +01:00
|
|
|
# The list of ASM files that RGBASM will be invoked on.
|
|
|
|
|
SRCS = $(call rwildcard,src,*.asm)
|
2018-10-19 00:45:50 +02:00
|
|
|
|
2020-04-25 19:13:38 +02:00
|
|
|
## Project-specific configuration
|
|
|
|
|
# Use this to override the above
|
|
|
|
|
include project.mk
|
2018-10-19 00:45:50 +02:00
|
|
|
|
|
|
|
|
# `all` (Default target): build the ROM
|
2023-11-05 11:53:46 +01:00
|
|
|
all: ${ROM}
|
2018-10-19 00:45:50 +02:00
|
|
|
.PHONY: all
|
|
|
|
|
|
|
|
|
|
# `clean`: Clean temp and bin files
|
|
|
|
|
clean:
|
2023-11-05 11:53:46 +01:00
|
|
|
${RM_RF} bin obj assets
|
2019-04-28 19:36:07 +02:00
|
|
|
.PHONY: clean
|
2018-10-19 00:45:50 +02:00
|
|
|
|
|
|
|
|
# `rebuild`: Build everything from scratch
|
2019-04-28 19:36:07 +02:00
|
|
|
# It's important to do these two in order if we're using more than one job
|
2018-10-19 00:45:50 +02:00
|
|
|
rebuild:
|
2023-11-05 11:53:46 +01:00
|
|
|
${MAKE} clean
|
|
|
|
|
${MAKE} all
|
2019-04-28 19:36:07 +02:00
|
|
|
.PHONY: rebuild
|
2018-10-19 00:45:50 +02:00
|
|
|
|
2023-11-05 11:53:46 +01:00
|
|
|
# By default, asset recipes convert files in `assets/` into other files in `assets/`.
|
|
|
|
|
# This line causes assets not found in `assets/` to be also looked for in `src/assets/`.
|
|
|
|
|
# "Source" assets can thus be safely stored there without `make clean` removing them!
|
2021-08-31 17:49:52 +02:00
|
|
|
VPATH := src
|
2021-03-14 11:39:20 +01:00
|
|
|
|
2023-11-05 11:53:46 +01:00
|
|
|
# Define how to compress files using the PackBits16 codec.
|
|
|
|
|
# (The compressor script requires Python 3.)
|
|
|
|
|
assets/%.pb16: src/tools/pb16.py assets/%
|
2023-11-24 12:23:42 +01:00
|
|
|
@${MKDIR_P} "${@D}"
|
2021-03-14 11:39:20 +01:00
|
|
|
$^ $@
|
2021-03-14 12:22:48 +01:00
|
|
|
|
2023-11-05 11:53:46 +01:00
|
|
|
# How to build a ROM.
|
|
|
|
|
# Notice that the build date is always refreshed.
|
|
|
|
|
bin/%.${ROMEXT}: $(patsubst src/%.asm,obj/%.o,${SRCS})
|
2023-11-24 12:23:42 +01:00
|
|
|
@${MKDIR_P} "${@D}"
|
2023-11-05 11:53:46 +01:00
|
|
|
${RGBASM} ${ASFLAGS} -o obj/build_date.o src/assets/build_date.asm
|
|
|
|
|
${RGBLINK} ${LDFLAGS} -m bin/$*.map -n bin/$*.sym -o $@ $^ \
|
|
|
|
|
&& ${RGBFIX} -v ${FIXFLAGS} $@
|
|
|
|
|
|
|
|
|
|
# `.mk` files are auto-generated dependency lists of the source ASM files, to save a lot of hassle.
|
|
|
|
|
# Also add all obj dependencies to the dep file too, so Make knows to remake it.
|
|
|
|
|
# Caution: some of these flags were added in RGBDS 0.4.0, using an earlier version WILL NOT WORK
|
|
|
|
|
# (and produce weird errors).
|
|
|
|
|
obj/%.mk: src/%.asm
|
2023-11-24 12:23:42 +01:00
|
|
|
@${MKDIR_P} "${@D}"
|
2023-11-05 11:53:46 +01:00
|
|
|
${RGBASM} ${ASFLAGS} -M $@ -MG -MP -MQ ${@:.mk=.o} -MQ $@ -o ${@:.mk=.o} $<
|
|
|
|
|
# DO NOT merge this with the rule above, otherwise Make will assume that the `.o` file is generated,
|
|
|
|
|
# even when it isn't!
|
|
|
|
|
# This causes weird issues that depend, among other things, on the version of Make.
|
|
|
|
|
obj/%.o: obj/%.mk
|
|
|
|
|
@touch $@
|
|
|
|
|
|
|
|
|
|
ifeq ($(filter clean,${MAKECMDGOALS}),)
|
|
|
|
|
include $(patsubst src/%.asm,obj/%.mk,${SRCS})
|
|
|
|
|
endif
|