#!/usr/bin/env python3 # SPDX-License-Identifier: GPL-2.0-only """Fetch Atari800 at its pin and build libatari800.so, the library the driver loads. python3 -I build.py # build/libatari800.so python3 -I build.py --version # atari800-build 0.1.0 (Atari800 98cc2dc) JOBS=2 python3 -I build.py # parallel jobs for make (default 2) Part of the atari800 tool in emu-tools-gpl2 (README.md; GPL-2.0-only). The recipe was moved here on 2026-11-25 (decisions page T3) from a5200-python's docs/validation.md ("Atari800 build recipe"), where alewman first wrote it under MIT (``../../notices/MIT-emulator-family.txt``), and it builds the library that recipe built: 1. ``./autogen.sh`` in the fetched tree, then ``configure --target=libatari800`` with ``CFLAGS="-O2 -fPIC"`` in ``build/obj``; 2. ``make CFLAGS="-O2 -fPIC -DNETSIO"`` (overriding ``CFLAGS`` drops the ``-Werror`` configure appends, on which gcc 15 stops at a redefined ``ULONG``; ``-DNETSIO`` is kept); 3. a shared library linked from the archive's members: the first eight from ``src/libatari800/``, the rest each by its first path under ``src`` (the archive holds three ``sound.o`` and two each of ``input.o``, ``video.o``, ``statesav.o``, so it cannot be linked whole), with pthreads and libm. The recipe took "its first path" from ``find``; here the paths are sorted first, so the choice does not depend on the directory order. The source is fetched with git at the pin (shallow) into ``upstream/atari800`` (autogen needs a tree it can write); the build lands in ``build/``. Both are git-ignored; Atari800 is never committed. ``build/build-info.json`` records the pin and the options. Exit status as the family's tool contract says: 0 built (or already built), 2 a usage error, 3 the source could not be fetched, anything else a failed build. Nothing is ever deleted. """ from __future__ import annotations import json import os import subprocess import sys import time from pathlib import Path TOOL, VERSION = "atari800-build", "0.1.0" HERE = Path(__file__).resolve().parent SOURCE = HERE / "upstream" / "atari800" BUILD = HERE / "build" OBJ = BUILD / "obj" LIBRARY = BUILD / "libatari800.so" REPOSITORY = "https://github.com/atari800/atari800" PIN = "98cc2dc749867c9c7317a0271ba062a6c797f886" # 2026-10-20 EXIT_OK, EXIT_USAGE, EXIT_MISSING = 0, 2, 3 NICE = ["nice", "-n", "10"] CONFIGURE_CFLAGS = "-O2 -fPIC" MAKE_CFLAGS = "-O2 -fPIC -DNETSIO" FIRST = ("api.o", "main.o", "init.o", "exit.o", "input.o", "video.o", "statesav.o", "sound.o") def run(command: list[str], cwd: Path, env: dict | None = None) -> None: print("+", " ".join(command), flush=True) if subprocess.run(NICE + command, cwd=cwd, env=env).returncode: raise SystemExit(1) def fetch() -> None: if (SOURCE / ".complete").exists(): return if SOURCE.exists(): raise SystemExit(f"{SOURCE} is incomplete (an interrupted fetch?): move it aside first") SOURCE.mkdir(parents=True) git = ["git", "-C", str(SOURCE)] try: for command in ( [*git, "init", "-q"], [*git, "remote", "add", "origin", REPOSITORY], [*git, "fetch", "-q", "--depth", "1", "origin", PIN], [*git, "-c", "advice.detachedHead=false", "checkout", "-q", "FETCH_HEAD"], ): subprocess.run(command, check=True) except (OSError, subprocess.CalledProcessError) as error: print(f"could not fetch {REPOSITORY} at {PIN}: {error}", file=sys.stderr) raise SystemExit(EXIT_MISSING) from error (SOURCE / ".complete").write_text(PIN + "\n") def build() -> Path: if LIBRARY.exists(): print(f"already built: {LIBRARY}") return LIBRARY fetch() jobs = os.environ.get("JOBS", "2") if not (SOURCE / "configure").exists(): run(["./autogen.sh"], SOURCE) OBJ.mkdir(parents=True, exist_ok=True) env = dict(os.environ, CFLAGS=CONFIGURE_CFLAGS) run([str(SOURCE / "configure"), "--target=libatari800"], OBJ, env) run(["make", f"-j{jobs}", f"CFLAGS={MAKE_CFLAGS}"], OBJ) src = OBJ / "src" members = subprocess.run(["ar", "t", str(src / "libatari800.a")], capture_output=True, text=True, check=True).stdout.split() # fmt: skip objects = [src / "libatari800" / name for name in FIRST] seen: set[str] = set() for name in members[len(FIRST):]: if name in seen: continue seen.add(name) found = sorted(p for p in src.rglob(name) if "libatari800" not in p.relative_to(src).parts) if not found: raise SystemExit(f"{name}: in the archive but not under {src}") objects.append(found[0]) run(["gcc", "-shared", "-o", str(LIBRARY), *map(str, objects), "-lpthread", "-lm"], src) info = { "tool": TOOL, "tool_version": VERSION, "upstream": {"name": "Atari800", "url": REPOSITORY, "commit": PIN}, "configure": ["--target=libatari800", f"CFLAGS={CONFIGURE_CFLAGS}"], "make": [f"CFLAGS={MAKE_CFLAGS}"], "objects": len(objects), "was": "a5200-python docs/validation.md, Atari800 build recipe", "built": time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime()), } (BUILD / "build-info.json").write_text(json.dumps(info, indent=1) + "\n") print(f"built {LIBRARY}") return LIBRARY def main(argv: list[str]) -> int: if argv == ["--version"]: print(f"{TOOL} {VERSION} (Atari800 {PIN[:7]})") return EXIT_OK if argv: print("usage: python3 -I build.py [--version]", file=sys.stderr) return EXIT_USAGE build() return EXIT_OK if __name__ == "__main__": raise SystemExit(main(sys.argv[1:]))