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
- 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
2019-03-07 00:33:29 +01:00
2020-10-23 02:28:24 +02:00
### Sources ###
2020-10-19 06:42:17 +02:00
2020-10-23 02:28:24 +02:00
i n c l u d e s o u r c e s . m k
2020-04-28 02:22:56 +02:00
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
i f d e f A S S E T S _ F S
ASSETS_FS_OBJ = $( BUILD_DIR) /$( ASSETS_FS) .o
2020-08-15 01:12:41 +02:00
e n d i f
2020-04-28 02:22:56 +02:00
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
i f n d e f E M U L A T O R
i f n e q ( $( shell command -v mupen 64plus -gui ) , )
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 ###
2019-03-07 00:33:29 +01:00
2020-05-12 05:00:21 +02: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
2020-08-10 08:16:13 +02:00
LD = $( CROSS) ld
2020-05-12 05:00:21 +02:00
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
2020-10-21 05:58:03 +02:00
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-05-12 05:00:21 +02:00
2020-04-28 12:45:56 +02: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 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 )
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-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 $< $@
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 )
e n d i f
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-04-28 02:22:56 +02:00
2020-10-23 02:28:24 +02:00
### Object Targets (see sources.mk) ###
i f n d e f O B J E C T S
$( warning OBJECTS is not defined by `sources .mk '.)
e l s e
# 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-04-28 02:22:56 +02:00
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 $@ )
2020-05-12 05:00:21 +02:00
$( LD) -r -b binary -o $@ $<
2020-04-28 02:22:56 +02:00
2020-10-23 02:28:24 +02:00
# Compressed data
$(filter %.Yay0.o,$(OBJECTS)) : $( BUILD_DIR ) /%.Yay 0.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
e n d i f
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.
i f n d e f A S S E T S _ F S _ S O U R C E S
i f d e f A S S E T S _ F S
$( warning ASSETS_FS_SOURCES is not defined by `sources .mk ' but ASSETS_FS is .)
e n d i f
e l s e
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
e n d i f
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