#!/bin/sh

pkg_config_check() 
{

local error=""
echo -n "Checking for $1..."
$PKG_CONFIG --exists $1

if [  $? -ne 0 ];
then
    error_flag=1
    error="${error}Problem\n"
    error="${error}  $1 could not be located in you system.\n"
    error="${error}Suggestions\n"
    error="${error}  1. You can get it at $2.\n" 
    error="${error}  2. If you have already installed $1 make sure that the directory\n"
    error="${error}     the file $1.pc is located in, is listed in \$PKG_CONFIG_PATH.\n\n"

    echo "Error"
#    echo
#    echo "Problem"
#    echo "   $1 could not be located in you system."
#    echo "Suggestions"
#    echo "1. You can get it at $2." 
#    echo "2. If you have already installed $1 make sure that the directory"
#    echo "   the file $1.pc is located in, is listed in \$PKG_CONFIG_PATH."
    
else 
    echo "OK"
fi
    
cur_err=$error
}

#check for pkg-config
PKG_CONFIG=`which pkg-config`
if [ -z $PKG_CONFIG ];
then
    echo "pkg-config could not be located in your system. If you have it"
    echo "make sure that it is in your path."
    exit 1
fi

error_flag=0
#check for mono
pkg_config_check mono http://www.mono-project.com
errors=${errors}$cur_err

#check for gtk-sharp
pkg_config_check gtk-sharp http://www.mono-project.com 
errors=${errors}$cur_err

#check for glade-sharp
pkg_config_check glade-sharp http://www.mono-project.com
errors=${errors}$cur_err

if [ $error_flag -eq 1 ];
then
    echo
    echo "The following problems were encountered during the configuration:"
    echo
    echo -e $errors
    exit 1
fi

prefix="/usr/local"

# Parse options

ac_prev=

for ac_option
do

if test -n "$ac_prev"; then
    eval "$ac_prev=\$ac_option"
    ac_prev=
    continue
fi

ac_optarg=`expr "x$ac_option" : 'x[^=]*=\(.*\)'`
case $ac_option in
    -prefix | --prefix | --prefi | --pref | --pre | --pr | --p)
	ac_prev=prefix ;;
    -prefix=* | --prefix=* | --prefi=* | --pref=* | --pre=* | --pr=* | --p=*)
	prefix=$ac_optarg ;;
esac
	
done

echo "PREFIX=$prefix" > config.make

echo
echo "Configuration completed successfuly."
echo "Installation directory prefix is: $prefix"
echo "Now run 'make' and 'make install'"
