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
# If MAPGENFLAG set to 1, tells LDFLAGS to generate a mapfile, which makes linking take several minutes.
MAPGENFLAG ?= 1
i f e q ( $( VERBOSE ) , 0 )
QUIET := @
e n d i f
#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
NAME := mp1
VERSION ?= 0
# Overkill epilogue fixup strategy. Set to 1 if necessary.
EPILOGUE_PROCESS := 0
BUILD_DIR := build/$( NAME) .$( VERSION)
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
EPILOGUE_DIR := epilogue/$( NAME) .$( VERSION)
e n d i f
# 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
i f e q ( $( MAPGENFLAG ) , 1 )
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
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
i n c l u d e e _ f i l e s . m k
e n d i f
2022-04-12 04:53:51 +00:00
O_FILES := $( INIT_O_FILES) $( EXTAB_O_FILES) $( EXTABINDEX_O_FILES) $( METROTRK_FILES) \
2022-04-16 04:01:44 +00:00
$( METROIDPRIME) $( WORLDFORMAT) $( WEAPONS) $( METARENDER) $( GUISYS) $( COLLISION) \
2022-04-18 04:35:01 +00:00
$( KYOTO) $( RODATA_O_FILES) $( SDATA_O_FILES) $( SBSS_O_FILES) $( SDATA2_O_FILES) $( 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-04-12 04:53:51 +00:00
$( OS_FILES) $( PAD_FILES) $( VI_FILES) $( MSL_PPCEABI_BARE_H) $( MUSYX_FILES) \
2022-04-02 09:50:35 +00:00
$( DTK_FILES) $( CARD_FILES) $( SI_FILES) $( EXI_FILES) $( THP_FILES) \
2022-04-12 05:19:33 +00:00
$( GBA_FILES) $( CTORS_O_FILES) $( DTORS_O_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
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
E_FILES := $( EPILOGUE_UNSCHEDULED)
e n d i f
#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
2022-04-13 03:55:49 +00:00
MWCC_VERSION := 2.7
2022-03-23 21:22:48 +00:00
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
MWCC_EPI_VERSION := 1.2.5
MWCC_EPI_EXE := mwcceppc.exe
e n d i f
MWLD_VERSION := 2.6
# 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 )
WINE :=
AS := $( DEVKITPPC) /bin/powerpc-eabi-as.exe
CPP := $( DEVKITPPC) /bin/powerpc-eabi-cpp.exe -P
e l s e
WINE ?= wine
2022-04-08 21:26:47 +00:00
DEVKITPPC ?= /opt/devkitpro/devkitPPC
2022-04-13 03:55:49 +00:00
DEPENDS := $( DEPENDS:.d= .d.unix)
2022-03-23 21:22:48 +00:00
AS := $( DEVKITPPC) /bin/powerpc-eabi-as
CPP := $( DEVKITPPC) /bin/powerpc-eabi-cpp -P
e n d i f
CC = $( WINE) tools/mwcc_compiler/$( MWCC_VERSION) /mwcceppc.exe
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
CC_EPI = $( WINE) tools/mwcc_compiler/$( MWCC_EPI_VERSION) /$( MWCC_EPI_EXE)
e n d i f
LD := $( WINE) tools/mwcc_compiler/$( MWLD_VERSION) /mwldeppc.exe
ELF2DOL := tools/elf2dol
SHA1SUM := sha1sum
PYTHON := python3
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-04-13 03:55:49 +00:00
INCLUDES := -i include/
2022-03-23 21:22:48 +00:00
ASM_INCLUDES := -I include/
ASFLAGS := -mgekko $( ASM_INCLUDES) --defsym version = $( VERSION)
i f e q ( $( VERBOSE ) , 1 )
# this set of LDFLAGS outputs warnings.
LDFLAGS := $( MAPGEN) -fp hard -nodefaults
e n d i f
i f e q ( $( VERBOSE ) , 0 )
# this set of LDFLAGS generates no warnings.
LDFLAGS := $( MAPGEN) -fp hard -nodefaults -w off
e n d i f
2022-04-15 19:24:52 +00:00
CFLAGS_1.2 = -proc gekko -nodefaults -Cpp_exceptions off -RTTI off -fp hard -fp_contract on -str reuse,pool,readonly -rostr -O4,p -maxerrors 1 -use_lmw_stmw on -enum int -inline auto -MMD $( INCLUDES)
2022-04-13 03:55:49 +00:00
CFLAGS = $( CFLAGS_1.2) -gccinc
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
$(BUILD_DIR)/src/os/__start.o : MWCC_VERSION := 1.2.5
2022-04-13 03:55:49 +00:00
$(BUILD_DIR)/src/os/__start.o : CFLAGS := $( CFLAGS_ 1.2)
2022-04-04 10:14:22 +00:00
$(BUILD_DIR)/src/Dolphin/PPCArch.o : MWCC_VERSION := 1.2.5
2022-04-13 03:55:49 +00:00
$(BUILD_DIR)/src/Dolphin/PPCArch.o : CFLAGS := $( CFLAGS_ 1.2)
2022-03-23 21:22:48 +00:00
#-------------------------------------------------------------------------------
# Recipes
#-------------------------------------------------------------------------------
### Default target ###
default : all
all : $( DOL )
ALL_DIRS := $( sort $( dir $( O_FILES) ) )
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
EPI_DIRS := $( sort $( dir $( E_FILES) ) )
e n d i f
# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $( ALL_DIRS)
# ifeq ($(EPILOGUE_PROCESS),1)
# Make sure profile directory exists before compiling anything
# DUMMY != mkdir -p $(EPI_DIRS)
# endif
.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
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
@echo Linking ELF $@
$(ELF) : $( O_FILES ) $( E_FILES ) $( LDSCRIPT )
$( QUIET) @echo $( O_FILES) > build/o_files
$( QUIET) $( LD) $( LDFLAGS) -o $@ -lcf $( LDSCRIPT) @build/o_files
e l s e
$(ELF) : $( O_FILES ) $( LDSCRIPT )
@echo Linking ELF $@
$( QUIET) @echo $( O_FILES) > build/o_files
$( QUIET) $( LD) $( LDFLAGS) -o $@ -lcf $( LDSCRIPT) @build/o_files
e n d i f
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
@echo Assembling $<
$( QUIET) $( AS) $( ASFLAGS) -o $@ $<
$(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
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
$(EPILOGUE_DIR)/%.o : %.c $( BUILD_DIR ) /%.o
@echo Frank is fixing $<
$( QUIET) $( PYTHON) $( FRANK) $( word 2,$^) $( word 2,$^)
$(EPILOGUE_DIR)/%.o : %.cp $( BUILD_DIR ) /%.o
@echo Frank is fixing $<
$( QUIET) $( PYTHON) $( FRANK) $( word 2,$^) $( word 2,$^)
$(EPILOGUE_DIR)/%.o : %.cpp $( BUILD_DIR ) /%.o
@echo Frank is fixing $<
$( QUIET) $( PYTHON) $( FRANK) $( word 2,$^) $( word 2,$^)
e n d i f
# If we need Frank, add the following after the @echo
# $(QUIET) $(CC_EPI) $(CFLAGS) -c -o $@ $<
### Debug Print ###
print-% : ; $( info $ * is a $ ( flavor $ *) variable set to [$ ( $ *) ]) @true