#!/bin/sh

if [ $# -eq 0 ]; then
    echo "Usage: $0 <SAGE_VERSION>"
    exit 1
fi


CUR=`pwd`
#./rebuild 

#make

if [ $? -ne 0 ]; then
    echo "Error building documentation"
    exit 1
fi 

if [ $? -ne 0 ]; then
    echo "Error pushing documentation to sage.math"
    exit 1
fi 

cd "$CUR"

ROOT=`pwd`
PKG="doc-$1"
TMPPKG="/tmp/$PKG"

mkdir -p $TMPPKG
cp -prv * .hg* $TMPPKG/
cd $TMPPKG
chmod a+r -R *
make clobber

# Remove temporary dvi files I build when working with the docs
# (these take a lot of space)

rm -f */*.dvi
rm -f */*.pdf
rm -rf doc-* 
rm -f */*.log

cp -prv $ROOT/html .
chmod a+r -R *
rm -f ref*

cd ..

tar jcvf $PKG.spkg $PKG

rm -rf "$TMPPKG"
mv $PKG.spkg $ROOT/

