#!/bin/sh
set -e
if test "x$1" = "x" ; then
	url=http://twistedmatrix.com/documents/TwistedDocs/current/api/%s.html
else
	url=http://twistedmatrix.com/documents/TwistedDocs/TwistedDocs-$1/api/%s.html
fi
templ=doc/howto/template.tpl
if sh -c 'which python2.2 > /dev/null'; then PYTHON=2.2; fi
if sh -c 'which python2.3 > /dev/null'; then PYTHON=2.3; fi
LORE="python$PYTHON ./bin/lore"
echo "Man-->Lore"
$LORE -p --input man --output lore --config ext=-man.xhtml doc/man/*.1
for doc in doc doc/man doc/howto doc/howto/tutorial doc/howto/policy doc/specifications doc/vision; do
	echo "Lore-->Lint"
	$LORE -n --output lint $doc/*.xhtml |sed 's/^/WARNING: /'
	echo "Lore-->HTML"
	$LORE -p --config template=$templ --config baseurl=$url \
	           --config ext=.html --config version=$1 -l ../howto/ \
	           $doc/*.xhtml
	echo "Lore-->LaTeX"
	$LORE -p --output latex --config section $doc/*.xhtml
done
cp admin/book.tex doc/howto
cd doc/howto
for i in 1 2;do latex book.tex < /dev/null;done
latex book.tex </dev/null | sed '/^LaTeX Warning:/s/^/WARNING: /'
dvips -o book.ps book.dvi
ps2pdf13 book.ps book.pdf
rm *.eps *.tex *.aux *.log book.dvi book.toc ../man/*.tex \
   ../specifications/*.tex ../man/*-man.xhtml ../vision/*.tex ../*.tex
