#!/usr/bin/env python3 # SPDX-License-Identifier: MIT """Build the referees from what scripts/fetch_references.py fetched, under reference/build/. No sudo, nothing installed outside reference/. Each step is skipped when its output exists. 1. ``toolchain``: unpack the pinned marsdev bundle (m68k-elf and sh-elf GCC, sjasm) into ``reference/build/mars/`` (needs ``fetch_references.py --large``). 2. ``testpico``: build notaz's testpico twice from ``reference/src/megadrive-notaz``, in a copy under ``reference/build/testpico/``: the hardware build (the one whose results notaz checked on his machine) and the ``PICO=1`` build he makes for PicoDrive. The board runs the hardware build; the other is for comparing. The closed-box detectors are not built here and their sources are not fetched (Aubrey, 2026-11-24): they run as shipped programs. PicoDrive and BlastEm are libretro cores, the files ``scripts/libretro_frames.py`` loads, placed by the user where ``PICODRIVE_CORE`` and ``BLASTEM_CORE`` say (``scripts/sweep.sh``; PicoDrive's default place is ``reference/build/picodrive/picodrive_libretro.so``). jgenesis, the MiSTer core and Gens are not used. Not built here either: - **ares** (ISC) is large (the whole multi-system tree and its GUI); it is read as source. - **MAME 0.285** is the system one (``/usr/games/mame``, drivers ``32x``, ``32xj``, ``32xe``, ``32x_scd``); it wants the boot ROMs as MAME's ``32x`` romset, which the user brings (docs/mame-oracle.md). python scripts/build_referees.py # every step python scripts/build_referees.py testpico # one step """ from __future__ import annotations import json import os import shutil import subprocess import sys from pathlib import Path ROOT = Path(__file__).resolve().parents[1] BUILD = ROOT / "reference" / "build" REPOS = { Path(e["path"]).name: e for e in json.loads((ROOT / "scripts" / "pinned_repos.json").read_text()) } MARS = BUILD / "mars" def run(*command: str | Path, cwd: Path | None = None, env: dict[str, str] | None = None) -> None: print("+", " ".join(str(part) for part in command), flush=True) subprocess.run([str(part) for part in command], cwd=cwd, env=env, check=True) def toolchain() -> None: if (MARS / "m68k-elf" / "bin" / "m68k-elf-gcc").exists(): return bundle = BUILD / "marsdev-v1.0.0-rc1-linux-x86_64.tar.xz" if not bundle.exists(): raise SystemExit(f"{bundle.name} missing: run scripts/fetch_references.py --large") run("tar", "-xJf", bundle, "-C", BUILD) def sjasm() -> None: """sjasm 0.42c: testpico's Z80 source needs it; marsdev's 0.39j rejects its macros.""" if (BUILD / "sjasm" / "bin" / "sjasm").exists(): return work = BUILD / "sjasm" run( "cmake", "-S", ROOT / "reference" / "src" / "sjasm", "-B", work / "cmake", "-DCMAKE_BUILD_TYPE=Release", ) run("cmake", "--build", work / "cmake", f"-j{os.cpu_count() or 4}") (work / "bin").mkdir(exist_ok=True) shutil.copy2(work / "cmake" / "sjasm", work / "bin" / "sjasm") def mars_env() -> dict[str, str]: env = dict(os.environ) # sjasm 0.42c first, ahead of marsdev's 0.39j. paths = [ BUILD / "sjasm" / "bin", MARS / "m68k-elf" / "bin", MARS / "sh-elf" / "bin", MARS / "bin", ] env["PATH"] = os.pathsep.join([*map(str, paths), env["PATH"]]) return env def testpico() -> None: toolchain() sjasm() source = ROOT / "reference" / "src" / "megadrive-notaz" / "testpico" for variant, extra in (("hardware", []), ("for-pd", ["PICO=1"])): work = BUILD / "testpico" / variant if list(work.glob("testpico-*.bin")): continue if work.exists(): shutil.rmtree(work) shutil.copytree(source, work) # The Makefile names the ROM after `git describe`; outside a repository that # is empty, so pass the pinned revision explicitly. rev = REPOS["megadrive-notaz"]["rev"][:7] suffix = rev + ("-for-pd" if extra else "") run("make", f"SUFFIX={suffix}", *extra, cwd=work, env=mars_env()) STEPS = {"toolchain": toolchain, "testpico": testpico} def main() -> int: wanted = sys.argv[1:] or list(STEPS) for name in wanted: print(f"== {name}") STEPS[name]() return 0 if __name__ == "__main__": sys.exit(main())