#! /bin/sh
#
# configuration script for Healpix
# will configure (and compile) the C, C++, F90 and IDL packages
#
# It is free of bashims, and should work with
#          Bourne Shell       (sh)
#          Bourne-Again Shell (bash)
#          Korn Shell         (ksh)
# and most versions of 
#          Debian Almquist Shell (dash)
#
# If is crashes unexpectedly, try replacing the first line above
# from   #! /bin/sh 
# to     #! /bin/bash
# or     #! /bin/ksh
#
# 2008-03-26, IAP, EH
# 2009-01-08: added comments on shells above
#

# version number
HPXVERSION=3.11

#-------------
welcome () {
    echo
    echo "*************************"
    echo " Welcome to Healpix $HPXVERSION"
    echo "*************************"
    echo
    echo "This script takes care of the configuration and compilation"
    echo "of the C, C++, F90, IDL and Python packages of the Healpix distribution."

}


# read functions definition
. ./hpxconfig_functions.sh

# foreplay1
setTopDefaults
HPX_CONF_DIR=${HPX_CONF_DIR_HOME}

# ----------------- options parsing ----------------------
usage="Usage: ./$(basename $0) [?|-h|-L|-v]"
usage2="Type    ./$(basename $0) -h    for extended help"
# do not accept options starting with a non-dash or with double dash
if [ ${#} -gt 0 ]; then
	    if [ "${1:0:1}" != "-"  -o  "${1:0:2}" = "--"  -o "${1}" = "-" ]; then
		echo 
		echo "${usage}"
		echo
		echo "${usage2}"
		echo
		exit -1
	    fi
fi

while getopts 'hLv' OPTION
do
    case ${OPTION} in
	h) 
	echo
	echo "Configure script for Healpix ${HPXVERSION}"
	echo
	echo "${usage}"
	echo
	echo "?   Print usage and exit" 
	echo
	echo "-h  Print this help message and exit" 
	echo
	echo "-L  Put the configuration directory in ${HPX_CONF_DIR_INPLACE}" 
	echo "    (instead of installer's home: ${HPX_CONF_DIR_HOME})."
	echo "    Recommended when doing a system wide installation to be used by several users."
	echo
	echo "-v  Print Healpix version and exit"
	echo
	exit 0
	;;
	L)
        HPX_CONF_DIR=${HPX_CONF_DIR_INPLACE}
	echo 
        echo "Note: the configuration directory will be ${HPX_CONF_DIR}"
	echo
	;;
	v)
	echo "${HPXVERSION}"
	exit 0
	;;
	?)
	echo
	echo "${usage}"
	echo
	echo "${usage2}"
	echo
	exit -1
	;;
   esac
done
# --------------------------------------------------------

#-------------

# foreplay2
setConfDir
welcome
makeTopConf
readyTopMakefile
#installProfile

# loop over main menu
while [ true ]  ; do 
	mainMenu
done

# done
goodBye
exit
