#!/bin/sh # SPDX-License-Identifier: GPL-3.0-or-later # Fetch the four Nuked chip models at their pins into upstream/ (git-ignored) and build the # harness family into build/ (git-ignored), with the flags the consumers used (-O2 -w; the # warnings would quote the models' source). Writes build/build-info.json for the manifest. # # ./build.sh fetch what is missing, build all six harnesses # CC=clang ./build.sh another compiler # # No patches: each harness calls only what its model's public header declares. Never deletes # anything: a checkout at another commit with local changes stops the script. set -eu HERE=$(cd "$(dirname "$0")" && pwd) UP=$HERE/upstream OUT=$HERE/build CC=${CC:-cc} CFLAGS=${CFLAGS:--O2 -w} fetch() { # name url commit dir=$UP/$1 if [ ! -d "$dir/.git" ]; then git clone --quiet "$2" "$dir" fi if [ "$(git -C "$dir" rev-parse HEAD)" != "$3" ]; then if [ -n "$(git -C "$dir" status --porcelain)" ]; then echo "build.sh: $dir has local changes and is not at $3; move it aside first" >&2 exit 1 fi git -C "$dir" fetch --quiet origin git -C "$dir" -c advice.detachedHead=false checkout --quiet "$3" fi } mkdir -p "$UP" "$OUT" fetch Nuked-OPN2 https://github.com/nukeykt/Nuked-OPN2 335747d78cb0abbc3b55b004e62dad9763140115 fetch Nuked-OPLL https://github.com/nukeykt/Nuked-OPLL 1269cf5a783b65583b50fa2464d08be75830aaa0 fetch Nuked-PSG https://github.com/nukeykt/Nuked-PSG d15a168c676f4669e23660be9225b34ad7c1764e fetch Nuked-OPM https://github.com/nukeykt/Nuked-OPM f209e6ed3712032b641d53ce8fb24824eae6adc3 harness() { # binary source model model.c $CC $CFLAGS -I "$UP/$3" -o "$OUT/$1" "$HERE/src/$2" "$UP/$3/$4" echo "built $OUT/$1 ($3 @ $(git -C "$UP/$3" rev-parse --short HEAD))" } harness opn2-stream opn2_stream.c Nuked-OPN2 ym3438.c harness opn2-events opn2_events.c Nuked-OPN2 ym3438.c harness opll-stream opll_stream.c Nuked-OPLL opll.c harness psg-stream psg_stream.c Nuked-PSG ympsg.c harness psg-events psg_events.c Nuked-PSG ympsg.c harness opm-events opm_events.c Nuked-OPM opm.c printf '{"compiler": "%s", "cflags": "%s", "built": "%s", "upstreams": {' \ "$($CC --version | head -n 1)" "$CFLAGS" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" > "$OUT/build-info.json" sep="" for name in Nuked-OPN2 Nuked-OPLL Nuked-PSG Nuked-OPM; do printf '%s"%s": "%s"' "$sep" "$name" "$(git -C "$UP/$name" rev-parse HEAD)" >> "$OUT/build-info.json" sep=", " done printf '}}\n' >> "$OUT/build-info.json"