#!/bin/bash 
# script to build BALL / BALLView to create and compile a Debian/Ubuntu source package

set -e

#adapt to your settings
export BALL_PATH=`pwd | sed -e 's%/debian-upstream$%%g' -e 's%/debian$%%g'`
if [ ! -d "$BALL_PATH" ]; then
	echo "$0: cannot find directory '$BALL_PATH' as presumed root of the source tree."
	echo "Pwd: " `pwd`
	exit -1
fi
unset QTDIR
echo $1

if [ "$1" == "configure" ]
then
	cd $BALL_PATH
	mkdir build && cd build && cmake .. -DCMAKE_INSTALL_PREFIX=./usr -DBALL_PATH=/usr -DBALL_DATA_PATH=/usr/share/BALL-1.4/data
	exit $?
fi
 																			
if [ "$1" == "build" ]
then
	cd $BALL_PATH/build && make -j 2 all doc doc_tutorial install
#	cd $BALL_PATH/source && echo "Running doxygen... This can take a while..." && make doc && echo "Doxygen done!" && make depend && mymake && make install
#	cd $BALL_PATH/source/PYTHON/EXTENSIONS && mymake && make install
#	cd $BALL_PATH/source/APPLICATIONS/BALLVIEW && mymake  		
	exit $?
fi

if [ "$1" == "install" ]
then
	bash debian/createBALLDeb source
	exit $?
fi

if [ "$1" == "clean" ]
then
	cd $BALL_PATH/source 
	if [ -f Makefile ] 
	then 
		make clean 
		cd PYTHON/EXTENSIONS
		make clean
		rm -rf ../lib/Linux*
		rm -rf ../doc/doxygen/latex/*
		rm -f $BALL_PATH/source/config.status 2>/dev/null
	fi
	exit $?
fi
