#!/usr/bin/env bash
# build-opl.sh: opl.wasm from Nuked OPL3 (nuked-opl3/, unmodified) and opl-shim.c. Needs clang and wasm-ld:
#   nix-shell -p llvmPackages.clang-unwrapped llvmPackages.lld --run ./build-opl.sh      (or: npm run build-opl)
# opl.wasm is checked in, so building the page does not need clang.
set -euo pipefail
cd "$(dirname "$0")"
clang --target=wasm32 -O2 -nostdlib -nostdlibinc -isystem nuked-opl3/include -ffreestanding \
  -fno-builtin -Wall -Wno-unused-function \
  -Wl,--no-entry -Wl,--strip-all -Wl,--export-memory -Wl,-z,stack-size=65536 -Wl,--initial-memory=262144 \
  -o opl.wasm opl-shim.c nuked-opl3/opl3.c
ls -l opl.wasm
