#!/bin/sh

_exit() {
	echo $@
	popd
	exit 1
}

DOCSRCDIR=`dirname $0`/../docs-xml

pushd $DOCSRCDIR || exit 1

git clean -d -x -f
autoconf && \
	./configure --with-papersize=letter && \
	make smbdotconf/parameters.all.xml && \
	make release

if [ $? != 0 ]; then
        _exit "Docs build failed!"
fi

mkdir -p ../docs
rsync -Ca --delete --exclude=.git output/ ../docs/
rsync -Ca --exclude=.svn registry ../docs/
rsync -Ca --exclude=.svn archives/ ../docs/

cd ../docs || _exit "Error changing dir to ${DOCSDIR}/../docs/"

/bin/rm -rf test.pdf Samba4*pdf htmldocs/Samba4* htmldocs/test
mv manpages-3 manpages
mv htmldocs/manpages-3 htmldocs/manpages

cd ../docs-xml || _exit "Error changing dir to ${DOCSDIR}/../docs-xml/"
make distclean

echo "Success"
popd
exit
