2021-09-27 04:00:46 +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
2021-12-10 18:29:26 +00:00
# If 0, tells the console to chill out. (Quiets the make process.)
VERBOSE ?= 0
# If MAPGENFLAG set to 1, tells LDFLAGS to generate a mapfile, which makes linking take several minutes.
MAPGENFLAG ?= 0
i f e q ( $( VERBOSE ) , 0 )
QUIET := @
e n d i f
2021-09-27 04:00:46 +00:00
#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
NAME := pikmin2
2022-01-31 03:39:28 +00:00
VERSION ?= usa
2021-09-27 04:00:46 +00:00
#VERSION := usa.demo
2022-01-31 03:39:28 +00:00
i f e q ( $( VERSION ) , u s a )
VERNUM = 2
e l s e i f e q ( $( VERSION ) , u s a . d e m o )
VERNUM = 1
e l s e
VERNUM = 0
e n d i f
2022-01-13 23:08:37 +00:00
# Overkill epilogue fixup strategy. Set to 1 if necessary.
2022-01-13 23:38:39 +00:00
EPILOGUE_PROCESS := 1
2022-01-13 23:08:37 +00:00
2022-04-08 22:06:23 +00:00
# Update the README after build
UPDATE_README ?= 1
2021-09-27 04:00:46 +00:00
BUILD_DIR := build/$( NAME) .$( VERSION)
2022-01-13 23:08:37 +00:00
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
EPILOGUE_DIR := epilogue/$( NAME) .$( VERSION)
e n d i f
2021-09-27 04:00:46 +00:00
# Inputs
S_FILES := $( wildcard asm/*.s)
C_FILES := $( wildcard src/*.c)
2021-09-30 00:20:15 +00:00
CPP_FILES := $( wildcard src/*.cpp)
2021-12-01 01:53:08 +00:00
CPP_FILES += $( wildcard src/*.cp)
2021-09-27 04:00:46 +00:00
LDSCRIPT := $( BUILD_DIR) /ldscript.lcf
2021-10-22 23:07:01 +00:00
READMEGEN := tools/UpdateReadme.exe
2021-09-27 04:00:46 +00:00
# Outputs
DOL := $( BUILD_DIR) /main.dol
ELF := $( DOL:.dol= .elf)
2021-10-21 18:06:39 +00:00
MAP := $( BUILD_DIR) /pikmin2UP.MAP
2021-09-27 04:00:46 +00:00
2021-12-10 18:29:26 +00:00
i f e q ( $( MAPGENFLAG ) , 1 )
MAPGEN := -map $( MAP)
e n d i f
2021-09-27 04:00:46 +00:00
i n c l u d e o b j _ f i l e s . m k
2022-01-13 23:08:37 +00:00
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
2021-09-27 04:00:46 +00:00
2021-10-22 21:07:38 +00:00
O_FILES := $( GROUP_0_FILES) $( JSYSTEM) $( DOLPHIN) \
$( YAMASHITA) $( KANDO) $( NISHIMURA) $( OGAWA) $( HIKINO) $( MORIMURA) $( EBISAWA) $( KONO) \
2022-08-03 21:41:17 +00:00
$( BOOTUP) $( COMMON) $( GC) $( UTILITY)
2022-01-13 23:08:37 +00:00
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
2022-01-30 18:04:20 +00:00
E_FILES := $( EPILOGUE_UNSCHEDULED)
2022-01-13 23:08:37 +00:00
e n d i f
2021-09-27 04:00:46 +00:00
#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
2021-10-01 22:55:22 +00:00
MWCC_VERSION := 2.6
2022-01-13 23:08:37 +00:00
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
2022-01-13 23:38:39 +00:00
MWCC_EPI_VERSION := 1.2.5
2022-01-13 23:08:37 +00:00
MWCC_EPI_EXE := mwcceppc.exe
e n d i f
2021-11-07 02:33:59 +00:00
MWLD_VERSION := 2.6
2021-09-27 04:00:46 +00:00
# Programs
i f e q ( $( WINDOWS ) , 1 )
WINE :=
2021-09-30 00:20:15 +00:00
AS := $( DEVKITPPC) /bin/powerpc-eabi-as.exe
CPP := $( DEVKITPPC) /bin/powerpc-eabi-cpp.exe -P
2022-06-13 22:14:48 +00:00
PYTHON := python
2021-09-27 04:00:46 +00:00
e l s e
2021-11-07 02:33:59 +00:00
WINE ?= wine
2022-04-08 23:11:12 +00:00
# Disable wine debug output for cleanliness
export WINEDEBUG ?= -all
# Default devkitPPC path
DEVKITPPC ?= /opt/devkitpro/devkitPPC
2021-09-30 00:20:15 +00:00
AS := $( DEVKITPPC) /bin/powerpc-eabi-as
CPP := $( DEVKITPPC) /bin/powerpc-eabi-cpp -P
2022-06-13 22:14:48 +00:00
PYTHON := python3
2021-09-27 04:00:46 +00:00
e n d i f
2021-10-03 20:01:08 +00:00
CC = $( WINE) tools/mwcc_compiler/$( MWCC_VERSION) /mwcceppc.exe
2022-01-13 23:08:37 +00:00
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
CC_EPI = $( WINE) tools/mwcc_compiler/$( MWCC_EPI_VERSION) /$( MWCC_EPI_EXE)
e n d i f
2021-09-27 04:00:46 +00:00
LD := $( WINE) tools/mwcc_compiler/$( MWLD_VERSION) /mwldeppc.exe
ELF2DOL := tools/elf2dol
SHA1SUM := sha1sum
2022-01-13 23:38:39 +00:00
FRANK := tools/franklite.py
2022-01-13 23:08:37 +00:00
2021-09-27 04:00:46 +00:00
# Options
2021-09-30 00:20:15 +00:00
INCLUDES := -i include/
2021-12-10 18:39:59 +00:00
ASM_INCLUDES := -I include/
2021-09-27 04:00:46 +00:00
2022-01-31 03:39:28 +00:00
ASFLAGS := -mgekko $( ASM_INCLUDES) --defsym version = $( VERNUM)
2021-12-10 18:29:26 +00:00
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-08-04 00:05:18 +00:00
CFLAGS := -Cpp_exceptions off -enum int -inline auto -proc gekko -RTTI off -fp hard -fp_contract on -rostr -O4,p -use_lmw_stmw on -common on -sdata 8 -sdata2 8 -nodefaults -DVERNUM= $( VERNUM) $( INCLUDES)
2021-09-27 04:00:46 +00:00
2021-12-10 18:29:26 +00:00
i f e q ( $( VERBOSE ) , 0 )
2021-12-12 18:28:17 +00:00
# this set of ASFLAGS generates no warnings.
ASFLAGS += -W
2021-12-10 18:29:26 +00:00
e n d i f
2022-01-13 23:08:37 +00:00
$(BUILD_DIR)/src/Dolphin/dvdFatal.o : MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/Dolphin/dvderror.o : MWCC_VERSION := 1.2.5
2022-02-09 05:11:25 +00:00
$(BUILD_DIR)/src/Dolphin/dvdidutils.o : MWCC_VERSION := 1.2.5
2022-01-13 23:08:37 +00:00
$(BUILD_DIR)/src/Dolphin/__start.o : MWCC_VERSION := 1.2.5
2022-04-24 21:57:59 +00:00
$(BUILD_DIR)/src/Dolphin/__ppc_eabi_init.o : MWCC_VERSION := 1.2.5
2022-01-13 23:08:37 +00:00
$(BUILD_DIR)/src/Dolphin/OSLink.o : MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/Dolphin/PPCArch.o : MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/Dolphin/vec.o : MWCC_VERSION := 1.2.5
2022-06-29 21:05:43 +00:00
$(BUILD_DIR)/src/Dolphin/GBA.o : MWCC_VERSION := 1.2.5
2022-06-28 05:43:11 +00:00
$(BUILD_DIR)/src/Dolphin/GBARead.o : MWCC_VERSION := 1.2.5
2022-06-28 17:14:36 +00:00
$(BUILD_DIR)/src/Dolphin/GBAWrite.o : MWCC_VERSION := 1.2.5
2022-01-13 23:08:37 +00:00
$(BUILD_DIR)/src/Dolphin/GDBase.o : MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/Dolphin/SISamplingRate.o : MWCC_VERSION := 1.2.5
2022-01-14 22:45:30 +00:00
$(BUILD_DIR)/src/Dolphin/fstload.o : MWCC_VERSION := 1.2.5
2022-01-15 17:49:46 +00:00
$(BUILD_DIR)/src/Dolphin/db.o : MWCC_VERSION := 1.2.5
2022-04-28 02:35:57 +00:00
$(BUILD_DIR)/src/Dolphin/OSAudioSystem.o : MWCC_VERSION := 1.2.5
2022-06-12 20:50:07 +00:00
$(BUILD_DIR)/src/Dolphin/OSAlloc.o : MWCC_VERSION := 1.2.5
2022-06-24 17:50:39 +00:00
$(BUILD_DIR)/src/Dolphin/OS.o : MWCC_VERSION := 1.2.5
2022-08-25 21:17:42 +00:00
$(BUILD_DIR)/src/Dolphin/OSCache.o : MWCC_VERSION := 1.2.5
2021-10-03 19:56:42 +00:00
2022-01-05 23:54:02 +00:00
# Dirty hack to overwrite sdata
2022-06-26 20:54:49 +00:00
# It seems TRK-related files need -sdata 0
2022-01-05 23:54:02 +00:00
$(BUILD_DIR)/src/Dolphin/main_TRK.o : CFLAGS += -sdata 0
2022-06-26 20:54:49 +00:00
$(BUILD_DIR)/src/Dolphin/mainloop.o : CFLAGS += -sdata 0
2022-08-18 21:51:05 +00:00
$(BUILD_DIR)/src/Dolphin/nubinit.o : CFLAGS += -sdata 0
2022-01-14 01:19:32 +00:00
$(BUILD_DIR)/src/Dolphin/target_options.o : CFLAGS += -sdata 0
2022-06-26 20:54:49 +00:00
2022-01-13 23:08:37 +00:00
# Disable read-only strings
2022-06-24 17:50:39 +00:00
$(BUILD_DIR)/src/Dolphin/SISamplingRate.o : CFLAGS += -str noreadonly
$(BUILD_DIR)/src/Dolphin/fstload.o : CFLAGS += -str noreadonly
$(BUILD_DIR)/src/Dolphin/db.o : CFLAGS += -str noreadonly
$(BUILD_DIR)/src/Dolphin/OS.o : CFLAGS += -str noreadonly
2022-08-25 21:17:42 +00:00
$(BUILD_DIR)/src/Dolphin/OSCache.o : CFLAGS += -str noreadonly
2022-06-29 21:05:43 +00:00
$(BUILD_DIR)/src/Dolphin/GBA.o : CFLAGS += -str noreadonly
2022-06-24 17:50:39 +00:00
2022-08-25 05:29:52 +00:00
# This is inline-deferred for some reason
$(BUILD_DIR)/src/Dolphin/mbstring.o : CFLAGS := -Cpp_exceptions off -enum int -inline deferred -proc gekko -RTTI off -fp hard -fp_contract on -rostr -O 4, p -use_lmw_stmw on -common on -sdata 8 -sdata 2 8 -nodefaults -DVERNUM =$( VERNUM ) $( INCLUDES )
2022-08-03 21:41:17 +00:00
# Disable common BSS pool
$(DOLPHIN) : CFLAGS += -common off
2022-04-06 04:33:58 +00:00
# Enable string pooling
$(BUILD_DIR)/src/Dolphin/locale.o : CFLAGS += -str pool
2022-01-05 23:54:02 +00:00
2021-09-27 04:00:46 +00:00
#-------------------------------------------------------------------------------
# Recipes
#-------------------------------------------------------------------------------
### Default target ###
default : all
all : $( DOL )
2021-12-03 05:57:25 +00:00
ALL_DIRS := $( sort $( dir $( O_FILES) ) )
2022-01-13 23:08:37 +00:00
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
EPI_DIRS := $( sort $( dir $( E_FILES) ) )
e n d i f
2021-09-27 04:00:46 +00:00
# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $( ALL_DIRS)
2022-01-13 23:38:39 +00:00
# ifeq ($(EPILOGUE_PROCESS),1)
2022-01-13 23:08:37 +00:00
# Make sure profile directory exists before compiling anything
2022-01-13 23:38:39 +00:00
# DUMMY != mkdir -p $(EPI_DIRS)
# endif
2022-01-13 23:08:37 +00:00
2021-10-04 14:10:08 +00:00
.PHONY : tools
2021-09-27 04:00:46 +00:00
$(LDSCRIPT) : ldscript .lcf
2021-12-10 18:29:26 +00:00
$( QUIET) $( CPP) -MMD -MP -MT $@ -MF $@ .d -I include/ -I . -DBUILD_DIR= $( BUILD_DIR) -o $@ $<
2021-09-27 04:00:46 +00:00
$(DOL) : $( ELF ) | tools
2021-12-10 18:29:26 +00:00
$( QUIET) $( ELF2DOL) $< $@
$( QUIET) $( SHA1SUM) -c sha1/$( NAME) .$( VERSION) .sha1
2021-11-08 00:59:19 +00:00
i f n e q ( $( findstring -map ,$ ( LDFLAGS ) ) , )
2022-04-08 23:11:12 +00:00
$( QUIET) $( PYTHON) tools/calcprogress.py $( DOL) $( MAP)
2021-11-08 00:59:19 +00:00
e n d i f
2022-04-08 22:06:23 +00:00
i f e q ( $( UPDATE_README ) , 1 )
$( WINE) $( READMEGEN)
e n d i f
2021-09-27 04:00:46 +00:00
clean :
rm -f -d -r build
2022-01-13 23:08:37 +00:00
rm -f -d -r epilogue
2022-02-04 08:22:41 +00:00
find . -name '*.o' -exec rm { } +
find . -name 'ctx.c' -exec rm { } +
find ./include -name "*.s" -type f -delete
2021-10-04 14:10:08 +00:00
$( MAKE) -C tools clean
tools :
$( MAKE) -C tools
2021-09-27 04:00:46 +00:00
2022-01-13 23:08:37 +00:00
# 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
2021-09-27 04:00:46 +00:00
$(ELF) : $( O_FILES ) $( LDSCRIPT )
2021-12-10 18:29:26 +00:00
@echo Linking ELF $@
$( QUIET) @echo $( O_FILES) > build/o_files
$( QUIET) $( LD) $( LDFLAGS) -o $@ -lcf $( LDSCRIPT) @build/o_files
2022-01-13 23:08:37 +00:00
e n d i f
2021-09-27 04:00:46 +00:00
$(BUILD_DIR)/%.o : %.s
2021-12-10 18:29:26 +00:00
@echo Assembling $<
$( QUIET) $( AS) $( ASFLAGS) -o $@ $<
2022-01-13 23:08:37 +00:00
2021-09-27 04:00:46 +00:00
$(BUILD_DIR)/%.o : %.c
2021-12-20 03:48:45 +00:00
@echo "Compiling " $<
2021-12-10 18:29:26 +00:00
$( QUIET) $( CC) $( CFLAGS) -c -o $@ $<
2021-09-30 00:20:15 +00:00
2021-12-18 02:09:49 +00:00
$(BUILD_DIR)/%.o : %.cp
2021-12-20 03:48:45 +00:00
@echo "Compiling " $<
2021-12-18 02:09:49 +00:00
$( QUIET) $( CC) $( CFLAGS) -c -o $@ $<
2022-01-13 23:08:37 +00:00
2021-09-30 00:20:15 +00:00
$(BUILD_DIR)/%.o : %.cpp
2021-12-20 03:48:45 +00:00
@echo "Compiling " $<
2021-12-10 18:29:26 +00:00
$( QUIET) $( CC) $( CFLAGS) -c -o $@ $<
2021-09-27 04:00:46 +00:00
2022-01-13 23:08:37 +00:00
i f e q ( $( EPILOGUE_PROCESS ) , 1 )
$(EPILOGUE_DIR)/%.o : %.c $( BUILD_DIR ) /%.o
@echo Frank is fixing $<
2022-01-13 23:38:39 +00:00
$( QUIET) $( PYTHON) $( FRANK) $( word 2,$^) $( word 2,$^)
2022-01-13 23:08:37 +00:00
$(EPILOGUE_DIR)/%.o : %.cp $( BUILD_DIR ) /%.o
@echo Frank is fixing $<
2022-01-13 23:38:39 +00:00
$( QUIET) $( PYTHON) $( FRANK) $( word 2,$^) $( word 2,$^)
2022-01-13 23:08:37 +00:00
$(EPILOGUE_DIR)/%.o : %.cpp $( BUILD_DIR ) /%.o
@echo Frank is fixing $<
2022-01-13 23:38:39 +00:00
$( QUIET) $( PYTHON) $( FRANK) $( word 2,$^) $( word 2,$^)
2022-01-13 23:08:37 +00:00
e n d i f
2022-01-13 23:38:39 +00:00
# If we need Frank, add the following after the @echo
# $(QUIET) $(CC_EPI) $(CFLAGS) -c -o $@ $<
2022-01-13 23:08:37 +00:00
2022-06-22 16:45:42 +00:00
### Extremely lazy recipes for generating context ###
# Example usage: make build/pikmin2.usa/src/plugProjectYamashitaU/farmMgr.h
$(BUILD_DIR)/%.h : %.c
@echo "Compiling and generating context for " $<
$( QUIET) $( CC) $( CFLAGS) -E -c -o $@ $<
$(BUILD_DIR)/%.h : %.cp
@echo "Compiling and generating context for " $<
$( QUIET) $( CC) $( CFLAGS) -E -c -o $@ $<
$(BUILD_DIR)/%.h : %.cpp
@echo "Compiling and generating context for " $<
$( QUIET) $( CC) $( CFLAGS) -E -c -o $@ $<
2021-09-27 04:00:46 +00:00
### Debug Print ###
print-% : ; $( info $ * is a $ ( flavor $ *) variable set to [$ ( $ *) ]) @true