papermario/Makefile

174 lines
3.9 KiB
Makefile
Raw Normal View History

2020-10-23 02:28:24 +02:00
### Build Options ###
2020-05-12 07:04:13 +02:00
2020-10-23 02:28:24 +02:00
# Override these options in settings.mk or with `make SETTING=value'.
2020-10-22 04:09:23 +02:00
2020-10-23 02:28:24 +02:00
BASEROM = baserom.z64
TARGET = papermario
COMPARE = 1
NON_MATCHING = 0
-include settings.mk
# Fail early if baserom does not exist
ifeq ($(wildcard $(BASEROM)),)
$(error Baserom `$(BASEROM)' not found.)
endif
2019-03-07 00:33:29 +01:00
2020-10-23 02:28:24 +02:00
### Sources ###
2020-10-23 02:28:24 +02:00
include sources.mk
2020-10-23 02:28:24 +02:00
### Output ###
2019-03-07 00:33:29 +01:00
BUILD_DIR = build
2020-10-23 02:28:24 +02:00
ROM = $(TARGET).z64
ELF = $(BUILD_DIR)/$(TARGET).elf
LD_SCRIPT = $(TARGET).ld
LD_MAP = $(BUILD_DIR)/$(TARGET).map
2019-03-07 00:33:29 +01:00
2020-10-23 02:28:24 +02:00
ifdef ASSETS_FS
ASSETS_FS_OBJ = $(BUILD_DIR)/$(ASSETS_FS).o
endif
2020-10-23 02:28:24 +02:00
### Tools ###
2020-08-13 04:13:48 +02:00
2020-10-23 02:28:24 +02:00
PYTHON = python3
N64CKSUM = tools/n64crc
SPLAT_YAML = tools/splat.yaml
SPLAT = $(PYTHON) tools/n64splat/split.py $(BASEROM) $(SPLAT_YAML) .
YAY0COMPRESS = tools/Yay0compress
BUILD_ASSETS_FS := $(PYTHON) tools/build_assets_fs.py $(ASSETS_FS) $(BUILD_DIR)/$(ASSETS_FS)
2019-03-07 00:33:29 +01:00
2020-10-23 02:28:24 +02:00
ifndef EMULATOR
ifneq ($(shell command -v mupen64plus-gui),)
EMULATOR = mupen64plus-gui
else
EMULATOR = mupen64plus
endif
endif
2019-03-07 00:33:29 +01:00
2020-10-23 02:28:24 +02:00
### Compiler Options ###
2019-03-07 00:33:29 +01:00
CROSS = mips-linux-gnu-
AS = $(CROSS)as
2020-10-23 02:28:24 +02:00
OLD_AS = tools/mips-nintendo-nu64-as
CC = tools/cc1
CPP = cpp
LD = $(CROSS)ld
OBJCOPY = $(CROSS)objcopy
2020-10-20 00:47:29 +02:00
CPPFLAGS = -Iinclude -Isrc -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2
2020-09-02 20:35:25 +02:00
ASFLAGS = -EB -Iinclude -march=vr4300 -mtune=vr4300
2020-10-05 22:04:33 +02:00
OLDASFLAGS = -EB -Iinclude -G 0
CFLAGS = -O2 -quiet -G 0 -mcpu=vr4300 -mfix4300 -mips3 -mgp32 -mfp32 -Wimplicit -Wuninitialized -Wshadow
2020-10-23 02:28:24 +02:00
LDFLAGS = -T undefined_syms.txt -T undefined_funcs.txt -T $(LD_SCRIPT) -Map $(LD_MAP) --no-check-sections
2020-10-23 02:28:24 +02:00
### Targets ###
2019-03-07 00:33:29 +01:00
clean:
2020-10-23 02:28:24 +02:00
rm -rf $(BUILD_DIR)
2020-08-13 04:13:48 +02:00
2020-10-23 02:28:24 +02:00
setup: clean submodules split
2020-08-13 04:13:48 +02:00
submodules:
git submodule update --init --recursive
split:
2020-10-23 02:28:24 +02:00
rm -rf bin assets
$(SPLAT) --modes ld bin Yay0 PaperMarioMapFS
2020-08-13 04:13:48 +02:00
2020-10-16 00:11:56 +02:00
split-all:
2020-10-23 02:28:24 +02:00
rm -rf bin assets
$(SPLAT) --modes all
test: $(ROM)
ifdef EMULATOR
$(EMULATOR) $<
else
@echo "N64 emulator not detected." && false
endif
2020-10-16 00:11:56 +02:00
2020-10-23 02:28:24 +02:00
$(LD_SCRIPT): $(SPLAT_YAML)
$(SPLAT) --modes ld
2020-10-12 20:46:04 +02:00
2020-10-23 02:28:24 +02:00
$(ROM): $(BUILD_DIR)/$(TARGET).bin
@cp $< $@
ifeq ($(COMPARE),1)
@sha1sum -c checksum.sha1 || (echo 'The build succeeded, but did not match the base ROM. This is expected if you are making changes to the game. To skip this check, use "make COMPARE=0".' && false)
endif
2019-03-07 00:33:29 +01:00
2020-10-23 02:28:24 +02:00
$(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf
$(OBJCOPY) $< $@ -O binary
2019-03-07 00:33:29 +01:00
2020-10-23 02:28:24 +02:00
$(BUILD_DIR)/$(TARGET).elf: $(LD_SCRIPT) $(OBJECTS) $(ASSETS_FS_OBJ)
$(LD) $(LDFLAGS) -o $@
2019-03-07 00:33:29 +01:00
2020-10-23 02:28:24 +02:00
# `make print-VARNAME' to print the value of $(VARNAME)
print-%: ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
2020-10-23 02:28:24 +02:00
### Object Targets (see sources.mk) ###
ifndef OBJECTS
$(warning OBJECTS is not defined by `sources.mk'.)
else
# C
$(filter %.c.o,$(OBJECTS)): $(BUILD_DIR)/%.c.o: %.c
@mkdir -p $(shell dirname $@)
2020-10-23 19:39:38 +02:00
cpp $(CPPFLAGS) $< | tools/compile_dsl_macros.py > $(BUILD_DIR)/$*.i
$(CC) $(CFLAGS) -o - $(BUILD_DIR)/$*.i | $(OLD_AS) $(OLDASFLAGS) - -o $@
2020-10-23 02:28:24 +02:00
# Assembly
$(filter %.s.o,$(OBJECTS)): $(BUILD_DIR)/%.s.o: %.s
@mkdir -p $(shell dirname $@)
$(AS) $(ASFLAGS) -o $@ $<
# Uncompressed data
$(filter %.bin.o,$(OBJECTS)): $(BUILD_DIR)/%.bin.o: %.bin
@mkdir -p $(shell dirname $@)
$(LD) -r -b binary -o $@ $<
2020-10-23 02:28:24 +02:00
# Compressed data
$(filter %.Yay0.o,$(OBJECTS)): $(BUILD_DIR)/%.Yay0.o: %.bin
@mkdir -p $(shell dirname $@)
$(YAY0COMPRESS) $< $(BUILD_DIR)/$*.Yay0
$(LD) -r -b binary -o $@ $(BUILD_DIR)/$*.Yay0
2020-10-18 05:54:32 +02:00
2020-10-23 02:28:24 +02:00
endif
2020-10-17 22:37:46 +02:00
2020-10-18 05:54:32 +02:00
2020-10-23 02:28:24 +02:00
### Asset Filesystem (see sources.mk) ###
2020-10-18 05:54:32 +02:00
2020-10-23 02:28:24 +02:00
# Complain if ASSETS_FS_SOURCES is undefined but ASSETS_FS is.
ifndef ASSETS_FS_SOURCES
ifdef ASSETS_FS
$(warning ASSETS_FS_SOURCES is not defined by `sources.mk' but ASSETS_FS is.)
endif
else
2020-10-18 05:54:32 +02:00
2020-10-23 02:28:24 +02:00
$(BUILD_DIR)/$(ASSETS_FS)/%: $(ASSETS_FS)/%
@mkdir -p $(shell dirname $@)
@rm -f $@
$(BUILD_ASSETS_FS) $*
2019-03-07 00:33:29 +01:00
2020-10-23 02:28:24 +02:00
$(ASSETS_FS_OBJ): $(ASSETS_FS).json $(foreach file,$(ASSETS_FS_SOURCES),$(BUILD_DIR)/$(file))
$(BUILD_ASSETS_FS)
$(LD) -r -b binary -o $@ $(BUILD_DIR)/$(ASSETS_FS).bin
2019-03-07 00:33:29 +01:00
2020-10-23 02:28:24 +02:00
endif
2019-03-07 00:33:29 +01:00
2020-04-25 07:52:11 +02:00
2020-10-23 02:28:24 +02:00
### Make Settings ###
2020-04-25 07:52:11 +02:00
2020-10-23 02:28:24 +02:00
.PHONY: clean test setup submodules split $(ROM)
.DEFAULT_GOAL := $(ROM)
# Remove built-in implicit rules to improve performance
MAKEFLAGS += --no-builtin-rules