forge/build.sh
2026-10-06 16:57:52 -05:00

56 lines
2.4 KiB
Bash
Executable file

#!/usr/bin/env bash
# Builds Forge: the vocabulary chapter from the manifest in forge/Author.singe, the book as
# build/Forge.html and build/Forge.pdf, and the distributable build/Forge.game -- forge/ with the
# book and four samples beside it, packed by Singe's own --pack. Singe is not part of this
# project: point SINGE at the engine binary to pack with, or leave it to find the newest build in a
# Singe tree beside this one.
#
# ./build.sh uses ../singe/.builddir/Singe-v*-Linux-x86_64
# SINGE=/path/to/Singe-v3.00-Linux-x86_64 ./build.sh
#
# Needs lua5.4, asciidoctor and asciidoctor-pdf. The version comes from VERSION: four numbers,
# patch 1 meaning a beta and tweak saying which, so 1.00.1.1 is "1.00b1", as Singe numbers itself.
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
out=$here/build
singe=${SINGE:-$(ls -t "$here"/../singe/.builddir/Singe-v*-Linux-x86_64 2>/dev/null | head -1)}
for tool in lua5.4 asciidoctor asciidoctor-pdf; do
if ! command -v "$tool" > /dev/null; then
echo "error: $tool not found" >&2
exit 1
fi
done
if [[ -z $singe || ! -x $singe ]]; then
echo "error: no Singe binary; set SINGE to the engine to pack with" >&2
exit 1
fi
read -r major minor patch tweak <<< "$(tr '.' ' ' < "$here/VERSION")"
if [[ $patch == 1 ]]; then
version="${major}.${minor}b${tweak}"
else
version="${major}.${minor}"
fi
mkdir -p "$out"
# The vocabulary tables come from the manifest itself, so the book cannot drift from it.
(cd "$here" && lua5.4 util/forgeVocabulary.lua > docs/ForgeVocabulary.adoc)
asciidoctor -a data-uri -a revnumber="$version" "$here/docs/Forge.adoc" -o "$out/Forge.html"
asciidoctor-pdf -a revnumber="$version" "$here/docs/Forge.adoc" -o "$out/Forge.pdf"
# The package: the scripts, the kit, the tutorials, the book, and the samples that need no art
# beyond what Singe ships, so the chooser has something to open on a fresh install. Packing
# refuses to overwrite, and it runs in the staging folder because Singe writes Singe/ and data/ into
# its working directory.
stage=$out/stage
rm -rf "$stage" "$out/Forge.game"
mkdir -p "$stage"
cp -r "$here/forge" "$stage/Forge"
cp "$out/Forge.pdf" "$stage/Forge/"
cp "$here"/testScripts/author/{platformer,breakout,qte,fmv}.forge "$stage/Forge/"
(cd "$stage" && "$singe" --pack "$stage/Forge" "$out/Forge.game")
rm -rf "$stage"
echo "Forge $version, packed with $singe:"
ls -la "$out/Forge.html" "$out/Forge.pdf" "$out/Forge.game"