dtk-template/configure.py

294 lines
6.9 KiB
Python
Raw Normal View History

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-18 01:21:54 +00:00
from tools.project import (
Object,
ProgressCategory,
ProjectConfig,
calculate_progress,
generate_build,
is_windows,
)
2023-10-05 03:26:02 +00:00
# Game versions
DEFAULT_VERSION = 0
VERSIONS = [
"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],
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)",
)
parser.add_argument(
"--binutils",
2024-03-05 01:13:10 +00:00
metavar="BINARY",
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
)
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",
)
parser.add_argument(
"--non-matching",
dest="non_matching",
action="store_true",
help="builds equivalent (but non-matching) or modded objects",
)
parser.add_argument(
"--no-progress",
dest="progress",
action="store_false",
help="disable progress calculation",
)
2023-10-05 03:26:02 +00:00
args = parser.parse_args()
config = ProjectConfig()
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
config.objdiff_path = args.objdiff
config.binutils_path = args.binutils
2023-10-05 03:26:02 +00:00
config.compilers_path = args.compilers
config.generate_map = args.map
config.non_matching = args.non_matching
2023-10-05 03:26:02 +00:00
config.sjiswrap_path = args.sjiswrap
config.progress = args.progress
2023-10-05 03:26:02 +00:00
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:
config.asm_dir = None
2023-10-05 03:26:02 +00:00
# Tool versions
config.binutils_tag = "2.42-1"
config.compilers_tag = "20240706"
2024-11-24 07:16:24 +00:00
config.dtk_tag = "v1.3.0"
config.objdiff_tag = "v2.4.0"
config.sjiswrap_tag = "v1.2.0"
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"
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",
]
2024-09-07 15:27:42 +00:00
if args.debug:
config.ldflags.append("-g") # Or -gdwarf-2 for Wii linkers
if args.map:
config.ldflags.append("-mapunused")
# config.ldflags.append("-listclosure") # For Wii linkers
# Use for any additional files that should cause a re-configure when modified
config.reconfig_deps = []
2023-10-05 03:26:02 +00:00
# Optional numeric ID for decomp.me preset
# Can be overridden in libraries or objects
config.scratch_preset_id = None
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",
"-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 15:27:42 +00:00
# Debug flags
if args.debug:
# Or -sym dwarf-2 for Wii compilers
2023-10-05 03:26:02 +00:00
cflags_base.extend(["-sym on", "-DDEBUG=1"])
else:
cflags_base.append("-DNDEBUG=1")
# Metrowerks library flags
cflags_runtime = [
*cflags_base,
"-use_lmw_stmw on",
"-str reuse,pool,readonly",
"-gccinc",
"-common off",
"-inline auto",
2023-10-05 03:26:02 +00:00
]
# REL flags
cflags_rel = [
*cflags_base,
"-sdata 0",
"-sdata2 0",
]
config.linker_version = "GC/1.3.2"
2023-10-05 03:26:02 +00:00
# Helper function for Dolphin libraries
def DolphinLib(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
2023-10-05 03:26:02 +00:00
return {
"lib": lib_name,
"mw_version": "GC/1.2.5n",
2023-10-05 03:26:02 +00:00
"cflags": cflags_base,
"progress_category": "sdk",
2023-10-05 03:26:02 +00:00
"objects": objects,
}
# Helper function for REL script objects
def Rel(lib_name: str, objects: List[Object]) -> Dict[str, Any]:
2023-10-05 03:26:02 +00:00
return {
"lib": lib_name,
"mw_version": "GC/1.3.2",
2023-10-05 03:26:02 +00:00
"cflags": cflags_rel,
"progress_category": "game",
2023-10-05 03:26:02 +00:00
"objects": objects,
}
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
2024-10-17 04:52:23 +00:00
# Object is only matching for specific versions
def MatchingFor(*versions):
return config.version in versions
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,
"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"),
],
},
]
# 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)