2023-10-05 03:26:02 +00:00
|
|
|
#!/usr/bin/env python3
|
|
|
|
|
|
|
|
###
|
|
|
|
# Generates build files for the project.
|
|
|
|
# This file also includes the project configuration,
|
|
|
|
# such as compiler flags and the object matching status.
|
|
|
|
#
|
|
|
|
# Usage:
|
|
|
|
# python3 configure.py
|
|
|
|
# ninja
|
|
|
|
#
|
|
|
|
# Append --help to see available options.
|
|
|
|
###
|
|
|
|
|
|
|
|
import argparse
|
2024-03-05 01:13:10 +00:00
|
|
|
import sys
|
2023-10-05 03:26:02 +00:00
|
|
|
from pathlib import Path
|
2024-03-05 01:13:10 +00:00
|
|
|
from typing import Any, Dict, List
|
2024-09-04 14:55:19 +00:00
|
|
|
from tools.project import *
|
2023-10-05 03:26:02 +00:00
|
|
|
|
|
|
|
# Game versions
|
|
|
|
DEFAULT_VERSION = 0
|
|
|
|
VERSIONS = [
|
2024-01-24 06:21:46 +00:00
|
|
|
"GAMEID", # 0
|
2023-10-05 03:26:02 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
parser = argparse.ArgumentParser()
|
|
|
|
parser.add_argument(
|
|
|
|
"mode",
|
2024-03-05 01:13:10 +00:00
|
|
|
choices=["configure", "progress"],
|
2023-10-05 03:26:02 +00:00
|
|
|
default="configure",
|
2024-03-05 01:13:10 +00:00
|
|
|
help="script mode (default: configure)",
|
2023-10-05 03:26:02 +00:00
|
|
|
nargs="?",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2024-05-17 00:32:30 +00:00
|
|
|
"-v",
|
2023-10-05 03:26:02 +00:00
|
|
|
"--version",
|
2024-03-05 01:13:10 +00:00
|
|
|
choices=VERSIONS,
|
|
|
|
type=str.upper,
|
2023-10-05 03:26:02 +00:00
|
|
|
default=VERSIONS[DEFAULT_VERSION],
|
2024-03-05 05:13:39 +00:00
|
|
|
help="version to build",
|
2023-10-05 03:26:02 +00:00
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--build-dir",
|
2024-03-05 01:13:10 +00:00
|
|
|
metavar="DIR",
|
2023-10-05 03:26:02 +00:00
|
|
|
type=Path,
|
|
|
|
default=Path("build"),
|
|
|
|
help="base build directory (default: build)",
|
|
|
|
)
|
2024-03-04 05:47:05 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--binutils",
|
2024-03-05 01:13:10 +00:00
|
|
|
metavar="BINARY",
|
2024-03-04 05:47:05 +00:00
|
|
|
type=Path,
|
|
|
|
help="path to binutils (optional)",
|
|
|
|
)
|
2023-10-05 03:26:02 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--compilers",
|
2024-03-05 01:13:10 +00:00
|
|
|
metavar="DIR",
|
2023-10-05 03:26:02 +00:00
|
|
|
type=Path,
|
|
|
|
help="path to compilers (optional)",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--map",
|
|
|
|
action="store_true",
|
|
|
|
help="generate map file(s)",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--debug",
|
|
|
|
action="store_true",
|
|
|
|
help="build with debug info (non-matching)",
|
|
|
|
)
|
|
|
|
if not is_windows():
|
|
|
|
parser.add_argument(
|
|
|
|
"--wrapper",
|
2024-03-05 01:13:10 +00:00
|
|
|
metavar="BINARY",
|
2023-10-05 03:26:02 +00:00
|
|
|
type=Path,
|
|
|
|
help="path to wibo or wine (optional)",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
2024-03-05 01:13:10 +00:00
|
|
|
"--dtk",
|
|
|
|
metavar="BINARY | DIR",
|
2023-10-05 03:26:02 +00:00
|
|
|
type=Path,
|
2024-03-05 01:13:10 +00:00
|
|
|
help="path to decomp-toolkit binary or source (optional)",
|
2023-10-05 03:26:02 +00:00
|
|
|
)
|
2024-08-13 00:09:10 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--objdiff",
|
|
|
|
metavar="BINARY | DIR",
|
|
|
|
type=Path,
|
|
|
|
help="path to objdiff-cli binary or source (optional)",
|
|
|
|
)
|
2023-10-05 03:26:02 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--sjiswrap",
|
2024-03-05 01:13:10 +00:00
|
|
|
metavar="EXE",
|
2023-10-05 03:26:02 +00:00
|
|
|
type=Path,
|
|
|
|
help="path to sjiswrap.exe (optional)",
|
|
|
|
)
|
|
|
|
parser.add_argument(
|
|
|
|
"--verbose",
|
|
|
|
action="store_true",
|
|
|
|
help="print verbose output",
|
|
|
|
)
|
2024-05-18 20:50:32 +00:00
|
|
|
parser.add_argument(
|
|
|
|
"--non-matching",
|
|
|
|
dest="non_matching",
|
|
|
|
action="store_true",
|
|
|
|
help="builds equivalent (but non-matching) or modded objects",
|
|
|
|
)
|
2023-10-05 03:26:02 +00:00
|
|
|
args = parser.parse_args()
|
|
|
|
|
|
|
|
config = ProjectConfig()
|
2024-05-18 20:50:32 +00:00
|
|
|
config.version = str(args.version)
|
2023-10-05 03:26:02 +00:00
|
|
|
version_num = VERSIONS.index(config.version)
|
|
|
|
|
|
|
|
# Apply arguments
|
|
|
|
config.build_dir = args.build_dir
|
2024-03-05 01:13:10 +00:00
|
|
|
config.dtk_path = args.dtk
|
2024-08-13 00:09:10 +00:00
|
|
|
config.objdiff_path = args.objdiff
|
2024-03-04 05:47:05 +00:00
|
|
|
config.binutils_path = args.binutils
|
2023-10-05 03:26:02 +00:00
|
|
|
config.compilers_path = args.compilers
|
|
|
|
config.debug = args.debug
|
|
|
|
config.generate_map = args.map
|
2024-05-18 20:50:32 +00:00
|
|
|
config.non_matching = args.non_matching
|
2023-10-05 03:26:02 +00:00
|
|
|
config.sjiswrap_path = args.sjiswrap
|
|
|
|
if not is_windows():
|
|
|
|
config.wrapper = args.wrapper
|
2024-08-13 00:08:26 +00:00
|
|
|
# Don't build asm unless we're --non-matching
|
|
|
|
if not config.non_matching:
|
2024-03-05 05:13:39 +00:00
|
|
|
config.asm_dir = None
|
2023-10-05 03:26:02 +00:00
|
|
|
|
|
|
|
# Tool versions
|
2024-03-04 05:47:05 +00:00
|
|
|
config.binutils_tag = "2.42-1"
|
2024-08-13 00:09:10 +00:00
|
|
|
config.compilers_tag = "20240706"
|
2024-09-05 02:34:10 +00:00
|
|
|
config.dtk_tag = "v0.9.5"
|
2024-09-04 14:55:19 +00:00
|
|
|
config.objdiff_tag = "v2.0.0-beta.5"
|
2023-10-05 03:26:02 +00:00
|
|
|
config.sjiswrap_tag = "v1.1.1"
|
2024-06-24 04:31:59 +00:00
|
|
|
config.wibo_tag = "0.6.11"
|
2023-10-05 03:26:02 +00:00
|
|
|
|
|
|
|
# Project
|
|
|
|
config.config_path = Path("config") / config.version / "config.yml"
|
|
|
|
config.check_sha_path = Path("config") / config.version / "build.sha1"
|
2024-03-04 05:47:05 +00:00
|
|
|
config.asflags = [
|
|
|
|
"-mgekko",
|
|
|
|
"--strip-local-absolute",
|
|
|
|
"-I include",
|
|
|
|
f"-I build/{config.version}/include",
|
|
|
|
f"--defsym version={version_num}",
|
|
|
|
]
|
2023-10-05 03:26:02 +00:00
|
|
|
config.ldflags = [
|
|
|
|
"-fp hardware",
|
|
|
|
"-nodefaults",
|
2023-11-22 01:14:13 +00:00
|
|
|
# "-listclosure", # Uncomment for Wii linkers
|
2023-10-05 03:26:02 +00:00
|
|
|
]
|
2024-05-18 20:50:32 +00:00
|
|
|
# Use for any additional files that should cause a re-configure when modified
|
|
|
|
config.reconfig_deps = []
|
2023-10-05 03:26:02 +00:00
|
|
|
|
|
|
|
# Base flags, common to most GC/Wii games.
|
|
|
|
# Generally leave untouched, with overrides added below.
|
|
|
|
cflags_base = [
|
|
|
|
"-nodefaults",
|
|
|
|
"-proc gekko",
|
|
|
|
"-align powerpc",
|
|
|
|
"-enum int",
|
|
|
|
"-fp hardware",
|
|
|
|
"-Cpp_exceptions off",
|
|
|
|
# "-W all",
|
|
|
|
"-O4,p",
|
|
|
|
"-inline auto",
|
|
|
|
'-pragma "cats off"',
|
|
|
|
'-pragma "warn_notinlined off"',
|
|
|
|
"-maxerrors 1",
|
|
|
|
"-nosyspath",
|
|
|
|
"-RTTI off",
|
|
|
|
"-fp_contract on",
|
|
|
|
"-str reuse",
|
2024-01-24 06:21:46 +00:00
|
|
|
"-multibyte", # For Wii compilers, replace with `-enc SJIS`
|
2023-11-26 05:45:22 +00:00
|
|
|
"-i include",
|
|
|
|
f"-i build/{config.version}/include",
|
2023-10-05 03:26:02 +00:00
|
|
|
f"-DVERSION={version_num}",
|
|
|
|
]
|
|
|
|
|
2024-09-07 08:18:53 +00:00
|
|
|
# Conditionally-added flags
|
|
|
|
if config.generate_map:
|
|
|
|
# List unused symbols when generating a map file
|
|
|
|
config.ldflags.append("-mapunused")
|
|
|
|
|
2023-10-05 03:26:02 +00:00
|
|
|
if config.debug:
|
2024-09-07 08:18:53 +00:00
|
|
|
# Debug flags
|
2023-10-05 03:26:02 +00:00
|
|
|
cflags_base.extend(["-sym on", "-DDEBUG=1"])
|
2024-09-07 08:18:53 +00:00
|
|
|
config.ldflags.append("-g")
|
2023-10-05 03:26:02 +00:00
|
|
|
else:
|
2024-09-07 08:18:53 +00:00
|
|
|
# No-debug flags
|
2023-10-05 03:26:02 +00:00
|
|
|
cflags_base.append("-DNDEBUG=1")
|
|
|
|
|
|
|
|
# Metrowerks library flags
|
|
|
|
cflags_runtime = [
|
|
|
|
*cflags_base,
|
|
|
|
"-use_lmw_stmw on",
|
|
|
|
"-str reuse,pool,readonly",
|
|
|
|
"-gccinc",
|
|
|
|
"-common off",
|
2024-01-24 06:21:46 +00:00
|
|
|
"-inline auto",
|
2023-10-05 03:26:02 +00:00
|
|
|
]
|
|
|
|
|
|
|
|
# REL flags
|
|
|
|
cflags_rel = [
|
|
|
|
*cflags_base,
|
|
|
|
"-sdata 0",
|
|
|
|
"-sdata2 0",
|
|
|
|
]
|
|
|
|
|
2023-11-22 01:14:13 +00:00
|
|
|
config.linker_version = "GC/1.3.2"
|
2023-10-05 03:26:02 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Helper function for Dolphin libraries
|
2024-01-24 06:21:46 +00:00
|
|
|
def DolphinLib(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
|
2023-10-05 03:26:02 +00:00
|
|
|
return {
|
|
|
|
"lib": lib_name,
|
2023-11-22 01:14:13 +00:00
|
|
|
"mw_version": "GC/1.2.5n",
|
2023-10-05 03:26:02 +00:00
|
|
|
"cflags": cflags_base,
|
2024-09-04 14:55:19 +00:00
|
|
|
"progress_category": "sdk",
|
2023-10-05 03:26:02 +00:00
|
|
|
"objects": objects,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# Helper function for REL script objects
|
2024-01-24 06:21:46 +00:00
|
|
|
def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
|
2023-10-05 03:26:02 +00:00
|
|
|
return {
|
|
|
|
"lib": lib_name,
|
2023-11-22 01:14:13 +00:00
|
|
|
"mw_version": "GC/1.3.2",
|
2023-10-05 03:26:02 +00:00
|
|
|
"cflags": cflags_rel,
|
2024-09-04 14:55:19 +00:00
|
|
|
"progress_category": "game",
|
2023-10-05 03:26:02 +00:00
|
|
|
"objects": objects,
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2024-05-18 20:50:32 +00:00
|
|
|
Matching = True # Object matches and should be linked
|
|
|
|
NonMatching = False # Object does not match and should not be linked
|
|
|
|
Equivalent = config.non_matching # Object should be linked when configured with --non-matching
|
2023-10-05 03:26:02 +00:00
|
|
|
|
|
|
|
config.warn_missing_config = True
|
|
|
|
config.warn_missing_source = False
|
|
|
|
config.libs = [
|
|
|
|
{
|
|
|
|
"lib": "Runtime.PPCEABI.H",
|
|
|
|
"mw_version": config.linker_version,
|
|
|
|
"cflags": cflags_runtime,
|
2024-09-04 14:55:19 +00:00
|
|
|
"progress_category": "sdk", # str | List[str]
|
2023-10-05 03:26:02 +00:00
|
|
|
"objects": [
|
|
|
|
Object(NonMatching, "Runtime.PPCEABI.H/global_destructor_chain.c"),
|
|
|
|
Object(NonMatching, "Runtime.PPCEABI.H/__init_cpp_exceptions.cpp"),
|
|
|
|
],
|
|
|
|
},
|
|
|
|
]
|
|
|
|
|
2024-09-04 14:55:19 +00:00
|
|
|
# Optional extra categories for progress tracking
|
|
|
|
# Adjust as desired for your project
|
|
|
|
config.progress_categories = [
|
|
|
|
ProgressCategory("game", "Game Code"),
|
|
|
|
ProgressCategory("sdk", "SDK Code"),
|
|
|
|
]
|
|
|
|
config.progress_each_module = args.verbose
|
|
|
|
|
2023-10-05 03:26:02 +00:00
|
|
|
if args.mode == "configure":
|
|
|
|
# Write build.ninja and objdiff.json
|
|
|
|
generate_build(config)
|
|
|
|
elif args.mode == "progress":
|
|
|
|
# Print progress and write progress.json
|
|
|
|
calculate_progress(config)
|
|
|
|
else:
|
|
|
|
sys.exit("Unknown mode: " + args.mode)
|