2020-05-14 11:18:12 +02:00
2019-08-25 06:46:40 +02:00
# Makefile to rebuild SM64 split image
### Default target ###
default : all
### Build Options ###
2019-12-02 03:52:53 +01:00
# These options can either be changed by modifying the makefile, or
# by building with 'make SETTING=value'. 'make clean' may be required.
2020-06-20 03:32:12 +02:00
# Build debug version
DEBUG ?= 0
2019-08-25 06:46:40 +02:00
# Version of the game to build
VERSION ?= us
# Graphics microcode used
2020-06-20 03:32:12 +02:00
GRUCODE ?= f3dex2e
2019-08-25 06:46:40 +02:00
# If COMPARE is 1, check the output sha1sum when building 'all'
COMPARE ?= 1
2019-12-02 03:52:53 +01:00
# If NON_MATCHING is 1, define the NON_MATCHING and AVOID_UB macros when building (recommended)
2020-05-10 10:11:27 +02:00
NON_MATCHING ?= 1
2020-05-08 09:38:50 +02:00
# Build and optimize for Raspberry Pi(s)
TARGET_RPI ?= 0
2020-05-16 21:30:27 +02:00
2020-05-19 21:22:52 +02:00
# Build for Emscripten/WebGL
TARGET_WEB ?= 0
2020-05-16 21:30:27 +02:00
# Makeflag to enable OSX fixes
OSX_BUILD ?= 0
2020-04-03 20:57:26 +02:00
2020-05-19 21:22:52 +02:00
# Specify the target you are building for, TARGET_BITS=0 means native
TARGET_ARCH ?= native
TARGET_BITS ?= 0
2020-09-01 08:52:36 +02:00
# Enable immediate load by default
IMMEDIATELOAD ?= 1
# Enable better camera by default
BETTERCAMERA ?= 1
# Enable no drawing distance by default
NODRAWINGDISTANCE ?= 1
2020-05-16 14:41:57 +02:00
# Disable texture fixes by default (helps with them purists)
TEXTURE_FIX ?= 0
2020-05-13 23:33:12 +02:00
# Enable extended options menu by default
EXT_OPTIONS_MENU ?= 1
2020-05-18 10:45:28 +02:00
# Disable text-based save-files by default
TEXTSAVES ?= 0
2020-06-01 11:13:05 +02:00
# Load resources from external files
EXTERNAL_DATA ?= 0
2020-06-08 22:48:23 +02:00
# Enable Discord Rich Presence
DISCORDRPC ?= 0
2020-09-05 02:02:09 +02:00
# Enable docker build workarounds
DOCKERBUILD ?= 0
2020-05-08 03:24:42 +02:00
2020-05-19 21:22:52 +02:00
# Various workarounds for weird toolchains
2020-05-08 03:24:42 +02:00
2020-05-19 21:22:52 +02:00
NO_BZERO_BCOPY ?= 0
NO_LDIV ?= 0
2020-06-11 02:44:08 +02:00
# Backend selection
2020-05-20 05:58:35 +02:00
2020-06-11 02:44:08 +02:00
# Renderers: GL, GL_LEGACY, D3D11, D3D12
RENDER_API ?= GL
2020-08-15 06:15:28 +02:00
# Window managers: SDL1, SDL2, DXGI (forced if D3D11 or D3D12 in RENDER_API)
2020-06-11 02:44:08 +02:00
WINDOW_API ?= SDL2
2020-08-15 06:15:28 +02:00
# Audio backends: SDL1, SDL2
2020-06-11 02:44:08 +02:00
AUDIO_API ?= SDL2
2020-08-30 15:06:22 +02:00
# Controller backends (can have multiple, space separated): SDL2, SDL1
2020-06-11 02:44:08 +02:00
CONTROLLER_API ?= SDL2
2020-05-20 05:58:35 +02:00
2020-06-07 20:05:26 +02:00
# Misc settings for EXTERNAL_DATA
BASEDIR ?= res
BASEPACK ?= base.zip
2020-05-19 21:22:52 +02:00
# Automatic settings for PC port(s)
WINDOWS_BUILD ?= 0
2020-06-02 21:37:43 +02:00
# Attempt to detect OS
2020-05-19 21:22:52 +02:00
i f e q ( $( OS ) , W i n d o w s _ N T )
2020-06-02 21:37:43 +02:00
HOST_OS ?= Windows
e l s e
HOST_OS ?= $( shell uname -s 2>/dev/null || echo Unknown)
# some weird MINGW/Cygwin env that doesn't define $OS
ifneq ( ,$( findstring MINGW,HOST_OS) )
HOST_OS := Windows
endif
e n d i f
i f e q ( $( TARGET_WEB ) , 0 )
2020-06-07 14:16:09 +02:00
ifeq ( $( HOST_OS) ,Windows)
WINDOWS_BUILD := 1
endif
2020-05-17 02:04:55 +02:00
e n d i f
2020-05-19 21:22:52 +02:00
# MXE overrides
2020-05-19 15:38:08 +02:00
i f e q ( $( WINDOWS_BUILD ) , 1 )
ifeq ( $( CROSS) ,i686-w64-mingw32.static-)
2020-05-19 21:22:52 +02:00
TARGET_ARCH = i386pe
2020-05-19 15:38:08 +02:00
TARGET_BITS = 32
2020-05-19 21:22:52 +02:00
NO_BZERO_BCOPY := 1
2020-05-19 15:38:08 +02:00
else ifeq ( $( CROSS) ,x86_64-w64-mingw32.static-)
2020-05-19 21:22:52 +02:00
TARGET_ARCH = i386pe
2020-05-19 15:38:08 +02:00
TARGET_BITS = 64
2020-05-19 21:22:52 +02:00
NO_BZERO_BCOPY := 1
2020-05-19 15:38:08 +02:00
endif
e n d i f
2020-05-07 20:21:22 +02:00
i f n e q ( $( TARGET_BITS ) , 0 )
BITS := -m$( TARGET_BITS)
e n d i f
2020-05-10 10:11:27 +02:00
# Release (version) flag defs
2019-08-25 06:46:40 +02:00
i f e q ( $( VERSION ) , j p )
2020-06-02 18:44:34 +02:00
VERSION_DEF := VERSION_JP
2019-08-25 06:46:40 +02:00
e l s e
i f e q ( $( VERSION ) , u s )
2020-06-02 18:44:34 +02:00
VERSION_DEF := VERSION_US
2019-08-25 06:46:40 +02:00
e l s e
i f e q ( $( VERSION ) , e u )
2020-06-02 18:44:34 +02:00
VERSION_DEF := VERSION_EU
2020-03-02 04:42:52 +01:00
e l s e
i f e q ( $( VERSION ) , s h )
$( warning Building SH is experimental and is prone to breaking. Try at your own risk.)
2020-06-02 18:44:34 +02:00
VERSION_DEF := VERSION_SH
2020-03-02 04:42:52 +01:00
# TODO: GET RID OF THIS!!! We should mandate assets for Shindou like EU but we dont have the addresses extracted yet so we'll just pretend you have everything extracted for now.
2020-05-08 09:38:50 +02:00
NOEXTRACT := 1
2019-08-25 06:46:40 +02:00
e l s e
$( error unknown version " $( VERSION) " )
e n d i f
e n d i f
e n d i f
2020-03-02 04:42:52 +01:00
e n d i f
2019-08-25 06:46:40 +02:00
2020-06-02 18:44:34 +02:00
TARGET := sm64.$( VERSION)
VERSION_CFLAGS := -D$( VERSION_DEF) -D_LANGUAGE_C
VERSION_ASFLAGS := --defsym $( VERSION_DEF) = 1
2020-05-21 19:19:20 +02:00
# Stuff for showing the git hash in the intro on nightly builds
# From https://stackoverflow.com/questions/44038428/include-git-commit-hash-and-or-branch-name-in-c-c-source
2020-09-12 01:07:45 +02:00
#ifeq ($(shell git rev-parse --abbrev-ref HEAD),nightly)
2020-05-21 19:19:20 +02:00
GIT_HASH = ` git rev-parse --short HEAD`
COMPILE_TIME = ` date -u +'%Y-%m-%d %H:%M:%S UTC' `
VERSION_CFLAGS += -DNIGHTLY -DGIT_HASH= " \" $( GIT_HASH) \" " -DCOMPILE_TIME= " \" $( COMPILE_TIME) \" "
2020-09-12 01:07:45 +02:00
#endif
2020-05-21 19:19:20 +02:00
2019-08-25 06:46:40 +02:00
# Microcode
i f e q ( $( GRUCODE ) , f 3 d e x ) # Fast3DEX
2020-06-02 18:44:34 +02:00
GRUCODE_DEF := F3DEX_GBI
GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED = 1
2019-08-25 06:46:40 +02:00
TARGET := $( TARGET) .f3dex
COMPARE := 0
e l s e
2020-06-20 03:32:12 +02:00
i f e q ( $( GRUCODE ) , f 3 d e x 2 ) # Fast3DEX2
2020-06-02 18:44:34 +02:00
GRUCODE_DEF := F3DEX_GBI_2
GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED = 1
2019-08-25 06:46:40 +02:00
TARGET := $( TARGET) .f3dex2
COMPARE := 0
e l s e
2020-06-20 03:32:12 +02:00
i f e q ( $( GRUCODE ) , f 3 d e x 2 e ) # Fast3DEX2 Extended (PC default)
GRUCODE_DEF := F3DEX_GBI_2E
2020-05-07 20:21:22 +02:00
TARGET := $( TARGET) .f3dex2e
COMPARE := 0
e l s e
2019-08-25 06:46:40 +02:00
i f e q ( $( GRUCODE ) , f 3 d _ n e w ) # Fast3D 2.0H (Shindou)
2020-06-02 18:44:34 +02:00
GRUCODE_DEF := F3D_NEW
2019-08-25 06:46:40 +02:00
TARGET := $( TARGET) .f3d_new
COMPARE := 0
e l s e
i f e q ( $( GRUCODE ) , f 3 d z e x ) # Fast3DZEX (2.0J / Animal Forest - Dōbutsu no Mori)
$( warning Fast3DZEX is experimental. Try at your own risk.)
2020-06-02 18:44:34 +02:00
GRUCODE_DEF := F3DEX_GBI_2
GRUCODE_ASFLAGS := --defsym F3DEX_GBI_SHARED = 1
2019-08-25 06:46:40 +02:00
TARGET := $( TARGET) .f3dzex
COMPARE := 0
e n d i f
e n d i f
e n d i f
e n d i f
2020-05-07 20:21:22 +02:00
e n d i f
2019-08-25 06:46:40 +02:00
2020-06-02 18:44:34 +02:00
GRUCODE_CFLAGS := -D$( GRUCODE_DEF)
GRUCODE_ASFLAGS := $( GRUCODE_ASFLAGS) --defsym $( GRUCODE_DEF) = 1
2020-05-10 10:11:27 +02:00
# Default build is for PC now
VERSION_CFLAGS := $( VERSION_CFLAGS) -DNON_MATCHING -DAVOID_UB
2019-08-25 06:46:40 +02:00
2020-05-10 10:11:27 +02:00
i f e q ( $( TARGET_RPI ) , 1 ) # Define RPi to change SDL2 title & GLES2 hints
VERSION_CFLAGS += -DUSE_GLES
2019-08-25 06:46:40 +02:00
e n d i f
2020-05-16 21:30:27 +02:00
i f e q ( $( OSX_BUILD ) , 1 ) # Modify GFX & SDL2 for OSX GL
VERSION_CFLAGS += -DOSX_BUILD
e n d i f
2020-05-10 10:11:27 +02:00
VERSION_ASFLAGS := --defsym AVOID_UB = 1
COMPARE := 0
2020-05-07 20:21:22 +02:00
i f e q ( $( TARGET_WEB ) , 1 )
2020-06-16 23:15:27 +02:00
VERSION_CFLAGS := $( VERSION_CFLAGS) -DTARGET_WEB -DUSE_GLES
2020-05-07 20:21:22 +02:00
e n d i f
2020-06-11 02:44:08 +02:00
# Check backends
i f n e q ( , $( filter $ ( RENDER_API ) ,D 3D 11 D 3D 12) )
ifneq ( $( WINDOWS_BUILD) ,1)
$( error DirectX is only supported on Windows)
endif
ifneq ( $( WINDOW_API) ,DXGI)
$( warning DirectX renderers require DXGI, forcing WINDOW_API value)
WINDOW_API := DXGI
endif
e l s e
ifeq ( $( WINDOW_API) ,DXGI)
$( error DXGI can only be used with DirectX renderers)
endif
e n d i f
2019-08-25 06:46:40 +02:00
################### Universal Dependencies ###################
# (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.)
i f n e q ( $( MAKECMDGOALS ) , c l e a n )
i f n e q ( $( MAKECMDGOALS ) , d i s t c l e a n )
# Make sure assets exist
NOEXTRACT ?= 0
i f e q ( $( NOEXTRACT ) , 0 )
DUMMY != ./extract_assets.py $( VERSION) >& 2 || echo FAIL
i f e q ( $( DUMMY ) , F A I L )
$( error Failed to extract assets)
e n d i f
e n d i f
# Make tools if out of date
2020-05-16 21:30:27 +02:00
DUMMY != make -C tools >& 2 || echo FAIL
2019-08-25 06:46:40 +02:00
i f e q ( $( DUMMY ) , F A I L )
$( error Failed to build tools)
e n d i f
e n d i f
e n d i f
################ Target Executable and Sources ###############
# BUILD_DIR is location where all build artifacts are placed
BUILD_DIR_BASE := build
2020-05-10 10:11:27 +02:00
2020-05-07 20:21:22 +02:00
i f e q ( $( TARGET_WEB ) , 1 )
BUILD_DIR := $( BUILD_DIR_BASE) /$( VERSION) _web
e l s e
BUILD_DIR := $( BUILD_DIR_BASE) /$( VERSION) _pc
e n d i f
2019-08-25 06:46:40 +02:00
LIBULTRA := $( BUILD_DIR) /libultra.a
2020-05-10 10:11:27 +02:00
2020-05-07 20:21:22 +02:00
i f e q ( $( TARGET_WEB ) , 1 )
EXE := $( BUILD_DIR) /$( TARGET) .html
2020-05-10 10:11:27 +02:00
else
ifeq ( $( WINDOWS_BUILD) ,1)
EXE := $( BUILD_DIR) /$( TARGET) .exe
2020-05-08 09:38:50 +02:00
2020-05-10 10:11:27 +02:00
else # Linux builds/binary namer
ifeq ( $( TARGET_RPI) ,1)
EXE := $( BUILD_DIR) /$( TARGET) .arm
else
EXE := $( BUILD_DIR) /$( TARGET)
endif
endif
2020-05-08 09:38:50 +02:00
e n d i f
2019-08-25 06:46:40 +02:00
ELF := $( BUILD_DIR) /$( TARGET) .elf
LD_SCRIPT := sm64.ld
2019-11-03 20:36:27 +01:00
MIO0_DIR := $( BUILD_DIR) /bin
2019-08-25 06:46:40 +02:00
SOUND_BIN_DIR := $( BUILD_DIR) /sound
TEXTURE_DIR := textures
ACTOR_DIR := actors
2019-11-03 20:36:27 +01:00
LEVEL_DIRS := $( patsubst levels/%,%,$( dir $( wildcard levels/*/header.h) ) )
2019-08-25 06:46:40 +02:00
# Directories containing source files
2020-05-10 10:11:27 +02:00
# Hi, I'm a PC
2020-09-13 06:16:10 +02:00
SRC_DIRS := src src/engine src/game src/audio src/menu src/buffers actors levels bin data assets src/pc src/pc/gfx src/pc/audio src/pc/controller src/pc/fs src/pc/fs/packtypes
SRC_DIRS += src/pc/network src/pc/network/packets src/pc/network/socket src/pc/network/discord
2020-05-10 10:11:27 +02:00
ASM_DIRS :=
2020-09-15 03:29:47 +02:00
#ifeq ($(DISCORDRPC),1)
# SRC_DIRS += src/pc/discord
#endif
2020-06-08 22:48:23 +02:00
2019-08-25 06:46:40 +02:00
BIN_DIRS := bin bin/$( VERSION)
ULTRA_SRC_DIRS := lib/src lib/src/math
ULTRA_ASM_DIRS := lib/asm lib/data
ULTRA_BIN_DIRS := lib/bin
GODDARD_SRC_DIRS := src/goddard src/goddard/dynlists
2020-04-03 20:57:26 +02:00
MIPSISET := -mips2
MIPSBIT := -32
2019-08-25 06:46:40 +02:00
2020-06-05 13:40:08 +02:00
i f e q ( $( DEBUG ) , 1 )
OPT_FLAGS := -g
2019-08-25 06:46:40 +02:00
e l s e
2020-06-01 11:13:05 +02:00
OPT_FLAGS := -O2
2019-08-25 06:46:40 +02:00
e n d i f
2020-05-10 10:11:27 +02:00
# Set BITS (32/64) to compile for
OPT_FLAGS += $( BITS)
2020-05-07 20:21:22 +02:00
i f e q ( $( TARGET_WEB ) , 1 )
OPT_FLAGS := -O2 -g4 --source-map-base http://localhost:8080/
e n d i f
2020-05-08 09:38:50 +02:00
i f e q ( $( TARGET_RPI ) , 1 )
2020-05-10 10:11:27 +02:00
machine = $( shell sh -c 'uname -m 2>/dev/null || echo unknown' )
2020-05-08 09:38:50 +02:00
# Raspberry Pi B+, Zero, etc
2020-05-10 10:11:27 +02:00
ifneq ( ,$( findstring armv6l,$( machine) ) )
2020-05-08 09:38:50 +02:00
OPT_FLAGS := -march= armv6zk+fp -mfpu= vfp -Ofast
endif
2020-05-10 10:11:27 +02:00
# Raspberry Pi 2 and 3 in ARM 32bit mode
2020-05-08 09:38:50 +02:00
ifneq ( ,$( findstring armv7l,$( machine) ) )
model = $( shell sh -c 'cat /sys/firmware/devicetree/base/model 2>/dev/null || echo unknown' )
ifneq ( ,$( findstring 3,$( model) ) )
OPT_FLAGS := -march= armv8-a+crc -mtune= cortex-a53 -mfpu= neon-fp-armv8 -O3
else
OPT_FLAGS := -march= armv7-a -mtune= cortex-a7 -mfpu= neon-vfpv4 -O3
endif
endif
2020-05-10 10:11:27 +02:00
# RPi3 or RPi4, in ARM64 (aarch64) mode. NEEDS TESTING 32BIT.
# DO NOT pass -mfpu stuff here, thats for 32bit ARM only and will fail for 64bit ARM.
2020-05-08 09:38:50 +02:00
ifneq ( ,$( findstring aarch64,$( machine) ) )
2020-05-10 10:11:27 +02:00
model = $( shell sh -c 'cat /sys/firmware/devicetree/base/model 2>/dev/null || echo unknown' )
ifneq ( ,$( findstring 3,$( model) ) )
OPT_FLAGS := -march= armv8-a+crc -mtune= cortex-a53 -O3
else ifneq ( ,$( findstring 4,$( model) ) )
OPT_FLAGS := -march= armv8-a+crc+simd -mtune= cortex-a72 -O3
endif
2020-05-08 09:38:50 +02:00
endif
2020-04-03 20:57:26 +02:00
e n d i f
2019-08-25 06:46:40 +02:00
# File dependencies and variables for specific files
i n c l u d e M a k e f i l e . s p l i t
# Source code files
2019-11-03 20:36:27 +01: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)
2020-05-07 20:21:22 +02:00
CXX_FILES := $( foreach dir,$( SRC_DIRS) ,$( wildcard $( dir) /*.cpp) )
2019-08-25 06:46:40 +02:00
S_FILES := $( foreach dir,$( ASM_DIRS) ,$( wildcard $( dir) /*.s) )
GODDARD_C_FILES := $( foreach dir,$( GODDARD_SRC_DIRS) ,$( wildcard $( dir) /*.c) )
2020-05-10 10:11:27 +02:00
2020-05-07 20:21:22 +02:00
GENERATED_C_FILES := $( BUILD_DIR) /assets/mario_anim_data.c $( BUILD_DIR) /assets/demo_data.c \
$( addprefix $( BUILD_DIR) /bin/,$( addsuffix _skybox.c,$( notdir $( basename $( wildcard textures/skyboxes/*.png) ) ) ) )
2020-06-21 01:21:46 +02:00
ULTRA_C_FILES := \
alBnkfNew.c \
guLookAtRef.c \
guMtxF2L.c \
guNormalize.c \
guOrthoF.c \
guPerspectiveF.c \
guRotateF.c \
guScaleF.c \
guTranslateF.c \
ldiv.c
C_FILES := $( filter-out src/game/main.c,$( C_FILES) )
ULTRA_C_FILES := $( addprefix lib/src/,$( ULTRA_C_FILES) )
2020-05-10 10:11:27 +02:00
# "If we're not N64, use the above"
2019-08-25 06:46:40 +02:00
2020-03-02 04:42:52 +01:00
i f e q ( $( VERSION ) , s h )
SOUND_BANK_FILES := $( wildcard sound/sound_banks/*.json)
SOUND_SEQUENCE_FILES := $( wildcard sound/sequences/jp/*.m64) \
$( wildcard sound/sequences/*.m64) \
$( foreach file,$( wildcard sound/sequences/jp/*.s) ,$( BUILD_DIR) /$( file:.s= .m64) ) \
$( foreach file,$( wildcard sound/sequences/*.s) ,$( BUILD_DIR) /$( file:.s= .m64) )
e l s e
2019-08-25 06:46:40 +02:00
SOUND_BANK_FILES := $( wildcard sound/sound_banks/*.json)
SOUND_SEQUENCE_FILES := $( wildcard sound/sequences/$( VERSION) /*.m64) \
$( wildcard sound/sequences/*.m64) \
$( foreach file,$( wildcard sound/sequences/$( VERSION) /*.s) ,$( BUILD_DIR) /$( file:.s= .m64) ) \
$( foreach file,$( wildcard sound/sequences/*.s) ,$( BUILD_DIR) /$( file:.s= .m64) )
2020-03-02 04:42:52 +01:00
e n d i f
2019-08-25 06:46:40 +02:00
SOUND_SAMPLE_DIRS := $( wildcard sound/samples/*)
SOUND_SAMPLE_AIFFS := $( foreach dir,$( SOUND_SAMPLE_DIRS) ,$( wildcard $( dir) /*.aiff) )
SOUND_SAMPLE_TABLES := $( foreach file,$( SOUND_SAMPLE_AIFFS) ,$( BUILD_DIR) /$( file:.aiff= .table) )
SOUND_SAMPLE_AIFCS := $( foreach file,$( SOUND_SAMPLE_AIFFS) ,$( BUILD_DIR) /$( file:.aiff= .aifc) )
2020-06-02 18:44:34 +02:00
SOUND_OBJ_FILES := $( SOUND_BIN_DIR) /sound_data.o
2019-08-25 06:46:40 +02:00
# Object files
O_FILES := $( foreach file,$( C_FILES) ,$( BUILD_DIR) /$( file:.c= .o) ) \
2020-05-07 20:21:22 +02:00
$( foreach file,$( CXX_FILES) ,$( BUILD_DIR) /$( file:.cpp= .o) ) \
2019-08-25 06:46:40 +02:00
$( foreach file,$( S_FILES) ,$( BUILD_DIR) /$( file:.s= .o) ) \
2019-11-03 20:36:27 +01:00
$( foreach file,$( GENERATED_C_FILES) ,$( file:.c= .o) )
2019-08-25 06:46:40 +02:00
ULTRA_O_FILES := $( foreach file,$( ULTRA_S_FILES) ,$( BUILD_DIR) /$( file:.s= .o) ) \
$( foreach file,$( ULTRA_C_FILES) ,$( BUILD_DIR) /$( file:.c= .o) )
GODDARD_O_FILES := $( foreach file,$( GODDARD_C_FILES) ,$( BUILD_DIR) /$( file:.c= .o) )
2020-06-08 22:48:23 +02:00
RPC_LIBS :=
2020-09-15 03:29:47 +02:00
#ifeq ($(DISCORDRPC),1)
# ifeq ($(WINDOWS_BUILD),1)
# RPC_LIBS := lib/discord/libdiscord-rpc.dll
# else ifeq ($(OSX_BUILD),1)
# # needs testing
# RPC_LIBS := lib/discord/libdiscord-rpc.dylib
# else
# RPC_LIBS := lib/discord/libdiscord-rpc.so
# endif
#endif
2020-06-08 22:48:23 +02:00
2020-09-13 06:16:10 +02:00
DISCORD_SDK_LIBS :=
i f e q ( $( WINDOWS_BUILD ) , 1 )
DISCORD_SDK_LIBS := lib/discordsdk/discord_game_sdk.dll
e l s e i f e q ( $( OSX_BUILD ) , 1 )
# needs testing
DISCORD_SDK_LIBS := lib/discordsdk/discord_game_sdk.dylib
e l s e
2020-09-15 08:26:55 +02:00
DISCORD_SDK_LIBS := lib/discordsdk/libdiscord_game_sdk.so
2020-09-13 06:16:10 +02:00
e n d i f
2019-08-25 06:46:40 +02:00
# Automatic dependency files
DEP_FILES := $( O_FILES:.o= .d) $( ULTRA_O_FILES:.o= .d) $( GODDARD_O_FILES:.o= .d) $( BUILD_DIR) /$( LD_SCRIPT) .d
# Segment elf files
SEG_FILES := $( SEGMENT_ELF_FILES) $( ACTOR_ELF_FILES) $( LEVEL_ELF_FILES)
##################### Compiler Options #######################
2020-05-07 20:21:22 +02:00
INCLUDE_CFLAGS := -I include -I $( BUILD_DIR) -I $( BUILD_DIR) /include -I src -I .
ENDIAN_BITWIDTH := $( BUILD_DIR) /endian-and-bitwidth
2020-05-10 10:11:27 +02:00
# Huge deleted N64 section was here
2020-05-07 20:21:22 +02:00
2020-05-19 21:22:52 +02:00
AS := $( CROSS) as
2020-05-10 10:11:27 +02:00
2020-05-16 21:30:27 +02:00
i f e q ( $( OSX_BUILD ) , 1 )
2020-06-02 21:37:43 +02:00
AS := i686-w64-mingw32-as
2020-05-16 21:30:27 +02:00
e n d i f
2020-05-10 10:11:27 +02:00
i f n e q ( $( TARGET_WEB ) , 1 ) # As in, not-web PC port
2020-07-14 18:54:07 +02:00
CC ?= $( CROSS) gcc
CXX ?= $( CROSS) g++
2020-05-07 20:21:22 +02:00
e l s e
CC := emcc
2020-06-16 21:24:54 +02:00
CXX := emcc
2020-05-07 20:21:22 +02:00
e n d i f
2020-05-10 10:11:27 +02:00
2020-09-16 06:48:14 +02:00
LD := $( CXX)
2020-05-19 21:22:52 +02:00
2020-09-15 03:29:47 +02:00
#ifeq ($(DISCORDRPC),1)
# LD := $(CXX)
#else ifeq ($(WINDOWS_BUILD),1)
# ifeq ($(CROSS),i686-w64-mingw32.static-) # fixes compilation in MXE on Linux and WSL
# LD := $(CC)
# else ifeq ($(CROSS),x86_64-w64-mingw32.static-)
# LD := $(CC)
# else
# LD := $(CXX)
# endif
#endif
2020-05-10 10:11:27 +02:00
2020-05-16 17:21:16 +02:00
i f e q ( $( WINDOWS_BUILD ) , 1 ) # fixes compilation in MXE on Linux and WSL
CPP := cpp -P
2020-05-16 17:56:58 +02:00
OBJCOPY := objcopy
2020-05-16 21:30:27 +02:00
OBJDUMP := $( CROSS) objdump
2020-05-19 21:22:52 +02:00
e l s e i f e q ( $( OSX_BUILD ) , 1 )
CPP := cpp-9 -P
OBJDUMP := i686-w64-mingw32-objdump
OBJCOPY := i686-w64-mingw32-objcopy
2020-05-16 21:30:27 +02:00
e l s e # Linux & other builds
2020-05-16 18:01:23 +02:00
CPP := $( CROSS) cpp -P
2020-05-16 17:56:58 +02:00
OBJCOPY := $( CROSS) objcopy
2020-05-16 21:30:27 +02:00
OBJDUMP := $( CROSS) objdump
e n d i f
2020-05-07 20:21:22 +02:00
PYTHON := python3
2020-05-12 16:08:34 +02:00
SDLCONFIG := $( CROSS) sdl2-config
2020-05-07 20:21:22 +02:00
2020-06-11 02:44:08 +02:00
# configure backend flags
BACKEND_CFLAGS := -DRAPI_$( RENDER_API) = 1 -DWAPI_$( WINDOW_API) = 1 -DAAPI_$( AUDIO_API) = 1
# can have multiple controller APIs
BACKEND_CFLAGS += $( foreach capi,$( CONTROLLER_API) ,-DCAPI_$( capi) = 1)
2020-08-15 06:15:28 +02:00
BACKEND_LDFLAG0S :=
SDL1_USED := 0
2020-06-11 02:44:08 +02:00
SDL2_USED := 0
# for now, it's either SDL+GL or DXGI+DirectX, so choose based on WAPI
i f e q ( $( WINDOW_API ) , D X G I )
DXBITS := ` cat $( ENDIAN_BITWIDTH) | tr ' ' '\n' | tail -1`
2020-07-07 13:18:46 +02:00
ifeq ( $( RENDER_API) ,D3D12)
2020-06-11 05:11:11 +02:00
BACKEND_CFLAGS += -Iinclude/dxsdk
2020-06-11 02:44:08 +02:00
endif
BACKEND_LDFLAGS += -ld3dcompiler -ldxgi -ldxguid
BACKEND_LDFLAGS += -lsetupapi -ldinput8 -luser32 -lgdi32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion -luuid -static
2020-08-15 06:15:28 +02:00
e l s e i f e q ( $( findstring SDL ,$ ( WINDOW_API ) ) , S D L )
2020-06-11 02:44:08 +02:00
ifeq ( $( WINDOWS_BUILD) ,1)
BACKEND_LDFLAGS += -lglew32 -lglu32 -lopengl32
else ifeq ( $( TARGET_RPI) ,1)
BACKEND_LDFLAGS += -lGLESv2
else ifeq ( $( OSX_BUILD) ,1)
BACKEND_LDFLAGS += -framework OpenGL ` pkg-config --libs glew`
else
BACKEND_LDFLAGS += -lGL
endif
e n d i f
2020-08-15 06:15:28 +02:00
i f n e q ( , $( findstring SDL 2,$ ( AUDIO_API ) $ ( WINDOW_API ) $ ( CONTROLLER_API ) ) )
SDL2_USED := 1
e n d i f
i f n e q ( , $( findstring SDL 1,$ ( AUDIO_API ) $ ( WINDOW_API ) $ ( CONTROLLER_API ) ) )
SDL1_USED := 1
2020-06-11 02:44:08 +02:00
e n d i f
2020-08-15 06:15:28 +02:00
i f e q ( $( SDL 1_USED ) $( SDL 2_USED ) , 1 1 )
$( error Cannot link both SDL1 and SDL2 at the same time )
2020-06-11 02:44:08 +02:00
e n d i f
# SDL can be used by different systems, so we consolidate all of that shit into this
2020-08-15 06:15:28 +02:00
i f e q ( $( SDL 2_USED ) , 1 )
SDLCONFIG := $( CROSS) sdl2-config
BACKEND_CFLAGS += -DHAVE_SDL2= 1
e l s e i f e q ( $( SDL 1_USED ) , 1 )
SDLCONFIG := $( CROSS) sdl-config
BACKEND_CFLAGS += -DHAVE_SDL1= 1
e n d i f
i f n e q ( $( SDL 1_USED ) $( SDL 2_USED ) , 0 0 )
BACKEND_CFLAGS += ` $( SDLCONFIG) --cflags`
2020-06-11 02:44:08 +02:00
ifeq ( $( WINDOWS_BUILD) ,1)
2020-06-12 23:53:01 +02:00
BACKEND_LDFLAGS += ` $( SDLCONFIG) --static-libs` -lsetupapi -luser32 -limm32 -lole32 -loleaut32 -lshell32 -lwinmm -lversion
2020-06-11 02:44:08 +02:00
else
BACKEND_LDFLAGS += ` $( SDLCONFIG) --libs`
endif
e n d i f
2020-05-07 20:21:22 +02:00
i f e q ( $( WINDOWS_BUILD ) , 1 )
2020-08-09 22:23:27 +02:00
CC_CHECK := $( CC) -fsyntax-only -fsigned-char $( BACKEND_CFLAGS) $( INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $( VERSION_CFLAGS) $( GRUCODE_CFLAGS) -DWINSOCK
CFLAGS := $( OPT_FLAGS) $( INCLUDE_CFLAGS) $( BACKEND_CFLAGS) $( VERSION_CFLAGS) $( GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv -DWINSOCK
2020-05-07 20:21:22 +02:00
e l s e i f e q ( $( TARGET_WEB ) , 1 )
2020-06-11 02:44:08 +02:00
CC_CHECK := $( CC) -fsyntax-only -fsigned-char $( BACKEND_CFLAGS) $( INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $( VERSION_CFLAGS) $( GRUCODE_CFLAGS) -s USE_SDL = 2
CFLAGS := $( OPT_FLAGS) $( INCLUDE_CFLAGS) $( BACKEND_CFLAGS) $( VERSION_CFLAGS) $( GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv -s USE_SDL = 2
2020-05-10 10:11:27 +02:00
2020-05-08 09:38:50 +02:00
# Linux / Other builds below
2020-05-07 20:21:22 +02:00
e l s e
2020-06-11 02:44:08 +02:00
CC_CHECK := $( CC) -fsyntax-only -fsigned-char $( BACKEND_CFLAGS) $( INCLUDE_CFLAGS) -Wall -Wextra -Wno-format-security $( VERSION_CFLAGS) $( GRUCODE_CFLAGS)
CFLAGS := $( OPT_FLAGS) $( INCLUDE_CFLAGS) $( BACKEND_CFLAGS) $( VERSION_CFLAGS) $( GRUCODE_CFLAGS) -fno-strict-aliasing -fwrapv
2020-05-07 20:21:22 +02:00
e n d i f
2020-09-04 06:48:50 +02:00
# Identify that this is a coop build so that one patch can be applied to EX
# and/or COOP. They can choose to ifdef entity synchronization out.
CC_CHECK += -DCOOP
CFLAGS += -DCOOP
2020-09-04 11:04:37 +02:00
# Enforce -Werror in strict mode
i f e q ( $( STRICT ) , 1 )
2020-09-04 10:55:54 +02:00
CC_CHECK += -Werror -Wno-error= unused-variable -Wno-error= unused-parameter
CFLAGS += -Werror -Wno-error= unused-variable -Wno-error= unused-parameter
e n d i f
2020-05-13 23:33:12 +02:00
2020-09-02 07:06:36 +02:00
# Check for debug option
i f e q ( $( DEBUG ) , 1 )
CC_CHECK += -DDEBUG
CFLAGS += -DDEBUG
e n d i f
2020-09-04 10:55:54 +02:00
# Check for enhancement options
2020-07-31 05:42:39 +02:00
# Check for immediate load option
i f e q ( $( IMMEDIATELOAD ) , 1 )
CC_CHECK += -DIMMEDIATELOAD
CFLAGS += -DIMMEDIATELOAD
e n d i f
2020-09-05 02:02:09 +02:00
# Check for docker build workaround option
i f e q ( $( DOCKERBUILD ) , 1 )
CC_CHECK += -DDOCKERBUILD
CFLAGS += -DDOCKERBUILD
e n d i f
2020-05-13 23:33:12 +02:00
# Check for Puppycam option
2020-05-08 03:24:42 +02:00
i f e q ( $( BETTERCAMERA ) , 1 )
2020-05-13 23:33:12 +02:00
CC_CHECK += -DBETTERCAMERA
CFLAGS += -DBETTERCAMERA
EXT_OPTIONS_MENU := 1
2020-05-08 03:24:42 +02:00
e n d i f
2020-09-15 03:29:47 +02:00
#ifeq ($(TEXTSAVES),1)
# CC_CHECK += -DTEXTSAVES
# CFLAGS += -DTEXTSAVES
#endif
2020-05-18 10:45:28 +02:00
2020-05-12 09:26:16 +02:00
# Check for no drawing distance option
2020-09-15 03:29:47 +02:00
#ifeq ($(NODRAWINGDISTANCE),1)
2020-05-13 23:33:12 +02:00
CC_CHECK += -DNODRAWINGDISTANCE
CFLAGS += -DNODRAWINGDISTANCE
2020-09-15 03:29:47 +02:00
#endif
2020-05-12 09:26:16 +02:00
2020-06-08 22:48:23 +02:00
# Check for Discord Rich Presence option
2020-09-15 03:29:47 +02:00
#ifeq ($(DISCORDRPC),1)
# CC_CHECK += -DDISCORDRPC
# CFLAGS += -DDISCORDRPC
#endif
2020-06-08 22:48:23 +02:00
2020-05-16 14:41:57 +02:00
# Check for texture fix option
i f e q ( $( TEXTURE_FIX ) , 1 )
2020-05-13 23:33:12 +02:00
CC_CHECK += -DTEXTURE_FIX
CFLAGS += -DTEXTURE_FIX
e n d i f
# Check for extended options menu option
i f e q ( $( EXT_OPTIONS_MENU ) , 1 )
CC_CHECK += -DEXT_OPTIONS_MENU
CFLAGS += -DEXT_OPTIONS_MENU
2020-05-16 14:41:57 +02:00
e n d i f
2020-05-19 15:32:01 +02:00
# Check for no bzero/bcopy workaround option
i f e q ( $( NO_BZERO_BCOPY ) , 1 )
CC_CHECK += -DNO_BZERO_BCOPY
CFLAGS += -DNO_BZERO_BCOPY
e n d i f
2020-05-19 21:22:52 +02:00
# Use internal ldiv()/lldiv()
i f e q ( $( NO_LDIV ) , 1 )
CC_CHECK += -DNO_LDIV
CFLAGS += -DNO_LDIV
e n d i f
2020-05-20 05:58:35 +02:00
# Use OpenGL 1.3
i f e q ( $( LEGACY_GL ) , 1 )
CC_CHECK += -DLEGACY_GL
CFLAGS += -DLEGACY_GL
e n d i f
2020-05-25 03:21:36 +02:00
# Load external textures
2020-06-01 11:13:05 +02:00
i f e q ( $( EXTERNAL_DATA ) , 1 )
2020-06-07 20:05:26 +02:00
CC_CHECK += -DEXTERNAL_DATA -DFS_BASEDIR= " \" $( BASEDIR) \" "
CFLAGS += -DEXTERNAL_DATA -DFS_BASEDIR= " \" $( BASEDIR) \" "
2020-05-25 03:21:36 +02:00
# tell skyconv to write names instead of actual texture data and save the split tiles so we can use them later
2020-06-07 21:00:57 +02:00
SKYTILE_DIR := $( BUILD_DIR) /textures/skybox_tiles
SKYCONV_ARGS := --store-names --write-tiles " $( SKYTILE_DIR) "
2020-05-25 03:21:36 +02:00
e n d i f
2020-05-07 20:21:22 +02:00
ASFLAGS := -I include -I $( BUILD_DIR) $( VERSION_ASFLAGS)
i f e q ( $( TARGET_WEB ) , 1 )
LDFLAGS := -lm -lGL -lSDL2 -no-pie -s TOTAL_MEMORY = 20MB -g4 --source-map-base http://localhost:8080/ -s "EXTRA_EXPORTED_RUNTIME_METHODS=['callMain']"
2020-06-11 02:44:08 +02:00
2020-05-16 19:59:27 +02:00
e l s e i f e q ( $( WINDOWS_BUILD ) , 1 )
2020-09-13 06:16:10 +02:00
LDFLAGS := $( BITS) -march= $( TARGET_ARCH) -Llib -lpthread $( BACKEND_LDFLAGS) -static
2020-05-17 03:54:03 +02:00
ifeq ( $( CROSS) ,)
2020-05-17 02:24:29 +02:00
LDFLAGS += -no-pie
2020-05-16 19:35:56 +02:00
endif
ifeq ( $( WINDOWS_CONSOLE) ,1)
2020-05-16 17:21:16 +02:00
LDFLAGS += -mconsole
endif
2020-06-11 02:44:08 +02:00
2020-05-16 19:59:27 +02:00
e l s e i f e q ( $( TARGET_RPI ) , 1 )
2020-06-11 02:44:08 +02:00
LDFLAGS := $( OPT_FLAGS) -lm $( BACKEND_LDFLAGS) -no-pie
e l s e i f e q ( $( OSX_BUILD ) , 1 )
LDFLAGS := -lm $( BACKEND_LDFLAGS) -no-pie -lpthread
2020-05-16 21:30:27 +02:00
e l s e
2020-06-11 02:44:08 +02:00
LDFLAGS := $( BITS) -march= $( TARGET_ARCH) -lm $( BACKEND_LDFLAGS) -no-pie -lpthread
2020-09-15 03:29:47 +02:00
# ifeq ($(DISCORDRPC),1)
# LDFLAGS += -ldl -Wl,-rpath .
# endif
2020-06-11 02:44:08 +02:00
2020-09-13 06:16:10 +02:00
e n d i f
# coop specific libraries
i f e q ( $( WINDOWS_BUILD ) , 1 )
LDFLAGS += -L"ws2_32" -lwsock32
2020-09-15 08:26:55 +02:00
LDFLAGS += -Wl,-Bdynamic -ldiscord_game_sdk -Wl,-Bstatic
e l s e
LDFLAGS += -ldiscord_game_sdk -Wl,-rpath . -Wl,-rpath lib/discordsdk
2020-09-13 06:16:10 +02:00
e n d i f
# End of LDFLAGS
2019-08-25 06:46:40 +02:00
2020-03-02 04:42:52 +01:00
# Prevent a crash with -sopt
export LANG := C
2019-08-25 06:46:40 +02:00
####################### Other Tools #########################
2020-05-10 10:11:27 +02:00
# N64 conversion tools
2019-08-25 06:46:40 +02:00
TOOLS_DIR = tools
MIO0TOOL = $( TOOLS_DIR) /mio0
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
2019-11-03 20:36:27 +01:00
EXTRACT_DATA_FOR_MIO = $( TOOLS_DIR) /extract_data_for_mio
SKYCONV = $( TOOLS_DIR) /skyconv
2019-08-25 06:46:40 +02:00
EMULATOR = mupen64plus
EMU_FLAGS = --noosd
LOADER = loader64
LOADER_FLAGS = -vwf
SHA1SUM = sha1sum
2020-05-26 01:59:38 +02:00
ZEROTERM = $( PYTHON) $( TOOLS_DIR) /zeroterm.py
2019-08-25 06:46:40 +02:00
###################### Dependency Check #####################
2020-05-10 10:11:27 +02:00
# Stubbed
2019-08-25 06:46:40 +02:00
######################## Targets #############################
2020-05-07 20:21:22 +02:00
all : $( EXE )
2019-08-25 06:46:40 +02:00
2020-06-02 21:37:43 +02:00
# thank you apple very cool
i f e q ( $( HOST_OS ) , D a r w i n )
CP := gcp
e l s e
CP := cp
e n d i f
2020-06-09 17:15:49 +02:00
i f e q ( $( EXTERNAL_DATA ) , 1 )
2020-06-07 20:05:26 +02:00
BASEPACK_PATH := $( BUILD_DIR) /$( BASEDIR) /$( BASEPACK)
BASEPACK_LST := $( BUILD_DIR) /basepack.lst
2020-06-02 21:37:43 +02:00
2020-05-26 01:18:09 +02:00
# depend on resources as well
2020-06-07 20:05:26 +02:00
all : $( BASEPACK_PATH )
# phony target for building resources
res : $( BASEPACK_PATH )
# prepares the basepack.lst
$(BASEPACK_LST) : $( EXE )
@mkdir -p $( BUILD_DIR) /$( BASEDIR)
@echo -n > $( BASEPACK_LST)
@echo " $( BUILD_DIR) /sound/bank_sets sound/bank_sets " >> $( BASEPACK_LST)
@echo " $( BUILD_DIR) /sound/sequences.bin sound/sequences.bin " >> $( BASEPACK_LST)
@echo " $( BUILD_DIR) /sound/sound_data.ctl sound/sound_data.ctl " >> $( BASEPACK_LST)
@echo " $( BUILD_DIR) /sound/sound_data.tbl sound/sound_data.tbl " >> $( BASEPACK_LST)
2020-06-07 21:00:57 +02:00
@$( foreach f, $( wildcard $( SKYTILE_DIR) /*) , echo $( f) gfx/$( f:$( BUILD_DIR) /%= %) >> $( BASEPACK_LST) ; )
2020-06-07 20:05:26 +02:00
@find actors -name \* .png -exec echo "{} gfx/{}" >> $( BASEPACK_LST) \;
@find levels -name \* .png -exec echo "{} gfx/{}" >> $( BASEPACK_LST) \;
@find textures -name \* .png -exec echo "{} gfx/{}" >> $( BASEPACK_LST) \;
# prepares the resource ZIP with base data
$(BASEPACK_PATH) : $( BASEPACK_LST )
2020-06-08 05:06:40 +02:00
@$( PYTHON) $( TOOLS_DIR) /mkzip.py $( BASEPACK_LST) $( BASEPACK_PATH)
2020-06-02 16:57:23 +02:00
2020-05-25 03:21:36 +02:00
e n d i f
2019-08-25 06:46:40 +02:00
clean :
$( RM) -r $( BUILD_DIR_BASE)
2020-05-07 20:21:22 +02:00
cleantools :
$( MAKE) -s -C tools clean
2019-08-25 06:46:40 +02:00
distclean :
$( RM) -r $( BUILD_DIR_BASE)
./extract_assets.py --clean
test : $( ROM )
$( EMULATOR) $( EMU_FLAGS) $<
load : $( ROM )
$( LOADER) $( LOADER_FLAGS) $<
2020-06-09 17:15:49 +02:00
$(BUILD_DIR)/$(RPC_LIBS) :
@$( CP) -f $( RPC_LIBS) $( BUILD_DIR)
2020-09-13 06:16:10 +02:00
$(BUILD_DIR)/$(DISCORD_SDK_LIBS) :
@$( CP) -f $( DISCORD_SDK_LIBS) $( BUILD_DIR)
2019-08-25 06:46:40 +02:00
libultra : $( BUILD_DIR ) /libultra .a
2020-06-02 18:44:34 +02:00
$(BUILD_DIR)/asm/boot.o : $( IPL 3_RAW_FILES )
$(BUILD_DIR)/src/game/crash_screen.o : $( CRASH_TEXTURE_C_FILES )
2019-08-25 06:46:40 +02:00
2020-06-02 18:44:34 +02:00
$(BUILD_DIR)/lib/rsp.o : $( BUILD_DIR ) /rsp /rspboot .bin $( BUILD_DIR ) /rsp /fast 3d .bin $( BUILD_DIR ) /rsp /audio .bin
2020-05-10 10:11:27 +02:00
2020-05-08 03:24:42 +02:00
#Required so the compiler doesn't complain about this not existing.
$(BUILD_DIR)/src/game/camera.o : $( BUILD_DIR ) /include /text_strings .h
2019-08-25 06:46:40 +02:00
2019-10-05 21:08:05 +02:00
$(BUILD_DIR)/include/text_strings.h : include /text_strings .h .in
2019-08-25 06:46:40 +02:00
$( TEXTCONV) charmap.txt $< $@
2019-10-05 21:08:05 +02:00
$(BUILD_DIR)/include/text_menu_strings.h : include /text_menu_strings .h .in
$( TEXTCONV) charmap_menu.txt $< $@
2020-05-22 00:36:39 +02:00
$(BUILD_DIR)/include/text_options_strings.h : include /text_options_strings .h .in
$( TEXTCONV) charmap.txt $< $@
2019-08-25 06:46:40 +02:00
i f e q ( $( VERSION ) , e u )
2019-12-02 03:52:53 +01:00
TEXT_DIRS := text/de text/us text/fr
2020-02-03 06:51:26 +01:00
# EU encoded text inserted into individual segment 0x19 files,
# and course data also duplicated in leveldata.c
2019-12-02 03:52:53 +01:00
$(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
2020-02-03 06:51:26 +01:00
$(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-12-02 03:52:53 +01:00
2020-03-02 04:42:52 +01:00
e l s e
i f e q ( $( VERSION ) , s h )
TEXT_DIRS := text/jp
$(BUILD_DIR)/bin/segment2.o : $( BUILD_DIR ) /text /jp /define_text .inc .c
2019-08-25 06:46:40 +02:00
e l s e
2019-12-02 03:52:53 +01:00
TEXT_DIRS := text/$( VERSION)
2019-08-25 06:46:40 +02:00
# non-EU encoded text inserted into segment 0x02
2019-12-02 03:52:53 +01:00
$(BUILD_DIR)/bin/segment2.o : $( BUILD_DIR ) /text /$( VERSION ) /define_text .inc .c
2019-08-25 06:46:40 +02:00
e n d i f
2020-03-02 04:42:52 +01:00
e n d i f
2019-08-25 06:46:40 +02:00
2020-02-03 06:51:26 +01:00
$(BUILD_DIR)/text/%/define_courses.inc.c : text /define_courses .inc .c text /%/courses .h
2020-07-04 17:18:55 +02:00
$( CPP) $( VERSION_CFLAGS) $< -o - -I text/$* / | $( TEXTCONV) charmap.txt - $@
2020-02-03 06:51:26 +01:00
2019-12-02 03:52:53 +01:00
$(BUILD_DIR)/text/%/define_text.inc.c : text /define_text .inc .c text /%/courses .h text /%/dialogs .h
2020-07-04 17:18:55 +02:00
$( CPP) $( VERSION_CFLAGS) $< -o - -I text/$* / | $( TEXTCONV) charmap.txt - $@
2019-12-02 03:52:53 +01:00
2020-06-02 18:44:34 +02:00
RSP_DIRS := $( BUILD_DIR) /rsp
ALL_DIRS := $( BUILD_DIR) $( addprefix $( BUILD_DIR) /,$( SRC_DIRS) $( ASM_DIRS) $( GODDARD_SRC_DIRS) $( ULTRA_SRC_DIRS) $( ULTRA_ASM_DIRS) $( ULTRA_BIN_DIRS) $( BIN_DIRS) $( TEXTURE_DIRS) $( TEXT_DIRS) $( SOUND_SAMPLE_DIRS) $( addprefix levels/,$( LEVEL_DIRS) ) include) $( MIO0_DIR) $( addprefix $( MIO0_DIR) /,$( VERSION) ) $( SOUND_BIN_DIR) $( SOUND_BIN_DIR) /sequences/$( VERSION) $( RSP_DIRS)
2019-08-25 06:46:40 +02:00
# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $( ALL_DIRS)
2019-10-06 01:40:22 +02:00
$(BUILD_DIR)/include/text_strings.h : $( BUILD_DIR ) /include /text_menu_strings .h
2020-05-22 00:36:39 +02:00
$(BUILD_DIR)/include/text_strings.h : $( BUILD_DIR ) /include /text_options_strings .h
2020-05-10 10:11:27 +02:00
2020-05-08 13:41:12 +02:00
i f e q ( $( VERSION ) , e u )
$(BUILD_DIR)/src/menu/file_select.o : $( BUILD_DIR ) /include /text_strings .h $( BUILD_DIR ) /bin /eu /translation_en .o $( BUILD_DIR ) /bin /eu /translation_de .o $( BUILD_DIR ) /bin /eu /translation_fr .o
$(BUILD_DIR)/src/menu/star_select.o : $( BUILD_DIR ) /include /text_strings .h $( BUILD_DIR ) /bin /eu /translation_en .o $( BUILD_DIR ) /bin /eu /translation_de .o $( BUILD_DIR ) /bin /eu /translation_fr .o
$(BUILD_DIR)/src/game/ingame_menu.o : $( BUILD_DIR ) /include /text_strings .h $( BUILD_DIR ) /bin /eu /translation_en .o $( BUILD_DIR ) /bin /eu /translation_de .o $( BUILD_DIR ) /bin /eu /translation_fr .o
2020-05-15 20:38:35 +02:00
$(BUILD_DIR)/src/game/options_menu.o : $( BUILD_DIR ) /include /text_strings .h $( BUILD_DIR ) /bin /eu /translation_en .o $( BUILD_DIR ) /bin /eu /translation_de .o $( BUILD_DIR ) /bin /eu /translation_fr .o
2020-05-08 13:41:12 +02:00
O_FILES += $( BUILD_DIR) /bin/eu/translation_en.o $( BUILD_DIR) /bin/eu/translation_de.o $( BUILD_DIR) /bin/eu/translation_fr.o
2020-09-15 03:29:47 +02:00
#ifeq ($(DISCORDRPC),1)
# $(BUILD_DIR)/src/pc/discord/discordrpc.o: $(BUILD_DIR)/include/text_strings.h $(BUILD_DIR)/bin/eu/translation_en.o $(BUILD_DIR)/bin/eu/translation_de.o $(BUILD_DIR)/bin/eu/translation_fr.o
#endif
2020-05-08 13:41:12 +02:00
e l s e
2019-10-06 01:40:22 +02:00
$(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 06:46:40 +02:00
$(BUILD_DIR)/src/game/ingame_menu.o : $( BUILD_DIR ) /include /text_strings .h
2020-05-15 20:38:35 +02:00
$(BUILD_DIR)/src/game/options_menu.o : $( BUILD_DIR ) /include /text_strings .h
2020-09-15 03:29:47 +02:00
#ifeq ($(DISCORDRPC),1)
# $(BUILD_DIR)/src/pc/discord/discordrpc.o: $(BUILD_DIR)/include/text_strings.h
#endif
2020-05-08 13:41:12 +02:00
e n d i f
2019-08-25 06:46:40 +02:00
################################################################
# TEXTURE GENERATION #
################################################################
# RGBA32, RGBA16, IA16, IA8, IA4, IA1, I8, I4
2020-06-02 18:44:34 +02:00
2020-06-01 11:13:05 +02:00
i f e q ( $( EXTERNAL_DATA ) , 1 )
2020-06-02 18:44:34 +02:00
2020-05-25 03:21:36 +02:00
$(BUILD_DIR)/% : %.png
2020-05-26 01:59:38 +02:00
$( ZEROTERM) " $( patsubst %.png,%,$^) " > $@
2020-06-02 18:44:34 +02:00
2020-05-25 03:21:36 +02:00
e l s e
2020-06-02 18:44:34 +02:00
2019-08-25 06:46:40 +02:00
$(BUILD_DIR)/% : %.png
$( N64GRAPHICS) -i $@ -g $< -f $( lastword $( subst ., ,$@ ) )
2020-06-02 18:44:34 +02:00
2020-05-25 03:21:36 +02:00
e n d i f
2019-08-25 06:46:40 +02:00
2019-11-03 20:36:27 +01:00
$(BUILD_DIR)/%.inc.c : $( BUILD_DIR ) /% %.png
hexdump -v -e '1/1 "0x%X,"' $< > $@
echo >> $@
2020-06-01 11:13:05 +02:00
i f e q ( $( EXTERNAL_DATA ) , 0 )
2020-06-02 18:44:34 +02:00
2019-08-25 06:46:40 +02:00
# Color Index CI8
$(BUILD_DIR)/%.ci8 : %.ci 8.png
$( N64GRAPHICS_CI) -i $@ -g $< -f ci8
# Color Index CI4
$(BUILD_DIR)/%.ci4 : %.ci 4.png
$( N64GRAPHICS_CI) -i $@ -g $< -f ci4
2020-06-02 18:44:34 +02:00
2020-05-25 03:21:36 +02:00
e n d i f
2019-08-25 06:46:40 +02:00
################################################################
# compressed segment generation
2020-05-10 10:11:27 +02:00
# PC Area
2019-08-25 06:46:40 +02:00
$(BUILD_DIR)/%.table : %.aiff
$( AIFF_EXTRACT_CODEBOOK) $< >$@
$(BUILD_DIR)/%.aifc : $( BUILD_DIR ) /%.table %.aiff
$( VADPCM_ENC) -c $^ $@
2020-06-02 18:44:34 +02:00
$(BUILD_DIR)/rsp/%.bin $(BUILD_DIR)/rsp/%_data.bin : rsp /%.s
$( RSPASM) -sym $@ .sym -definelabel $( VERSION_DEF) 1 -definelabel $( GRUCODE_DEF) 1 -strequ CODE_FILE $( BUILD_DIR) /rsp/$* .bin -strequ DATA_FILE $( BUILD_DIR) /rsp/$* _data.bin $<
2019-12-02 03:52:53 +01:00
$(ENDIAN_BITWIDTH) : tools /determine -endian -bitwidth .c
$( CC) -c $( CFLAGS) -o $@ .dummy2 $< 2>$@ .dummy1; true
grep -o 'msgbegin --endian .* --bitwidth .* msgend' $@ .dummy1 > $@ .dummy2
head -n1 <$@ .dummy2 | cut -d' ' -f2-5 > $@
@rm $@ .dummy1
@rm $@ .dummy2
$(SOUND_BIN_DIR)/sound_data.ctl : sound /sound_banks / $( SOUND_BANK_FILES ) $( SOUND_SAMPLE_AIFCS ) $( ENDIAN_BITWIDTH )
$( PYTHON) tools/assemble_sound.py $( BUILD_DIR) /sound/samples/ sound/sound_banks/ $( SOUND_BIN_DIR) /sound_data.ctl $( SOUND_BIN_DIR) /sound_data.tbl $( VERSION_CFLAGS) $$ ( cat $( ENDIAN_BITWIDTH) )
2019-08-25 06:46:40 +02:00
$(SOUND_BIN_DIR)/sound_data.tbl : $( SOUND_BIN_DIR ) /sound_data .ctl
2019-12-02 03:52:53 +01:00
@true
2019-08-25 06:46:40 +02:00
2020-03-02 04:42:52 +01:00
i f e q ( $( VERSION ) , s h )
$(SOUND_BIN_DIR)/sequences.bin : $( SOUND_BANK_FILES ) sound /sequences .json sound /sequences / sound /sequences /jp / $( SOUND_SEQUENCE_FILES ) $( ENDIAN_BITWIDTH )
$( PYTHON) tools/assemble_sound.py --sequences $@ $( SOUND_BIN_DIR) /bank_sets sound/sound_banks/ sound/sequences.json $( SOUND_SEQUENCE_FILES) $( VERSION_CFLAGS) $$ ( cat $( ENDIAN_BITWIDTH) )
e l s e
2019-12-02 03:52:53 +01:00
$(SOUND_BIN_DIR)/sequences.bin : $( SOUND_BANK_FILES ) sound /sequences .json sound /sequences / sound /sequences /$( VERSION ) / $( SOUND_SEQUENCE_FILES ) $( ENDIAN_BITWIDTH )
$( PYTHON) tools/assemble_sound.py --sequences $@ $( SOUND_BIN_DIR) /bank_sets sound/sound_banks/ sound/sequences.json $( SOUND_SEQUENCE_FILES) $( VERSION_CFLAGS) $$ ( cat $( ENDIAN_BITWIDTH) )
2020-03-02 04:42:52 +01:00
e n d i f
2019-09-01 21:50:50 +02:00
$(SOUND_BIN_DIR)/bank_sets : $( SOUND_BIN_DIR ) /sequences .bin
2019-12-02 03:52:53 +01:00
@true
2019-08-25 06:46:40 +02:00
$(SOUND_BIN_DIR)/%.m64 : $( SOUND_BIN_DIR ) /%.o
$( OBJCOPY) -j .rodata $< -O binary $@
$(SOUND_BIN_DIR)/%.o : $( SOUND_BIN_DIR ) /%.s
$( AS) $( ASFLAGS) -o $@ $<
2020-06-01 11:13:05 +02:00
i f e q ( $( EXTERNAL_DATA ) , 1 )
2020-06-02 18:44:34 +02:00
$(SOUND_BIN_DIR)/%.inc.c : $( SOUND_BIN_DIR ) /%
2020-06-20 17:05:45 +02:00
$( ZEROTERM) " $( patsubst $( BUILD_DIR) /%,%,$^) " | hexdump -v -e '1/1 "0x%X,"' > $@
2020-06-01 11:13:05 +02:00
e l s e
2020-05-10 10:11:27 +02:00
2020-06-02 18:44:34 +02:00
$(SOUND_BIN_DIR)/%.inc.c : $( SOUND_BIN_DIR ) /%
hexdump -v -e '1/1 "0x%X,"' $< > $@
echo >> $@
2019-08-25 06:46:40 +02:00
2020-06-01 11:13:05 +02:00
e n d i f
2020-06-02 18:44:34 +02:00
$(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
2019-12-02 03:52:53 +01:00
$(BUILD_DIR)/levels/scripts.o : $( BUILD_DIR ) /include /level_headers .h
$(BUILD_DIR)/include/level_headers.h : levels /level_headers .h .in
$( CPP) -I . levels/level_headers.h.in | $( PYTHON) tools/output_level_headers.py > $( BUILD_DIR) /include/level_headers.h
2019-11-03 20:36:27 +01:00
$(BUILD_DIR)/assets/mario_anim_data.c : $( wildcard assets /anims /*.inc .c )
$( PYTHON) tools/mario_anims_converter.py > $@
$(BUILD_DIR)/assets/demo_data.c : assets /demo_data .json $( wildcard assets /demos /*.bin )
$( PYTHON) tools/demo_data_converter.py assets/demo_data.json $( VERSION_CFLAGS) > $@
2019-08-25 06:46:40 +02:00
# Source code
2020-02-03 06:51:26 +01:00
$(BUILD_DIR)/levels/%/leveldata.o : OPT_FLAGS := -g
$(BUILD_DIR)/actors/%.o : OPT_FLAGS := -g
$(BUILD_DIR)/bin/%.o : OPT_FLAGS := -g
2019-08-25 06:46:40 +02:00
$(BUILD_DIR)/src/goddard/%.o : OPT_FLAGS := -g
$(BUILD_DIR)/src/goddard/%.o : MIPSISET := -mips 1
$(BUILD_DIR)/src/audio/%.o : OPT_FLAGS := -O 2 -Wo , -loopunroll , 0
$(BUILD_DIR)/src/audio/load.o : OPT_FLAGS := -O 2 -framepointer -Wo , -loopunroll , 0
$(BUILD_DIR)/lib/src/%.o : OPT_FLAGS :=
$(BUILD_DIR)/lib/src/math/ll%.o : MIPSISET := -mips 3 -32
$(BUILD_DIR)/lib/src/math/%.o : OPT_FLAGS := -O 2
$(BUILD_DIR)/lib/src/math/ll%.o : OPT_FLAGS :=
$(BUILD_DIR)/lib/src/ldiv.o : OPT_FLAGS := -O 2
$(BUILD_DIR)/lib/src/string.o : OPT_FLAGS := -O 2
$(BUILD_DIR)/lib/src/gu%.o : OPT_FLAGS := -O 3
$(BUILD_DIR)/lib/src/al%.o : OPT_FLAGS := -O 3
i f e q ( $( VERSION ) , e u )
$(BUILD_DIR)/lib/src/_Litob.o : OPT_FLAGS := -O 3
$(BUILD_DIR)/lib/src/_Ldtob.o : OPT_FLAGS := -O 3
$(BUILD_DIR)/lib/src/_Printf.o : OPT_FLAGS := -O 3
2020-02-03 06:51:26 +01:00
$(BUILD_DIR)/lib/src/sprintf.o : OPT_FLAGS := -O 3
# enable loop unrolling except for external.c (external.c might also have used
# unrolling, but it makes one loop harder to match)
$(BUILD_DIR)/src/audio/%.o : OPT_FLAGS := -O 2
$(BUILD_DIR)/src/audio/load.o : OPT_FLAGS := -O 2
$(BUILD_DIR)/src/audio/external.o : OPT_FLAGS := -O 2 -Wo , -loopunroll , 0
2020-03-02 04:42:52 +01:00
e l s e
# The source-to-source optimizer copt is enabled for audio. This makes it use
# acpp, which needs -Wp,-+ to handle C++-style comments.
$(BUILD_DIR)/src/audio/effects.o : OPT_FLAGS := -O 2 -Wo , -loopunroll , 0 -sopt , -inline =sequence_channel_process_sound , -scalaroptimize =1 -Wp , -+
2020-04-03 20:57:26 +02:00
$(BUILD_DIR)/src/audio/synthesis.o : OPT_FLAGS := -O 2 -sopt , -scalaroptimize =1 -Wp , -+
2020-06-02 18:44:34 +02:00
#$(BUILD_DIR)/src/audio/seqplayer.o: OPT_FLAGS := -O2 -sopt,-inline_manual,-scalaroptimize=1 -Wp,-+ #-Wo,-v,-bb,-l,seqplayer_list.txt
2020-03-02 04:42:52 +01:00
# Add a target for build/eu/src/audio/*.copt to make it easier to see debug
$(BUILD_DIR)/src/audio/%.acpp : src /audio /%.c
2020-06-02 18:44:34 +02:00
$( QEMU_IRIX) -silent -L $( IRIX_ROOT) $( IRIX_ROOT) /usr/lib/acpp $( TARGET_CFLAGS) $( INCLUDE_CFLAGS) $( VERSION_CFLAGS) $( MATCH_CFLAGS) $( GRUCODE_CFLAGS) -D__sgi -+ $< > $@
$(BUILD_DIR)/src/audio/seqplayer.copt : $( BUILD_DIR ) /src /audio /seqplayer .acpp
$( QEMU_IRIX) -silent -L $( IRIX_ROOT) $( IRIX_ROOT) /usr/lib/copt -signed -I= $< -CMP= $@ -cp= i -scalaroptimize= 1 -inline_manual
2020-03-02 04:42:52 +01:00
$(BUILD_DIR)/src/audio/%.copt : $( BUILD_DIR ) /src /audio /%.acpp
$( QEMU_IRIX) -silent -L $( IRIX_ROOT) $( IRIX_ROOT) /usr/lib/copt -signed -I= $< -CMP= $@ -cp= i -scalaroptimize= 1
2020-06-02 18:44:34 +02:00
2019-08-25 06:46:40 +02:00
e n d i f
2019-12-02 03:52:53 +01:00
# Rebuild files with 'GLOBAL_ASM' if the NON_MATCHING flag changes.
$(GLOBAL_ASM_O_FILES) : $( GLOBAL_ASM_DEP ) .$( NON_MATCHING )
$(GLOBAL_ASM_DEP).$(NON_MATCHING) :
@rm -f $( GLOBAL_ASM_DEP) .*
2019-08-25 06:46:40 +02:00
touch $@
2020-05-07 20:21:22 +02:00
$(BUILD_DIR)/%.o : %.cpp
@$( CXX) -fsyntax-only $( CFLAGS) -MMD -MP -MT $@ -MF $( BUILD_DIR) /$* .d $<
$( CXX) -c $( CFLAGS) -o $@ $<
2019-08-25 06:46:40 +02:00
$(BUILD_DIR)/%.o : %.c
2020-06-02 18:44:34 +02:00
@$( CC_CHECK) $( CC_CHECK_CFLAGS) -MMD -MP -MT $@ -MF $( BUILD_DIR) /$* .d $<
2019-08-25 06:46:40 +02:00
$( CC) -c $( CFLAGS) -o $@ $<
2019-11-03 20:36:27 +01:00
$(BUILD_DIR)/%.o : $( BUILD_DIR ) /%.c
2020-06-02 18:44:34 +02:00
@$( CC_CHECK) $( CC_CHECK_CFLAGS) -MMD -MP -MT $@ -MF $( BUILD_DIR) /$* .d $<
2019-11-03 20:36:27 +01:00
$( CC) -c $( CFLAGS) -o $@ $<
$(BUILD_DIR)/%.o : %.s
2019-08-25 06:46:40 +02:00
$( AS) $( ASFLAGS) -MD $( BUILD_DIR) /$* .d -o $@ $<
2020-09-13 06:16:10 +02:00
$(EXE) : $( O_FILES ) $( MIO 0_FILES :.mio 0=.o ) $( SOUND_OBJ_FILES ) $( ULTRA_O_FILES ) $( GODDARD_O_FILES ) $( BUILD_DIR ) /$( RPC_LIBS ) $( BUILD_DIR ) /$( DISCORD_SDK_LIBS )
2020-06-09 17:15:49 +02:00
$( LD) -L $( BUILD_DIR) -o $@ $( O_FILES) $( SOUND_OBJ_FILES) $( ULTRA_O_FILES) $( GODDARD_O_FILES) $( LDFLAGS)
2019-08-25 06:46:40 +02:00
2020-05-25 03:21:36 +02:00
.PHONY : all clean distclean default diff test load libultra res
2019-12-02 03:52:53 +01:00
.PRECIOUS : $( BUILD_DIR ) /bin /%.elf $( SOUND_BIN_DIR ) /%.ctl $( SOUND_BIN_DIR ) /%.tbl $( SOUND_SAMPLE_TABLES ) $( SOUND_BIN_DIR ) /%.s $( BUILD_DIR ) /%
2019-08-25 06:46:40 +02:00
.DELETE_ON_ERROR :
# Remove built-in rules, to improve performance
MAKEFLAGS += --no-builtin-rules
- i n c l u d e $( DEP_FILES )
print-% : ; $( info $ * is a $ ( flavor $ *) variable set to [$ ( $ *) ]) @true