Files
Microtransactions64/Makefile

757 lines
27 KiB
Makefile
Raw Normal View History

2019-08-25 00:46:40 -04:00
# Makefile to rebuild SM64 split image
2020-12-03 14:26:38 -05:00
include util.mk
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
# Default target
2019-08-25 00:46:40 -04:00
default: all
2020-12-03 14:26:38 -05:00
# Preprocessor definitions
DEFINES :=
2019-08-25 00:46:40 -04:00
2021-01-03 13:09:20 -05:00
SRC_DIRS :=
2020-12-03 14:26:38 -05:00
#==============================================================================#
# Build Options #
#==============================================================================#
# These options can either be set by building with 'make SETTING=value'.
# 'make clean' may be required first.
2019-12-01 21:52:53 -05:00
# Build for the N64 (turn this off for ports)
TARGET_N64 ?= 1
2020-12-03 14:26:38 -05:00
2021-01-02 22:48:12 -05:00
# CONSOLE - selects the console to target
2021-01-02 22:52:48 -05:00
# bb - Targets the iQue Player (codenamed BB)
# n64 - Targets the N64
2021-01-02 22:48:12 -05:00
CONSOLE ?= n64
2021-01-02 22:52:48 -05:00
$(eval $(call validate-option,CONSOLE,n64 bb))
2021-01-02 22:48:12 -05:00
ifeq ($(CONSOLE),n64)
INCLUDE_DIRS += include/n64
LIBS_DIR := lib/n64
2021-01-02 22:52:48 -05:00
else ifeq ($(CONSOLE),bb)
2021-01-02 22:48:12 -05:00
INCLUDE_DIRS += include/ique
LIBS_DIR := lib/ique
DEFINES += BBPLAYER=1
endif
2020-12-03 14:26:38 -05:00
# COMPILER - selects the C compiler to use
# gcc - uses the GNU C Compiler
2020-12-09 09:05:40 -05:00
COMPILER ?= gcc
2021-02-01 18:23:36 -05:00
$(eval $(call validate-option,COMPILER,gcc))
2020-04-03 14:57:26 -04:00
2019-08-25 00:46:40 -04:00
2021-01-11 00:46:56 -05:00
# SAVETYPE - selects the save type
# eep4k - uses EEPROM 4kbit
# eep16k - uses EEPROM 16kbit (There aren't any differences in syntax, but this is provided just in case)
# sram - uses SRAM 256Kbit
SAVETYPE ?= eep4k
$(eval $(call validate-option,SAVETYPE,eep4k eep16k sram))
ifeq ($(SAVETYPE),eep4k)
DEFINES += EEP=1 EEP4K=1
else ifeq ($(SAVETYPE),eep16k)
DEFINES += EEP=1 EEP16K=1
else ifeq ($(SAVETYPE),sram)
DEFINES += SRAM=1
endif
2021-01-26 15:56:34 -05:00
DEFINES += NO_ERRNO_H=1 NO_GZIP=1
2021-01-03 13:09:20 -05:00
COMPRESS ?= yay0
2021-03-23 17:41:15 -04:00
$(eval $(call validate-option,COMPRESS,mio0 yay0 gzip rnc1 rnc2))
2021-01-03 13:09:20 -05:00
ifeq ($(COMPRESS),gzip)
2021-01-26 15:56:34 -05:00
DEFINES += GZIP=1
else ifeq ($(COMPRESS),rnc1)
DEFINES += RNC1=1
else ifeq ($(COMPRESS),rnc2)
DEFINES += RNC2=1
2021-01-03 13:09:20 -05:00
else ifeq ($(COMPRESS),yay0)
DEFINES += YAY0=1
2021-03-23 17:41:15 -04:00
else ifeq ($(COMPRESS),mio0)
DEFINES += MIO0=1
2021-01-03 13:09:20 -05:00
endif
2021-01-24 14:06:58 -05:00
GZIPVER ?= std
$(eval $(call validate-option,GZIPVER,std libdef))
2020-12-03 14:26:38 -05:00
# VERSION - selects the version of the game to build
# jp - builds the 1996 Japanese version
# us - builds the 1996 North American version
# eu - builds the 1997 PAL version
# sh - builds the 1997 Japanese Shindou version, with rumble pak support
VERSION ?= us
$(eval $(call validate-option,VERSION,jp us eu sh))
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
ifeq ($(VERSION),jp)
DEFINES += VERSION_JP=1
OPT_FLAGS := -g
GRUCODE ?= f3dzex
2020-12-03 14:26:38 -05:00
else ifeq ($(VERSION),us)
DEFINES += VERSION_US=1
OPT_FLAGS := -g
GRUCODE ?= f3dzex
2020-12-03 14:26:38 -05:00
else ifeq ($(VERSION),eu)
DEFINES += VERSION_EU=1
OPT_FLAGS := -O2
GRUCODE ?= f3dzex
2020-12-03 14:26:38 -05:00
else ifeq ($(VERSION),sh)
DEFINES += VERSION_SH=1
OPT_FLAGS := -O2
GRUCODE ?= f3dzex
2020-03-01 22:42:52 -05:00
endif
2019-08-25 00:46:40 -04:00
2020-06-02 12:44:34 -04:00
TARGET := sm64.$(VERSION)
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
# GRUCODE - selects which RSP microcode to use.
# f3d_old - default for JP and US versions
# f3d_new - default for EU and Shindou versions
# f3dex -
# f3dex2 -
# f3dzex - newer, experimental microcode used in Animal Crossing
# super3d - extremely experimental version of Fast3D lacking many features for speed
2020-12-03 22:27:06 -05:00
$(eval $(call validate-option,GRUCODE,f3d_old f3dex f3dex2 f3d_new f3dzex super3d))
2020-12-03 14:26:38 -05:00
ifeq ($(GRUCODE),f3d_old)
DEFINES += F3D_OLD=1
else ifeq ($(GRUCODE),f3d_new) # Fast3D 2.0H
DEFINES += F3D_NEW=1
else ifeq ($(GRUCODE),f3dex) # Fast3DEX
DEFINES += F3DEX_GBI=1 F3DEX_GBI_SHARED=1
else ifeq ($(GRUCODE),f3dex2) # Fast3DEX2
2020-12-03 14:26:38 -05:00
DEFINES += F3DEX_GBI_2=1 F3DEX_GBI_SHARED=1
else ifeq ($(GRUCODE),f3dzex) # Fast3DZEX (2.08J / Animal Forest - Dōbutsu no Mori)
2020-12-03 14:26:38 -05:00
DEFINES += F3DZEX_GBI_2=1 F3DEX_GBI_2=1 F3DEX_GBI_SHARED=1
else ifeq ($(GRUCODE),super3d) # Super3D
$(warning Super3D is experimental. Try at your own risk.)
DEFINES += SUPER3D_GBI=1 F3D_NEW=1
2019-08-25 00:46:40 -04:00
endif
2020-12-03 14:26:38 -05:00
2021-02-01 18:23:36 -05:00
ifeq ($(COMPILER),gcc)
2020-12-03 14:26:38 -05:00
NON_MATCHING := 1
MIPSISET := -mips3
2021-01-25 00:05:45 -05:00
OPT_FLAGS := -O2
2019-08-25 00:46:40 -04:00
endif
2020-12-03 14:26:38 -05:00
# NON_MATCHING - whether to build a matching, identical copy of the ROM
# 1 - enable some alternate, more portable code that does not produce a matching ROM
# 0 - build a matching ROM
NON_MATCHING ?= 1
2020-12-03 14:26:38 -05:00
$(eval $(call validate-option,NON_MATCHING,0 1))
2020-06-02 12:44:34 -04:00
2019-12-01 21:52:53 -05:00
ifeq ($(TARGET_N64),0)
NON_MATCHING := 1
2019-08-25 00:46:40 -04:00
endif
2019-12-01 21:52:53 -05:00
ifeq ($(NON_MATCHING),1)
2020-12-03 14:26:38 -05:00
DEFINES += NON_MATCHING=1 AVOID_UB=1
2019-08-25 00:46:40 -04:00
COMPARE := 0
endif
2020-12-03 14:26:38 -05:00
# COMPARE - whether to verify the SHA-1 hash of the ROM after building
# 1 - verifies the SHA-1 hash of the selected version of the game
# 0 - does not verify the hash
2020-12-03 19:23:06 -05:00
COMPARE ?= 0
2020-12-03 14:26:38 -05:00
$(eval $(call validate-option,COMPARE,0 1))
2021-01-02 22:48:12 -05:00
TARGET_STRING := sm64.$(VERSION).$(CONSOLE).$(GRUCODE)
2020-12-03 14:26:38 -05:00
# If non-default settings were chosen, disable COMPARE
ifeq ($(filter $(TARGET_STRING), sm64.jp.f3d_old sm64.us.f3d_old sm64.eu.f3d_new sm64.sh.f3d_new),)
COMPARE := 0
endif
2020-12-09 16:38:26 -05:00
# UNF - whether to use UNFLoader flashcart library
# 1 - includes code in ROM
# 0 - does not
UNF ?= 0
$(eval $(call validate-option,UNF,0 1))
ifeq ($(UNF),1)
DEFINES += UNF=1
SRC_DIRS += src/usb
2021-04-11 20:49:21 -04:00
endif
# ISVPRINT - whether to fake IS-Viewer presence,
# allowing for usage of CEN64 (and possibly Project64) to print messages to terminal.
# 1 - includes code in ROM
# 0 - does not
ISVPRINT ?= 0
$(eval $(call validate-option,ISVPRINT,0 1))
ifeq ($(ISVPRINT),1)
DEFINES += ISVPRINT=1
ULTRALIB := ultra_d
else
ULTRALIB := ultra_rom
endif
# HVQM - whether to use HVQM fmv library
# 1 - includes code in ROM
# 0 - does not
HVQM ?= 0
$(eval $(call validate-option,HVQM,0 1))
ifeq ($(HVQM),1)
DEFINES += HVQM=1
SRC_DIRS += src/hvqm
endif
# GODDARD - whether to use libgoddard (Mario Head)
# 1 - includes code in ROM
# 0 - does not
GODDARD ?= 0
$(eval $(call validate-option,GODDARD,0 1))
ifeq ($(GODDARD),1)
DEFINES += GODDARD=1
2020-12-09 16:38:26 -05:00
endif
2020-12-03 14:26:38 -05:00
# Whether to hide commands or not
VERBOSE ?= 0
ifeq ($(VERBOSE),0)
V := @
endif
# Whether to colorize build messages
COLOR ?= 1
# display selected options unless 'make clean' or 'make distclean' is run
ifeq ($(filter clean distclean,$(MAKECMDGOALS)),)
$(info ==== Build Options ====)
$(info Version: $(VERSION))
$(info Microcode: $(GRUCODE))
2021-01-02 22:48:12 -05:00
$(info Console: $(CONSOLE))
2020-12-03 14:26:38 -05:00
$(info Target: $(TARGET))
ifeq ($(COMPARE),1)
$(info Compare ROM: yes)
else
$(info Compare ROM: no)
endif
ifeq ($(NON_MATCHING),1)
$(info Build Matching: no)
else
$(info Build Matching: yes)
endif
$(info =======================)
endif
#==============================================================================#
# Universal Dependencies #
#==============================================================================#
TOOLS_DIR := tools
2019-08-25 00:46:40 -04:00
2019-08-25 00:46:40 -04:00
# (This is a bit hacky, but a lot of rules implicitly depend
# on tools and assets, and we use directory globs further down
# in the makefile that we want should cover assets.)
2020-12-03 14:26:38 -05:00
PYTHON := python3
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
ifeq ($(filter clean distclean print-%,$(MAKECMDGOALS)),)
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
# Make sure assets exist
NOEXTRACT ?= 0
ifeq ($(NOEXTRACT),0)
DUMMY != $(PYTHON) extract_assets.py $(VERSION) >&2 || echo FAIL
ifeq ($(DUMMY),FAIL)
$(error Failed to extract assets)
endif
endif
# Make tools if out of date
$(info Building tools...)
2021-02-01 18:23:36 -05:00
DUMMY != $(MAKE) -s -C $(TOOLS_DIR) >&2 || echo FAIL
2020-12-03 14:26:38 -05:00
ifeq ($(DUMMY),FAIL)
$(error Failed to build tools)
endif
$(info Building ROM...)
2019-08-25 00:46:40 -04:00
endif
2020-12-03 14:26:38 -05:00
#==============================================================================#
# Target Executable and Sources #
#==============================================================================#
2019-08-25 00:46:40 -04:00
BUILD_DIR_BASE := build
2020-12-03 14:26:38 -05:00
# BUILD_DIR is the location where all build artifacts are placed
BUILD_DIR := $(BUILD_DIR_BASE)/$(VERSION)
2020-12-08 19:28:12 -05:00
ROM := $(BUILD_DIR)/$(TARGET_STRING).z64
ELF := $(BUILD_DIR)/$(TARGET_STRING).elf
2021-01-25 22:55:36 -05:00
LIBZ := $(BUILD_DIR)/libz.a
2020-12-03 14:26:38 -05:00
LD_SCRIPT := sm64.ld
YAY0_DIR := $(BUILD_DIR)/bin
2020-12-03 14:26:38 -05:00
SOUND_BIN_DIR := $(BUILD_DIR)/sound
TEXTURE_DIR := textures
ACTOR_DIR := actors
LEVEL_DIRS := $(patsubst levels/%,%,$(dir $(wildcard levels/*/header.h)))
2019-08-25 00:46:40 -04:00
# Directories containing source files
SRC_DIRS += src src/game src/engine src/audio src/menu src/buffers actors levels bin data assets asm lib sound
2021-01-25 22:55:36 -05:00
LIBZ_SRC_DIRS := src/libz
GODDARD_SRC_DIRS := src/goddard src/goddard/dynlists
2019-08-25 00:46:40 -04:00
BIN_DIRS := bin bin/$(VERSION)
# File dependencies and variables for specific files
include Makefile.split
# Source code files
2020-12-03 14:26:38 -05:00
LEVEL_C_FILES := $(wildcard levels/*/leveldata.c) $(wildcard levels/*/script.c) $(wildcard levels/*/geo.c)
C_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.c)) $(LEVEL_C_FILES)
2021-01-25 22:55:36 -05:00
LIBZ_C_FILES := $(foreach dir,$(LIBZ_SRC_DIRS),$(wildcard $(dir)/*.c))
GODDARD_C_FILES := $(foreach dir,$(GODDARD_SRC_DIRS),$(wildcard $(dir)/*.c))
2020-12-03 14:26:38 -05:00
S_FILES := $(foreach dir,$(SRC_DIRS),$(wildcard $(dir)/*.s))
2019-11-03 14:36:27 -05:00
GENERATED_C_FILES := $(BUILD_DIR)/assets/mario_anim_data.c $(BUILD_DIR)/assets/demo_data.c
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
# Sound files
SOUND_BANK_FILES := $(wildcard sound/sound_banks/*.json)
SOUND_SAMPLE_DIRS := $(wildcard sound/samples/*)
SOUND_SAMPLE_AIFFS := $(foreach dir,$(SOUND_SAMPLE_DIRS),$(wildcard $(dir)/*.aiff))
2019-08-25 00:46:40 -04:00
SOUND_SAMPLE_TABLES := $(foreach file,$(SOUND_SAMPLE_AIFFS),$(BUILD_DIR)/$(file:.aiff=.table))
2020-12-03 14:26:38 -05:00
SOUND_SAMPLE_AIFCS := $(foreach file,$(SOUND_SAMPLE_AIFFS),$(BUILD_DIR)/$(file:.aiff=.aifc))
SOUND_SEQUENCE_DIRS := sound/sequences sound/sequences/$(VERSION)
# all .m64 files in SOUND_SEQUENCE_DIRS, plus all .m64 files that are generated from .s files in SOUND_SEQUENCE_DIRS
SOUND_SEQUENCE_FILES := \
$(foreach dir,$(SOUND_SEQUENCE_DIRS),\
$(wildcard $(dir)/*.m64) \
$(foreach file,$(wildcard $(dir)/*.s),$(BUILD_DIR)/$(file:.s=.m64)) \
)
2019-08-25 00:46:40 -04:00
# Object files
O_FILES := $(foreach file,$(C_FILES),$(BUILD_DIR)/$(file:.c=.o)) \
$(foreach file,$(S_FILES),$(BUILD_DIR)/$(file:.s=.o)) \
2020-12-08 21:41:03 -05:00
$(foreach file,$(GENERATED_C_FILES),$(file:.c=.o)) \
lib/PR/hvqm/hvqm2sp1.o lib/PR/hvqm/hvqm2sp2.o
2019-08-25 00:46:40 -04:00
2021-01-25 22:55:36 -05:00
LIBZ_O_FILES := $(foreach file,$(LIBZ_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
GODDARD_O_FILES := $(foreach file,$(GODDARD_C_FILES),$(BUILD_DIR)/$(file:.c=.o))
2021-01-25 22:55:36 -05:00
2019-08-25 00:46:40 -04:00
# Automatic dependency files
DEP_FILES := $(O_FILES:.o=.d) $(LIBZ_O_FILES:.o=.d) $(GODDARD_O_FILES:.o=.d) $(BUILD_DIR)/$(LD_SCRIPT).d
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
#==============================================================================#
# Compiler Options #
#==============================================================================#
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
# detect prefix for MIPS toolchain
2021-01-01 15:42:01 -05:00
ifneq ($(call find-command,mips64-elf-ld),)
CROSS := mips64-elf-
2021-01-23 13:28:35 -05:00
else ifneq ($(call find-command,mips-n64-ld),)
CROSS := mips-n64-
else ifneq ($(call find-command,mips64-ld),)
CROSS := mips64-
2021-01-01 15:42:01 -05:00
else ifneq ($(call find-command,mips-linux-gnu-ld),)
2019-08-25 00:46:40 -04:00
CROSS := mips-linux-gnu-
2020-12-03 14:26:38 -05:00
else ifneq ($(call find-command,mips64-linux-gnu-ld),)
2020-04-03 14:57:26 -04:00
CROSS := mips64-linux-gnu-
else ifneq ($(call find-command,mips-ld),)
CROSS := mips-
2020-12-03 14:26:38 -05:00
else
$(error Unable to detect a suitable MIPS toolchain installed)
2019-08-25 00:46:40 -04:00
endif
export LD_LIBRARY_PATH=./tools
2020-12-03 14:26:38 -05:00
AS := $(CROSS)as
ifeq ($(COMPILER),gcc)
CC := $(CROSS)gcc
2019-10-05 15:08:05 -04:00
endif
2020-12-03 14:26:38 -05:00
# Prefer gcc's cpp if installed on the system
ifneq (,$(call find-command,cpp-10))
CPP := cpp-10
else
CPP := cpp
endif
2021-01-23 13:28:35 -05:00
ifneq ($(call find-command,mips-n64-ld),)
LD := mips-n64-ld
else
LD := tools/mips64-elf-ld
2021-01-23 13:28:35 -05:00
endif
2019-08-25 00:46:40 -04:00
AR := $(CROSS)ar
OBJDUMP := $(CROSS)objdump
OBJCOPY := $(CROSS)objcopy
2020-12-03 14:26:38 -05:00
ifeq ($(TARGET_N64),1)
TARGET_CFLAGS := -nostdinc -DTARGET_N64 -D_LANGUAGE_C
CC_CFLAGS := -fno-builtin
2020-04-03 14:57:26 -04:00
endif
2021-01-02 22:48:12 -05:00
INCLUDE_DIRS += include $(BUILD_DIR) $(BUILD_DIR)/include src . include/hvqm
2019-12-01 21:52:53 -05:00
ifeq ($(TARGET_N64),1)
2020-12-03 14:26:38 -05:00
INCLUDE_DIRS += include/libc
2019-12-01 21:52:53 -05:00
endif
2020-12-03 14:26:38 -05:00
C_DEFINES := $(foreach d,$(DEFINES),-D$(d))
DEF_INC_CFLAGS := $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(C_DEFINES)
2019-11-03 14:36:27 -05:00
2020-12-03 14:26:38 -05:00
# C compiler options
CFLAGS = -G 0 $(OPT_FLAGS) $(TARGET_CFLAGS) $(MIPSISET) $(DEF_INC_CFLAGS)
2020-04-03 14:57:26 -04:00
ifeq ($(COMPILER),gcc)
2020-12-03 14:26:38 -05:00
CFLAGS += -mno-shared -march=vr4300 -mfix4300 -mabi=32 -mhard-float -mdivide-breaks -fno-stack-protector -fno-common -fno-zero-initialized-in-bss -fno-PIC -mno-abicalls -fno-strict-aliasing -fno-inline-functions -ffreestanding -fwrapv -Wall -Wextra
else
CFLAGS += -non_shared -Wab,-r4300_mul -Xcpluscomm -Xfullwarn -signed -32
2020-04-03 14:57:26 -04:00
endif
2020-12-03 14:26:38 -05:00
ASFLAGS := -march=vr4300 -mabi=32 $(foreach i,$(INCLUDE_DIRS),-I$(i)) $(foreach d,$(DEFINES),--defsym $(d))
RSPASMFLAGS := $(foreach d,$(DEFINES),-definelabel $(subst =, ,$(d)))
# C preprocessor flags
CPPFLAGS := -P -Wno-trigraphs $(DEF_INC_CFLAGS)
#==============================================================================#
# Miscellaneous Tools #
#==============================================================================#
2019-08-25 00:46:40 -04:00
# N64 tools
YAY0TOOL := $(TOOLS_DIR)/slienc
2021-03-23 17:41:15 -04:00
MIO0TOOL := $(TOOLS_DIR)/mio0
RNCPACK := $(TOOLS_DIR)/rncpack
2021-01-03 13:09:20 -05:00
ROMALIGN := $(TOOLS_DIR)/romalign
FILESIZER := $(TOOLS_DIR)/filesizer
2020-12-03 14:26:38 -05:00
N64CKSUM := $(TOOLS_DIR)/n64cksum
N64GRAPHICS := $(TOOLS_DIR)/n64graphics
N64GRAPHICS_CI := $(TOOLS_DIR)/n64graphics_ci
TEXTCONV := $(TOOLS_DIR)/textconv
AIFF_EXTRACT_CODEBOOK := $(TOOLS_DIR)/aiff_extract_codebook
VADPCM_ENC := $(TOOLS_DIR)/vadpcm_enc
EXTRACT_DATA_FOR_MIO := $(TOOLS_DIR)/extract_data_for_mio
SKYCONV := $(TOOLS_DIR)/skyconv
2021-01-24 14:06:58 -05:00
ifeq ($(GZIPVER),std)
GZIP := gzip
else
GZIP := libdeflate-gzip
endif
2020-12-03 14:26:38 -05:00
# Use the system installed armips if available. Otherwise use the one provided with this repository.
ifneq (,$(call find-command,armips))
RSPASM := armips
else
RSPASM := $(TOOLS_DIR)/armips
endif
ENDIAN_BITWIDTH := $(BUILD_DIR)/endian-and-bitwidth
2019-08-25 00:46:40 -04:00
EMULATOR = mupen64plus
EMU_FLAGS = --noosd
LOADER = loader64
LOADER_FLAGS = -vwf
SHA1SUM = sha1sum
2020-12-03 14:26:38 -05:00
PRINT = printf
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
ifeq ($(COLOR),1)
NO_COL := \033[0m
RED := \033[0;31m
GREEN := \033[0;32m
BLUE := \033[0;34m
YELLOW := \033[0;33m
BLINK := \033[33;5m
2020-06-02 12:44:34 -04:00
endif
2020-04-03 14:57:26 -04:00
# Use Objcopy instead of extract_data_for_mio
ifeq ($(COMPILER),gcc)
2020-12-03 14:26:38 -05:00
EXTRACT_DATA_FOR_MIO := $(OBJCOPY) -O binary --only-section=.data
2020-04-03 14:57:26 -04:00
endif
2020-12-03 14:26:38 -05:00
# Common build print status function
define print
@$(PRINT) "$(GREEN)$(1) $(YELLOW)$(2)$(GREEN) -> $(BLUE)$(3)$(NO_COL)\n"
endef
#==============================================================================#
# Main Targets #
#==============================================================================#
2019-08-25 00:46:40 -04:00
all: $(ROM)
ifeq ($(COMPARE),1)
2020-12-03 14:26:38 -05:00
@$(PRINT) "$(GREEN)Checking if ROM matches.. $(NO_COL)\n"
@$(SHA1SUM) --quiet -c $(TARGET).sha1 && $(PRINT) "$(TARGET): $(GREEN)OK$(NO_COL)\n" || ($(PRINT) "$(YELLOW)Building the ROM file has succeeded, but does not match the original ROM.\nThis is expected, and not an error, if you are making modifications.\nTo silence this message, use 'make COMPARE=0.' $(NO_COL)\n" && false)
2019-08-25 00:46:40 -04:00
endif
clean:
$(RM) -r $(BUILD_DIR_BASE)
2020-12-03 14:26:38 -05:00
distclean: clean
$(PYTHON) extract_assets.py --clean
$(MAKE) -C $(TOOLS_DIR) clean
2019-08-25 00:46:40 -04:00
test: $(ROM)
$(EMULATOR) $(EMU_FLAGS) $<
load: $(ROM)
$(LOADER) $(LOADER_FLAGS) $<
libultra: $(BUILD_DIR)/libultra.a
2020-12-03 14:26:38 -05:00
# Extra object file dependencies
$(BUILD_DIR)/asm/boot.o: $(IPL3_RAW_FILES)
2020-06-02 12:44:34 -04:00
$(BUILD_DIR)/src/game/crash_screen.o: $(CRASH_TEXTURE_C_FILES)
2021-01-01 15:42:01 -05:00
$(BUILD_DIR)/src/game/version.o: $(BUILD_DIR)/src/game/version_data.h
2020-12-03 14:26:38 -05:00
$(BUILD_DIR)/lib/rsp.o: $(BUILD_DIR)/rsp/rspboot.bin $(BUILD_DIR)/rsp/fast3d.bin $(BUILD_DIR)/rsp/audio.bin
$(SOUND_BIN_DIR)/sound_data.o: $(SOUND_BIN_DIR)/sound_data.ctl.inc.c $(SOUND_BIN_DIR)/sound_data.tbl.inc.c $(SOUND_BIN_DIR)/sequences.bin.inc.c $(SOUND_BIN_DIR)/bank_sets.inc.c
$(BUILD_DIR)/levels/scripts.o: $(BUILD_DIR)/include/level_headers.h
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
ifeq ($(VERSION),sh)
$(BUILD_DIR)/src/audio/load.o: $(SOUND_BIN_DIR)/bank_sets.inc.c $(SOUND_BIN_DIR)/sequences_header.inc.c $(SOUND_BIN_DIR)/ctl_header.inc.c $(SOUND_BIN_DIR)/tbl_header.inc.c
endif
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
$(CRASH_TEXTURE_C_FILES): TEXTURE_ENCODING := u32
2019-10-05 15:08:05 -04:00
2020-04-03 14:57:26 -04:00
ifeq ($(COMPILER),gcc)
2021-01-25 22:55:36 -05:00
$(BUILD_DIR)/src/libz/%.o: OPT_FLAGS := -Os
2020-04-03 14:57:26 -04:00
endif
2019-08-25 00:46:40 -04:00
ifeq ($(VERSION),eu)
2020-12-03 14:26:38 -05:00
TEXT_DIRS := text/de text/us text/fr
# EU encoded text inserted into individual segment 0x19 files,
# and course data also duplicated in leveldata.c
$(BUILD_DIR)/bin/eu/translation_en.o: $(BUILD_DIR)/text/us/define_text.inc.c
$(BUILD_DIR)/bin/eu/translation_de.o: $(BUILD_DIR)/text/de/define_text.inc.c
$(BUILD_DIR)/bin/eu/translation_fr.o: $(BUILD_DIR)/text/fr/define_text.inc.c
$(BUILD_DIR)/levels/menu/leveldata.o: $(BUILD_DIR)/include/text_strings.h
$(BUILD_DIR)/levels/menu/leveldata.o: $(BUILD_DIR)/text/us/define_courses.inc.c
$(BUILD_DIR)/levels/menu/leveldata.o: $(BUILD_DIR)/text/de/define_courses.inc.c
$(BUILD_DIR)/levels/menu/leveldata.o: $(BUILD_DIR)/text/fr/define_courses.inc.c
2019-08-25 00:46:40 -04:00
else
2020-12-03 14:26:38 -05:00
ifeq ($(VERSION),sh)
TEXT_DIRS := text/jp
$(BUILD_DIR)/bin/segment2.o: $(BUILD_DIR)/text/jp/define_text.inc.c
else
TEXT_DIRS := text/$(VERSION)
# non-EU encoded text inserted into segment 0x02
$(BUILD_DIR)/bin/segment2.o: $(BUILD_DIR)/text/$(VERSION)/define_text.inc.c
endif
2020-03-01 22:42:52 -05:00
endif
2019-08-25 00:46:40 -04:00
2020-12-09 16:38:26 -05:00
$(BUILD_DIR)/src/usb/usb.o: OPT_FLAGS := -O0
$(BUILD_DIR)/src/usb/usb.o: CFLAGS += -Wno-unused-variable -Wno-sign-compare -Wno-unused-function
$(BUILD_DIR)/src/usb/debug.o: OPT_FLAGS := -O0
$(BUILD_DIR)/src/usb/debug.o: CFLAGS += -Wno-unused-parameter -Wno-maybe-uninitialized
ALL_DIRS := $(BUILD_DIR) $(addprefix $(BUILD_DIR)/,$(SRC_DIRS) $(GODDARD_SRC_DIRS) $(LIBZ_SRC_DIRS) $(ULTRA_BIN_DIRS) $(BIN_DIRS) $(TEXTURE_DIRS) $(TEXT_DIRS) $(SOUND_SAMPLE_DIRS) $(addprefix levels/,$(LEVEL_DIRS)) rsp include) $(YAY0_DIR) $(addprefix $(YAY0_DIR)/,$(VERSION)) $(SOUND_BIN_DIR) $(SOUND_BIN_DIR)/sequences/$(VERSION)
2019-08-25 00:46:40 -04:00
# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $(ALL_DIRS)
2019-10-05 19:40:22 -04:00
$(BUILD_DIR)/include/text_strings.h: $(BUILD_DIR)/include/text_menu_strings.h
$(BUILD_DIR)/src/menu/file_select.o: $(BUILD_DIR)/include/text_strings.h
$(BUILD_DIR)/src/menu/star_select.o: $(BUILD_DIR)/include/text_strings.h
2019-08-25 00:46:40 -04:00
$(BUILD_DIR)/src/game/ingame_menu.o: $(BUILD_DIR)/include/text_strings.h
2020-12-03 14:26:38 -05:00
#==============================================================================#
# Texture Generation #
#==============================================================================#
TEXTURE_ENCODING := u8
# Convert PNGs to RGBA32, RGBA16, IA16, IA8, IA4, IA1, I8, I4 binary files
2019-08-25 00:46:40 -04:00
$(BUILD_DIR)/%: %.png
2020-12-03 14:26:38 -05:00
$(call print,Converting:,$<,$@)
$(V)$(N64GRAPHICS) -s raw -i $@ -g $< -f $(lastword $(subst ., ,$@))
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
$(BUILD_DIR)/%.inc.c: %.png
$(call print,Converting:,$<,$@)
$(V)$(N64GRAPHICS) -s $(TEXTURE_ENCODING) -i $@ -g $< -f $(lastword ,$(subst ., ,$(basename $<)))
2019-11-03 14:36:27 -05:00
2019-08-25 00:46:40 -04:00
# Color Index CI8
$(BUILD_DIR)/%.ci8: %.ci8.png
2020-12-03 14:26:38 -05:00
$(call print,Converting:,$<,$@)
$(V)$(N64GRAPHICS_CI) -i $@ -g $< -f ci8
2019-08-25 00:46:40 -04:00
# Color Index CI4
$(BUILD_DIR)/%.ci4: %.ci4.png
2020-12-03 14:26:38 -05:00
$(call print,Converting:,$<,$@)
$(V)$(N64GRAPHICS_CI) -i $@ -g $< -f ci4
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
#==============================================================================#
# Compressed Segment Generation #
#==============================================================================#
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
# Link segment file to resolve external labels
2019-08-25 00:46:40 -04:00
# TODO: ideally this would be `-Trodata-segment=0x07000000` but that doesn't set the address
2020-12-03 14:26:38 -05:00
$(BUILD_DIR)/%.elf: $(BUILD_DIR)/%.o
$(call print,Linking ELF file:,$<,$@)
$(V)$(LD) -e 0 -Ttext=$(SEGMENT_ADDRESS) -Map $@.map -o $@ $<
# Override for leveldata.elf, which otherwise matches the above pattern
2019-08-25 00:46:40 -04:00
.SECONDEXPANSION:
2019-11-03 14:36:27 -05:00
$(BUILD_DIR)/levels/%/leveldata.elf: $(BUILD_DIR)/levels/%/leveldata.o $(BUILD_DIR)/bin/$$(TEXTURE_BIN).elf
2020-12-03 14:26:38 -05:00
$(call print,Linking ELF file:,$<,$@)
$(V)$(LD) -e 0 -Ttext=$(SEGMENT_ADDRESS) -Map $@.map --just-symbols=$(BUILD_DIR)/bin/$(TEXTURE_BIN).elf -o $@ $<
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
$(BUILD_DIR)/%.bin: $(BUILD_DIR)/%.elf
2021-03-21 15:44:17 +00:00
$(call print,Extracting compressible data from:,$<,$@)
2020-12-03 14:26:38 -05:00
$(V)$(EXTRACT_DATA_FOR_MIO) $< $@
2019-11-03 14:36:27 -05:00
$(BUILD_DIR)/levels/%/leveldata.bin: $(BUILD_DIR)/levels/%/leveldata.elf
2021-03-21 15:44:17 +00:00
$(call print,Extracting compressible data from:,$<,$@)
2020-12-03 14:26:38 -05:00
$(V)$(EXTRACT_DATA_FOR_MIO) $< $@
2019-11-03 14:36:27 -05:00
2021-01-03 13:09:20 -05:00
ifeq ($(COMPRESS),gzip)
include gziprules.mk
else ifeq ($(COMPRESS),rnc1)
include rnc1rules.mk
else ifeq ($(COMPRESS),rnc2)
include rnc2rules.mk
2021-02-01 18:54:23 -05:00
else ifeq ($(COMPRESS),yay0)
include yay0rules.mk
2021-03-23 17:41:15 -04:00
else ifeq ($(COMPRESS),mio0)
include mio0rules.mk
2021-01-03 13:09:20 -05:00
endif
2020-12-03 14:26:38 -05:00
#==============================================================================#
# Sound File Generation #
#==============================================================================#
2019-08-25 00:46:40 -04:00
$(BUILD_DIR)/%.table: %.aiff
2020-12-03 14:26:38 -05:00
$(call print,Extracting codebook:,$<,$@)
$(V)$(AIFF_EXTRACT_CODEBOOK) $< >$@
2019-08-25 00:46:40 -04:00
$(BUILD_DIR)/%.aifc: $(BUILD_DIR)/%.table %.aiff
2020-12-03 14:26:38 -05:00
$(call print,Encoding VADPCM:,$<,$@)
$(V)$(VADPCM_ENC) -c $^ $@
2020-06-02 12:44:34 -04:00
2020-12-03 14:26:38 -05:00
$(ENDIAN_BITWIDTH): $(TOOLS_DIR)/determine-endian-bitwidth.c
@$(PRINT) "$(GREEN)Generating endian-bitwidth $(NO_COL)\n"
$(V)$(CC) -c $(CFLAGS) -o $@.dummy2 $< 2>$@.dummy1; true
$(V)grep -o 'msgbegin --endian .* --bitwidth .* msgend' $@.dummy1 > $@.dummy2
$(V)head -n1 <$@.dummy2 | cut -d' ' -f2-5 > $@
@$(RM) $@.dummy1
@$(RM) $@.dummy2
2019-12-01 21:52:53 -05:00
$(SOUND_BIN_DIR)/sound_data.ctl: sound/sound_banks/ $(SOUND_BANK_FILES) $(SOUND_SAMPLE_AIFCS) $(ENDIAN_BITWIDTH)
2020-12-03 14:26:38 -05:00
@$(PRINT) "$(GREEN)Generating: $(BLUE)$@ $(NO_COL)\n"
$(V)$(PYTHON) $(TOOLS_DIR)/assemble_sound.py $(BUILD_DIR)/sound/samples/ sound/sound_banks/ $(SOUND_BIN_DIR)/sound_data.ctl $(SOUND_BIN_DIR)/ctl_header $(SOUND_BIN_DIR)/sound_data.tbl $(SOUND_BIN_DIR)/tbl_header $(C_DEFINES) $$(cat $(ENDIAN_BITWIDTH))
2019-08-25 00:46:40 -04:00
$(SOUND_BIN_DIR)/sound_data.tbl: $(SOUND_BIN_DIR)/sound_data.ctl
2019-12-01 21:52:53 -05:00
@true
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
$(SOUND_BIN_DIR)/ctl_header: $(SOUND_BIN_DIR)/sound_data.ctl
@true
2019-09-01 15:50:50 -04:00
2020-12-03 14:26:38 -05:00
$(SOUND_BIN_DIR)/tbl_header: $(SOUND_BIN_DIR)/sound_data.ctl
2019-12-01 21:52:53 -05:00
@true
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
$(SOUND_BIN_DIR)/sequences.bin: $(SOUND_BANK_FILES) sound/sequences.json $(SOUND_SEQUENCE_DIRS) $(SOUND_SEQUENCE_FILES) $(ENDIAN_BITWIDTH)
@$(PRINT) "$(GREEN)Generating: $(BLUE)$@ $(NO_COL)\n"
$(V)$(PYTHON) $(TOOLS_DIR)/assemble_sound.py --sequences $@ $(SOUND_BIN_DIR)/sequences_header $(SOUND_BIN_DIR)/bank_sets sound/sound_banks/ sound/sequences.json $(SOUND_SEQUENCE_FILES) $(C_DEFINES) $$(cat $(ENDIAN_BITWIDTH))
$(SOUND_BIN_DIR)/bank_sets: $(SOUND_BIN_DIR)/sequences.bin
@true
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
$(SOUND_BIN_DIR)/sequences_header: $(SOUND_BIN_DIR)/sequences.bin
@true
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
$(SOUND_BIN_DIR)/%.m64: $(SOUND_BIN_DIR)/%.o
$(call print,Converting to M64:,$<,$@)
$(V)$(OBJCOPY) -j .rodata $< -O binary $@
2020-06-02 12:44:34 -04:00
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
#==============================================================================#
# Generated Source Code Files #
#==============================================================================#
2019-12-01 21:52:53 -05:00
2020-12-03 14:26:38 -05:00
# Convert binary file to a comma-separated list of byte values for inclusion in C code
$(BUILD_DIR)/%.inc.c: $(BUILD_DIR)/%
$(call print,Piping:,$<,$@)
$(V)hexdump -v -e '1/1 "0x%X,"' $< > $@
$(V)echo >> $@
2019-12-01 21:52:53 -05:00
2020-12-03 14:26:38 -05:00
# Generate animation data
2019-11-03 14:36:27 -05:00
$(BUILD_DIR)/assets/mario_anim_data.c: $(wildcard assets/anims/*.inc.c)
2020-12-03 14:26:38 -05:00
@$(PRINT) "$(GREEN)Generating animation data $(NO_COL)\n"
$(V)$(PYTHON) $(TOOLS_DIR)/mario_anims_converter.py > $@
2019-11-03 14:36:27 -05:00
2020-12-03 14:26:38 -05:00
# Generate demo input data
2019-11-03 14:36:27 -05:00
$(BUILD_DIR)/assets/demo_data.c: assets/demo_data.json $(wildcard assets/demos/*.bin)
2020-12-03 14:26:38 -05:00
@$(PRINT) "$(GREEN)Generating demo data $(NO_COL)\n"
$(V)$(PYTHON) $(TOOLS_DIR)/demo_data_converter.py assets/demo_data.json $(DEF_INC_CFLAGS) > $@
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
# Encode in-game text strings
$(BUILD_DIR)/include/text_strings.h: include/text_strings.h.in
$(call print,Encoding:,$<,$@)
$(V)$(TEXTCONV) charmap.txt $< $@
$(BUILD_DIR)/include/text_menu_strings.h: include/text_menu_strings.h.in
$(call print,Encoding:,$<,$@)
$(V)$(TEXTCONV) charmap_menu.txt $< $@
$(BUILD_DIR)/text/%/define_courses.inc.c: text/define_courses.inc.c text/%/courses.h
@$(PRINT) "$(GREEN)Preprocessing: $(BLUE)$@ $(NO_COL)\n"
$(V)$(CPP) $(CPPFLAGS) $< -o - -I text/$*/ | $(TEXTCONV) charmap.txt - $@
$(BUILD_DIR)/text/%/define_text.inc.c: text/define_text.inc.c text/%/courses.h text/%/dialogs.h
@$(PRINT) "$(GREEN)Preprocessing: $(BLUE)$@ $(NO_COL)\n"
$(V)$(CPP) $(CPPFLAGS) $< -o - -I text/$*/ | $(TEXTCONV) charmap.txt - $@
2020-06-02 12:44:34 -04:00
2020-12-03 14:26:38 -05:00
# Level headers
$(BUILD_DIR)/include/level_headers.h: levels/level_headers.h.in
$(call print,Preprocessing level headers:,$<,$@)
$(V)$(CPP) $(CPPFLAGS) -I . levels/level_headers.h.in | $(PYTHON) $(TOOLS_DIR)/output_level_headers.py > $(BUILD_DIR)/include/level_headers.h
2019-08-25 00:46:40 -04:00
2021-01-01 15:42:01 -05:00
# Generate version_data.h
$(BUILD_DIR)/src/game/version_data.h: tools/make_version.sh
@$(PRINT) "$(GREEN)Generating: $(BLUE)$@ $(NO_COL)\n"
$(V)tools/make_version.sh $(CROSS) > $@
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
#==============================================================================#
# Compilation Recipes #
#==============================================================================#
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
# Compile C code
$(BUILD_DIR)/%.o: %.c
$(call print,Compiling:,$<,$@)
2020-12-08 19:28:12 -05:00
$(V)$(CC) -c $(CFLAGS) -MMD -MF $(BUILD_DIR)/$*.d -o $@ $<
2019-11-03 14:36:27 -05:00
$(BUILD_DIR)/%.o: $(BUILD_DIR)/%.c
2020-12-03 14:26:38 -05:00
$(call print,Compiling:,$<,$@)
2020-12-08 19:28:12 -05:00
$(V)$(CC) -c $(CFLAGS) -MMD -MF $(BUILD_DIR)/$*.d -o $@ $<
2020-12-03 14:26:38 -05:00
# Assemble assembly code
2019-11-03 14:36:27 -05:00
$(BUILD_DIR)/%.o: %.s
2020-12-03 14:26:38 -05:00
$(call print,Assembling:,$<,$@)
$(V)$(CC) -c $(CFLAGS) $(foreach i,$(INCLUDE_DIRS),-Wa,-I$(i)) -x assembler-with-cpp -MMD -MF $(BUILD_DIR)/$*.d -o $@ $<
2020-12-03 14:26:38 -05:00
2021-01-30 21:07:43 -05:00
$(BUILD_DIR)/sound/sequences/00_sound_player.o: sound/sequences/00_sound_player.s
$(call print,Assembling:,$<,$@)
$(V)$(AS) $(ASFLAGS) -MD $(BUILD_DIR)/sound/sequences/00_sound_player.d -o $@ $<
2020-12-03 14:26:38 -05:00
# Assemble RSP assembly code
$(BUILD_DIR)/rsp/%.bin $(BUILD_DIR)/rsp/%_data.bin: rsp/%.s
$(call print,Assembling:,$<,$@)
$(V)$(RSPASM) -sym $@.sym $(RSPASMFLAGS) -strequ CODE_FILE $(BUILD_DIR)/rsp/$*.bin -strequ DATA_FILE $(BUILD_DIR)/rsp/$*_data.bin $<
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
# Run linker script through the C preprocessor
2019-08-25 00:46:40 -04:00
$(BUILD_DIR)/$(LD_SCRIPT): $(LD_SCRIPT)
2020-12-03 14:26:38 -05:00
$(call print,Preprocessing linker script:,$<,$@)
$(V)$(CPP) $(CPPFLAGS) -DBUILD_DIR=$(BUILD_DIR) -MMD -MP -MT $@ -MF $@.d -o $@ $<
2019-08-25 00:46:40 -04:00
# Link libgoddard
$(BUILD_DIR)/libgoddard.a: $(GODDARD_O_FILES)
@$(PRINT) "$(GREEN)Linking libgoddard: $(BLUE)$@ $(NO_COL)\n"
$(V)$(AR) rcs -o $@ $(GODDARD_O_FILES)
2021-01-25 22:55:36 -05:00
# Link libz
$(BUILD_DIR)/libz.a: $(LIBZ_O_FILES)
@$(PRINT) "$(GREEN)Linking libz: $(BLUE)$@ $(NO_COL)\n"
$(V)$(AR) rcs -o $@ $(LIBZ_O_FILES)
2020-12-03 14:26:38 -05:00
# Link SM64 ELF file
$(ELF): $(O_FILES) $(YAY0_OBJ_FILES) $(SEG_FILES) $(BUILD_DIR)/$(LD_SCRIPT) undefined_syms.txt $(BUILD_DIR)/libz.a $(BUILD_DIR)/libgoddard.a
2020-12-03 14:26:38 -05:00
@$(PRINT) "$(GREEN)Linking ELF file: $(BLUE)$@ $(NO_COL)\n"
2021-04-12 18:21:14 -04:00
$(V)$(LD) --gc-sections -L $(BUILD_DIR) -T undefined_syms.txt -T $(BUILD_DIR)/$(LD_SCRIPT) -Map $(BUILD_DIR)/sm64.$(VERSION).map --no-check-sections $(addprefix -R ,$(SEG_FILES)) -o $@ $(O_FILES) -L$(LIBS_DIR) -l$(ULTRALIB) -Llib -lgcc -lnustd -lhvqm2 -lz -lgoddard -u sprintf -u osMapTLB
2019-08-25 00:46:40 -04:00
2020-12-03 14:26:38 -05:00
# Build ROM
2019-08-25 00:46:40 -04:00
$(ROM): $(ELF)
2020-12-03 14:26:38 -05:00
$(call print,Building ROM:,$<,$@)
$(V)$(OBJCOPY) --pad-to=0x100000 --gap-fill=0xFF $< $@ -O binary
2021-01-25 00:44:33 -05:00
$(V)$(N64CKSUM) $@
2019-08-25 00:46:40 -04:00
$(BUILD_DIR)/$(TARGET).objdump: $(ELF)
$(OBJDUMP) -D $< > $@
.PHONY: all clean distclean default diff test load
2020-06-02 12:44:34 -04:00
# with no prerequisites, .SECONDARY causes no intermediate target to be removed
.SECONDARY:
2019-08-25 00:46:40 -04:00
# Remove built-in rules, to improve performance
MAKEFLAGS += --no-builtin-rules
-include $(DEP_FILES)
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true