#!/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/.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.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" <