#! /bin/sh
#
# Copyright 2009 Yorba Foundation
#
# This software is licensed under the GNU LGPL (version 2.1 or later).
# See the COPYING file in this distribution. 

CONFIG_IN=configure.in

configure_help() {
    printf "\nUsage:\n"
    printf "\t./configure [OPTIONS]...\n"
    printf "\n"
    printf "Options:\n"
    printf "\t-h, --help\t\tPrint this help and exit.\n"
    printf "\t--prefix=PREFIX\t\tPrepend PREFIX to program installation paths.\n"
    printf "\t\t\t\t[/usr/local]\n"
    printf "\t--assume-pkgs\t\tTurn off package version checking.\n"
    printf "\n"
}

abort() {
    printf "%s: Invalid argument %s\n" $0 $1
    configure_help
    exit 1
}

while [ $# != 0 ]
do
    option=`echo $1 | sed 's/=.*//'`
    if [ `echo $1 | grep '='` ]
    then
        value=`echo $1 | sed 's/.*=//'`
    fi

    case $option in
        -h | --help)        configure_help
                            exit 0
                            ;;
        
        --prefix)           if [ ! $value ]
                            then
                                abort $1
                            fi
                            
                            variables="${variables}PREFIX=$value\n"
                            ;;
        
        --assume-pkgs)      variables="${variables}ASSUME_PKGS=1\n"
                            ;;

        *)                  abort $1
                            ;;
    esac
    
    shift
done

rm -f $CONFIG_IN
touch $0
if [ $variables ]
then
    echo -n $variables > $CONFIG_IN
    echo "CONFIG_IN=${CONFIG_IN}" >> $CONFIG_IN
fi

printf "Configured.  Type 'make' to build, 'make install' to install.\n"
