#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Build the referees from the pinned source trees into reference/build/. - ``nba_sst``: NanoBoyAdvance's ARM7TDMI (Codeberg master ``e8482c1``) on stand-in Bus and Scheduler headers, run one SingleStepTests case at a time. It records every bus cycle NBA makes, internal ones included, which the corpus does not. Since 2026-11-25 (decisions page T3) it is built outside this repository, with NBA's source, by emu-tools-gpl's nanoboyadvance tool (GPL-3.0-or-later): this runs ``$EMU_TOOLS_GPL/tools/nanoboyadvance/build.py --machine arm7tdmi-sst`` as a program, and the referee lands at ``$EMU_TOOLS_GPL/tools/nanoboyadvance/build/arm7tdmi-sst/nba_sst`` (``EMU_TOOLS_GPL`` names a checkout of emu-tools-gpl); without it this referee is skipped and the others are built. - ``reference/build/mul_model.so``: zayd's Booth-multiplier model (``multiplication-algorithm``) behind ``referees/multiply/mul_model.c``, for ``scripts/multiply_model.py``. - ``mgba_disasm``: mGBA's ARM and Thumb disassembler (``src/arm/decoder*.c`` at ``fd9dc5c``) behind our MPL-2.0 ``mgba_disasm.c``, for ``scripts/disasm_judge.py``. Since 2026-11-25 (decisions page T3) the driver, mGBA's source and the build are outside this repository, in emu-tools-gpl's mgba tool: this runs ``$EMU_TOOLS_GPL/tools/mgba/build.py --machine arm-disasm`` as a program, and the disassembler lands at ``$EMU_TOOLS_GPL/tools/mgba/build/arm-disasm/mgba_disasm``; without ``EMU_TOOLS_GPL`` it is skipped. Needs ``g++`` with C++20 (GCC 11 or newer) and ``gcc``. Takes about 20 seconds. python scripts/fetch_references.py --no-repos # (once) then the trees: python scripts/fetch_references.py python scripts/build_referees.py python scripts/referee_sst.py # score NBA against the corpus python scripts/multiply_model.py # the corpus's multiplies against the model python scripts/disasm_judge.py # the disassembler against mGBA and MAME """ from __future__ import annotations import os import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] BUILD = ROOT / "reference" / "build" # The NBA referee is a GPL tool built outside the repository (referees/README.md), at a # fixed path under the emu-tools-gpl checkout that EMU_TOOLS_GPL names. NBA_BUILD = Path("tools") / "nanoboyadvance" / "build.py" MGBA_BUILD = Path("tools") / "mgba" / "build.py" def build_nba() -> int: root = os.environ.get("EMU_TOOLS_GPL") script = Path(root) / NBA_BUILD if root else None if script is None or not script.exists(): print( f"skipping nba_sst: set EMU_TOOLS_GPL (its build is $EMU_TOOLS_GPL/{NBA_BUILD})", file=sys.stderr, ) return 0 command = [sys.executable, "-I", str(script), "--machine", "arm7tdmi-sst"] return subprocess.run(command, check=False).returncode def build_multiply() -> int: source = ROOT / "reference" / "src" / "multiplication-algorithm" if not (source / "impl.h").exists(): print("multiplication-algorithm is not fetched", file=sys.stderr) return 1 BUILD.mkdir(parents=True, exist_ok=True) command = [ "gcc", "-O2", "-shared", "-fPIC", f"-I{source}", str(ROOT / "referees" / "multiply" / "mul_model.c"), "-o", str(BUILD / "mul_model.so"), ] print(" ".join(command)) result = subprocess.run(command, check=False) if result.returncode == 0: print(f"built {(BUILD / 'mul_model.so').relative_to(ROOT)}") return result.returncode def build_mgba_disasm() -> int: root = os.environ.get("EMU_TOOLS_GPL") script = Path(root) / MGBA_BUILD if root else None if script is None or not script.exists(): print( f"skipping mgba_disasm: set EMU_TOOLS_GPL (its build is $EMU_TOOLS_GPL/{MGBA_BUILD})", file=sys.stderr, ) return 0 command = [sys.executable, "-I", str(script), "--machine", "arm-disasm"] return subprocess.run(command, check=False).returncode def main() -> int: return build_nba() or build_multiply() or build_mgba_disasm() if __name__ == "__main__": sys.exit(main())