Files
Binx/Makefile

97 lines
3.3 KiB
Makefile
Raw Normal View History

2018-10-19 00:45:50 +02:00
.SUFFIXES:
################################################
# #
# CONSTANT DEFINITIONS #
# #
################################################
2018-10-19 00:45:50 +02:00
# Directory constants
SRCDIR := src
BINDIR := bin
OBJDIR := obj
DEPDIR := dep
RESDIR := res
2018-10-19 00:45:50 +02:00
# Program constants
MKDIR := $(shell which mkdir)
# Shortcut if you want to use a local copy of RGBDS
RGBDS =
RGBASM = $(RGBDS)rgbasm
RGBLINK = $(RGBDS)rgblink
RGBFIX = $(RGBDS)rgbfix
ROM = $(BINDIR)/$(ROMNAME).$(ROMEXT)
2018-10-19 00:45:50 +02:00
# Argument constants
INCDIRS = $(SRCDIR)/ $(SRCDIR)/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)
2018-10-19 00:45:50 +02:00
# The list of "root" ASM files that RGBASM will be invoked on
SRCS = $(wildcard $(SRCDIR)/*.asm)
2018-10-19 00:45:50 +02:00
## Project-specific configuration
# Use this to override the above
include project.mk
2018-10-19 00:45:50 +02:00
################################################
# #
# 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 := $(SRCDIR)
# Define how to compress files using the PackBits16 codec
# Compressor script requires Python 3
$(RESDIR)/%.pb16: $(SRCDIR)/tools/pb16.py $(RESDIR)/%
2019-04-28 19:38:16 +02:00
$^ $@
###############################################
# #
# COMPILATION #
# #
###############################################
2018-10-19 00:45:50 +02:00
# `all` (Default target): build the ROM
all: $(ROM)
2018-10-19 00:45:50 +02:00
.PHONY: all
# `clean`: Clean temp and bin files
clean:
-rm -rf $(BINDIR) $(OBJDIR) $(DEPDIR) $(RESDIR)
.PHONY: clean
2018-10-19 00:45:50 +02:00
# `rebuild`: Build everything from scratch
# 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:
$(MAKE) clean
$(MAKE) all
.PHONY: rebuild
2018-10-19 00:45:50 +02:00
# How to build a ROM
$(BINDIR)/%.$(ROMEXT) $(BINDIR)/%.sym $(BINDIR)/%.map: $(patsubst $(SRCDIR)/%.asm,$(OBJDIR)/%.o,$(SRCS))
@$(MKDIR) -p $(@D)
2018-10-19 00:45:50 +02:00
$(RGBASM) $(ASFLAGS) -o $(OBJDIR)/build_date.o $(SRCDIR)/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: $(SRCDIR)/%.asm
@$(MKDIR) -p $(dir $(OBJDIR)/$* $(DEPDIR)/$*)
$(RGBASM) $(ASFLAGS) -M $(DEPDIR)/$*.mk -MG -MP -MQ $(OBJDIR)/$*.o -MQ $(DEPDIR)/$*.mk -o $(OBJDIR)/$*.o $<
2018-10-19 00:45:50 +02:00
ifneq ($(MAKECMDGOALS),clean)
-include $(patsubst $(SRCDIR)/%.asm,$(DEPDIR)/%.mk,$(SRCS))
endif