#!/bin/sh
	
if [ -z "$1" ]; then
   echo "usage: [-v] $0 <docbook file>"
   echo
   echo "*NOTE* you need xsltproc, fop and nwalsh docbook stylesheets" 
   echo "       installed for this to work!"
   echo
   exit 0
fi

if [ "$1" = "-v" ]; then
   echo "Version @version@"
   exit 1
fi

BASENAME=`basename $1 .xml` || exit 1
FO="$BASENAME.fo" 
PDF="$BASENAME.pdf"

xsltproc -o /tmp/titlepage.xsl                                           \
	 --xinclude                                                      \
         /usr/share/xml/docbook/stylesheet/nwalsh/template/titlepage.xsl \
         @datadir@/common/titlepage.templates.xml || exit 1

xsltproc --xinclude                    \
	 --stringparam hyphenate false \
	 --stringparam formal.title.placement "figure after" \
	 --stringparam ulink.show 1 \
         --stringparam  body.font.master  9 \
         --stringparam  title.font.master  11 \
         --stringparam draft.watermark.image "@datadir@/common/draft.png" \
         --output $FO               \
         @datadir@/common/poky-db-pdf.xsl    \
	 $1                 || exit 1

fop -c @datadir@/common/fop-config.xml -fo $FO -pdf $PDF       || exit 1

rm -f $FO
rm -f  /tmp/titlepage.xsl

echo
echo " #### Success! $PDF ready. ####"
echo