#!/bin/bash

if [ ! -f documentation/manual/tred.xml ]; then
  echo "not in tred/ directory"
  exit 1
fi
DEVELDIR=`dirname $0`

. "$DEVELDIR/config.sh"

echo "Generating documentation from tred POD"
$DEVELDIR/pod2db.sh tred > documentation/manual/tred_cmd.xml

echo "Generating documentation from tred.def"
$DEVELDIR/pod2db.sh tredlib/tred.def > documentation/manual/tred_def.xml

DEVELDIR="${DEVELDIR:-$PWD}"
pushd "$DEVELDIR" >/dev/null
DEVELDIR=`pwd -P`
popd >/dev/null



"$DEVELDIR"/make_pod_html documentation

echo "Generating manpages from POD"
cd documentation
[ -d man ] || mkdir man
[ -d man/man1 ] || mkdir man/man1
[ -d man/man3 ] || mkdir man/man3

for man in btred.1 ntred.1 PML_mak.3 tred_def.3; do
  sect=${man##*.}
  pod2man "pod/${man%.[13]}.pod" > "man/man$sect/$man"
done

for module in "${local_pm[@]}"; do
  pod2man "pod/${module}.pod" > "man/man3/${module}.3pm"
done

RUNXSLT="xsltproc --xinclude --stringparam html.stylesheet blue.css"

echo "Generating TrEd manual"
$RUNXSLT --stringparam root.filename tred manual/manual.xsl manual/tred.xml

echo "Generating on-line help map"
xsh2 ../devel/make_help_map.xsh manual/tred.xml ar*.html > ../tredlib/TrEd/Help.pm

echo "Generating bTrEd tutorial"
$RUNXSLT -o bn-tutorial.html manual/manual_one_page.xsl bn-tutorial.xml
xsh2 -q "$DEVELDIR"/rewrite.xsh "$DEVELDIR"/rewrite_tred.xml bn-tutorial.html
$RUNXSLT -o btred-tutorial.html manual/manual_one_page.xsl btred_tutorial.xml

rm -f *.html~

echo "done."
