#!/bin/bash
# $Id: make,v 1.1.1.1 2006/12/12 09:40:08 frm Exp $

DOCBOOK=manual.docbook


if [[ "$1" == "clean" ]]; then
    rm -rf api man
    rm errorlog.txt

    # be careful because "user" folder contains style.css
    rm user/*.html

    exit 0
fi

function test_for
{
    out=`$1 --version 2>&1 >/dev/null`
    if test $? != 0; then
        echo "Please install the $1 program and retry."
        exit 1
    fi
}

# test for presence of required tools
test_for xmllint
test_for xsltproc
test_for doxygen

# validate docbook
echo "===> VALIDATING"
xmllint --xinclude --postvalid --noent --noout $DOCBOOK
if test $? != 0; then exit $?; fi

# generate HTML
echo "===> GENERATING HTML"
mkdir -p user
xsltproc --xinclude -o user/ html.xsl $DOCBOOK

# generate the manpage
echo "===> GENERATING MANPAGE"
mkdir -p man
xsltproc --xinclude -o man/ manpage.xsl $DOCBOOK

# generate the API docs using Doxygen
echo "===> GENERATING API DOCS"
doxygen >/dev/null
