2020-10-23 02:28:24 +02:00
### Build Options ###
# Override these options in settings.mk or with `make SETTING=value'.
BASEROM = baserom.z64
TARGET = papermario
COMPARE = 1
NON_MATCHING = 0
2020-10-28 22:34:04 +01:00
WATCH_INCLUDES = 1
2020-10-23 02:28:24 +02:00
- i n c l u d e s e t t i n g s . m k
# Fail early if baserom does not exist
i f e q ( $( wildcard $ ( BASEROM ) ) , )
$( error Baserom `$ ( BASEROM ) ' not found .)
e n d i f
2020-05-12 07:04:13 +02:00
2020-10-28 21:57:00 +01:00
# NON_MATCHING=1 implies COMPARE=0
i f e q ( $( NON_MATCHING ) , 1 )
o v e r r i d e COMPARE = 0
e n d i f
2020-10-23 02:28:24 +02:00
### Output ###
2019-03-07 00:33:29 +01:00
2020-10-28 21:57:00 +01:00
BUILD_DIR := build
ROM := $( TARGET) .z64
ELF := $( BUILD_DIR) /$( TARGET) .elf
LD_SCRIPT := $( TARGET) .ld
LD_MAP := $( BUILD_DIR) /$( TARGET) .map
ASSETS_BIN := $( BUILD_DIR) /bin/assets/assets.bin
2020-04-28 02:22:56 +02:00
2020-10-23 02:28:24 +02:00
### Tools ###
2020-10-28 21:57:00 +01:00
PYTHON := python3
N64CKSUM := tools/n64crc
SPLAT_YAML := tools/splat.yaml
2020-10-23 02:28:24 +02:00
SPLAT = $( PYTHON) tools/n64splat/split.py $( BASEROM) $( SPLAT_YAML) .
YAY0COMPRESS = tools/Yay0compress
i f n d e f E M U L A T O R
2020-10-23 14:47:07 +02:00
i f n e q ( $( shell which mupen 64plus -gui ) , )
2020-10-23 02:28:24 +02:00
EMULATOR = mupen64plus-gui
e l s e
EMULATOR = mupen64plus
e n d i f
e n d i f
2019-03-07 00:33:29 +01:00
2020-10-23 02:28:24 +02:00
### Compiler Options ###
2020-10-28 21:57:00 +01:00
CROSS := mips-linux-gnu-
AS := $( CROSS) as
OLD_AS := tools/mips-nintendo-nu64-as
CC := tools/cc1
CPP := cpp
LD := $( CROSS) ld
OBJCOPY := $( CROSS) objcopy
2020-05-12 05:00:21 +02:00
2020-10-29 17:08:00 +01:00
CPPFLAGS := -Iinclude -Isrc -D _LANGUAGE_C -ffreestanding -DF3DEX_GBI_2 -D_MIPS_SZLONG= 32 -Wundef -Wcomment
2020-10-28 21:57:00 +01:00
ASFLAGS := -EB -Iinclude -march= vr4300 -mtune= vr4300
OLDASFLAGS := -EB -Iinclude -G 0
CFLAGS := -O2 -quiet -G 0 -mcpu= vr4300 -mfix4300 -mips3 -mgp32 -mfp32 -Wimplicit -Wuninitialized -Wshadow
LDFLAGS := -T undefined_syms.txt -T undefined_funcs.txt -T $( BUILD_DIR) /$( LD_SCRIPT) -Map $( LD_MAP) --no-check-sections
2020-04-28 12:45:56 +02:00
2020-10-23 11:36:00 +02:00
i f e q ( $( NON_MATCHING ) , 1 )
CPPFLAGS += -DNON_MATCHING
e n d i f
2019-03-07 00:33:29 +01:00
2020-10-28 21:57:00 +01:00
### Sources ###
i n c l u d e s o u r c e s . m k
2020-10-28 23:08:14 +01:00
%.d : ;
2020-10-28 22:34:04 +01:00
i f e q ( $( WATCH_INCLUDES ) , 1 )
2020-10-28 23:08:14 +01:00
- i n c l u d e $( foreach obj , $ ( OBJECTS ) , $ ( obj ) .mk )
2020-10-28 22:34:04 +01:00
e n d i f
2020-10-28 21:57:00 +01:00
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 11:36:20 +02:00
clean-code :
rm -rf $( BUILD_DIR) /src
2020-10-23 02:28:24 +02:00
setup : clean submodules split
2020-10-23 14:47:07 +02:00
make -C tools
2020-08-13 04:13:48 +02:00
submodules :
git submodule update --init --recursive
split :
2020-10-28 21:57:00 +01:00
rm -rf bin
2020-10-23 02:28:24 +02:00
$( SPLAT) --modes ld bin Yay0 PaperMarioMapFS
2020-08-13 04:13:48 +02:00
2020-10-28 21:57:00 +01:00
split-bin :
$( SPLAT) --modes ld bin
2020-10-16 00:11:56 +02:00
split-all :
2020-10-28 21:57:00 +01:00
rm -rf bin
2020-10-23 02:28:24 +02:00
$( SPLAT) --modes all
test : $( ROM )
i f d e f E M U L A T O R
$( EMULATOR) $<
e l s e
@echo "N64 emulator not detected." && false
e n d i f
2020-10-12 20:46:04 +02:00
2020-10-28 21:57:00 +01:00
# Compressed files
%.Yay0 : %
@mkdir -p $( shell dirname $@ )
$( YAY0COMPRESS) $< $@
$(BUILD_DIR)/%.bin.Yay0 : %.bin
@mkdir -p $( shell dirname $@ )
$( YAY0COMPRESS) $< $@
2020-04-28 02:22:56 +02:00
2020-10-28 21:57:00 +01:00
# Data objects
$(BUILD_DIR)/%.bin.o : %.bin
@mkdir -p $( shell dirname $@ )
$( LD) -r -b binary -o $@ $<
2020-10-23 02:28:24 +02:00
2020-10-28 21:57:00 +01:00
# Compressed data objects
$(BUILD_DIR)/%.Yay0.o : $( BUILD_DIR ) /%.bin .Yay 0
@mkdir -p $( shell dirname $@ )
$( LD) -r -b binary -o $@ $<
2020-10-23 02:28:24 +02:00
2020-10-28 21:57:00 +01:00
# Compile C files
2020-10-28 23:08:14 +01:00
$(BUILD_DIR)/%.c.o : %.c $( BUILD_DIR ) /%.d
2020-10-23 02:28:24 +02:00
@mkdir -p $( shell dirname $@ )
2020-10-29 17:08:00 +01:00
$( CPP) $( CPPFLAGS) -MP -MD -o - $< -MF $@ .mk -MT $( BUILD_DIR) /$* .d | $( CC) $( CFLAGS) -o - - | $( OLD_AS) $( OLDASFLAGS) -o $@ -
2020-10-23 22:06:06 +02:00
2020-10-28 21:57:00 +01:00
# Compile C files (with DSL macros)
2020-10-28 23:08:14 +01:00
$(foreach cfile, $(DSL_C_FILES), $(BUILD_DIR)/$(cfile).o) : $( BUILD_DIR ) /%.c .o : %.c $( BUILD_DIR ) /%.d
2020-10-28 21:57:00 +01:00
@mkdir -p $( shell dirname $@ )
2020-10-29 17:08:00 +01:00
$( CPP) $( CPPFLAGS) -MP -MD -o - $< -MF $@ .mk -MT $( BUILD_DIR) /$* .d | tools/compile_dsl_macros.py | $( CC) $( CFLAGS) -o - - | $( OLD_AS) $( OLDASFLAGS) -o $@ -
2020-04-28 02:22:56 +02:00
2020-10-28 21:57:00 +01:00
# Assemble handwritten ASM
$(BUILD_DIR)/%.s.o : %.s
2020-10-23 02:28:24 +02:00
@mkdir -p $( shell dirname $@ )
$( AS) $( ASFLAGS) -o $@ $<
2020-10-28 21:57:00 +01:00
ASSET_FILES := $( foreach asset, $( ASSETS) , $( BUILD_DIR) /bin/assets/$( asset) )
YAY0_ASSET_FILES := $( foreach asset, $( filter-out %_tex, $( ASSET_FILES) ) , $( asset) .Yay0)
$(BUILD_DIR)/bin/assets/% : bin /assets /%.bin
2020-10-23 02:28:24 +02:00
@mkdir -p $( shell dirname $@ )
2020-10-28 21:57:00 +01:00
@cp $< $@
2020-04-28 02:22:56 +02:00
2020-10-28 21:57:00 +01:00
$(ASSETS_BIN) : $( ASSET_FILES ) $( YAY 0_ASSET_FILES )
2020-10-23 02:28:24 +02:00
@mkdir -p $( shell dirname $@ )
2020-10-28 21:57:00 +01:00
@echo " building $@ "
@$( PYTHON) tools/build_assets_bin.py $@ $( ASSET_FILES)
2020-10-18 05:54:32 +02:00
2020-10-28 21:57:00 +01:00
$(ASSETS_BIN : .bin =.o ): $( ASSETS_BIN )
$( LD) -r -b binary -o $@ $<
2020-10-18 05:54:32 +02:00
2020-10-28 21:57:00 +01:00
$(LD_SCRIPT) : $( SPLAT_YAML )
$( SPLAT) --modes ld
2020-10-18 05:54:32 +02:00
2020-10-28 21:57:00 +01:00
$(BUILD_DIR)/$(LD_SCRIPT) : $( LD_SCRIPT )
@mkdir -p $( shell dirname $@ )
$( CPP) -P -DBUILD_DIR= $( BUILD_DIR) -o $@ $<
2020-10-19 23:29:40 +02:00
2020-10-28 21:57:00 +01:00
$(ROM) : $( BUILD_DIR ) /$( TARGET ) .bin
@cp $< $@
i f e q ( $( 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 )
2020-10-23 02:28:24 +02:00
e n d i f
2020-10-19 23:29:40 +02:00
2020-10-28 21:57:00 +01:00
$(BUILD_DIR)/$(TARGET).bin : $( BUILD_DIR ) /$( TARGET ) .elf
$( OBJCOPY) $< $@ -O binary
2019-03-07 00:33:29 +01:00
2020-10-28 21:57:00 +01:00
$(BUILD_DIR)/$(TARGET).elf : $( BUILD_DIR ) /$( LD_SCRIPT ) $( OBJECTS )
$( LD) $( LDFLAGS) -o $@
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 ###
.PHONY : clean test setup submodules split $( ROM )
2020-10-28 21:57:00 +01:00
.DELETE_ON_ERROR :
.SECONDARY :
.PRECIOUS : $( ROM ) %.Yay 0
2020-10-23 02:28:24 +02:00
.DEFAULT_GOAL := $( ROM)
# Remove built-in implicit rules to improve performance
MAKEFLAGS += --no-builtin-rules