#!/bin/bash

function usage
{
    # Temporary function stub
    echo "USAGE: ./install_full --install_path <directory where CompuCell will be installed>"
    echo "or"
    echo "USAGE: ./install_full -i <directory where CompuCell will be installed>"
}

export install_path

while [ "$1" != "" ]; do
    case $1 in
        -i | --install_path )           shift
                                install_path=$1
                                echo "install_path: $install_path"
                                ;;
        -h | --help )           usage
                                exit
                                ;;
        * )                     usage
                                exit 1
    esac
    shift
done



echo
echo
echo "WORKING ON EXTRALIBS. PLEASE WAIT..."
echo
echo


cd extralibs

if ./install_basicutils_and_friends ; then
    echo "OK"
else
    echo "PROBLEMS WITH INSTALLATION"
    exit 1
fi

echo "MAKING EXTRALIBS VISIBLE TO COMPUCELL "

cd ..

#libraries
cp extralibs/basicutils/basicutils_install/lib/* CompuCellNew/lib
cp extralibs/xercesutils/xercesutils_install/lib/* CompuCellNew/lib
cp extralibs/xmlcereal/xmlcereal_install/lib/* CompuCellNew/lib

rm CompuCellNew/lib/*.la

#now include files

cp extralibs/basicutils/basicutils_install/include/BasicUtils/* CompuCellNew/src/include/BasicUtils
cp extralibs/xercesutils/xercesutils_install/include/XercesUtils/* CompuCellNew/src/include/XercesUtils
cp extralibs/xmlcereal/xmlcereal_install/include/XMLCereal/* CompuCellNew/src/include/XMLCereal


#copying xerces.config
#cp extralibs/xerces.config CompuCell/CompuCellNew/

if [ -d $install_path ]
then
echo "Directory $install_path already exists"
else
mkdir $install_path
fi

#copying examples
cp -r examples/* $install_path

#writing run script
./prepare_run_scritp.sh -i $install_path

cd CompuCellNew
if ./install_CompuCell -i $install_path; then
    echo "moving to CompuCellPlayer..."
else
    echo "Errors during compilation. Exiting"
    exit 1
fi

cd ../CompuCellPlayer
./install_CompuCellPlayer -i $install_path

exit

