diff --git a/Makefile b/Makefile index f069da28..376af1b5 100644 --- a/Makefile +++ b/Makefile @@ -59,7 +59,10 @@ O_FILES := $(INIT_O_FILES) $(EXTAB_O_FILES) $(EXTABINDEX_O_FILES) $(METROTRK_FIL $(OS_FILES) $(PAD_FILES) $(VI_FILES) $(MSL_PPCEABI_BARE_H) $(MUSYX_FILES) \ $(DTK_FILES) $(CARD_FILES) $(SI_FILES) $(EXI_FILES) $(THP_FILES) \ $(GBA_FILES) $(CTORS_O_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) + ifeq ($(EPILOGUE_PROCESS),1) E_FILES := $(EPILOGUE_UNSCHEDULED) endif @@ -67,7 +70,7 @@ endif # Tools #------------------------------------------------------------------------------- -MWCC_VERSION := 2.6 +MWCC_VERSION := 2.7 ifeq ($(EPILOGUE_PROCESS),1) MWCC_EPI_VERSION := 1.2.5 MWCC_EPI_EXE := mwcceppc.exe @@ -83,6 +86,7 @@ ifeq ($(WINDOWS),1) else WINE ?= wine DEVKITPPC ?= /opt/devkitpro/devkitPPC + DEPENDS := $(DEPENDS:.d=.d.unix) AS := $(DEVKITPPC)/bin/powerpc-eabi-as CPP := $(DEVKITPPC)/bin/powerpc-eabi-cpp -P endif @@ -95,10 +99,11 @@ ELF2DOL := tools/elf2dol SHA1SUM := sha1sum PYTHON := python3 +TRANSFORM_DEP := tools/transform-dep.py FRANK := tools/franklite.py # Options -INCLUDES := -i include/ -i include/Kyoto_CWD/ -i include/rstl/ +INCLUDES := -i include/ ASM_INCLUDES := -I include/ ASFLAGS := -mgekko $(ASM_INCLUDES) --defsym version=$(VERSION) @@ -110,7 +115,8 @@ ifeq ($(VERBOSE),0) # this set of LDFLAGS generates no warnings. LDFLAGS := $(MAPGEN) -fp hard -nodefaults -w off endif -CFLAGS = -Cpp_exceptions off -enum int -inline auto -proc gekko -RTTI off -fp hard -fp_contract on -str pool -rostr -O4,p -use_lmw_stmw on -sdata 8 -sdata2 8 -nodefaults $(INCLUDES) +CFLAGS_1.2 = -Cpp_exceptions off -enum int -inline auto -proc gekko -RTTI off -fp hard -fp_contract on -str pool -rostr -O4,p -use_lmw_stmw on -sdata 8 -sdata2 8 -nodefaults -MMD $(INCLUDES) +CFLAGS = $(CFLAGS_1.2) -gccinc ifeq ($(VERBOSE),0) # this set of ASFLAGS generates no warnings. @@ -118,7 +124,9 @@ ASFLAGS += -W endif $(BUILD_DIR)/src/os/__start.o: MWCC_VERSION := 1.2.5 +$(BUILD_DIR)/src/os/__start.o: CFLAGS := $(CFLAGS_1.2) $(BUILD_DIR)/src/Dolphin/PPCArch.o: MWCC_VERSION := 1.2.5 +$(BUILD_DIR)/src/Dolphin/PPCArch.o: CFLAGS := $(CFLAGS_1.2) #------------------------------------------------------------------------------- # Recipes @@ -152,15 +160,11 @@ $(DOL): $(ELF) | tools $(QUIET) $(ELF2DOL) $< $@ $(QUIET) $(SHA1SUM) -c sha1/$(NAME).$(VERSION).sha1 ifneq ($(findstring -map,$(LDFLAGS)),) - $(QUIET) $(PYTHON) tools/calcprogress.py $@ + $(QUIET) $(PYTHON) tools/calcprogress.py $(DOL) $(MAP) endif clean: - rm -f -d -r build - rm -f -d -r epilogue - find . -name '*.o' -exec rm {} + - find . -name 'ctx.c' -exec rm {} + - find ./include -name "*.s" -type f -delete + $(RM) $(O_FILES) $(DEPENDS) $(MAKE) -C tools clean tools: $(MAKE) -C tools @@ -178,21 +182,27 @@ $(ELF): $(O_FILES) $(LDSCRIPT) $(QUIET) $(LD) $(LDFLAGS) -o $@ -lcf $(LDSCRIPT) @build/o_files endif +%.d.unix: %.d $(TRANSFORM_DEP) + @echo Processing $< + $(QUIET) $(PYTHON) $(TRANSFORM_DEP) $< $@ + +-include $(DEPENDS) + $(BUILD_DIR)/%.o: %.s @echo Assembling $< $(QUIET) $(AS) $(ASFLAGS) -o $@ $< $(BUILD_DIR)/%.o: %.c @echo "Compiling " $< - $(QUIET) $(CC) $(CFLAGS) -c -o $@ $< + $(QUIET) $(CC) $(CFLAGS) -c -o $(dir $@) $< $(BUILD_DIR)/%.o: %.cp @echo "Compiling " $< - $(QUIET) $(CC) $(CFLAGS) -c -o $@ $< - + $(QUIET) $(CC) $(CFLAGS) -c -o $(dir $@) $< + $(BUILD_DIR)/%.o: %.cpp @echo "Compiling " $< - $(QUIET) $(CC) $(CFLAGS) -c -o $@ $< + $(QUIET) $(CC) $(CFLAGS) -c -o $(dir $@) $< ifeq ($(EPILOGUE_PROCESS),1) $(EPILOGUE_DIR)/%.o: %.c $(BUILD_DIR)/%.o diff --git a/deincbin.sh b/deincbin.sh index ea18cbe8..efad59b9 100644 --- a/deincbin.sh +++ b/deincbin.sh @@ -1,4 +1,3 @@ -#! /bin/bash - +#!/bin/bash -e python tools/deincbin.py "$1" > "$1.deincbin.s" mv "$1.deincbin.s" "$1" diff --git a/diff_settings.py b/diff_settings.py new file mode 100644 index 00000000..8b64e653 --- /dev/null +++ b/diff_settings.py @@ -0,0 +1,9 @@ +def apply(config, args): + config["arch"] = "ppc" + config["objdump_executable"] = "/opt/devkitpro/devkitPPC/bin/powerpc-eabi-objdump" + config["objdump_flags"] = ["-M", "gekko"] + config["source_directories"] = ["."] + config["make_flags"] = [ + "VERBOSE=1", + args.objfile.replace("src/", "asm/") # also build asm obj + ] diff --git a/rename.sh b/rename.sh index 2ef6bf7a..15c74b99 100644 --- a/rename.sh +++ b/rename.sh @@ -1,2 +1,3 @@ +#!/bin/bash -e echo "$1 -> $2" find . -type f -name '*.s' | xargs sed -i "s/$1/$2/g" diff --git a/tools/calcprogress.py b/tools/calcprogress.py index 4c283a8f..f9e24ce4 100644 --- a/tools/calcprogress.py +++ b/tools/calcprogress.py @@ -31,8 +31,8 @@ import math # # ############################################### -DOL_PATH = "baserom.dol" -MAP_PATH = "build/mp1.0/MetroidPrime.MAP" +DOL_PATH = sys.argv[1] +MAP_PATH = sys.argv[2] MEM1_HI = 0x81200000 MEM1_LO = 0x80004000 diff --git a/tools/diff-obj.sh b/tools/diff-obj.sh new file mode 100755 index 00000000..063aeade --- /dev/null +++ b/tools/diff-obj.sh @@ -0,0 +1,2 @@ +#!/bin/bash -e +../asm_differ/diff.py -mwo -f build/mp1.0/src/"$1" "$2" --width 100 -U 20 \ No newline at end of file diff --git a/tools/transform-dep.py b/tools/transform-dep.py new file mode 100755 index 00000000..18e43071 --- /dev/null +++ b/tools/transform-dep.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python3 +import argparse +import subprocess + +def import_d_file(in_file) -> str: + out_text = '' + + with open(in_file) as file: + for idx, line in enumerate(file): + if idx == 0: + if line.endswith(' \\\n'): + out_text += line[:-3].replace('\\', '/') + " \\\n" + else: + out_text += line.replace('\\', '/') + else: + suffix = '' + if line.endswith(' \\\n'): + suffix = ' \\' + path = line.lstrip()[:-3] + else: + path = line.strip() + if path.startswith('Z:'): + # direct mapping to unix path + path = path[2:].replace('\\', '/') + else: + # use winepath (very slow!) + cmd = subprocess.run(['winepath', '-u', path], capture_output=True, env={'WINEDEBUG': '-all'}) + if cmd.returncode != 0: + print("winepath failed with exit code %d:" % cmd.returncode, cmd.stderr) + exit(1) + path = cmd.stdout.decode('utf-8').rstrip() + out_text += "\t" + path + suffix + "\n" + + return out_text + +def main(): + parser = argparse.ArgumentParser( + description="""Transform a .d file from Wine paths to normal paths""" + ) + parser.add_argument( + "d_file", + help="""Dependency file in""", + ) + parser.add_argument( + "d_file_out", + help="""Dependency file out""", + ) + args = parser.parse_args() + + output = import_d_file(args.d_file) + + with open(args.d_file_out, "w", encoding="UTF-8") as f: + f.write(output) + + +if __name__ == "__main__": + main() \ No newline at end of file