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:
ISSOtm
2023-11-05 11:53:46 +01:00
parent 6718b2190c
commit 06ea1ea0fa
5 changed files with 110 additions and 128 deletions

2
.gitignore vendored
View File

@@ -1,4 +1,4 @@
/bin/ /bin/
/obj/ /obj/
/dep/ /dep/
/res/ /assets/

138
Makefile
View File

@@ -1,121 +1,89 @@
.SUFFIXES: .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))
# CONSTANT DEFINITIONS #
# #
################################################
## Directory constants # Program constants.
# These directories can be placed elsewhere if you want; directories whose placement # POSIX OSes (the sane default).
# 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 RM_RF := rm -rf
MKDIR_P := mkdir -p MKDIR_P := mkdir -p
else ifeq ($(strip $(shell which rm)),)
# Windows # Windows *really* tries its hardest to be Special™!
RM_RF := -del /q RM_RF := -del /q
MKDIR_P := -mkdir MKDIR_P := -mkdir
endif endif
# Shortcut if you want to use a local copy of RGBDS RGBDS ?= # Shortcut if you want to use a local copy of RGBDS.
RGBDS := RGBASM := ${RGBDS}rgbasm
RGBASM := $(RGBDS)rgbasm RGBLINK := ${RGBDS}rgblink
RGBLINK := $(RGBDS)rgblink RGBFIX := ${RGBDS}rgbfix
RGBFIX := $(RGBDS)rgbfix RGBGFX := ${RGBDS}rgbgfx
ROM = $(BINDIR)/$(ROMNAME).$(ROMEXT) ROM = bin/${ROMNAME}.${ROMEXT}
# Argument constants # Argument constants
INCDIRS = src/ src/include/ INCDIRS = src/ src/include/
WARNINGS = all extra WARNINGS = all extra
ASFLAGS = -p $(PADVALUE) $(addprefix -i,$(INCDIRS)) $(addprefix -W,$(WARNINGS)) ASFLAGS = -p ${PADVALUE} $(addprefix -I,${INCDIRS}) $(addprefix -W,${WARNINGS})
LDFLAGS = -p $(PADVALUE) LDFLAGS = -p ${PADVALUE}
FIXFLAGS = -p $(PADVALUE) -v -i "$(GAMEID)" -k "$(LICENSEE)" -l $(OLDLIC) -m $(MBC) -n $(VERSION) -r $(SRAMSIZE) -t $(TITLE) 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 # The list of ASM files that RGBASM will be invoked on.
SRCS = $(wildcard src/*.asm) SRCS = $(call rwildcard,src,*.asm)
## Project-specific configuration ## Project-specific configuration
# Use this to override the above # Use this to override the above
include project.mk include project.mk
################################################
# #
# TARGETS #
# #
################################################
# `all` (Default target): build the ROM # `all` (Default target): build the ROM
all: $(ROM) all: ${ROM}
.PHONY: all .PHONY: all
# `clean`: Clean temp and bin files # `clean`: Clean temp and bin files
clean: clean:
$(RM_RF) $(BINDIR) ${RM_RF} bin obj assets
$(RM_RF) $(OBJDIR)
$(RM_RF) $(DEPDIR)
$(RM_RF) res
.PHONY: clean .PHONY: clean
# `rebuild`: Build everything from scratch # `rebuild`: Build everything from scratch
# It's important to do these two in order if we're using more than one job # It's important to do these two in order if we're using more than one job
rebuild: rebuild:
$(MAKE) clean ${MAKE} clean
$(MAKE) all ${MAKE} all
.PHONY: rebuild .PHONY: rebuild
############################################### # 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/`.
# COMPILATION # # "Source" assets can thus be safely stored there without `make clean` removing them!
# #
###############################################
# 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
VPATH := src VPATH := src
# Define how to compress files using the PackBits16 codec # Define how to compress files using the PackBits16 codec.
# Compressor script requires Python 3 # (The compressor script requires Python 3.)
res/%.pb16: src/tools/pb16.py res/% assets/%.pb16: src/tools/pb16.py assets/%
@$(MKDIR_P) $(@D) @${MKDIR_P} ${@D}
$^ $@ $^ $@
# Catch non-existent files # How to build a ROM.
# KEEP THIS LAST!! # Notice that the build date is always refreshed.
%: bin/%.${ROMEXT}: $(patsubst src/%.asm,obj/%.o,${SRCS})
@false @${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

View File

@@ -12,19 +12,31 @@ Make sure you have [RGBDS](https://github.com/rednex/rgbds), at least version 0.
## Customizing ## Customizing
Edit `project.mk` to customize most things specific to the project (like the game name, file name and extension, etc.). Everything has accompanying doc comments. Edit `project.mk` to customize most things specific to the project (like the game name, file name and extension, etc.).
Everything has accompanying doc comments.
Everything in the `src` folder is the source, and can be freely modified however you want. The basic structure in place should hint you at how things are organized. If you want to create a new "module", you simply need to drop a `.asm` file in the `src` directory, name does not matter. All `.asm` files in that root directory will be individually compiled by RGBASM. Everything in the `src` directory is the source, and can be freely modified however you want.
Any `.asm` files in that directory (and its sub-directories, recursively) will be individually assembled, automatically.
If you need some files not to be assembled directly (because they are only meant to be `INCLUDE`d), you can either rename them (typically, to `.inc`), or move them outside of `src` (typically, to a directory called `include`).
The file at `src/res/build_date.asm` is compiled individually to include a build date in your ROM. Always comes in handy. The file at `src/assets/build_date.asm` is compiled individually to include a build date in your ROM.
Always comes in handy.
If you want to add resources, I recommend using the `src/res` folder. Add rules in the Makefile; an example is provided for compressing files using PB16 (a variation of [PackBits](https://wiki.nesdev.com/w/index.php/Tile_compression#PackBits)). If you want to add resources, I recommend using the `src/assets` directory.
Add rules in the Makefile; an example is provided for compressing files using PB16 (a variation of [PackBits](https://wiki.nesdev.com/w/index.php/Tile_compression#PackBits)).
## Compiling ## Compiling
Simply open you favorite command prompt / terminal, place yourself in this directory (the one the Makefile is located in), and run the command `make`. This should create a bunch of things, including the output in the `bin` folder. Simply open you favorite command prompt / terminal, place yourself in this directory (the one the Makefile is located in), and run the command `make`.
This should create a bunch of things, including the output in the `bin` directory.
If you get errors that you don't understand, try running `make clean`. If that gives the same error, try deleting the `deps` folder. If that still doesn't work, try deleting the `bin` and `obj` folders as well. If that still doesn't work, you probably did something wrong yourself. Pass the `-s` flag to `make` if it spews too much input for your tastes.
Päss the `-j <N>` flag to `make` to build more things in parallel, replacing `<N>` with however many things you want to build in parallel; your number of (logical) CPU cores is often a good pick (so, `-j 8` for me), run the command `nproc` to obtain it.
If you get errors that you don't understand, try running `make clean`.
If that gives the same error, try deleting the `assets` directory.
If that still doesn't work, try deleting the `bin` and `obj` directories as well.
If that still doesn't work, feel free to ask for help.
## See also ## See also
@@ -32,9 +44,10 @@ If you want something less barebones, already including some "base" code, check
Perhaps [a gbdev style guide](https://gbdev.io/guides/asmstyle) may be of interest to you? Perhaps [a gbdev style guide](https://gbdev.io/guides/asmstyle) may be of interest to you?
I recommend the [BGB](https://bgb.bircd.org) emulator for developing ROMs on Windows and, via Wine, Linux and macOS (64-bit build available for Catalina). [SameBoy](https://github.com/LIJI32/SameBoy) is more accurate, but has a much worse interface except on macOS. I recommend the [BGB](https://bgb.bircd.org) emulator for developing ROMs on Windows and, via Wine, Linux and macOS (64-bit build available for Catalina).
[SameBoy](https://github.com/LIJI32/SameBoy) is more accurate, but has a more lackluster interface outside of macOS.
### Libraries ### Libraries
- [Variable-width font engine](https://github.com/ISSOtm/gb-vwf) - [Variable-width font engine](https://github.com/ISSOtm/gb-vwf)
- [structs in RGBDS](https://github.com/ISSOtm/rgbds-structs) - [Structs in RGBDS](https://github.com/ISSOtm/rgbds-structs)

View File

@@ -1,66 +1,67 @@
# This file contains project configuration # This file contains project-specific configuration.
# You can override variables set in the Makefile here.
# Value that the ROM will be filled with # Value that the ROM will be filled with.
PADVALUE := 0xFF PADVALUE := 0xFF
## Header constants (passed to RGBFIX) ## Header constants (passed to RGBFIX).
# ROM version (typically starting at 0 and incremented for each published version) # ROM version (typically starting at 0 and incremented for each published version).
VERSION := 0 VERSION := 0
# 4-ASCII letter game ID # 4-ASCII letter game ID.
GAMEID := BOIL GAMEID := BOIL
# Game title, up to 11 ASCII chars # Game title, up to 11 ASCII chars.
TITLE := BOILERPLATE TITLE := BOILERPLATE
# New licensee, 2 ASCII chars # New licensee, 2 ASCII chars.
# Homebrew games FTW! # Homebrew games FTW!.
LICENSEE := HB LICENSEE := HB
# Old licensee, please set to 0x33 (required to get SGB compatibility) # Old licensee, please set to 0x33 (required to get SGB compatibility).
OLDLIC := 0x33 OLDLIC := 0x33
# MBC type, tells which hardware is in the cart # MBC type, tells which hardware is in the cart.
# See https://gbdev.io/pandocs/#_0147-cartridge-type or consult any copy of Pan Docs # You can get a list of valid values by running `rgbfix -m help`.
# If using no MBC, consider enabling `-t` below # See https://gbdev.io/pandocs/MBCs for more information, or consult any copy of Pan Docs.
# If using no MBC, consider enabling `-t` below.
MBC := 0x00 MBC := 0x00
# ROM size is set automatically by RGBFIX # ROM size is set automatically by RGBFIX.
# Size of the on-board SRAM; MBC type should indicate the presence of RAM # Size of the on-board SRAM; MBC type should indicate the presence of RAM.
# See https://gbdev.io/pandocs/#_0149-ram-size or consult any copy of Pan Docs # See https://gbdev.io/pandocs/The_Cartridge_Header#0149--ram-size or consult any copy of Pan Docs.
# Set this to 0 when using MBC2's built-in SRAM # Set this to 0 when using MBC2's built-in SRAM.
SRAMSIZE := 0x00 SRAMSIZE := 0x00
# ROM name # ROM name.
ROMNAME := boilerplate ROMNAME := boilerplate
ROMEXT := gb ROMEXT := gb
# Compilation parameters, uncomment to apply, comment to cancel # Compilation parameters, uncomment to apply, comment to cancel.
# "Sensible defaults" are included # "Sensible defaults" are included.
# Please refer to RGBDS' documentation.
# For example, offline: `man 1 rgbasm`; online: https://rgbds.gbdev.io/docs/rgbasm.1
# Disable automatic `nop` after `halt` # Export all labels.
ASFLAGS += -h # This means they must all have unique names, but they will all show up in the .sym and .map files.
# Export all labels
# This means they must all have unique names, but they will all show up in the .sym and .map files
# ASFLAGS += -E # ASFLAGS += -E
# Game Boy Color compatible # Game Boy Color compatible.
# FIXFLAGS += -c # FIXFLAGS += -c
# Game Boy Color required # Game Boy Color required.
# FIXFLAGS += -C # FIXFLAGS += -C
# Super Game Boy compatible # Super Game Boy compatible.
# FIXFLAGS += -s # FIXFLAGS += -s
# Game Boy mode # Game Boy mode.
# LDFLAGS += -d # LDFLAGS += -d
# No banked WRAM mode # No banked WRAM mode.
# LDFLAGS += -w # LDFLAGS += -w
# 32k mode # 32k mode.
# LDFLAGS += -t # LDFLAGS += -t