#!/bin/sh

set -eu

if test '@SPHINXBUILD@' = 'false'; then
    echo 'Warning: sphinx-build is missing. Not creating docs.' >&2
    exit 0
fi

cd '@builddir@'

# api.rst is always generated via sphinx's conf.py
@PYTHON@ @srcdir@/api2doc.py -o @srcdir@/api.rst

rm -f '@srcdir@/arm/platforms.rst'
cp '@TOP_SOURCE_DIR@/platforms.rst' '@srcdir@/arm/platforms.rst'

# html
@SPHINXBUILD@ -M html @srcdir@ @sphinxbuilddir@ @sphinxopts@

# singlehtml
@SPHINXBUILD@ -M singlehtml @srcdir@ @sphinxbuilddir@ @sphinxopts@

# text
@SPHINXBUILD@ -M text @srcdir@ @sphinxbuilddir@ @sphinxopts@

# mans
@SPHINXBUILD@ -M man @srcdir@ @sphinxbuilddir@ @sphinxopts@

# pdf
if test '@HAVE_PDFLATEX@' != 'no'; then
    @SPHINXBUILD@ -M latex @srcdir@ @sphinxbuilddir@ @sphinxopts@
    cd '@abs_sphinxbuilddir@/latex'
    @PDFLATEX_AND_OPTS@ kea-arm.tex
    makeindex -s python.ist kea-arm.idx
    @PDFLATEX_AND_OPTS@ kea-arm.tex
    @PDFLATEX_AND_OPTS@ kea-messages.tex
    makeindex -s python.ist kea-messages.idx
    @PDFLATEX_AND_OPTS@ kea-messages.tex
fi
