Overhaul boilerplate
Fix occasional build issues, which turned out to be improper use of multiple targets Update links to point to current URLs for resources Improve formatting where applicable Switch to recursively scanning for assembly files, as this has proven to scale better
This commit is contained in:
146
Makefile
146
Makefile
@@ -1,121 +1,89 @@
|
||||
|
||||
.SUFFIXES:
|
||||
.SUFFIXES: # Suppress a lot of useless default rules, which also provides a nice speedup.
|
||||
|
||||
################################################
|
||||
# #
|
||||
# CONSTANT DEFINITIONS #
|
||||
# #
|
||||
################################################
|
||||
# Recursive `wildcard` function.
|
||||
rwildcard = $(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
|
||||
|
||||
## Directory constants
|
||||
# These directories can be placed elsewhere if you want; directories whose placement
|
||||
# must be fixed, lest this Makefile breaks, are hardcoded throughout this Makefile
|
||||
BINDIR := bin
|
||||
OBJDIR := obj
|
||||
DEPDIR := dep
|
||||
|
||||
# Program constants
|
||||
ifneq ($(strip $(shell which rm)),)
|
||||
# POSIX OSes
|
||||
RM_RF := rm -rf
|
||||
MKDIR_P := mkdir -p
|
||||
else
|
||||
# Windows
|
||||
RM_RF := -del /q
|
||||
MKDIR_P := -mkdir
|
||||
# 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™!
|
||||
RM_RF := -del /q
|
||||
MKDIR_P := -mkdir
|
||||
endif
|
||||
|
||||
# Shortcut if you want to use a local copy of RGBDS
|
||||
RGBDS :=
|
||||
RGBASM := $(RGBDS)rgbasm
|
||||
RGBLINK := $(RGBDS)rgblink
|
||||
RGBFIX := $(RGBDS)rgbfix
|
||||
RGBDS ?= # Shortcut if you want to use a local copy of RGBDS.
|
||||
RGBASM := ${RGBDS}rgbasm
|
||||
RGBLINK := ${RGBDS}rgblink
|
||||
RGBFIX := ${RGBDS}rgbfix
|
||||
RGBGFX := ${RGBDS}rgbgfx
|
||||
|
||||
ROM = $(BINDIR)/$(ROMNAME).$(ROMEXT)
|
||||
ROM = bin/${ROMNAME}.${ROMEXT}
|
||||
|
||||
# Argument constants
|
||||
INCDIRS = src/ src/include/
|
||||
WARNINGS = all extra
|
||||
ASFLAGS = -p $(PADVALUE) $(addprefix -i,$(INCDIRS)) $(addprefix -W,$(WARNINGS))
|
||||
LDFLAGS = -p $(PADVALUE)
|
||||
FIXFLAGS = -p $(PADVALUE) -v -i "$(GAMEID)" -k "$(LICENSEE)" -l $(OLDLIC) -m $(MBC) -n $(VERSION) -r $(SRAMSIZE) -t $(TITLE)
|
||||
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}
|
||||
|
||||
# The list of "root" ASM files that RGBASM will be invoked on
|
||||
SRCS = $(wildcard src/*.asm)
|
||||
# The list of ASM files that RGBASM will be invoked on.
|
||||
SRCS = $(call rwildcard,src,*.asm)
|
||||
|
||||
## Project-specific configuration
|
||||
# Use this to override the above
|
||||
include project.mk
|
||||
|
||||
################################################
|
||||
# #
|
||||
# TARGETS #
|
||||
# #
|
||||
################################################
|
||||
|
||||
# `all` (Default target): build the ROM
|
||||
all: $(ROM)
|
||||
all: ${ROM}
|
||||
.PHONY: all
|
||||
|
||||
# `clean`: Clean temp and bin files
|
||||
clean:
|
||||
$(RM_RF) $(BINDIR)
|
||||
$(RM_RF) $(OBJDIR)
|
||||
$(RM_RF) $(DEPDIR)
|
||||
$(RM_RF) res
|
||||
${RM_RF} bin obj assets
|
||||
.PHONY: clean
|
||||
|
||||
# `rebuild`: Build everything from scratch
|
||||
# It's important to do these two in order if we're using more than one job
|
||||
rebuild:
|
||||
$(MAKE) clean
|
||||
$(MAKE) all
|
||||
${MAKE} clean
|
||||
${MAKE} all
|
||||
.PHONY: rebuild
|
||||
|
||||
###############################################
|
||||
# #
|
||||
# COMPILATION #
|
||||
# #
|
||||
###############################################
|
||||
|
||||
# How to build a ROM
|
||||
$(BINDIR)/%.$(ROMEXT) $(BINDIR)/%.sym $(BINDIR)/%.map: $(patsubst src/%.asm,$(OBJDIR)/%.o,$(SRCS))
|
||||
@$(MKDIR_P) $(@D)
|
||||
$(RGBASM) $(ASFLAGS) -o $(OBJDIR)/build_date.o src/res/build_date.asm
|
||||
$(RGBLINK) $(LDFLAGS) -m $(BINDIR)/$*.map -n $(BINDIR)/$*.sym -o $(BINDIR)/$*.$(ROMEXT) $^ $(OBJDIR)/build_date.o \
|
||||
&& $(RGBFIX) -v $(FIXFLAGS) $(BINDIR)/$*.$(ROMEXT)
|
||||
|
||||
# `.mk` files are auto-generated dependency lists of the "root" 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)
|
||||
$(OBJDIR)/%.o $(DEPDIR)/%.mk: src/%.asm
|
||||
@$(MKDIR_P) $(patsubst %/,%,$(dir $(OBJDIR)/$* $(DEPDIR)/$*))
|
||||
$(RGBASM) $(ASFLAGS) -M $(DEPDIR)/$*.mk -MG -MP -MQ $(OBJDIR)/$*.o -MQ $(DEPDIR)/$*.mk -o $(OBJDIR)/$*.o $<
|
||||
|
||||
ifneq ($(MAKECMDGOALS),clean)
|
||||
-include $(patsubst src/%.asm,$(DEPDIR)/%.mk,$(SRCS))
|
||||
endif
|
||||
|
||||
################################################
|
||||
# #
|
||||
# RESOURCE FILES #
|
||||
# #
|
||||
################################################
|
||||
|
||||
|
||||
# By default, asset recipes convert files in `res/` into other files in `res/`
|
||||
# This line causes assets not found in `res/` to be also looked for in `src/res/`
|
||||
# "Source" assets can thus be safely stored there without `make clean` removing them
|
||||
# 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!
|
||||
VPATH := src
|
||||
|
||||
# Define how to compress files using the PackBits16 codec
|
||||
# Compressor script requires Python 3
|
||||
res/%.pb16: src/tools/pb16.py res/%
|
||||
@$(MKDIR_P) $(@D)
|
||||
# Define how to compress files using the PackBits16 codec.
|
||||
# (The compressor script requires Python 3.)
|
||||
assets/%.pb16: src/tools/pb16.py assets/%
|
||||
@${MKDIR_P} ${@D}
|
||||
$^ $@
|
||||
|
||||
# Catch non-existent files
|
||||
# KEEP THIS LAST!!
|
||||
%:
|
||||
@false
|
||||
# How to build a ROM.
|
||||
# Notice that the build date is always refreshed.
|
||||
bin/%.${ROMEXT}: $(patsubst src/%.asm,obj/%.o,${SRCS})
|
||||
@${MKDIR_P} ${@D}
|
||||
${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
|
||||
@${MKDIR_P} ${@D}
|
||||
${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
|
||||
|
||||
Reference in New Issue
Block a user