#!/bin/sh # SPDX-License-Identifier: GPL-2.0-only # Fetch YM2608-LLE at its pin into upstream/ (git-ignored) and build both harnesses into build/ # (git-ignored), with the flags the consumers used (gcc -O2 -w; the warnings would quote the # model's source). Writes build/build-info.json for the manifest. # # ./build.sh fetch what is missing, build lle2610_probe and lle2612_ref # CC=clang ./build.sh another compiler (CFLAGS overrides the flags) # # The YM2610 build does not compile as published at this pin: patches/ym2610-build-fix.patch is # applied to a copy of the model in build/src-2610/, used for the YM2610 build only. The # YM2612 build compiles the fetched tree as published. Never deletes anything: a checkout at # another commit with local changes stops the script. set -eu HERE=$(cd "$(dirname "$0")" && pwd) UP=$HERE/upstream/YM2608-LLE OUT=$HERE/build URL=https://github.com/nukeykt/YM2608-LLE PIN=7a2aca7b6830b96e48e3a4e1a40d15525993fa60 CC=${CC:-gcc} CFLAGS=${CFLAGS:--O2 -w} mkdir -p "$HERE/upstream" "$OUT" if [ ! -d "$UP/.git" ]; then git clone --quiet "$URL" "$UP" fi if [ "$(git -C "$UP" rev-parse HEAD)" != "$PIN" ]; then if [ -n "$(git -C "$UP" status --porcelain)" ]; then echo "build.sh: $UP has local changes and is not at $PIN; move it aside first" >&2 exit 1 fi git -C "$UP" fetch --quiet origin git -C "$UP" -c advice.detachedHead=false checkout --quiet "$PIN" fi if [ -n "$(git -C "$UP" status --porcelain)" ]; then echo "build.sh: $UP has local changes; move it aside first" >&2 exit 1 fi # The YM2610 copy: refreshed from the pin on every build, then patched. copy=$OUT/src-2610 mkdir -p "$copy" cp "$UP"/*.h "$UP"/*.c "$copy/" # The hunk keeps the model's CRLF line ends; the count check makes sure exactly two lines went. patch --quiet --no-backup-if-mismatch -r - -d "$copy" -p1 < "$HERE/patches/ym2610-build-fix.patch" removed=$(( $(wc -l < "$UP/fmopna_impl.c") - $(wc -l < "$copy/fmopna_impl.c") )) [ "$removed" = 2 ] || { echo "build.sh: the patch removed $removed lines, expected 2" >&2; exit 1; } $CC --version | head -n 1 $CC $CFLAGS -I "$copy" -o "$OUT/lle2610_probe" "$HERE/lle2610_probe.c" "$copy/fmopna_2610.c" echo "built $OUT/lle2610_probe (YM2608-LLE @ ${PIN%"${PIN#???????}"}, YM2610 build, ym2610-build-fix.patch)" $CC $CFLAGS -I "$UP" -o "$OUT/lle2612_ref" "$HERE/lle2612_ref.c" "$UP/fmopna_2612.c" echo "built $OUT/lle2612_ref (YM2608-LLE @ ${PIN%"${PIN#???????}"}, YM2612 build)" printf '{"compiler": "%s", "cflags": "%s", "built": "%s", "upstream": "%s", "patches": {"lle2610_probe": ["ym2610-build-fix.patch"], "lle2612_ref": []}}\n' \ "$($CC --version | head -n 1)" "$CFLAGS" "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \ "$(git -C "$UP" rev-parse HEAD)" > "$OUT/build-info.json"