2022-03-23 21:22:48 +00:00
i f n e q ( $( findstring MINGW ,$ ( shell uname ) ) , )
WINDOWS := 1
e n d i f
i f n e q ( $( findstring MSYS ,$ ( shell uname ) ) , )
WINDOWS := 1
e n d i f
# If 0, tells the console to chill out. (Quiets the make process.)
2022-03-24 00:39:27 +00:00
VERBOSE ?= 0
2022-03-23 21:22:48 +00:00
2022-07-19 00:06:07 +00:00
# If GENERATE_MAP set to 1, tells LDFLAGS to generate a mapfile, which makes linking take several minutes.
2022-08-13 01:29:02 +00:00
GENERATE_MAP ?= 0
2022-03-23 21:22:48 +00:00
2022-09-01 00:22:20 +00:00
# Enable non-matching code & various fixes
NONMATCHING ?= 0
2022-03-23 21:22:48 +00:00
i f e q ( $( VERBOSE ) , 0 )
QUIET := @
e n d i f
#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
NAME := mp1
VERSION ?= 0
2022-08-23 03:54:30 +00:00
VERSION_NUM := $( VERSION)
i f e q ( $( VERSION ) , k o r )
VERSION_NUM := 2
e n d i f
2022-03-23 21:22:48 +00:00
BUILD_DIR := build/$( NAME) .$( VERSION)
# Inputs
S_FILES := $( wildcard asm/*.s)
C_FILES := $( wildcard src/*.c)
CPP_FILES := $( wildcard src/*.cpp)
CPP_FILES += $( wildcard src/*.cp)
LDSCRIPT := $( BUILD_DIR) /ldscript.lcf
# Outputs
DOL := $( BUILD_DIR) /main.dol
ELF := $( DOL:.dol= .elf)
MAP := $( BUILD_DIR) /MetroidPrime.MAP
2022-07-19 00:06:07 +00:00
i f e q ( $( GENERATE_MAP ) , 1 )
2022-03-23 21:22:48 +00:00
MAPGEN := -map $( MAP)
e n d i f
i n c l u d e o b j _ f i l e s . m k
2022-09-08 05:01:54 +00:00
O_FILES := $( METROTRK_FILES) \
2022-04-16 04:01:44 +00:00
$( METROIDPRIME) $( WORLDFORMAT) $( WEAPONS) $( METARENDER) $( GUISYS) $( COLLISION) \
2022-08-26 03:46:24 +00:00
$( KYOTO_1) $( ZLIB_FILES) $( KYOTO_2) $( AI_FILES) \
2022-04-12 05:19:33 +00:00
$( AR_FILES) $( BASE_FILES) $( DB_FILES) $( DSP_FILES) $( DVD_FILES) $( GX_FILES) $( MTX_FILES) \
2022-08-26 03:46:24 +00:00
$( OS_FILES) $( PAD_FILES) $( VI_FILES) $( MSL_PPCEABI_BARE_H) $( MSL_COMMON_MATH) $( MUSYX_FILES) \
2022-04-02 09:50:35 +00:00
$( DTK_FILES) $( CARD_FILES) $( SI_FILES) $( EXI_FILES) $( THP_FILES) \
2022-08-11 02:27:22 +00:00
$( GBA_FILES)
2022-04-13 03:55:49 +00:00
DEPENDS := $( O_FILES:.o= .d)
# If a specific .o file is passed as a target, also process its deps
DEPENDS += $( MAKECMDGOALS:.o= .d)
2022-03-23 21:22:48 +00:00
#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
2022-08-09 23:03:51 +00:00
MWCC_VERSION := 1.3.2
2022-08-11 02:27:22 +00:00
MWLD_VERSION := 1.3.2
2022-03-23 21:22:48 +00:00
# Programs
2022-04-08 21:26:47 +00:00
export WINEDEBUG ?= -all
2022-03-23 21:22:48 +00:00
i f e q ( $( WINDOWS ) , 1 )
2022-04-27 19:30:54 +00:00
WINE :=
2022-03-23 21:22:48 +00:00
AS := $( DEVKITPPC) /bin/powerpc-eabi-as.exe
CPP := $( DEVKITPPC) /bin/powerpc-eabi-cpp.exe -P
2022-07-18 23:38:32 +00:00
PYTHON := py
2022-09-12 01:07:45 +00:00
SHA1SUM := sha1sum
2022-03-23 21:22:48 +00:00
e l s e
2022-07-14 05:36:41 +00:00
WIBO := $( shell command -v wibo 2> /dev/null)
ifdef WIBO
WINE ?= wibo
else
WINE ?= wine
endif
2022-04-08 21:26:47 +00:00
DEVKITPPC ?= /opt/devkitpro/devkitPPC
2022-04-27 19:30:54 +00:00
DEPENDS := $( DEPENDS:.d= .d.unix)
AS := $( DEVKITPPC) /bin/powerpc-eabi-as
CPP := $( DEVKITPPC) /bin/powerpc-eabi-cpp -P
2022-07-18 23:38:32 +00:00
PYTHON := python3
2022-09-12 01:07:45 +00:00
SHA1SUM := shasum -a 1
2022-03-23 21:22:48 +00:00
e n d i f
2022-04-27 19:30:54 +00:00
CC = $( WINE) tools/mwcc_compiler/$( MWCC_VERSION) /mwcceppc.exe
2022-03-23 21:22:48 +00:00
LD := $( WINE) tools/mwcc_compiler/$( MWLD_VERSION) /mwldeppc.exe
ELF2DOL := tools/elf2dol
2022-04-13 03:55:49 +00:00
TRANSFORM_DEP := tools/transform-dep.py
2022-03-23 21:22:48 +00:00
FRANK := tools/franklite.py
# Options
2022-08-26 03:46:24 +00:00
INCLUDES := -i include/ -i libc/
2022-03-23 21:22:48 +00:00
ASM_INCLUDES := -I include/
2022-08-26 03:46:24 +00:00
# DotKuribo/llvm-project
CLANG_CC ?= clang-kuribo
CLANG_CFLAGS := --target= ppc32-kuribo -mcpu= 750 -nostdlib -fno-exceptions -fno-rtti -O3 -Wall -Wno-trigraphs -Wno-inline-new-delete -Wno-unused-private-field -fpermissive -std= gnu++11 $( ASM_INCLUDES)
2022-08-23 03:54:30 +00:00
ASFLAGS := -mgekko $( ASM_INCLUDES) --defsym version = $( VERSION_NUM)
2022-03-23 21:22:48 +00:00
i f e q ( $( VERBOSE ) , 1 )
# this set of LDFLAGS outputs warnings.
2022-07-18 13:51:34 +00:00
LDFLAGS := $( MAPGEN) -fp fmadd -nodefaults
2022-03-23 21:22:48 +00:00
e n d i f
i f e q ( $( VERBOSE ) , 0 )
# this set of LDFLAGS generates no warnings.
2022-07-18 13:51:34 +00:00
LDFLAGS := $( MAPGEN) -fp fmadd -nodefaults -w off
2022-03-23 21:22:48 +00:00
e n d i f
2022-09-01 00:22:20 +00:00
DEFINES = -DPRIME1 -DVERSION= $( VERSION_NUM) -DNONMATCHING= $( NONMATCHING)
2022-08-30 04:05:16 +00:00
CFLAGS_BASE = -proc gekko -nodefaults -Cpp_exceptions off -RTTI off -fp hard -fp_contract on -O4,p -maxerrors 1 -enum int -inline auto -str reuse -nosyspath -MMD $( DEFINES) $( INCLUDES)
2022-08-26 03:46:24 +00:00
CFLAGS = $( CFLAGS_BASE) -use_lmw_stmw on -str reuse,pool,readonly -gccinc -inline deferred,noauto -common on
CFLAGS_RUNTIME = $( CFLAGS_BASE) -use_lmw_stmw on -str reuse,pool,readonly -gccinc -inline deferred,auto
CFLAGS_MUSYX = $( CFLAGS_BASE) -str reuse,pool,readonly
2022-03-23 21:22:48 +00:00
i f e q ( $( VERBOSE ) , 0 )
# this set of ASFLAGS generates no warnings.
ASFLAGS += -W
e n d i f
2022-08-26 03:46:24 +00:00
$(METROTRK_FILES) : MWCC_VERSION := 1.2.5
$(METROTRK_FILES) : CFLAGS := $( CFLAGS_BASE )
$(BASE_FILES) : MWCC_VERSION := 1.2.5
$(BASE_FILES) : CFLAGS := $( CFLAGS_BASE )
2022-09-16 03:24:27 +00:00
$(AI_FILES) : MWCC_VERSION := 1.2.5e
2022-08-26 03:46:24 +00:00
$(AI_FILES) : CFLAGS := $( CFLAGS_BASE )
$(OS_FILES) : MWCC_VERSION := 1.2.5
$(OS_FILES) : CFLAGS := $( CFLAGS_BASE )
2022-09-10 20:32:26 +00:00
$(CARD_FILES) : MWCC_VERSION := 1.2.5
$(CARD_FILES) : CFLAGS := $( CFLAGS_BASE )
2022-09-16 02:22:52 +00:00
$(DVD_FILES) : MWCC_VERSION := 1.2.5
2022-09-16 01:17:42 +00:00
$(DVD_FILES) : CFLAGS := $( CFLAGS_BASE )
2022-09-16 02:22:52 +00:00
$(DSP_FILES) : MWCC_VERSION := 1.2.5
2022-08-26 03:46:24 +00:00
$(DSP_FILES) : CFLAGS := $( CFLAGS_BASE )
$(MUSYX_FILES) : CFLAGS := $( CFLAGS_MUSYX )
$(ZLIB_FILES) : CFLAGS := $( CFLAGS_RUNTIME )
$(MSL_PPCEABI_BARE_H) : CFLAGS := $( CFLAGS_RUNTIME )
$(MSL_COMMON_MATH) : CFLAGS := $( CFLAGS_RUNTIME )
2022-07-28 14:00:20 +00:00
2022-03-23 21:22:48 +00:00
#-------------------------------------------------------------------------------
# Recipes
#-------------------------------------------------------------------------------
### Default target ###
default : all
all : $( DOL )
ALL_DIRS := $( sort $( dir $( O_FILES) ) )
# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $( ALL_DIRS)
.PHONY : tools
$(LDSCRIPT) : ldscript .lcf
$( QUIET) $( CPP) -MMD -MP -MT $@ -MF $@ .d -I include/ -I . -DBUILD_DIR= $( BUILD_DIR) -o $@ $<
$(DOL) : $( ELF ) | tools
$( QUIET) $( ELF2DOL) $< $@
$( QUIET) $( SHA1SUM) -c sha1/$( NAME) .$( VERSION) .sha1
i f n e q ( $( findstring -map ,$ ( LDFLAGS ) ) , )
2022-04-13 03:55:49 +00:00
$( QUIET) $( PYTHON) tools/calcprogress.py $( DOL) $( MAP)
2022-03-23 21:22:48 +00:00
e n d i f
clean :
2022-04-13 03:55:49 +00:00
$( RM) $( O_FILES) $( DEPENDS)
2022-03-23 21:22:48 +00:00
$( MAKE) -C tools clean
tools :
$( MAKE) -C tools
# ELF creation makefile instructions
$(ELF) : $( O_FILES ) $( LDSCRIPT )
@echo Linking ELF $@
$( QUIET) @echo $( O_FILES) > build/o_files
$( QUIET) $( LD) $( LDFLAGS) -o $@ -lcf $( LDSCRIPT) @build/o_files
2022-04-13 03:55:49 +00:00
%.d.unix : %.d $( TRANSFORM_DEP )
@echo Processing $<
$( QUIET) $( PYTHON) $( TRANSFORM_DEP) $< $@
- i n c l u d e $( DEPENDS )
2022-03-23 21:22:48 +00:00
$(BUILD_DIR)/%.o : %.s
2022-08-26 03:46:24 +00:00
@echo "Assembling" $<
2022-03-23 21:22:48 +00:00
$( QUIET) $( AS) $( ASFLAGS) -o $@ $<
2022-08-26 03:46:24 +00:00
$(BUILD_DIR)/%.clang.o : %.cpp
@echo "Clang " $<
$( QUIET) $( CLANG_CC) $( CLANG_CFLAGS) -c -o $@ $<
2022-04-27 19:30:54 +00:00
$(BUILD_DIR)/%.ep.o : $( BUILD_DIR ) /%.o
@echo Frank is fixing $<
$( QUIET) $( PYTHON) $( FRANK) $< $@
2022-03-23 21:22:48 +00:00
$(BUILD_DIR)/%.o : %.c
@echo "Compiling " $<
2022-04-13 03:55:49 +00:00
$( QUIET) $( CC) $( CFLAGS) -c -o $( dir $@ ) $<
2022-03-23 21:22:48 +00:00
$(BUILD_DIR)/%.o : %.cp
@echo "Compiling " $<
2022-04-13 03:55:49 +00:00
$( QUIET) $( CC) $( CFLAGS) -c -o $( dir $@ ) $<
2022-03-23 21:22:48 +00:00
$(BUILD_DIR)/%.o : %.cpp
@echo "Compiling " $<
2022-04-13 03:55:49 +00:00
$( QUIET) $( CC) $( CFLAGS) -c -o $( dir $@ ) $<
2022-03-23 21:22:48 +00:00
### Debug Print ###
print-% : ; $( info $ * is a $ ( flavor $ *) variable set to [$ ( $ *) ]) @true