Files
makronix/docs/guide/build.sh
T
lotherk 632068d877 docs: bring the CNCL into the guide and explain it in the preface
Appendix C now contains the full CNCL 1.0 text, exactly as it is in
LICENSE (line-wrapped for the page), and the preface has a long section
that explains what the licence says, what it does not cover (NetBSD's
BSD licence, CDE/MCDE's LGPL, pkgsrc packages, Hack, DocBook) and why
Makronix uses a licence this short.

The same pass corrects the MCDE help claim: the cross-built MCDE
package has no help pages (options.mk turns docs off), so the
Information Manager holds this guide and no program help books.

Rebuilt all five forms: 67-page PDF, HTML, 27 manual pages, the dtinfo
library and www/guide.html.  check.sh green, test-tools 33 ok, 0 bad.
2026-11-16 08:32:32 +00:00

358 lines
12 KiB
Bash
Executable File

#!/bin/sh
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
#
# build.sh -- build The Makronix Guide.
#
# The guide has one source, docs/guide/book.xml with one file per chapter in
# docs/guide/chapters. This script derives the five forms from it:
#
# out/makronix-guide.html one self-contained HTML file (CSS and logo in it)
# out/makronix-guide.pdf the same page printed by Chrome
# out/man/*.7 one manual page per chapter and the index
# out/infolib/makronix.dti the MCDE Information Manager bookcase
#
# Usage: docs/guide/build.sh [all|html|pdf|man|infolib|check|install]
#
# The MCDE infolib step needs a host build of MCDE (make mcde-host); it uses
# build/mcde-root/dt/bin/dtdocbook2infolib.
set -eu
TOP=$(cd "$(dirname "$0")/../.." && pwd)
GUIDE=$TOP/docs/guide
OUT=$GUIDE/out
MCDE=$TOP/ext/src/mcde
ARCH=${ARCH:-amd64}
DESTDIR=${DESTDIR:-$TOP/build/obj/destdir.$ARCH}
DOCDIR=$TOP/src/share/doc/makronix
MANDIR=$TOP/src/share/man/man7
ETCDIR=$TOP/src/etc
WWW=$TOP/www
TMP=
cleanup()
{
[ -n "$TMP" ] && rm -rf "$TMP"
}
trap cleanup EXIT INT TERM
die()
{
echo "guide: $*" >&2
exit 1
}
find_tool()
{
for t in "$@"; do
if command -v "$t" >/dev/null 2>&1; then
command -v "$t"
return 0
fi
done
return 1
}
PANDOC=$(find_tool pandoc) || die "pandoc is not installed"
XMLLINT=$(find_tool xmllint) || die "xmllint is not installed"
MANDOC=$(find_tool mandoc) || die "mandoc is not installed"
PDFINFO=$(find_tool pdfinfo) || true
BASE64=$(find_tool base64) || die "base64 is not installed"
if [ -z "${CHROME:-}" ]; then
CHROME=$(find_tool google-chrome google-chrome-stable) || CHROME=
fi
find_mcde_bin()
{
for d in "$TOP/build/mcde-root/dt/bin" \
"$TOP/build/mcde-host-stage/usr/mdt/bin"; do
if [ -x "$d/dtdocbook2infolib" ] && [ -x "$d/dtsrcreate" ]; then
echo "$d"
return 0
fi
done
return 1
}
resolve_xml()
{
$XMLLINT --xinclude --noout "$GUIDE/book.xml" ||
die "book.xml does not resolve (XInclude or XML error)"
$XMLLINT --xinclude "$GUIDE/book.xml" > "$TMP/guide.xml"
}
write_template()
{
# The CSS is a plain file, not a pandoc variable: a stylesheet inside a
# template variable would be escaped. The logo goes in as a data URI so
# that the installed HTML is one file.
awk -v css="$GUIDE/style.css" '
/^@CSS@$/ {
while ((getline line < css) > 0) print line
close(css)
next
}
{ print }
' "$GUIDE/template.html5" > "$TMP/template.html5"
logo=$($BASE64 < "$TOP/docs/logo/makronix.png" | tr -d '\n')
awk -v logo="data:image/png;base64,$logo" '
{ gsub(/@LOGO@/, logo); print }
' "$TMP/template.html5" > "$TMP/template-html5"
}
build_html()
{
write_template
$PANDOC -f docbook -t html5 --standalone \
--toc --toc-depth=2 --syntax-highlighting=none \
--template="$TMP/template-html5" \
--metadata title="The Makronix Guide" \
--metadata subtitle="A guide to the Makronix operating system and the MCDE desktop" \
--metadata edition="Makronix 0.99.10 (Camouflage) -- November 2026" \
"$TMP/guide.xml" -o "$OUT/makronix-guide.html" ||
die "pandoc could not write the HTML"
[ -s "$OUT/makronix-guide.html" ] || die "empty HTML"
}
build_web()
{
$PANDOC -f docbook -t html4 --standalone \
--toc --toc-depth=1 --syntax-highlighting=none \
--template="$GUIDE/template-web.html" \
--metadata title="The Makronix Guide" \
--metadata subtitle="A guide to the Makronix operating system and the MCDE desktop" \
--metadata edition="Makronix 0.99.10 (Camouflage) -- November 2026" \
"$TMP/guide.xml" -o "$OUT/guide.html" ||
die "pandoc could not write the web page"
# HTML 4.01 Strict has no self-closing void elements.
sed -e 's|<br />|<br>|g' -e 's|<hr />|<hr>|g' \
"$OUT/guide.html" > "$OUT/guide.html.tmp" &&
mv "$OUT/guide.html.tmp" "$OUT/guide.html"
[ -s "$OUT/guide.html" ] || die "empty web page"
}
build_pdf()
{
[ -n "$CHROME" ] || die "Chrome (google-chrome or chromium) is required for the PDF"
[ -s "$OUT/makronix-guide.html" ] || build_html
rm -f "$OUT/makronix-guide.pdf"
"$CHROME" --headless=new --no-sandbox --disable-gpu \
--disable-dev-shm-usage --user-data-dir="$TMP/chrome" \
--no-pdf-header-footer \
--print-to-pdf="$OUT/makronix-guide.pdf" \
"file://$OUT/makronix-guide.html" >"$TMP/chrome.log" 2>&1 ||
{ cat "$TMP/chrome.log" >&2; die "Chrome could not print the PDF"; }
[ -s "$OUT/makronix-guide.pdf" ] || die "empty PDF"
}
upper()
{
printf '%s' "$1" | tr '[:lower:]' '[:upper:]'
}
build_man()
{
mkdir -p "$OUT/man"
: > "$TMP/man.index"
while IFS='|' read -r id title suffix file; do
case "$id" in ''|\#*) continue ;; esac
$XMLLINT --xinclude --xpath "//*[@id='$id']" "$TMP/guide.xml" \
> "$TMP/chapter.xml" ||
die "chapter $id not found in book.xml"
$PANDOC -f docbook -t man "$TMP/chapter.xml" > "$TMP/chapter.man" ||
die "pandoc could not write the man page for $id"
{
printf '.TH "%s" "7" "November 2026" "Makronix 0.99.10" "Makronix Guide"\n' \
"MAKRONIX-GUIDE-$(upper "$suffix")"
cat "$TMP/chapter.man"
} > "$OUT/man/makronix-guide-$suffix.7"
printf '%s|%s\n' "$suffix" "$title" >> "$TMP/man.index"
done < "$GUIDE/chapters.list"
{
printf '.TH "MAKRONIX-GUIDE" "7" "November 2026" "Makronix 0.99.10" "Makronix Guide"\n'
printf '.SH NAME\n'
printf 'makronix-guide \\- the Makronix Guide\n'
printf '.SH DESCRIPTION\n'
printf 'This is the guide to Makronix, a desktop operating system built on\n'
printf 'NetBSD, and to MCDE, its desktop. The guide has one chapter per\n'
printf 'manual page, and the same text is installed as a PDF and as an HTML\n'
printf 'file in\n'
printf '.I /usr/share/doc/makronix/\n'
printf '.PP\n'
printf 'The MCDE Information Manager\n'
printf '.Xr dtinfo 1\n'
printf 'opens the same text from its information library.\n'
printf '.SH CHAPTERS\n'
while IFS='|' read -r suffix title; do
printf '.TP\n'
printf '.B makronix-guide-%s(7)\n' "$suffix"
printf '%s\n' "$title"
done < "$TMP/man.index"
printf '.SH FILES\n'
printf '.TP\n'
printf '.I /usr/share/doc/makronix/makronix-guide.pdf\n'
printf 'The guide as a PDF.\n'
printf '.TP\n'
printf '.I /usr/share/doc/makronix/makronix-guide.html\n'
printf 'The guide as one HTML file.\n'
printf '.TP\n'
printf '.I /etc/dt/infolib/en_US.UTF-8/makronix.dti\n'
printf 'The guide as an MCDE information library.\n'
printf '.SH SEE ALSO\n'
printf '.BR dtinfo (1),\n'
printf '.BR man (1),\n'
printf '.BR afterboot (8)\n'
} > "$OUT/man/makronix-guide.7"
}
build_infolib()
{
MCDE_BIN=$(find_mcde_bin) ||
die "no host MCDE build (build/mcde-root/dt/bin); run make mcde-host first"
mkdir -p "$TMP/cde"
$PANDOC -f docbook -t "$GUIDE/tools/docbook-to-cde.lua" "$TMP/guide.xml" \
> "$TMP/cde/book.sgm" ||
die "the DocBook to CDE SGML writer failed"
grep -q '<Book>' "$TMP/cde/book.sgm" ||
die "the CDE writer produced no Book"
# A nested <para> is invalid in the CDE DTD; catch it here, not in dtinfo.
if grep -q '<para>[^<]*<para>' "$TMP/cde/book.sgm"; then
die "the CDE writer produced a nested para"
fi
cat > "$TMP/cde/bookcase.bc" <<EOF
<!DOCTYPE Bookcase PUBLIC "-//Common Desktop Environment//DTD DtInfo Bookcase Description//EN" [
<!ENTITY docsty SYSTEM "$MCDE/doc/common/docbook/docbook.stl">
<!ENTITY guideTOC SYSTEM "./TOC.sgm" SUBDOC>
<!ENTITY guide SYSTEM "./book.sgm" SUBDOC>
]>
<BOOKCASE StyleSheet="cdedoc">
<BOOKCASENAME>MAKRONIX</>
<BOOKCASEDESC>The Makronix Guide</>
&docsty;
<BOOK>
<TITLE>The Makronix Guide</>
<SHORTTITLE>Makronix Guide</>
<TOCFILE>&guideTOC;</>
<FILE>&guide;</>
</BOOK>
</BOOKCASE>
EOF
COMMON=$MCDE/doc/en_US.UTF-8/guides/common
PATH=$MCDE_BIN:$PATH
SGML_SEARCH_PATH=$TMP/cde:$MCDE/doc/en_US.UTF-8/guides:$MCDE/programs/dtdocbook/sgml
export PATH SGML_SEARCH_PATH
$MCDE_BIN/dtdocbook2infolib tocgen -L en_US.UTF-8 -T "$TMP/cde/toc" \
-m "$COMMON/catalog" -f "$TMP/cde/TOC.sgm" \
-id makronix.guide.toc -title "The Makronix Guide" \
"$TMP/cde/book.sgm" > "$TMP/cde/toc.log" 2>&1 ||
{ cat "$TMP/cde/toc.log" >&2; die "tocgen failed"; }
$MCDE_BIN/dtdocbook2infolib build -v -L en_US.UTF-8 \
-T "$TMP/cde/infolib-build" -m "$COMMON/catalog" \
-l "$TMP/cde/infolib" -n makronix -d "The Makronix Guide" \
"$TMP/cde/bookcase.bc" > "$TMP/cde/build.log" 2>&1 ||
{ cat "$TMP/cde/build.log" >&2; die "dtdocbook2infolib failed"; }
rm -rf "$OUT/infolib"
mkdir -p "$OUT/infolib"
cp -R "$TMP/cde/infolib" "$OUT/infolib/makronix.dti"
# Keep the generated SGML and bookcase beside the compiled library: they
# are the readable record of what dtinfo holds (and are not installed).
cp "$TMP/cde/book.sgm" "$OUT/infolib/book.sgm"
cp "$TMP/cde/TOC.sgm" "$OUT/infolib/TOC.sgm"
cp "$TMP/cde/bookcase.bc" "$OUT/infolib/bookcase.bc"
[ -f "$OUT/infolib/makronix.dti/bookcase.map" ] ||
die "the information library has no bookcase.map"
}
check_all()
{
[ -s "$OUT/makronix-guide.html" ] || die "missing HTML"
[ -s "$OUT/makronix-guide.pdf" ] || die "missing PDF"
[ -s "$OUT/guide.html" ] || die "missing web page"
grep -q 'class="content guide"' "$OUT/guide.html" ||
die "the web page has no site window"
grep -q 'href="guide.html" class="here"' "$OUT/guide.html" ||
die "the web page does not mark the Guide menu"
if $XMLLINT --html --noout "$OUT/guide.html" 2>"$TMP/web.err"; then
:
else
cat "$TMP/web.err" >&2
die "the web page does not parse as HTML"
fi
grep -q 'class="cover"' "$OUT/makronix-guide.html" ||
die "the HTML has no cover"
grep -q 'The Makronix Guide' "$OUT/makronix-guide.html" ||
die "the HTML does not name the guide"
[ -f "$OUT/man/makronix-guide.7" ] || die "missing man index"
n=0
for f in "$OUT"/man/*.7; do
[ -f "$f" ] || continue
head -1 "$f" | grep -q '^\.TH ' || die "$f has no .TH line"
$MANDOC -Tutf8 "$f" >/dev/null 2>"$TMP/mandoc.err" ||
{ cat "$TMP/mandoc.err" >&2; die "$f does not render"; }
n=$((n + 1))
done
[ "$n" -ge 2 ] || die "no man pages were generated"
[ -f "$OUT/infolib/makronix.dti/bookcase.map" ] ||
die "missing information library"
[ -f "$OUT/infolib/makronix.dti/MAKRONIX/MAKRONIX.dbd" ] ||
die "the information library has no book database"
if [ -n "$PDFINFO" ]; then
pages=$($PDFINFO "$OUT/makronix-guide.pdf" 2>/dev/null |
awk '/^Pages:/ { print $2 }')
[ -n "$pages" ] && [ "$pages" -gt 1 ] ||
die "the PDF has no pages"
echo "guide: $n manual pages, $pages PDF pages"
else
echo "guide: $n manual pages (pdfinfo not installed)"
fi
}
install_all()
{
[ -s "$OUT/makronix-guide.html" ] || die "build the guide first"
[ -s "$OUT/makronix-guide.pdf" ] || die "build the guide first"
[ -s "$OUT/guide.html" ] || die "build the web page first"
mkdir -p "$DOCDIR" "$MANDIR" "$ETCDIR" "$DOCDIR/infolib"
cp "$OUT/guide.html" "$WWW/guide.html"
cp "$OUT/makronix-guide.html" "$OUT/makronix-guide.pdf" "$DOCDIR/"
cp "$OUT"/man/*.7 "$MANDIR/"
rm -rf "$DOCDIR/infolib/makronix.dti"
cp -R "$OUT/infolib/makronix.dti" "$DOCDIR/infolib/"
# The Information Manager uses the default library name; the session
# script makes the Makronix Guide the default. The library data is
# installed under /usr/share/doc/makronix/infolib; src/etc/Makefile
# makes the symlink under /etc/dt/infolib.
cat > "$ETCDIR/makronix-xsession" <<'EOF'
# License: CNCL 1.0 (Could Not Care Less), see LICENSE at the top of the tree.
# The Makronix Guide is the default library of the Information Manager.
# See docs/guide and makronix-guide(7).
DTINFOLIBDEFAULT=makronix
export DTINFOLIBDEFAULT
EOF
chmod 755 "$ETCDIR/makronix-xsession"
echo "guide: installed into src/share/doc/makronix, src/share/man/man7, src/etc and www"
}
mkdir -p "$OUT"
TMP=$(mktemp -d "${TMPDIR:-/tmp}/makronix-guide.XXXXXX") ||
die "cannot create a temporary directory"
case ${1:-all} in
all)
resolve_xml
build_html
build_pdf
build_web
build_man
build_infolib
check_all
;;
html) resolve_xml; build_html ;;
pdf) resolve_xml; build_html; build_pdf ;;
web) resolve_xml; build_web ;;
man) resolve_xml; build_man ;;
infolib) resolve_xml; build_infolib ;;
check) check_all ;;
install) install_all ;;
*) echo "usage: $0 [all|html|pdf|web|man|infolib|check|install]" >&2; exit 1 ;;
esac