Skip to content

Commit

Permalink
Support specifying a dtk binary
Browse files Browse the repository at this point in the history
  • Loading branch information
ribbanya committed Mar 4, 2024
1 parent 6debc74 commit eee3d38
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
44 changes: 18 additions & 26 deletions configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@
# Append --help to see available options.
###

import sys
import argparse

import sys
from pathlib import Path
from typing import Dict, List, Any
from typing import Any, Dict, List

from tools.project import (
Object,
ProjectConfig,
Expand All @@ -31,91 +31,83 @@
"GAMEID", # 0
]

if len(VERSIONS) > 1:
versions_str = ", ".join(VERSIONS[:-1]) + f" or {VERSIONS[-1]}"
else:
versions_str = VERSIONS[0]

parser = argparse.ArgumentParser()
parser.add_argument(
"mode",
choices=["configure", "progress"],
default="configure",
help="configure or progress (default: configure)",
help="script mode (default: configure)",
nargs="?",
)
parser.add_argument(
"--version",
dest="version",
choices=VERSIONS,
type=str.upper,
default=VERSIONS[DEFAULT_VERSION],
help=f"version to build ({versions_str})",
help=f"version to build",
)
parser.add_argument(
"--build-dir",
dest="build_dir",
metavar="DIR",
type=Path,
default=Path("build"),
help="base build directory (default: build)",
)
parser.add_argument(
"--binutils",
dest="binutils",
metavar="BINARY",
type=Path,
help="path to binutils (optional)",
)
parser.add_argument(
"--compilers",
dest="compilers",
metavar="DIR",
type=Path,
help="path to compilers (optional)",
)
parser.add_argument(
"--map",
dest="map",
action="store_true",
help="generate map file(s)",
)
parser.add_argument(
"--debug",
dest="debug",
action="store_true",
help="build with debug info (non-matching)",
)
if not is_windows():
parser.add_argument(
"--wrapper",
dest="wrapper",
metavar="BINARY",
type=Path,
help="path to wibo or wine (optional)",
)
parser.add_argument(
"--build-dtk",
dest="build_dtk",
"--dtk",
metavar="BINARY | DIR",
type=Path,
help="path to decomp-toolkit source (optional)",
help="path to decomp-toolkit binary or source (optional)",
)
parser.add_argument(
"--sjiswrap",
dest="sjiswrap",
metavar="EXE",
type=Path,
help="path to sjiswrap.exe (optional)",
)
parser.add_argument(
"--verbose",
dest="verbose",
action="store_true",
help="print verbose output",
)
args = parser.parse_args()

config = ProjectConfig()
config.version = args.version.upper()
if config.version not in VERSIONS:
sys.exit(f"Invalid version '{config.version}', expected {versions_str}")
config.version = args.version
version_num = VERSIONS.index(config.version)

# Apply arguments
config.build_dir = args.build_dir
config.build_dtk_path = args.build_dtk
config.dtk_path = args.dtk
config.binutils_path = args.binutils
config.compilers_path = args.compilers
config.debug = args.debug
Expand Down
15 changes: 7 additions & 8 deletions tools/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def __init__(self) -> None:
self.binutils_tag: Optional[str] = None # Git tag
self.binutils_path: Optional[Path] = None # If None, download
self.dtk_tag: Optional[str] = None # Git tag
self.build_dtk_path: Optional[Path] = None # If None, download
self.dtk_path: Optional[Path] = None # If None, download
self.compilers_tag: Optional[str] = None # 1
self.compilers_path: Optional[Path] = None # If None, download
self.wibo_tag: Optional[str] = None # Git tag
Expand All @@ -82,9 +82,9 @@ def __init__(self) -> None:
self.warn_missing_config: bool = False # Warn on missing unit configuration
self.warn_missing_source: bool = False # Warn on missing source file
self.rel_strip_partial: bool = True # Generate PLFs with -strip_partial
self.rel_empty_file: Optional[str] = (
None # Object name for generating empty RELs
)
self.rel_empty_file: Optional[
str
] = None # Object name for generating empty RELs
self.shift_jis = (
True # Convert source files from UTF-8 to Shift JIS automatically
)
Expand Down Expand Up @@ -242,7 +242,7 @@ def generate_build_ninja(
deps="gcc",
)

if config.build_dtk_path:
if config.dtk_path:
dtk = build_tools_path / "release" / f"dtk{EXE}"
n.rule(
name="cargo",
Expand All @@ -254,8 +254,8 @@ def generate_build_ninja(
n.build(
outputs=dtk,
rule="cargo",
inputs=config.build_dtk_path / "Cargo.toml",
implicit=config.build_dtk_path / "Cargo.lock",
inputs=config.dtk_path / "Cargo.toml",
implicit=config.dtk_path / "Cargo.lock",
variables={
"bin": "dtk",
"target": build_tools_path,
Expand Down Expand Up @@ -559,7 +559,6 @@ def write(self, n: ninja_syntax.Writer) -> None:
def c_build(
obj: Object, options: Dict[str, Any], lib_name: str, src_path: Path
) -> Optional[Path]:

cflags_str = make_flags_str(options["cflags"])
if options["extra_cflags"] is not None:
extra_cflags_str = make_flags_str(options["extra_cflags"])
Expand Down

0 comments on commit eee3d38

Please sign in to comment.