papermario/Makefile

314 lines
8.6 KiB
Makefile
Raw Normal View History

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-12-22 01:37:37 +01:00
WSL_ELEVATE_GUI = 1
2020-10-23 02:28:24 +02:00
# Fail early if baserom does not exist
ifeq ($(wildcard $(BASEROM)),)
$(error Baserom `$(BASEROM)' not found.)
endif
2020-05-12 07:04:13 +02:00
# NON_MATCHING=1 implies COMPARE=0
ifeq ($(NON_MATCHING),1)
override COMPARE=0
endif
2020-10-23 02:28:24 +02:00
2020-10-29 18:45:40 +01:00
# PERMUTER=1 implies WATCH_INCLUDES=0
ifeq ($(PERMUTER),1)
override WATCH_INCLUDES=0
endif
2020-10-23 02:28:24 +02:00
### Output ###
2019-03-07 00:33:29 +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-11-07 13:06:38 +01:00
MSG_BIN := $(BUILD_DIR)/msg.bin
2020-11-11 14:52:04 +01:00
NPC_BIN := $(BUILD_DIR)/sprite/npc.bin
2020-12-22 17:31:31 +01:00
2020-10-23 02:28:24 +02:00
### Tools ###
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
EMULATOR = mupen64plus
2019-03-07 00:33:29 +01:00
CROSS := mips-linux-gnu-
AS := $(CROSS)as
OLD_AS := tools/mips-nintendo-nu64-as
CC := tools/cc1
2020-12-08 22:00:51 +01:00
CPP := cpp
LD := $(CROSS)ld
OBJCOPY := $(CROSS)objcopy
2020-12-22 10:35:44 +01:00
WSL := 0
JAVA := java
2020-12-05 23:17:55 +01:00
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Linux)
OS=linux
ICONV := iconv --from UTF-8 --to SHIFT-JIS
2020-12-22 10:35:44 +01:00
ifeq ($(findstring microsoft,$(shell cat /proc/sys/kernel/osrelease)),microsoft)
2020-12-22 01:09:55 +01:00
WSL := 1
2020-12-22 01:37:37 +01:00
ifeq ($(WSL_ELEVATE_GUI),1)
JAVA := powershell.exe -command java
endif
2020-12-22 01:09:55 +01:00
endif
2020-12-22 10:35:44 +01:00
endif
ifeq ($(UNAME_S),Darwin)
OS=mac
ICONV := tools/iconv.py UTF-8 SHIFT-JIS
endif
2020-12-22 01:09:55 +01:00
2020-12-05 23:17:55 +01:00
OLD_AS=tools/$(OS)/mips-nintendo-nu64-as
CC=tools/$(OS)/cc1
2020-12-22 10:35:44 +01:00
### Compiler Options ###
2020-12-25 00:39:47 +01:00
CPPFLAGS := -Iinclude -Isrc -D _LANGUAGE_C -D _FINALROM -ffreestanding -DF3DEX_GBI_2 -D_MIPS_SZLONG=32 -Wundef -Wcomment
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
2021-01-11 10:34:10 +01:00
LDFLAGS := -T undefined_syms.txt -T undefined_syms_auto.txt -T undefined_funcs.txt -T undefined_funcs_auto.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -Map $(LD_MAP) --no-check-sections
2020-10-29 18:45:40 +01:00
ifeq ($(WATCH_INCLUDES),1)
CPPMFLAGS = -MP -MD -MF $@.mk -MT $(BUILD_DIR)/$*.d
MDEPS = $(BUILD_DIR)/%.d
endif
2020-10-23 11:36:00 +02:00
ifeq ($(NON_MATCHING),1)
CPPFLAGS += -DNON_MATCHING
endif
2020-12-08 22:00:51 +01:00
-include settings.mk
2019-03-07 00:33:29 +01:00
### Sources ###
include sources.mk
2020-11-22 01:34:13 +01:00
ifeq ($(PERMUTER),1)
override OBJECTS:=$(filter %.c.o, $(OBJECTS))
endif
2020-10-28 23:08:14 +01:00
%.d: ;
2020-10-28 22:34:04 +01:00
ifeq ($(WATCH_INCLUDES),1)
2020-10-28 23:08:14 +01:00
-include $(foreach obj, $(OBJECTS), $(obj).mk)
2020-10-28 22:34:04 +01:00
endif
2020-12-22 17:31:31 +01:00
NPC_DIRS := $(foreach npc, $(NPC_SPRITES), sprite/npc/$(npc))
GENERATED_HEADERS := include/ld_addrs.h $(foreach dir, $(NPC_DIRS), include/$(dir).h)
2020-10-23 02:28:24 +02:00
### Targets ###
2019-03-07 00:33:29 +01:00
clean:
2021-01-09 17:39:46 +01:00
rm -rf $(BUILD_DIR) $(LD_SCRIPT)
clean-all:
2020-12-22 17:31:31 +01:00
rm -rf $(BUILD_DIR) bin msg img sprite .splat_cache $(LD_SCRIPT)
2020-08-13 04:13:48 +02:00
2020-10-23 11:36:20 +02:00
clean-code:
rm -rf $(BUILD_DIR)/src
2020-11-30 05:14:01 +01:00
tools:
2020-08-13 04:13:48 +02:00
2021-01-15 02:27:43 +01:00
setup: clean-all tools
@make split
2020-11-30 05:14:01 +01:00
2020-08-13 04:13:48 +02:00
split:
2020-12-22 17:25:05 +01:00
make $(LD_SCRIPT) -W $(SPLAT_YAML)
2020-08-13 04:13:48 +02:00
2020-10-31 19:30:16 +01:00
split-%:
2020-12-22 01:09:55 +01:00
$(SPLAT) --modes ld $* --verbose
2020-10-16 00:11:56 +02:00
split-all:
2020-12-03 22:06:15 +01:00
$(SPLAT) --modes all
2020-10-23 02:28:24 +02:00
test: $(ROM)
$(EMULATOR) $<
2020-10-12 20:46:04 +02:00
2021-01-09 17:39:46 +01:00
%.bin: $(LD_SCRIPT)
# Compressed files
%.Yay0: %
@mkdir -p $(shell dirname $@)
$(YAY0COMPRESS) $< $@
2021-01-14 11:25:55 +01:00
# $(BUILD_DIR)/%.bin.Yay0: %.bin
# @mkdir -p $(shell dirname $@)
# $(YAY0COMPRESS) $< $@
# Data objects
2021-01-14 11:25:55 +01:00
# $(BUILD_DIR)/%.bin.o: %.bin
# @mkdir -p $(shell dirname $@)
# $(LD) -r -b binary -o $@ $<
2020-10-23 02:28:24 +02:00
# Compressed data objects
2021-01-14 11:25:55 +01:00
# $(BUILD_DIR)/%.Yay0.o: $(BUILD_DIR)/%.bin.Yay0
# @mkdir -p $(shell dirname $@)
# $(LD) -r -b binary -o $@ $<
2020-10-23 02:28:24 +02:00
# Compile C files
2021-01-14 05:23:00 +01:00
# $(BUILD_DIR)/%.c.o: %.c $(MDEPS) | $(GENERATED_HEADERS)
# @mkdir -p $(shell dirname $@)
# $(CPP) $(CPPFLAGS) -o - $(CPPMFLAGS) $< | $(ICONV) | $(CC) $(CFLAGS) -o - | $(OLD_AS) $(OLDASFLAGS) -o $@ -
# # Compile C files (with DSL macros)
# $(foreach cfile, $(DSL_C_FILES), $(BUILD_DIR)/$(cfile).o): $(BUILD_DIR)/%.c.o: %.c $(MDEPS) tools/compile_dsl_macros.py | $(GENERATED_HEADERS)
# @mkdir -p $(shell dirname $@)
# $(CPP) $(CPPFLAGS) -o - $< $(CPPMFLAGS) | $(PYTHON) tools/compile_dsl_macros.py | $(ICONV) | $(CC) $(CFLAGS) -o - | $(OLD_AS) $(OLDASFLAGS) -o $@ -
# Assemble handwritten ASM
2021-01-14 11:49:14 +01:00
# $(BUILD_DIR)/%.s.o: %.s
# @mkdir -p $(shell dirname $@)
# $(AS) $(ASFLAGS) -o $@ $<
2020-10-23 02:28:24 +02:00
2021-01-14 11:49:14 +01:00
# # Data
# $(BUILD_DIR)/data/%.data.o: asm/data/%.data.s
# @mkdir -p $(shell dirname $@)
# $(AS) $(ASFLAGS) -o $@ $<
2020-11-29 06:22:33 +01:00
2021-01-14 11:49:14 +01:00
# # Rodata
# $(BUILD_DIR)/rodata/%.rodata.o: asm/data/%.rodata.s
# @mkdir -p $(shell dirname $@)
# $(AS) $(ASFLAGS) -o $@ $<
2020-11-29 20:37:53 +01:00
2020-10-31 19:30:16 +01:00
# Images
2021-01-14 12:23:22 +01:00
# $(BUILD_DIR)/%.png.o: $(BUILD_DIR)/%.png
# $(LD) -r -b binary -o $@ $<
# $(BUILD_DIR)/%.rgba16.png: %.png
# @mkdir -p $(shell dirname $@)
# $(PYTHON) tools/convert_image.py rgba16 $< $@ $(IMG_FLAGS)
# $(BUILD_DIR)/%.rgba32.png: %.png
# @mkdir -p $(shell dirname $@)
# $(PYTHON) tools/convert_image.py rgba32 $< $@ $(IMG_FLAGS)
# $(BUILD_DIR)/%.ci8.png: %.png
# @mkdir -p $(shell dirname $@)
# $(PYTHON) tools/convert_image.py ci8 $< $@ $(IMG_FLAGS)
# $(BUILD_DIR)/%.ci4.png: %.png
# @mkdir -p $(shell dirname $@)
# $(PYTHON) tools/convert_image.py ci4 $< $@ $(IMG_FLAGS)
# $(BUILD_DIR)/%.palette.png: %.png
# @mkdir -p $(shell dirname $@)
# $(PYTHON) tools/convert_image.py palette $< $@ $(IMG_FLAGS)
# $(BUILD_DIR)/%.ia4.png: %.png
# @mkdir -p $(shell dirname $@)
# $(PYTHON) tools/convert_image.py ia4 $< $@ $(IMG_FLAGS)
# $(BUILD_DIR)/%.ia8.png: %.png
# @mkdir -p $(shell dirname $@)
# $(PYTHON) tools/convert_image.py ia8 $< $@ $(IMG_FLAGS)
# $(BUILD_DIR)/%.ia16.png: %.png
# @mkdir -p $(shell dirname $@)
# $(PYTHON) tools/convert_image.py ia16 $< $@ $(IMG_FLAGS)
# $(BUILD_DIR)/%.i4.png: %.png
# @mkdir -p $(shell dirname $@)
# $(PYTHON) tools/convert_image.py i4 $< $@ $(IMG_FLAGS)
# $(BUILD_DIR)/%.i8.png: %.png
# @mkdir -p $(shell dirname $@)
# $(PYTHON) tools/convert_image.py i8 $< $@ $(IMG_FLAGS)
2020-10-31 19:30:16 +01:00
2020-11-07 02:09:11 +01:00
# Assets
2021-01-15 00:55:05 +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
# @mkdir -p $(shell dirname $@)
# @cp $< $@
# $(ASSETS_BIN): $(ASSET_FILES) $(YAY0_ASSET_FILES) sources.mk
# @mkdir -p $(shell dirname $@)
# @echo "building $@"
# @$(PYTHON) tools/build_assets_bin.py $@ $(ASSET_FILES)
# $(ASSETS_BIN:.bin=.o): $(ASSETS_BIN)
# $(LD) -r -b binary -o $@ $<
2020-10-18 05:54:32 +02:00
2020-11-07 02:09:11 +01:00
# Messages
# $(MSG_BIN): $(MESSAGES)
# @mkdir -p $(shell dirname $@)
# @echo "building $@"
# @$(PYTHON) tools/compile_messages.py $@ /dev/null $(MESSAGES)
# $(MSG_BIN:.bin=.o): $(MSG_BIN)
# $(LD) -r -b binary -o $@ $<
2020-11-11 14:52:04 +01:00
# Sprites
2021-01-14 13:25:28 +01:00
# $(foreach npc, $(NPC_SPRITES), $(eval $(BUILD_DIR)/sprite/npc/$(npc):: $(shell find sprite/npc/$(npc) -type f 2> /dev/null))) # dependencies
# NPC_YAY0 := $(foreach npc, $(NPC_SPRITES), $(BUILD_DIR)/sprite/npc/$(npc).Yay0)
# $(BUILD_DIR)/sprite/npc/%:: sprite/npc/% tools/compile_npc_sprite.py
# @mkdir -p $(shell dirname $@)
# $(PYTHON) tools/compile_npc_sprite.py $@ $<
# $(NPC_BIN): $(NPC_YAY0) tools/compile_npc_sprites.py
# @mkdir -p $(shell dirname $@)
# @echo "building $@"
# @$(PYTHON) tools/compile_npc_sprites.py $@ $(NPC_YAY0)
# $(NPC_BIN:.bin=.o): $(NPC_BIN)
# $(LD) -r -b binary -o $@ $<
2021-01-14 12:57:39 +01:00
# include/sprite/npc/%.h: sprite/npc/%/SpriteSheet.xml tools/gen_sprite_animations_h.py
# @mkdir -p $(shell dirname $@)
# @echo "building $@"
# @$(PYTHON) tools/gen_sprite_animations_h.py $@ sprite/npc/$* $(NPC_DIRS)
2020-12-22 16:53:16 +01:00
### Linker ###
2020-11-07 02:09:11 +01:00
2021-01-15 00:55:05 +01:00
# $(LD_SCRIPT): $(SPLAT_YAML)
# $(SPLAT) --modes ld bin Yay0 PaperMarioMapFS PaperMarioMessages img PaperMarioNpcSprites --new
2020-10-18 05:54:32 +02:00
2021-01-15 00:55:05 +01:00
# $(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT)
# @mkdir -p $(shell dirname $@)
# $(CPP) -P -DBUILD_DIR=$(BUILD_DIR) -o $@ $<
2021-01-15 00:55:05 +01: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
2021-01-15 00:55:05 +01:00
# $(BUILD_DIR)/$(TARGET).elf: $(BUILD_DIR)/$(LD_SCRIPT) $(OBJECTS)
# $(LD) $(LDFLAGS) -o $@
2019-03-07 00:33:29 +01:00
2021-01-15 00:55:05 +01:00
# $(BUILD_DIR)/$(TARGET).bin: $(BUILD_DIR)/$(TARGET).elf
# $(OBJCOPY) $< $@ -O binary
2020-10-29 18:45:40 +01:00
2021-01-14 13:05:55 +01:00
# include/ld_addrs.h: $(BUILD_DIR)/$(LD_SCRIPT)
# grep -E "[^\. ]+ =" $< -o | sed 's/^/extern void* /; s/ =/;/' > $@
2020-04-25 07:52:11 +02:00
2020-12-22 01:09:55 +01:00
### Star Rod (optional) ###
STAR_ROD := cd tools/star-rod && $(JAVA) -jar StarRod.jar
sprite/SpriteTable.xml: tools/star-rod sources.mk
$(PYTHON) tools/star-rod/spritetable.xml.py $(NPC_SPRITES) > $@
editor: tools/star-rod sprite/SpriteTable.xml
$(STAR_ROD)
2020-10-23 02:28:24 +02:00
### Make Settings ###
2021-01-15 02:27:43 +01:00
.PHONY: clean tools test setup split editor $(ROM)
.DELETE_ON_ERROR:
.SECONDARY:
.PRECIOUS: $(ROM) %.Yay0
2020-10-23 02:28:24 +02:00
.DEFAULT_GOAL := $(ROM)
# Remove built-in implicit rules to improve performance
MAKEFLAGS += --no-builtin-rules
2020-10-29 18:45:40 +01:00
# Fail targets if any command in the pipe exits with error
SHELL = /bin/bash -e -o pipefail