prime/Makefile

219 lines
7.0 KiB
Makefile
Raw Normal View History

2022-03-23 21:22:48 +00:00
ifneq ($(findstring MINGW,$(shell uname)),)
WINDOWS := 1
endif
ifneq ($(findstring MSYS,$(shell uname)),)
WINDOWS := 1
endif
# 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.
GENERATE_MAP ?= 1
2022-03-23 21:22:48 +00:00
ifeq ($(VERBOSE),0)
QUIET := @
endif
#-------------------------------------------------------------------------------
# Files
#-------------------------------------------------------------------------------
NAME := mp1
VERSION ?= 0
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
ifeq ($(GENERATE_MAP),1)
2022-03-23 21:22:48 +00:00
MAPGEN := -map $(MAP)
endif
include obj_files.mk
2022-08-10 05:34:11 +00:00
O_FILES := $(INIT_O_FILES) $(METROTRK_FILES) \
2022-04-16 04:01:44 +00:00
$(METROIDPRIME) $(WORLDFORMAT) $(WEAPONS) $(METARENDER) $(GUISYS) $(COLLISION) \
2022-07-18 05:21:27 +00:00
$(KYOTO) $(AI_FILES) \
$(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-08-10 05:34:11 +00:00
$(GBA_FILES) $(DTORS_O_FILES)
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-03-23 21:22:48 +00:00
MWLD_VERSION := 2.6
# Programs
export WINEDEBUG ?= -all
2022-03-23 21:22:48 +00:00
ifeq ($(WINDOWS),1)
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-03-23 21:22:48 +00:00
else
2022-07-14 05:36:41 +00:00
WIBO := $(shell command -v wibo 2> /dev/null)
ifdef WIBO
WINE ?= wibo
else
WINE ?= wine
endif
DEVKITPPC ?= /opt/devkitpro/devkitPPC
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-03-23 21:22:48 +00:00
endif
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
SHA1SUM := shasum -a 1
2022-03-23 21:22:48 +00:00
TRANSFORM_DEP := tools/transform-dep.py
2022-03-23 21:22:48 +00:00
FRANK := tools/franklite.py
# Options
INCLUDES := -i include/
2022-03-23 21:22:48 +00:00
ASM_INCLUDES := -I include/
ASFLAGS := -mgekko $(ASM_INCLUDES) --defsym version=$(VERSION)
ifeq ($(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
endif
ifeq ($(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
endif
2022-08-05 10:23:49 +00:00
CFLAGS_1.2 = -proc gekko -nodefaults -Cpp_exceptions off -RTTI off -fp fmadd -fp_contract on -O4,p -maxerrors 1 -enum int -inline auto -MMD $(INCLUDES)
2022-07-27 05:11:36 +00:00
CFLAGS_MUSYX = -proc gekko -nodefaults -Cpp_exceptions off -RTTI off -fp fmadd -str reuse,pool,readonly -O4,p -maxerrors 1 -enum int -inline auto -MMD $(INCLUDES)
2022-08-05 10:23:49 +00:00
CFLAGS = $(CFLAGS_1.2) -use_lmw_stmw on -str reuse,pool,readonly -gccinc -inline deferred,noauto
2022-08-10 03:00:57 +00:00
CFLAGS_ZLIB = $(CFLAGS_1.2) -use_lmw_stmw on -str reuse,pool,readonly -gccinc -inline deferred,auto
2022-08-05 10:23:49 +00:00
CFLAGS_1.2 += -str reuse
2022-03-23 21:22:48 +00:00
ifeq ($(VERBOSE),0)
# this set of ASFLAGS generates no warnings.
ASFLAGS += -W
endif
$(BUILD_DIR)/src/os/__start.o: MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/os/__start.o: CFLAGS := $(CFLAGS_1.2)
2022-07-28 13:19:26 +00:00
$(BUILD_DIR)/src/MetroTRK/mslsupp.o: MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/MetroTRK/mslsupp.o: CFLAGS := $(CFLAGS_1.2)
2022-04-04 10:14:22 +00:00
$(BUILD_DIR)/src/Dolphin/PPCArch.o: MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/Dolphin/PPCArch.o: CFLAGS := $(CFLAGS_1.2)
2022-08-05 10:23:49 +00:00
$(BUILD_DIR)/src/Dolphin/ai.o: MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/Dolphin/ai.o: CFLAGS := $(CFLAGS_1.2)
2022-04-24 17:43:04 +00:00
$(BUILD_DIR)/src/Dolphin/os/OSAudioSystem.o: MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/Dolphin/os/OSAudioSystem.o: CFLAGS := $(CFLAGS_1.2)
2022-07-28 13:19:26 +00:00
$(BUILD_DIR)/src/Dolphin/os/OSReset.o: MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/Dolphin/os/OSReset.o: CFLAGS := $(CFLAGS_1.2)
2022-04-30 08:32:00 +00:00
$(BUILD_DIR)/src/Dolphin/dsp/dsp.o: MWCC_VERSION := 1.2.5
$(BUILD_DIR)/src/Dolphin/dsp/dsp.o: CFLAGS := $(CFLAGS_1.2)
2022-07-30 09:12:25 +00:00
$(BUILD_DIR)/src/Dolphin/dsp/dsp_debug.o: CFLAGS := $(CFLAGS_1.2)
2022-07-28 13:19:26 +00:00
$(BUILD_DIR)/src/musyx/seq_api.o: CFLAGS := $(CFLAGS_MUSYX)
$(BUILD_DIR)/src/musyx/synth_dbtab.o: CFLAGS := $(CFLAGS_MUSYX)
2022-07-27 05:11:36 +00:00
$(BUILD_DIR)/src/musyx/snd_service.o: CFLAGS := $(CFLAGS_MUSYX)
2022-07-28 13:19:26 +00:00
$(BUILD_DIR)/src/musyx/snd_init.o: CFLAGS := $(CFLAGS_MUSYX)
$(BUILD_DIR)/src/musyx/dsp_import.o: CFLAGS := $(CFLAGS_MUSYX)
$(BUILD_DIR)/src/musyx/hw_memory.o: CFLAGS := $(CFLAGS_MUSYX)
$(BUILD_DIR)/src/musyx/reverb_fx.o: CFLAGS := $(CFLAGS_MUSYX)
2022-07-28 14:00:20 +00:00
$(BUILD_DIR)/src/musyx/delay_fx.o: CFLAGS := $(CFLAGS_MUSYX)
2022-07-28 15:50:05 +00:00
$(BUILD_DIR)/src/musyx/creverb_fx.o: CFLAGS := $(CFLAGS_MUSYX)
2022-08-05 10:23:49 +00:00
$(BUILD_DIR)/src/musyx/synth_ac.o: CFLAGS := $(CFLAGS_MUSYX)
2022-08-10 03:00:57 +00:00
$(BUILD_DIR)/src/Kyoto/zlib/adler32.o: CFLAGS := $(CFLAGS_ZLIB)
$(BUILD_DIR)/src/Kyoto/zlib/infblock.o: CFLAGS := $(CFLAGS_ZLIB)
$(BUILD_DIR)/src/Kyoto/zlib/infcodes.o: CFLAGS := $(CFLAGS_ZLIB)
$(BUILD_DIR)/src/Kyoto/zlib/inffast.o: CFLAGS := $(CFLAGS_ZLIB)
$(BUILD_DIR)/src/Kyoto/zlib/inflate.o: CFLAGS := $(CFLAGS_ZLIB)
$(BUILD_DIR)/src/Kyoto/zlib/inftrees.o: CFLAGS := $(CFLAGS_ZLIB)
$(BUILD_DIR)/src/Kyoto/zlib/infutil.o: CFLAGS := $(CFLAGS_ZLIB)
$(BUILD_DIR)/src/Kyoto/zlib/zutil.o: CFLAGS := $(CFLAGS_ZLIB)
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
ifneq ($(findstring -map,$(LDFLAGS)),)
$(QUIET) $(PYTHON) tools/calcprogress.py $(DOL) $(MAP)
2022-03-23 21:22:48 +00:00
endif
clean:
$(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
%.d.unix: %.d $(TRANSFORM_DEP)
@echo Processing $<
$(QUIET) $(PYTHON) $(TRANSFORM_DEP) $< $@
-include $(DEPENDS)
2022-03-23 21:22:48 +00:00
$(BUILD_DIR)/%.o: %.s
@echo Assembling $<
$(QUIET) $(AS) $(ASFLAGS) -o $@ $<
$(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 " $<
$(QUIET) $(CC) $(CFLAGS) -c -o $(dir $@) $<
2022-03-23 21:22:48 +00:00
$(BUILD_DIR)/%.o: %.cp
@echo "Compiling " $<
$(QUIET) $(CC) $(CFLAGS) -c -o $(dir $@) $<
2022-03-23 21:22:48 +00:00
$(BUILD_DIR)/%.o: %.cpp
@echo "Compiling " $<
$(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