#!/bin/bash

# poor man's poor rip off from the real configure stuff

usage() {
    cat <<EOF
$0 [options...]
  --prefix=DIR		prefix install directory for binaries and libraries
			[/usr/local]
  --precomplied-asn1	use precompiled ASN.1 files (no asn1c compiler needed)
  --enable-supl-debug	enable SUPL/RRLP protocol specific debugging
  --enable-debug	enable C debugging
  --enable-asn1-debug	enable debugging of ASN.1 parsing
  --asn1c-skeletons <path> where asn1c compiler should look ASN.1 skeleton files
EOF
    exit 1
}

# Identity of this package.
PACKAGE_NAME='supl'
PACKAGE_TARNAME='supl'
PACKAGE_VERSION='1.0.5'
PACKAGE_STRING='supl 1.0.5'
PACKAGE_BUGREPORT=''
PACKAGE_URL=''

var_prefix=/usr/local
var_precompiled=
var_debug=
var_asn1_debug=
var_asn1c_skeletons=

while test $# != 0
do
  case $1 in
  --*=* | -*=*)
    ac_option=`expr "X$1" : 'X\([^=]*\)='`
    ac_optarg=`expr "X$1" : 'X[^=]*=\(.*\)'`
    ac_shift=:
    ;;
  *)
    ac_option=$1
    ac_optarg=$2
    ac_shift=shift
    ;;
  esac

  case $ac_option in
      -prefix | --prefix)
	  var_prefix=$ac_optarg ;;
      -precompiled-asn1 | --precompiled-asn1 | -precompiled | --precompiled)
	  var_precompiled_asn=yes ;;
      -enable-debug | --enable-debug | -debug | --debug)
	  var_debug="-g" ;;
      -enable-supl-debug | --enable-supl-debug)
	  var_supl_debug="-DSUPL_DEBUG" ;;
      -enable-asn1-debug | --enable-asn1-debug)
	  var_asn1_debug="-DEMIT_ASN_DEBUG=1" ;;
      -asn1c-skeletons | --asn1c-skeletons)
	  var_asn1c_skeletons="-S $ac_optarg" ;;
      -help | --help)
	  usage ;;
      *)
	  usage ;;
  esac
  shift
done

# Check all directory arguments for consistency.
for ac_var in var_prefix
do
  eval ac_val=\$$ac_var
  # Remove trailing slashes.
  case $ac_val in
    */ )
      ac_val=`expr "X$ac_val" : 'X\(.*[^/]\)' \| "X$ac_val" : 'X\(.*\)'`
      eval $ac_var=\$ac_val;;
  esac
  # Be sure to have absolute directory names.
  case $ac_val in
    [\\/$]* | ?:[\\/]* )  continue;;
    NONE | '' ) case $ac_var in *prefix ) continue;; esac;;
  esac

  echo  "expected an absolute directory name for --$ac_var: $ac_val" >&2
  exit 1
done

cat <<EOF > config.mk
# Generated by ./configure script - `date`
# Modifications to this file are lost if ./configure is ran again.

CONF_VERSION = 1.0.5
CONF_CFLAGS = -Wall -O2 $var_debug
CONF_ASN_CFLAGS = $var_asn1_debug
CONF_PREFIX = $var_prefix
CONF_PRECOMPILED_ASN = $var_precompiled_asn
CONF_SUPL_DEBUG = $var_supl_debug
CONF_ASN1_SKELETONS = $var_asn1c_skeletons
EOF

echo Generated config.mk

exit 0
