#!/bin/sh

leave=no

#while [ $# -gt 0 ]
#do
#	case $1 in
#		--leaveHTML)	leave=yes	;;
#		*)		break		;;
#	esac
#
#	shift
#done

build=$1
[ "$build"  = "" ] && build=kde

appname=Rekall
appextn=rkl

uptodate=yes

for source in `find . -name '*.sgml'` `find . -name '*.png'` index.docbook.*
do

    [ .uptodate -nt "$source" ] || uptodate=no

done

if [ "$uptodate" = "yes" ]
then
	exit 0
fi

echo	Building documentation .....

#  Now we can do the docbook processing. We handle both KDE21 and KDE22
#  style processing....
#
kde21hdr='\"-//KDE//DTD DocBook V3.1-Based Variant V1.0//EN\"'
kde22hdr='\"-\/\/KDE\/\/DTD DocBook XML V4.1-Based Variant V1.0\/\/EN\" \"dtd\/kdex.dtd\"'

sed -e "s?__KDEHDR__?$kde22hdr?" \
    -e "s?__APPNAME__?$appname?" \
    -e "s?__APPEXTN__?$appextn?" \
    -e "s?__PREFIX__?$PREFIX?" index.docbook.skel > index.docbook.kde22

sed -e "s?__KDEHDR__?$kde21hdr?" \
    -e "s?__APPNAME__?$appname?" \
    -e "s?__APPEXTN__?$appextn?" \
    -e "s?__PREFIX__?$PREFIX?" index.docbook.skel > index.docbook.kde21

if	[ -x "$KDEDIR/bin/meinproc" ]
then
	rm -f index.docbook
	cp index.docbook.kde22 index.docbook

	$KDEDIR/bin/meinproc --check --cache index.cache.bz2 ./index.docbook

	# Slakware build fudge. On Henley, generate the set of HTML files
	# into the HTML directory and then make a tarball of them.
	#
	if [ "`hostname -s`" = "henley" ]
	then
		echo Building documentation tarball

		[ -d HTML ] || mkdir HTML
		cd HTML
		rm -rf *
		$KDEDIR/bin/meinproc --check ../index.docbook
		rm -f common
		cp -a $KDEDIR/share/doc/HTML/en/common .
		cp -a ../chap? ../chap?? .
		tar -czf ../HTML.tgz .
		cd ..
		[ "$leave" = no ] && rm -rf HTML
	fi

elif	[ -x "$KDEDIR/bin/kdb2html" ]
then
	# Slackware build fudge. We haven't got "jw" et.al. on slakware
	# so unpack the HTML tarball. Note: assumes slakware is using
	# KDE2.1.x
	#
	[ -x /usr/bin/jw ] || {
		echo	"******"
		echo	"****** jw not found"
		echo	"******"
		[ -f HTML.tgz ] && tar -xzf HTML.tgz
		exit	0
	}

	cp index.docbook.kde21 index.docbook

	jw -o HTML -c /usr/share/sgml/docbook/sgml-dtd-3.1/catalog \
		   -c $KDEDIR/share/apps/ksgmltools/catalog \
		   -d $KDEDIR/share/apps/ksgmltools/stylesheets/kde.dsl#HTML \
		   ./index.docbook
	rm -rf HTML/common common
else

	echo	"*** Unable to locate KDE docbook converter ***"
	exit	0
fi


# Extract the help files. Strangley, RedHat 7.1 python 1.5.2 seems happy with
# this, other distros have problems with 4suite.
#
echo	Extracting help files

if [ "`hostname -s`" = "henley" ]
then
	[ -d help ] || mkdir help
	rm -f help/*
	./extract.py
fi


touch	.uptodate
