88 lines
4.6 KiB
Python
88 lines
4.6 KiB
Python
#!/usr/bin/env python3
|
|
# SPDX-License-Identifier: GPL-3.0-or-later
|
|
"""Compile the original VCC Plus guest libraries with the installed CMOC."""
|
|
import argparse
|
|
import hashlib
|
|
import json
|
|
import os
|
|
from pathlib import Path
|
|
import shutil
|
|
import subprocess
|
|
import tempfile
|
|
|
|
ROOT = Path(__file__).resolve().parents[2]
|
|
SDK = ROOT / "sdk/cmoc"
|
|
LIBRARIES = {"ssc": "ssc", "orch90": "orch90", "gime": "gime", "input": "input", "bank": "bank", "sdc": "sdc", "vcccompat": "compat"}
|
|
|
|
|
|
def stage(runtime):
|
|
manifest_file = runtime / "manifest.json"
|
|
manifest = json.loads(manifest_file.read_text())
|
|
env = dict(os.environ, PATH=str(runtime / "bin") + ":/usr/bin:/bin", LC_ALL="C",
|
|
VCC_CMOC_COMPAT="0")
|
|
with tempfile.TemporaryDirectory(dir="/tmp", prefix="vcc-sdk-") as tmp:
|
|
work = Path(tmp)
|
|
include = work / "include"
|
|
shutil.copytree(SDK / "include", include)
|
|
shutil.copytree(SDK / "compat/include", include / "vcc/compat")
|
|
# Build against the pinned public header even when the ROM library has
|
|
# not yet been staged in a fresh runtime. Only SDK headers ship here.
|
|
shutil.copyfile(ROOT / "third_party/cmoc-libraries/decbfile/decbfile.h", include / "decbfile.h")
|
|
payload = {}
|
|
for name, source in LIBRARIES.items():
|
|
folder = work / source
|
|
folder.mkdir()
|
|
objects = []
|
|
flags = ["-I" + str(include)]
|
|
if name == "vcccompat":
|
|
flags.insert(0, "-I" + str(include / "vcc/compat"))
|
|
for header in (SDK / source).glob("*.h"):
|
|
shutil.copyfile(header, folder / header.name)
|
|
for unit in sorted((SDK / source).glob("*.c")):
|
|
shutil.copyfile(unit, folder / unit.name)
|
|
obj = unit.stem + ".o"
|
|
subprocess.run([runtime / "bin/cmoc", "--coco", "-O2", "-Werror",
|
|
*flags, "-c", "-o", obj, unit.name],
|
|
cwd=folder, env=env, check=True)
|
|
objects.append(obj)
|
|
if not objects:
|
|
raise ValueError("No compilation units for " + name)
|
|
archive = folder / ("lib" + name + ".a")
|
|
subprocess.run([runtime / "bin/lwar", "--create", archive.name, *objects],
|
|
cwd=folder, env=env, check=True)
|
|
if name == "vcccompat":
|
|
headers = [*sorted((include / "vcc/compat").glob("*.h")),
|
|
include / "vcc/printer.h", include / "vcc/cassette.h", include / "vcc/decimal.h"]
|
|
else:
|
|
headers = [include / ("vcc/" + name + ".h")]
|
|
files = {"share/cmoc/lib/" + archive.name: archive, "LICENSES/VCC-Guest-SDK.txt": ROOT / "COPYING"}
|
|
files.update({"share/cmoc/include/" + h.relative_to(include).as_posix(): h for h in headers})
|
|
version = {"vcccompat": "0.14.0", "ssc": "0.2.0", "orch90": "0.2.0"}.get(name, "0.1.0")
|
|
manifest.setdefault("libraries", {})[name] = dict(version=version, profile="coco",
|
|
license="GPL-3.0-or-later", filesSHA256={k: hashlib.sha256(p.read_bytes()).hexdigest() for k, p in files.items()})
|
|
if name == "vcccompat":
|
|
manifest["libraries"][name].update(diskReadStreams=True, diskWriteStreams=True, diskStreamPositioning=True,
|
|
boundedHeap=True, integerConversions=True, reentrantTokenizer=True,
|
|
diskUpdateStreams=True, createAppendUpdateStreams=True, diskFormattedOutput=True,
|
|
diskStreamClearError=True, printerFormattedOutput=True,
|
|
cassetteTextFiles=True, diskFileManagement=True, fixedDecimal=True)
|
|
if name == "ssc":
|
|
manifest["libraries"][name]["storedSpeechAndEffects"] = True
|
|
if name == "orch90":
|
|
manifest["libraries"][name]["backgroundPlayback"] = True
|
|
payload.update(files)
|
|
for path, original in payload.items():
|
|
target = runtime / path
|
|
target.parent.mkdir(parents=True, exist_ok=True)
|
|
shutil.copyfile(original, target)
|
|
shutil.copyfile(ROOT / "tools/toolchain/cmoc-runtime.sh", runtime / "bin/cmoc")
|
|
temporary = manifest_file.with_suffix(".json.new")
|
|
temporary.write_text(json.dumps(manifest, indent=2) + "\n")
|
|
temporary.replace(manifest_file)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("runtime", type=Path)
|
|
stage(parser.parse_args().runtime.resolve())
|