
#!/bin/bash

function usage
{
    # Temporary function stub
    echo "USAGE: ./generate_kdevelop_project -i <directory where CompuCell will be installed> -d <directory where kdevelop project will be writen to> -t <build type: Debug|Release>"
}

export source_dir=${PWD}

export install_path
export build_type=Release

export kdevelop_project_path=${source_dir}/kdevelop_project

#export source_dir

while [ "$1" != "" ]; do
    case $1 in
        -i | --install_path )           shift
                                install_path=$1
                                echo "install_path: $install_path"
                                ;;

        -d | --kdevelop_project_path )           shift
                                kdevelop_project_path=$1
                                echo "kdevelop_project_path: $kdevelop_project_path"
                                ;;

        -t | --build_type )           shift
                                build_type=$1
                                echo "build_type: $build_type"
                                ;;



        -h | --help )           usage
                                exit
                                ;;
        * )                     usage
                                exit 1
    esac
    shift
done


if [ -w $install_path ] 
then
    echo "Everything seems to be OK permission wise"
else
    if mkdir $install_path; then
	echo "Successfully created installation directory: $install_path"
        mkdir $install_path/cmake_binary_dir
    else
	echo "Could not create directory $install_path. Check if you have right permissions"
	exit 1
    fi

fi

echo "will generate kdevelop file in ${kdevelop_project_path}"

mkdir ${kdevelop_project_path}
cd ${kdevelop_project_path}
cmake -GKDevelop3 -DCMAKE_INSTALL_PREFIX:STRING=$install_path -DCMAKE_BUILD_TYPE:STRING=$build_type ${source_dir};

exit 0

