#!/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. 3. ``picodrive``: a full clone of the pinned PicoDrive revision with its submodules, built as the libretro core (``reference/build/picodrive/``). PicoDrive runs testpico with no boot ROMs at all (its built-in replacement), which is why it is the first referee; ``scripts/libretro_frames.py`` drives the core. Not built here, on purpose: - **jgenesis** compiles Sega's three 32X boot ROMs into its binary (``include_bytes!`` of ``backend/s32x-core/src/*.bin``), so building it means fetching them. Its pin leaves them out; it is read as source, a detector by reading. - **ares** 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()) def full_clone(name: str, target: Path) -> None: if target.exists(): return entry = REPOS[name] run("git", "clone", "-q", "--filter=blob:none", entry["url"], target) run("git", "-C", target, "checkout", "-q", entry["rev"]) run("git", "-C", target, "submodule", "update", "-q", "--init", "--recursive", "--depth", "1") def picodrive() -> None: target = BUILD / "picodrive" full_clone("picodrive", target) if list(target.glob("picodrive_libretro.so")): return run("make", "-f", "Makefile.libretro", f"-j{os.cpu_count() or 4}", cwd=target) STEPS = {"toolchain": toolchain, "testpico": testpico, "picodrive": picodrive} 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())