#!/bin/sh

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>"
}

CWD=${PWD}
cd ..
top_dir=${PWD}

cd ${CWD}

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

install_path=${top_dir}/basicutils/basicutils_install


TOP_BASIC_UTIL_DIR=${PWD}
libtoolize --force --copy --automake
aclocal -I ${TOP_BASIC_UTIL_DIR}/config/m4
autoheader
autoconf
automake --copy --add-missing

cd libltdl
libtoolize --force --copy --automake
aclocal -I "${TOP_BASIC_UTIL_DIR}"/config/m4
autoheader
autoconf
automake --copy --add-missing
cd ..
./configure --prefix=${install_path} --disable-libtool-lock

echo 
echo
echo "install_path=${install_path}"



if make; then
    if make install; then
	echo "BASICUTILS INSTALLATION SUCCESSFUL"
    else
    
	echo "PROBLEMS WITH INSTALLATION"
	echo "Check if you have permission to ${install_path} directory"
	exit 1
    
    fi
    
    
else
    echo "THERE WERE ERRORS DURING COMPILATION!"
    exit 1
fi

