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
2022-11-12 18:33:43 +00:00
# Use the all-in-one updater after successful build? (Fails on non-windows platforms)
USE_AOI ?= 0
2021-12-10 18:29:26 +00:00
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-10-19 22:11:49 +00:00
# Use the all-in-one updater after successful build? (Fails on non-windows platforms)
2022-11-12 18:33:43 +00:00
i f e q ( $( USE_AOI ) , 1 )
ifeq ( $( WINDOWS) , 1)
USE_AOI = 1
else
@echo "aoi.exe fails on non-windows platforms."
USE_AOI = 0
endif
2022-10-19 22:11:49 +00:00
e l s e
2022-11-12 18:33:43 +00:00
USE_AOI = 0
2022-10-19 22:11:49 +00:00
e n d i f
2022-04-08 22:06:23 +00:00
2021-09-27 04:00:46 +00:00
BUILD_DIR := build/$( NAME) .$( VERSION)
# 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
2022-10-17 23:05:30 +00:00
AOI := aoi.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
2023-02-02 04:20:03 +00:00
O_FILES := $( JSYSTEM) $( DOLPHIN) $( PLUGPROJECT) $( SYS) $( UTILITY)
2023-01-29 02:18:21 +00:00
DEPENDS := $( $( filter *.o,O_FILES) :.o= .d)
DEPENDS += $( $( filter *.o,E_FILES) :.o= .d)
2022-09-08 17:22:44 +00:00
# If a specific .o file is passed as a target, also process its deps
DEPENDS += $( MAKECMDGOALS:.o= .d)
2021-09-27 04:00:46 +00:00
#-------------------------------------------------------------------------------
# Tools
#-------------------------------------------------------------------------------
2021-10-01 22:55:22 +00:00
MWCC_VERSION := 2.6
2021-11-07 02:33:59 +00:00
MWLD_VERSION := 2.6
2021-09-27 04:00:46 +00:00
# Programs
2023-12-21 19:12:35 +00:00
POWERPC ?= tools/powerpc
2021-09-27 04:00:46 +00:00
i f e q ( $( WINDOWS ) , 1 )
WINE :=
2023-12-21 19:12:35 +00:00
AS := $( POWERPC) /powerpc-eabi-as.exe
2022-06-13 22:14:48 +00:00
PYTHON := python
2021-09-27 04:00:46 +00:00
e l s e
2022-09-08 17:22:44 +00:00
WIBO := $( shell command -v wibo 2> /dev/null)
ifdef WIBO
WINE ?= wibo
else
WINE ?= wine
endif
2022-04-08 23:11:12 +00:00
# Disable wine debug output for cleanliness
export WINEDEBUG ?= -all
2024-01-02 12:52:18 +00:00
AS := $( POWERPC) /powerpc-eabi-as
2022-06-13 22:14:48 +00:00
PYTHON := python3
2021-09-27 04:00:46 +00:00
e n d i f
2023-01-31 04:32:08 +00:00
COMPILERS ?= tools/mwcc_compiler
CC = $( WINE) $( COMPILERS) /$( MWCC_VERSION) /mwcceppc.exe
LD := $( WINE) $( COMPILERS) /$( MWLD_VERSION) /mwldeppc.exe
2023-02-04 18:57:12 +00:00
DTK := tools/dtk
ELF2DOL := $( DTK) elf2dol
SHASUM := $( DTK) shasum
2021-09-27 04:00:46 +00:00
2023-01-31 00:57:01 +00:00
i f n e q ( $( WINDOWS ) , 1 )
2022-09-08 17:22:44 +00:00
TRANSFORM_DEP := tools/transform-dep.py
2023-01-31 00:57:01 +00:00
e l s e
TRANSFORM_DEP := tools/transform-win.py
e n d i f
2022-01-13 23:08:37 +00:00
2021-09-27 04:00:46 +00:00
# Options
2023-04-22 06:37:22 +00:00
INCLUDES := -i include/ -i include/stl/
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
2023-01-29 02:18:21 +00:00
LIBRARY_LDFLAGS := -nodefaults -fp hard -proc gekko
2022-09-08 17:22:44 +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 -MMD -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
2023-01-29 02:18:21 +00:00
# this set of CFLAGS generates no warnings.
CFLAGS += -w off
2021-12-10 18:29:26 +00:00
e n d i f
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) ) )
2021-09-27 04:00:46 +00:00
# Make sure build directory exists before compiling anything
DUMMY != mkdir -p $( ALL_DIRS)
2023-12-21 21:18:27 +00:00
LDSCRIPT := ldscript.lcf
2021-09-27 04:00:46 +00:00
2023-02-04 18:57:12 +00:00
$(DOL) : $( ELF ) | $( DTK )
2021-12-10 18:29:26 +00:00
$( QUIET) $( ELF2DOL) $< $@
2023-02-04 18:57:12 +00:00
$( QUIET) $( SHASUM) -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-10-19 22:11:49 +00:00
i f e q ( $( USE_AOI ) , 1 )
$( WINE) ./aoi.exe
2022-04-08 22:06:23 +00:00
e n d i f
2021-09-27 04:00:46 +00:00
clean :
2023-01-30 22:07:17 +00:00
rm -f -d -r build
2023-02-04 18:57:12 +00:00
$(DTK) : tools /dtk_version
@echo " Downloading $@ "
$( QUIET) $( PYTHON) tools/download_dtk.py $< $@
2021-09-27 04:00:46 +00:00
2022-01-13 23:08:37 +00:00
# ELF creation makefile instructions
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
2021-09-27 04:00:46 +00:00
2022-09-08 17:22:44 +00:00
%.d.unix : %.d $( TRANSFORM_DEP )
@echo Processing $<
$( QUIET) $( PYTHON) $( TRANSFORM_DEP) $< $@
2023-01-29 02:18:21 +00:00
- i n c l u d e i n c l u d e _ l i n k . m k
2023-01-31 00:57:01 +00:00
DEPENDS := $( DEPENDS:.d= .d.unix)
i f n e q ( $( MAKECMDGOALS ) , c l e a n )
2022-09-08 17:22:44 +00:00
- i n c l u d e $( DEPENDS )
2023-01-31 00:57:01 +00:00
e n d i f
2022-09-08 17:22:44 +00:00
2021-09-27 04:00:46 +00:00
$(BUILD_DIR)/%.o : %.s
2021-12-10 18:29:26 +00:00
@echo Assembling $<
2022-10-15 05:53:33 +00:00
$( QUIET) mkdir -p $( dir $@ )
2021-12-10 18:29:26 +00:00
$( QUIET) $( AS) $( ASFLAGS) -o $@ $<
2022-01-13 23:08:37 +00:00
2022-10-15 05:53:33 +00:00
# for files with capitalized .C extension
$(BUILD_DIR)/%.o : %.C
@echo "Compiling " $<
$( QUIET) mkdir -p $( dir $@ )
$( QUIET) $( CC) $( CFLAGS) -c -o $( dir $@ ) $<
2021-09-27 04:00:46 +00:00
$(BUILD_DIR)/%.o : %.c
2021-12-20 03:48:45 +00:00
@echo "Compiling " $<
2022-10-15 05:53:33 +00:00
$( QUIET) mkdir -p $( dir $@ )
2022-09-08 17:22:44 +00:00
$( QUIET) $( CC) $( CFLAGS) -c -o $( dir $@ ) $<
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 " $<
2022-10-15 05:53:33 +00:00
$( QUIET) mkdir -p $( dir $@ )
2022-09-08 17:22:44 +00:00
$( QUIET) $( CC) $( CFLAGS) -c -o $( dir $@ ) $<
2021-09-30 00:20:15 +00:00
$(BUILD_DIR)/%.o : %.cpp
2021-12-20 03:48:45 +00:00
@echo "Compiling " $<
2022-10-15 05:53:33 +00:00
$( QUIET) mkdir -p $( dir $@ )
2022-09-08 17:22:44 +00:00
$( QUIET) $( CC) $( CFLAGS) -c -o $( dir $@ ) $<
2021-09-27 04:00:46 +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 $@ $<
2023-12-18 22:00:10 +00:00
2022-06-22 16:45:42 +00:00
$(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