configure.py: Add --compilers and --build-dir; cleanup

This commit is contained in:
Luke Street 2023-01-23 19:18:59 -05:00
parent 3417e5c576
commit 3ec17fbf33
2 changed files with 227 additions and 215 deletions

View File

@ -2,7 +2,7 @@
LIBS = [ LIBS = [
{ {
"lib": "TRK_MINNOW_DOLPHIN", "lib": "TRK_MINNOW_DOLPHIN",
"mwcc_version": "1.2.5", "mw_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -12,7 +12,7 @@ LIBS = [
{ {
"lib": "MetroidPrimeCW", "lib": "MetroidPrimeCW",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"mwcc_version": "1.3.2", "mw_version": "1.3.2",
"host": True, "host": True,
"objects": [ "objects": [
["MetroidPrime/main", False], ["MetroidPrime/main", False],
@ -372,7 +372,7 @@ LIBS = [
}, },
{ {
"lib": "WorldFormatCW", "lib": "WorldFormatCW",
"mwcc_version": "1.3.2", "mw_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True, "host": True,
"objects": [ "objects": [
@ -392,7 +392,7 @@ LIBS = [
}, },
{ {
"lib": "WeaponsCW", "lib": "WeaponsCW",
"mwcc_version": "1.3.2", "mw_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True, "host": True,
"objects": [ "objects": [
@ -408,14 +408,14 @@ LIBS = [
}, },
{ {
"lib": "MetaRenderCW", "lib": "MetaRenderCW",
"mwcc_version": "1.3.2", "mw_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True, "host": True,
"objects": ["MetaRender/CCubeRenderer"], "objects": ["MetaRender/CCubeRenderer"],
}, },
{ {
"lib": "GuiSysCW", "lib": "GuiSysCW",
"mwcc_version": "1.3.2", "mw_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True, "host": True,
"objects": [ "objects": [
@ -442,7 +442,7 @@ LIBS = [
}, },
{ {
"lib": "CollisionCW", "lib": "CollisionCW",
"mwcc_version": "1.3.2", "mw_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True, "host": True,
"objects": [ "objects": [
@ -461,7 +461,7 @@ LIBS = [
}, },
{ {
"lib": "Kyoto_CW1", "lib": "Kyoto_CW1",
"mwcc_version": "1.3.2", "mw_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True, "host": True,
"objects": [ "objects": [
@ -618,7 +618,7 @@ LIBS = [
}, },
{ {
"lib": "zlib", "lib": "zlib",
"mwcc_version": "1.3.2", "mw_version": "1.3.2",
"cflags": "$cflags_runtime", "cflags": "$cflags_runtime",
"host": True, "host": True,
"objects": [ "objects": [
@ -636,7 +636,7 @@ LIBS = [
}, },
{ {
"lib": "Kyoto_CW2", "lib": "Kyoto_CW2",
"mwcc_version": "1.3.2", "mw_version": "1.3.2",
"cflags": "$cflags_retro", "cflags": "$cflags_retro",
"host": True, "host": True,
"objects": [ "objects": [
@ -698,7 +698,7 @@ LIBS = [
}, },
{ {
"lib": "ai", "lib": "ai",
"mwcc_version": "1.2.5e", "mw_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -707,7 +707,7 @@ LIBS = [
}, },
{ {
"lib": "ar", "lib": "ar",
"mwcc_version": "1.2.5e", "mw_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -717,7 +717,7 @@ LIBS = [
}, },
{ {
"lib": "base", "lib": "base",
"mwcc_version": "1.2.5", "mw_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -726,7 +726,7 @@ LIBS = [
}, },
{ {
"lib": "db", "lib": "db",
"mwcc_version": "1.2.5", "mw_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -735,7 +735,7 @@ LIBS = [
}, },
{ {
"lib": "dsp", "lib": "dsp",
"mwcc_version": "1.2.5e", "mw_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -746,7 +746,7 @@ LIBS = [
}, },
{ {
"lib": "dvd", "lib": "dvd",
"mwcc_version": "1.2.5e", "mw_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -762,7 +762,7 @@ LIBS = [
}, },
{ {
"lib": "gx", "lib": "gx",
"mwcc_version": "1.2.5", "mw_version": "1.2.5",
"cflags": "$cflags_base -fp_contract off", "cflags": "$cflags_base -fp_contract off",
"host": False, "host": False,
"objects": [ "objects": [
@ -785,7 +785,7 @@ LIBS = [
}, },
{ {
"lib": "mtx", "lib": "mtx",
"mwcc_version": "1.2.5", "mw_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -798,7 +798,7 @@ LIBS = [
}, },
{ {
"lib": "os", "lib": "os",
"mwcc_version": "1.2.5e", "mw_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -829,7 +829,7 @@ LIBS = [
}, },
{ {
"lib": "pad", "lib": "pad",
"mwcc_version": "1.2.5e", "mw_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -839,14 +839,14 @@ LIBS = [
}, },
{ {
"lib": "vi", "lib": "vi",
"mwcc_version": "1.2.5", "mw_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": ["Dolphin/vi"], "objects": ["Dolphin/vi"],
}, },
{ {
"lib": "MSL_C.PPCEABI.bare.H", "lib": "MSL_C.PPCEABI.bare.H",
"mwcc_version": "1.3.2", "mw_version": "1.3.2",
"cflags": "$cflags_runtime", "cflags": "$cflags_runtime",
"host": False, "host": False,
"objects": [ "objects": [
@ -918,7 +918,7 @@ LIBS = [
}, },
{ {
"lib": "musyx", "lib": "musyx",
"mwcc_version": "1.3.2", "mw_version": "1.3.2",
"cflags": "$cflags_musyx", "cflags": "$cflags_musyx",
"host": False, "host": False,
"objects": [ "objects": [
@ -957,7 +957,7 @@ LIBS = [
}, },
{ {
"lib": "dtk", "lib": "dtk",
"mwcc_version": "1.2.5", "mw_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -966,7 +966,7 @@ LIBS = [
}, },
{ {
"lib": "card", "lib": "card",
"mwcc_version": "1.2.5e", "mw_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -990,7 +990,7 @@ LIBS = [
}, },
{ {
"lib": "si", "lib": "si",
"mwcc_version": "1.2.5e", "mw_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -1000,7 +1000,7 @@ LIBS = [
}, },
{ {
"lib": "exi", "lib": "exi",
"mwcc_version": "1.2.5", "mw_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -1010,7 +1010,7 @@ LIBS = [
}, },
{ {
"lib": "thp", "lib": "thp",
"mwcc_version": "1.2.5", "mw_version": "1.2.5",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -1020,7 +1020,7 @@ LIBS = [
}, },
{ {
"lib": "gba", "lib": "gba",
"mwcc_version": "1.2.5e", "mw_version": "1.2.5e",
"cflags": "$cflags_base", "cflags": "$cflags_base",
"host": False, "host": False,
"objects": [ "objects": [
@ -1041,6 +1041,7 @@ if __name__ == "__main__":
import sys import sys
import argparse import argparse
from pathlib import Path
from shutil import which from shutil import which
from tools import ninja_syntax from tools import ninja_syntax
@ -1072,17 +1073,20 @@ if __name__ == "__main__":
parser.add_argument( parser.add_argument(
"--devkitppc", "--devkitppc",
dest="devkitppc", dest="devkitppc",
type=Path,
help="path to devkitPPC", help="path to devkitPPC",
) )
if os.name != "nt" and not "_NT-" in os.uname().sysname: if os.name != "nt" and not "_NT-" in os.uname().sysname:
parser.add_argument( parser.add_argument(
"--wine", "--wine",
dest="wine", dest="wine",
type=Path,
help="path to wine (or wibo)", help="path to wine (or wibo)",
) )
parser.add_argument( parser.add_argument(
"--build-dtk", "--build-dtk",
dest="build_dtk", dest="build_dtk",
type=Path,
help="path to decomp-toolkit source", help="path to decomp-toolkit source",
) )
parser.add_argument( parser.add_argument(
@ -1091,10 +1095,24 @@ if __name__ == "__main__":
action="store_true", action="store_true",
help="build with debug info (non-matching)", help="build with debug info (non-matching)",
) )
parser.add_argument(
"--compilers",
dest="compilers",
type=Path,
default=Path("tools/mwcc_compiler"),
help="path to compilers",
)
parser.add_argument(
"--build-dir",
dest="build_dir",
type=Path,
default=Path("build"),
help="base build directory",
)
args = parser.parse_args() args = parser.parse_args()
# On Windows, we need this to use && in commands # On Windows, we need this to use && in commands
ALLOW_CHAIN = "cmd /c " if os.name == "nt" else "" chain = "cmd /c " if os.name == "nt" else ""
out = io.StringIO() out = io.StringIO()
n = ninja_syntax.Writer(out) n = ninja_syntax.Writer(out)
@ -1108,34 +1126,36 @@ if __name__ == "__main__":
if os.name != "nt" and "DEVKITPPC" in os.environ and not args.devkitppc: if os.name != "nt" and "DEVKITPPC" in os.environ and not args.devkitppc:
configure_args.extend(["--devkitppc", os.environ["DEVKITPPC"]]) configure_args.extend(["--devkitppc", os.environ["DEVKITPPC"]])
n.variable("configure_args", configure_args) n.variable("configure_args", configure_args)
n.variable("python", sys.executable)
n.newline() n.newline()
### ###
# Variables # Variables
### ###
n.comment("Variables") n.comment("Variables")
n.variable("version", args.version.lower()) version = args.version.lower()
if args.version.lower() == "kor": if args.version.lower() == "kor":
n.variable("version_num", "2") version_num = "2"
elif args.version.isnumeric() and int(args.version) in [0, 1]: elif args.version.isnumeric() and int(args.version) in [0, 1]:
n.variable("version_num", args.version) version_num = args.version
else: else:
sys.exit(f'Invalid version "{args.version}"') sys.exit(f'Invalid version "{args.version}"')
n.variable("builddir", "build/mp1.$version") n.variable("out", args.build_dir / f"mp1.{version}")
build_path = Path("$out")
if args.devkitppc: if args.devkitppc:
n.variable("devkitppc", args.devkitppc) dkp_path = args.devkitppc
elif os.name == "nt": elif os.name == "nt":
n.variable("devkitppc", "C:\devkitPro\devkitPPC") dkp_path = Path("C:\devkitPro\devkitPPC")
elif "DEVKITPPC" in os.environ: elif "DEVKITPPC" in os.environ:
n.variable("devkitppc", os.environ["DEVKITPPC"]) dkp_path = Path(os.environ["DEVKITPPC"])
else: else:
n.variable("devkitppc", "/opt/devkitpro/devkitPPC") dkp_path = Path("/opt/devkitpro/devkitPPC")
cflags_base = "-proc gekko -nodefaults -Cpp_exceptions off -RTTI off -fp hard -fp_contract on -O4,p -maxerrors 1 -enum int -inline auto -str reuse -nosyspath -MMD -DPRIME1 -DVERSION=$version_num -DNONMATCHING=0 -i include/ -i libc/"
cflags_base = f"-proc gekko -nodefaults -Cpp_exceptions off -RTTI off -fp hard -fp_contract on -O4,p -maxerrors 1 -enum int -inline auto -str reuse -nosyspath -MMD -DPRIME1 -DVERSION={version_num} -DNONMATCHING=0 -i include -i libc"
if args.debug: if args.debug:
cflags_base += " -sym on -D_DEBUG" cflags_base += " -sym on -D_DEBUG"
else: else:
cflags_base += " -DNDEBUG" cflags_base += " -DNDEBUG"
n.variable("cflags_base", cflags_base) n.variable("cflags_base", cflags_base)
n.variable( n.variable(
"cflags_retro", "cflags_retro",
@ -1146,72 +1166,110 @@ if __name__ == "__main__":
"$cflags_base -use_lmw_stmw on -str reuse,pool,readonly -gccinc -inline deferred,auto", "$cflags_base -use_lmw_stmw on -str reuse,pool,readonly -gccinc -inline deferred,auto",
) )
n.variable("cflags_musyx", "$cflags_base -str reuse,pool,readonly -fp_contract off") n.variable("cflags_musyx", "$cflags_base -str reuse,pool,readonly -fp_contract off")
asflags = "-mgekko -I include/ --defsym version=$version_num -W --strip-local-absolute -gdwarf-2" asflags = f"-mgekko -I include --defsym version={version_num} -W --strip-local-absolute -gdwarf-2"
n.variable("asflags", asflags) n.variable("asflags", asflags)
ldflags = "-fp fmadd -nodefaults -lcf ldscript.lcf" ldflags = "-fp fmadd -nodefaults -lcf ldscript.lcf"
if args.map: if args.map:
ldflags += " -map $builddir/MetroidPrime.MAP" map_path = build_path / "MetroidPrime.MAP"
ldflags += f" -map {map_path}"
if args.debug:
ldflags += " -g"
n.variable("ldflags", ldflags) n.variable("ldflags", ldflags)
n.variable("mwcc_version", "1.3.2") n.variable("mw_version", "1.3.2")
n.variable("python", sys.executable)
if os.name == "nt": if os.name == "nt":
n.variable("exe", ".exe") exe = ".exe"
wine = ""
else: else:
if "_NT-" in os.uname().sysname: if "_NT-" in os.uname().sysname:
# MSYS2 # MSYS2
n.variable("wine", "") wine = ""
elif args.wine: elif args.wine:
n.variable("wine", args.wine + " ") wine = f"{args.wine} "
elif which("wibo") is not None: elif which("wibo") is not None:
n.variable("wine", "wibo ") wine = "wibo "
else: else:
n.variable("wine", "wine ") wine = "wine "
n.variable("exe", "") exe = ""
n.newline()
###
# Tooling
###
n.comment("decomp-toolkit")
tools_path = Path("tools")
build_tools_path = args.build_dir / "tools"
def path(input: list[Path] | Path | None) -> list[str] | None:
if input is None:
return None
elif isinstance(input, list):
return list(map(str, input))
else:
return [str(input)]
if args.build_dtk:
dtk = build_tools_path / "release" / f"dtk{exe}"
n.rule(
name="cargo",
command="cargo build --release --manifest-path $in --bin $bin --target-dir $target",
description="CARGO $bin",
depfile=path(Path("$target") / "release" / "$bin.d"),
deps="gcc",
)
n.build(
outputs=path(dtk),
rule="cargo",
inputs=path(args.build_dtk / "Cargo.toml"),
variables={
"bin": "dtk",
"target": build_tools_path,
},
)
else:
dtk = build_tools_path / f"dtk{exe}"
download_dtk = tools_path / "download_dtk.py"
n.rule(
name="download_dtk",
command=f"$python {download_dtk} $in $out",
description="DOWNLOAD $out",
)
n.build(
outputs=path(dtk),
rule="download_dtk",
inputs="dtk_version",
implicit=path([download_dtk]),
)
n.newline() n.newline()
### ###
# Rules # Rules
### ###
if os.name == "nt": compiler_path = args.compilers / "$mw_version"
mwcc_command = "tools\\mwcc_compiler\\$mwcc_version\\mwcceppc.exe $cflags -c $in -o $basedir" mwcc = compiler_path / "mwcceppc.exe"
mwcc_frank_command = ( mwld = compiler_path / "mwldeppc.exe"
ALLOW_CHAIN franklite = tools_path / "franklite.py"
+ "tools\\mwcc_compiler\\$mwcc_version\\mwcceppc.exe $cflags -c $in -o $basedir && " gnu_as = dkp_path / "bin" / f"powerpc-eabi-as{exe}"
+ "$python tools/franklite.py $out $out"
) mwcc_cmd = f"{chain}{wine}{mwcc} $cflags -c $in -o $basedir"
link_elf_command = "tools\\mwcc_compiler\\$mwcc_version\\mwldeppc.exe $ldflags -o $out @$out.rsp" mwcc_frank_cmd = f"{mwcc_cmd} && $python {franklite} $out $out"
assemble_asm_command = ( mwld_cmd = f"{wine}{mwld} $ldflags -o $out @$out.rsp"
ALLOW_CHAIN as_cmd = (
+ "$devkitppc\\bin\\powerpc-eabi-as.exe $asflags -o $out $in -MD $out.d" f"{chain}{gnu_as} $asflags -o $out $in -MD $out.d"
+ " && $dtk elf fixup $out $out" + f" && {dtk} elf fixup $out $out"
) )
ar_cmd = f"{dtk} ar create $out @$out.rsp"
if os.name != "nt":
transform_dep = tools_path / "transform-dep.py"
transform_dep_cmd = f" && $python {transform_dep} $basefile.d $basefile.d"
mwcc_cmd += transform_dep_cmd
mwcc_frank_cmd += transform_dep_cmd
n.comment("Link ELF file") n.comment("Link ELF file")
n.rule( n.rule(
name="link", name="link",
command=link_elf_command, command=mwld_cmd,
description="LINK $out",
rspfile="$out.rsp",
rspfile_content="$in",
)
n.newline()
else:
mwcc_command = "${wine}tools/mwcc_compiler/$mwcc_version/mwcceppc.exe $cflags -c $in -o $basedir && $python tools/transform-dep.py $basefile.d $basefile.d"
mwcc_frank_command = (
"${wine}tools/mwcc_compiler/$mwcc_version/mwcceppc.exe $cflags -c $in -o $basedir && "
+ "$python tools/franklite.py $out $out && "
+ "$python tools/transform-dep.py $basefile.d $basefile.d"
)
link_elf_command = "${wine}tools/mwcc_compiler/$mwcc_version/mwldeppc.exe $ldflags -o $out @$out.rsp"
assemble_asm_command = (
"$devkitppc/bin/powerpc-eabi-as $asflags -o $out $in -MD $out.d"
+ " && $dtk elf fixup $out $out"
)
n.comment("Link ELF file")
n.rule(
name="link",
command=link_elf_command,
description="LINK $out", description="LINK $out",
rspfile="$out.rsp", rspfile="$out.rsp",
rspfile_content="$in_newline", rspfile_content="$in_newline",
@ -1221,7 +1279,7 @@ if __name__ == "__main__":
n.comment("MWCC build") n.comment("MWCC build")
n.rule( n.rule(
name="mwcc", name="mwcc",
command=mwcc_command, command=mwcc_cmd,
description="MWCC $out", description="MWCC $out",
depfile="$basefile.d", depfile="$basefile.d",
deps="gcc", deps="gcc",
@ -1231,7 +1289,7 @@ if __name__ == "__main__":
n.comment("MWCC build with franklite") n.comment("MWCC build with franklite")
n.rule( n.rule(
name="mwcc_frank", name="mwcc_frank",
command=mwcc_frank_command, command=mwcc_frank_cmd,
description="FRANK $out", description="FRANK $out",
depfile="$basefile.d", depfile="$basefile.d",
deps="gcc", deps="gcc",
@ -1241,7 +1299,7 @@ if __name__ == "__main__":
n.comment("Assemble asm") n.comment("Assemble asm")
n.rule( n.rule(
name="as", name="as",
command=assemble_asm_command, command=as_cmd,
description="AS $out", description="AS $out",
depfile="$out.d", depfile="$out.d",
deps="gcc", deps="gcc",
@ -1251,7 +1309,7 @@ if __name__ == "__main__":
n.comment("Create static library") n.comment("Create static library")
n.rule( n.rule(
name="ar", name="ar",
command="$dtk ar create $out @$out.rsp", command=ar_cmd,
description="AR $out", description="AR $out",
rspfile="$out.rsp", rspfile="$out.rsp",
rspfile_content="$in_newline", rspfile_content="$in_newline",
@ -1259,65 +1317,37 @@ if __name__ == "__main__":
n.newline() n.newline()
n.comment("Host build") n.comment("Host build")
n.variable("host_cflags", "-I include/ -Wno-trigraphs") n.variable("host_cflags", "-I include -Wno-trigraphs")
n.variable( n.variable(
"host_cppflags", "host_cppflags",
"-std=c++98 -I include/ -fno-exceptions -fno-rtti -D_CRT_SECURE_NO_WARNINGS -Wno-trigraphs -Wno-c++11-extensions", "-std=c++98 -I include -fno-exceptions -fno-rtti -D_CRT_SECURE_NO_WARNINGS -Wno-trigraphs -Wno-c++11-extensions",
) )
n.rule( n.rule(
name="host_cc", name="host_cc",
command="clang $host_cflags -c -o $out $in", command="clang $host_cflags -c -o $out $in",
description="host_cc $out", description="CC $out",
) )
n.rule( n.rule(
name="host_cpp", name="host_cpp",
command="clang++ $host_cppflags -c -o $out $in", command="clang++ $host_cppflags -c -o $out $in",
description="host_c++ $out", description="CXX $out",
) )
n.newline() n.newline()
###
# Tooling
###
n.comment("decomp-toolkit")
if args.build_dtk:
n.variable("dtk", os.path.join("build", "tools", "release", "dtk$exe"))
n.rule(
name="cargo",
command="cargo build --release --manifest-path $in --bin $bin --target-dir $target",
description="CARGO $bin",
depfile="$target/release/$bin.d",
deps="gcc",
)
n.build(
outputs="$dtk",
rule="cargo",
inputs=os.path.join(args.build_dtk, "Cargo.toml"),
variables={
"bin": "dtk",
"target": os.path.join("build", "tools"),
},
)
else:
n.variable("dtk", os.path.join("build", "tools", "dtk$exe"))
n.rule(
name="download_dtk",
command="$python tools/download_dtk.py $in $out",
description="DOWNLOAD $out",
)
n.build(
outputs="$dtk",
rule="download_dtk",
inputs="dtk_version",
implicit=["tools/download_dtk.py"],
)
### ###
# Rules for source files # Rules for source files
### ###
n.comment("Source files") n.comment("Source files")
all_source_files = [] src_path = Path("src")
all_host_source_files = [] asm_path = Path("asm")
build_src_path = build_path / "src"
build_host_path = build_path / "host"
build_asm_path = build_path / "asm"
build_lib_path = build_path / "lib"
source_inputs = []
host_source_inputs = []
link_inputs = []
for lib in LIBS: for lib in LIBS:
inputs = [] inputs = []
if "lib" in lib: if "lib" in lib:
@ -1325,6 +1355,7 @@ if __name__ == "__main__":
n.comment(f"{lib_name}.a") n.comment(f"{lib_name}.a")
else: else:
n.comment("Loose files") n.comment("Loose files")
for object in lib["objects"]: for object in lib["objects"]:
completed = None completed = None
add_to_all = True add_to_all = True
@ -1337,104 +1368,85 @@ if __name__ == "__main__":
completed = object[1] completed = object[1]
object = object[0] object = object[0]
mwcc_version = lib["mwcc_version"] mw_version = lib["mw_version"]
c_file = None c_file = None
if os.path.exists(os.path.join("src", f"{object}.cpp")): if os.path.exists(src_path / f"{object}.cpp"):
c_file = os.path.join("src", f"{object}.cpp") c_file = src_path / f"{object}.cpp"
elif os.path.exists(os.path.join("src", f"{object}.c")): elif os.path.exists(src_path / f"{object}.c"):
c_file = os.path.join("src", f"{object}.c") c_file = src_path / f"{object}.c"
if c_file is not None: if c_file is not None:
if completed is None: if completed is None:
print(f"Mark as incomplete: {c_file}") print(f"Mark as incomplete: {c_file}")
rule = "mwcc" rule = "mwcc"
if mwcc_version == "1.2.5e": if mw_version == "1.2.5e":
mwcc_version = "1.2.5" mw_version = "1.2.5"
if no_frank is False: if no_frank is False:
rule = "mwcc_frank" rule = "mwcc_frank"
n.build( n.build(
outputs=f"$builddir/src/{object}.o", outputs=path(build_src_path / f"{object}.o"),
rule=rule, rule=rule,
inputs=c_file, inputs=path(c_file),
variables={ variables={
"mwcc_version": mwcc_version, "mw_version": mw_version,
"cflags": lib["cflags"], "cflags": lib["cflags"],
"basedir": os.path.dirname(f"$builddir/src/{object}"), "basedir": os.path.dirname(build_src_path / f"{object}"),
"basefile": f"$builddir/src/{object}", "basefile": path(build_src_path / f"{object}"),
}, },
) )
if lib["host"]: if lib["host"]:
n.build( n.build(
outputs=f"$builddir/host/{object}.o", outputs=path(build_host_path / f"{object}.o"),
rule="host_cc" if c_file.endswith(".c") else "host_cpp", rule="host_cc" if c_file.suffix == ".c" else "host_cpp",
inputs=c_file, inputs=path(c_file),
variables={ variables={
"basedir": os.path.dirname(f"$builddir/src/{object}"), "basedir": os.path.dirname(build_host_path / object),
"basefile": f"$builddir/src/{object}", "basefile": path(build_host_path / object),
}, },
) )
n.build(
outputs=f"host/{c_file}",
rule="phony",
inputs=f"$builddir/host/{object}.o",
)
if add_to_all: if add_to_all:
all_host_source_files.append(f"$builddir/host/{object}.o") host_source_inputs.append(build_host_path / f"{object}.o")
if add_to_all: if add_to_all:
all_source_files.append(f"$builddir/src/{object}.o") source_inputs.append(build_src_path / f"{object}.o")
if os.path.exists(os.path.join("asm", f"{object}.s")): if os.path.exists(asm_path / f"{object}.s"):
n.build( n.build(
outputs=f"$builddir/asm/{object}.o", outputs=path(build_asm_path / f"{object}.o"),
rule="as", rule="as",
inputs=f"asm/{object}.s", inputs=path(asm_path / f"{object}.s"),
implicit="$dtk", implicit=path(dtk),
) )
if completed: if completed:
inputs.append(f"$builddir/src/{object}.o") inputs.append(build_src_path / f"{object}.o")
else: else:
inputs.append(f"$builddir/asm/{object}.o") inputs.append(build_asm_path / f"{object}.o")
if args.static_libs and "lib" in lib: if args.static_libs and "lib" in lib:
lib_name = lib["lib"] lib_name = lib["lib"]
n.build( n.build(
outputs=f"$builddir/lib/{lib_name}.a", outputs=path(build_lib_path / f"{lib_name}.a"),
rule="ar", rule="ar",
inputs=inputs, inputs=path(inputs),
implicit="$dtk", implicit=path(dtk),
) )
link_inputs.append(build_lib_path / f"{lib_name}.a")
else:
link_inputs.extend(inputs)
n.newline() n.newline()
### ###
# Link # Link
### ###
n.comment("Link") n.comment("Link")
inputs = []
for lib in LIBS:
if args.static_libs and "lib" in lib:
lib_name = lib["lib"]
inputs.append(f"$builddir/lib/{lib_name}.a")
else:
for object in lib["objects"]:
completed = False
if type(object) is list:
completed = object[1]
object = object[0]
if completed:
inputs.append(f"$builddir/src/{object}.o")
else:
inputs.append(f"$builddir/asm/{object}.o")
if args.map: if args.map:
n.build( n.build(
outputs="$builddir/main.elf", outputs=path(build_path / "main.elf"),
rule="link", rule="link",
inputs=inputs, inputs=path(link_inputs),
implicit_outputs="$builddir/MetroidPrime.MAP", implicit_outputs=path(map_path),
) )
else: else:
n.build( n.build(
outputs="$builddir/main.elf", outputs=path(build_path / "main.elf"),
rule="link", rule="link",
inputs=inputs, inputs=path(link_inputs),
) )
n.newline() n.newline()
@ -1445,7 +1457,7 @@ if __name__ == "__main__":
n.build( n.build(
outputs="all_source", outputs="all_source",
rule="phony", rule="phony",
inputs=all_source_files, inputs=path(source_inputs),
) )
n.newline() n.newline()
@ -1456,7 +1468,7 @@ if __name__ == "__main__":
n.build( n.build(
outputs="all_source_host", outputs="all_source_host",
rule="phony", rule="phony",
inputs=all_host_source_files, inputs=path(host_source_inputs),
) )
n.newline() n.newline()
@ -1466,16 +1478,16 @@ if __name__ == "__main__":
n.comment("Generate DOL") n.comment("Generate DOL")
n.rule( n.rule(
name="elf2dol", name="elf2dol",
command=ALLOW_CHAIN command=chain
+ "$dtk elf2dol $in $out && " + f"{dtk} elf2dol $in $out && "
+ "$dtk metroidbuildinfo $out buildstrings/mp1.$version.build", + f"{dtk} metroidbuildinfo $out buildstrings/mp1.{version}.build",
description="DOL $out", description="DOL $out",
) )
n.build( n.build(
outputs="$builddir/main.dol", outputs=path(build_path / "main.dol"),
rule="elf2dol", rule="elf2dol",
inputs="$builddir/main.elf", inputs=path(build_path / "main.elf"),
implicit="$dtk", implicit=path(dtk),
) )
n.newline() n.newline()
@ -1486,14 +1498,14 @@ if __name__ == "__main__":
n.comment("Check DOL hash") n.comment("Check DOL hash")
n.rule( n.rule(
name="check", name="check",
command="$dtk shasum -c $in -o $out", command=f"{dtk} shasum -c $in -o $out",
description="CHECK $in", description="CHECK $in",
) )
n.build( n.build(
outputs="$builddir/main.dol.ok", outputs=path(build_path / "main.dol.ok"),
rule="check", rule="check",
inputs="sha1/mp1.$version.sha1", inputs=f"sha1/mp1.{version}.sha1",
implicit=["$builddir/main.dol", "$dtk"], implicit=path([build_path / "main.dol", dtk]),
) )
n.newline() n.newline()
@ -1508,9 +1520,9 @@ if __name__ == "__main__":
description="PROGRESS $in", description="PROGRESS $in",
) )
n.build( n.build(
outputs="$builddir/main.dol.progress", outputs=path(build_path / "main.dol.progress"),
rule="progress", rule="progress",
inputs=["$builddir/main.dol", "$builddir/MetroidPrime.MAP"], inputs=path([build_path / "main.dol", map_path]),
implicit="progress.py", implicit="progress.py",
) )
n.newline() n.newline()
@ -1536,13 +1548,13 @@ if __name__ == "__main__":
### ###
n.comment("Default rule") n.comment("Default rule")
if args.check: if args.check:
dol_out = "$builddir/main.dol.ok" dol_out = build_path / "main.dol.ok"
else: else:
dol_out = "$builddir/main.dol" dol_out = build_path / "main.dol"
if args.map: if args.map:
n.default([dol_out, "$builddir/main.dol.progress"]) n.default(path([dol_out, build_path / "main.dol.progress"]))
else: else:
n.default([dol_out]) n.default(path([dol_out]))
with open("build.ninja", "w") as f: with open("build.ninja", "w") as f:
f.write(out.getvalue()) f.write(out.getvalue())

View File

@ -1,6 +1,6 @@
#!/bin/bash -e #!/bin/bash -e
VERSION="${VERSION:=0}" VERSION="${VERSION:=0}"
OBJDUMP="$DEVKITPPC/bin/powerpc-eabi-objdump -D -bbinary -EB -mpowerpc -M gekko" OBJDUMP="$DEVKITPPC/bin/powerpc-eabi-objdump -Dz -bbinary -EB -mpowerpc -M gekko"
if [ ! -z "$1" ]; then if [ ! -z "$1" ]; then
OPTIONS="--start-address=$(($1)) --stop-address=$(($2))" OPTIONS="--start-address=$(($1)) --stop-address=$(($2))"
fi fi