100 lines
4.9 KiB
Bash
Executable file
100 lines
4.9 KiB
Bash
Executable file
#!/usr/bin/env bash
|
|
# Build the four books: the user manual (docs/Manual.adoc, which ships inside the binary), the
|
|
# programming reference (docs/Reference.adoc), the Forge manual (docs/Forge.adoc), and the
|
|
# beginner's course (docs/Learn.adoc). Produces .builddir/<Book>.html and .pdf for each, and then
|
|
# packs the three books that do not ship in the binary, with the lesson files and the licence, into
|
|
# .builddir/Singe-Docs-v<version>.zip, the optional documentation download. The version comes from
|
|
# CMakeLists.txt.
|
|
#
|
|
# ./build-docs.sh the books as they ship
|
|
# ./build-docs.sh preview the same, with PREVIEW across every page, for proofreaders; the
|
|
# download is then named -preview so it cannot be mistaken for a
|
|
# release, and the binary's own copy of the manual (rendered by
|
|
# CMake, not here) is never touched.
|
|
set -euo pipefail
|
|
|
|
here=$(cd "$(dirname "$0")" && pwd)
|
|
preview=
|
|
suffix=
|
|
if [[ "${1:-}" == "preview" ]]; then
|
|
preview=1
|
|
suffix=-preview
|
|
elif [[ -n "${1:-}" ]]; then
|
|
echo "usage: $0 [preview]" >&2
|
|
exit 2
|
|
fi
|
|
src=$here/docs/Manual.adoc
|
|
forge=$here/docs/Forge.adoc
|
|
learn=$here/docs/Learn.adoc
|
|
ref=$here/docs/Reference.adoc
|
|
|
|
for doc in "$src" "$forge" "$learn" "$ref"; do
|
|
if [[ ! -f $doc ]]; then
|
|
echo "error: $doc not found" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
for tool in asciidoctor asciidoctor-pdf lua5.4 zip; do
|
|
if ! command -v "$tool" > /dev/null; then
|
|
echo "error: $tool not found (gem install asciidoctor asciidoctor-pdf rouge)" >&2
|
|
exit 1
|
|
fi
|
|
done
|
|
|
|
# The version, from the four numbers of the project() line: patch 1 means a beta and tweak says
|
|
# which, so 3.00.1.2 is the books' "3.00b2", exactly as the binary is named.
|
|
read -r major minor patch tweak <<< "$(sed -n 's/^project(singe2 VERSION \([0-9]*\)\.\([0-9]*\)\.\([0-9]*\)\.\([0-9]*\).*/\1 \2 \3 \4/p' "$here/CMakeLists.txt")"
|
|
if [[ $patch == 1 ]]; then
|
|
version="${major}.${minor}b${tweak}"
|
|
else
|
|
version="${major}.${minor}"
|
|
fi
|
|
|
|
# The watermark, when asked for: a page background for the PDFs, a head snippet for the HTML.
|
|
pdfOpts=()
|
|
# The HTML pages carry their pictures inside them (data-uri), so a page is one file wherever it is
|
|
# copied and the download needs no images folder beside it.
|
|
htmlOpts=(-a data-uri)
|
|
if [[ -n $preview ]]; then
|
|
pdfOpts=(-a "page-background-image=image:$here/docs/images/preview.svg[fit=fill]")
|
|
htmlOpts+=(-a docinfo=shared -a "docinfodir=$here/docs/preview")
|
|
fi
|
|
|
|
out=$here/.builddir
|
|
mkdir -p "$out"
|
|
# The Forge vocabulary tables come from the manifest itself, so the manual cannot drift from it.
|
|
lua5.4 "$here/util/forgeVocabulary.lua" > "$here/docs/ForgeVocabulary.adoc"
|
|
asciidoctor ${htmlOpts[@]+"${htmlOpts[@]}"} -a revnumber="$version" "$src" -o "$out/Manual.html"
|
|
asciidoctor-pdf ${pdfOpts[@]+"${pdfOpts[@]}"} -a revnumber="$version" "$src" -o "$out/Manual.pdf"
|
|
asciidoctor ${htmlOpts[@]+"${htmlOpts[@]}"} -a revnumber="$version" "$forge" -o "$out/Forge.html"
|
|
asciidoctor-pdf ${pdfOpts[@]+"${pdfOpts[@]}"} -a revnumber="$version" "$forge" -o "$out/Forge.pdf"
|
|
asciidoctor ${htmlOpts[@]+"${htmlOpts[@]}"} -a revnumber="$version" "$learn" -o "$out/Learn.html"
|
|
asciidoctor-pdf ${pdfOpts[@]+"${pdfOpts[@]}"} -a revnumber="$version" "$learn" -o "$out/Learn.pdf"
|
|
asciidoctor ${htmlOpts[@]+"${htmlOpts[@]}"} -a revnumber="$version" "$ref" -o "$out/Reference.html"
|
|
asciidoctor-pdf ${pdfOpts[@]+"${pdfOpts[@]}"} -a revnumber="$version" "$ref" -o "$out/Reference.pdf"
|
|
|
|
# The documentation download: everything but the user manual, which the binary carries. Built in
|
|
# a staging folder so the zip has one top-level directory and no stray build files.
|
|
stage=$out/Singe-Docs-v$version$suffix
|
|
rm -rf "$stage" "$stage.zip"
|
|
mkdir -p "$stage/learn"
|
|
cp "$out/Reference.pdf" "$out/Reference.html" "$out/Forge.pdf" "$out/Forge.html" "$out/Learn.pdf" "$out/Learn.html" "$stage/"
|
|
cp -r "$here/docs/learn/." "$stage/learn/"
|
|
cp "$here/COPYING" "$stage/"
|
|
cat > "$stage/README.txt" <<EOF
|
|
Singe $version documentation
|
|
|
|
Reference.pdf / .html Everything a game can do: the programming model and every function.
|
|
Learn.pdf / .html Learn to Program with Singe: thirty lessons from nothing to a finished game.
|
|
Forge.pdf / .html Forge, the authoring tool: ten tutorials and the vocabulary.
|
|
learn/ The finished script of every lesson, and the art kit the lessons use.
|
|
COPYING The licence, GPL version 3.
|
|
|
|
The user manual, Manual.pdf, is inside Singe itself and is unpacked into the Singe folder the first
|
|
time it runs. Forge is a separate download.
|
|
EOF
|
|
(cd "$out" && zip -q -r "Singe-Docs-v$version$suffix.zip" "Singe-Docs-v$version$suffix")
|
|
rm -rf "$stage"
|
|
|
|
echo "built:"
|
|
ls -la "$out/Manual.html" "$out/Manual.pdf" "$out/Reference.html" "$out/Reference.pdf" "$out/Forge.html" "$out/Forge.pdf" "$out/Learn.html" "$out/Learn.pdf" "$out/Singe-Docs-v$version$suffix.zip"
|