#!/bin/ksh -v

# script to pack up a tarball of the current state

VERSION=opensg-0.2b

TESTDIR=`pwd`/$VERSION

# create the test arena

rm -rf $TESTDIR
mkdir $TESTDIR

if [[ ! -d $TESTDIR ]]
then
	echo "Couldn't create testdir!"
	exit
fi

cd $TESTDIR

# redirect all outputs to the log file

MLOG=`pwd`/make.log

rm -f $MLOG

# redirect output to logfile
exec 3>&1 4>&2 1>$MLOG 2>&1 

# get the stuff

cvs -d:pserver:anonymous@cvs.OpenSG.sourceforge.net:/cvsroot/opensg co OpenSG

# do a test make using configure

cd OpenSG

ln -s Experimental/Common         Common.new
ln -s Experimental/CommonPackages CommonPackages.new
ln -s Experimental/CommonConf     CommonConf

cd Experimental
autoconf 
./configure --with-compiler=CC -with-stl=/igd/a4/op2010/Software/SGI/stdlib \
	--with-qt=/igd/a4/lib/qt-2.2 --with-glut=/igd/a4/lib/glut

cd Builds/*
gmake -j6

# reset output
exec 1>&3 2>&4

fgrep -i error $TESTDIR/mlog > $TESTDIR/elog

if [[ -s $TESTDIR/elog ]]
then

	echo 'ERROR during system make!'
	cat $TESTDIR/elog	
	exit
fi


# make the tests

rm $MLOG

# redirect output to logfile
exec 3>&1 4>&2 1>>$MLOG 2>&1 

cd SystemTest

ln -s .../SystemLib/obj-dbg/OSGScanParseSkel.tab.h .../SystemTest/obj-dbg
ln -s .../Experimental/VRMLLoader/std.wrl .
make 

# reset output
exec 1>&3 2>&4

fgrep -i error $TESTDIR/mlog > $TESTDIR/elog

if [[ -s $TESTDIR/elog ]]
then

	echo 'ERROR during test make!'
	cat $TESTDIR/elog	
	exit
fi


# do a testmake using standard configuration

rm $MLOG

# redirect output to logfile
exec 3>&1 4>&2 1>>$MLOG 2>&1 

cd ../../../..

make init
gmake -r -j6

# reset output
exec 1>&3 2>&4

fgrep -i error $TESTDIR/mlog > $TESTDIR/elog

if [[ -s $TESTDIR/elog ]]
then

	echo 'ERROR during standard make!'
	cat $TESTDIR/elog	
	exit
fi


# should run the tests here...


# clean up

gmake distclean

cd Experimental/Builds/*
gmake distclean

cd ../..
rm -rf Builds

cd ..

# make the doc. Everybody's gonna need it anyway

make doc

cd ..

# ok, done. Pack it up and ship.

echo "Make sucessful, pack 'er up."

mv OpenSG $VERSION

tar cf - $VERSION | gzip -9 > $VERSION.tgz

# now the one without doc...

rm -rf $VERSION/Doc/Code/html
tar cf - $VERSION | gzip -9 > $VERSION-nodoc.tgz

echo "Done:"
pwd
ls -l

