#!/usr/bin/env bash
# Build the user guide and export a single PDF to site/pdf/kat5200-user-guide.pdf
# Requires: mkdocs, mkdocs-material, pymdown-extensions, weasyprint, mkdocs-with-pdf.
# The mkdocs-with-pdf plugin lives in the local venv (.venv); the rest come from
# the system (pacman). The venv is created with --system-site-packages so it sees
# them. Run ./setup-venv.sh once if .venv is missing.
set -euo pipefail
cd "$(dirname "$0")"

if [ ! -x .venv/bin/python ]; then
  echo "No .venv found. Run ./setup-venv.sh first." >&2
  echo "For package builds, you can also configure with -DKAT_MANUAL_PDF=/path/to/kat5200-user-guide.pdf to use a prebuilt manual." >&2
  exit 1
fi

# mkdocs/material come from system site-packages; the venv adds with-pdf. Invoke
# via the venv python so the plugin is importable.
ENABLE_PDF_EXPORT=1 .venv/bin/python -m mkdocs build -f mkdocs-pdf.yml "$@"
echo "PDF: $(pwd)/site/pdf/kat5200-user-guide.pdf"
