#!/bin/sh

build="i686-pc-linux-gnu"
buildalias=""
buildtriplet="i686-pc-linux-gnu"
host="i686-pc-linux-gnu"
hostalias=""
hosttriplet="i686-pc-linux-gnu"
target="i686-pc-linux-gnu"
targetalias=""
targettriplet="i686-pc-linux-gnu"

prefix=/usr
exec_prefix=${prefix}
bindir=${exec_prefix}/bin
libdir=${exec_prefix}/lib

exec_prefix_set=no

libs="-ldl -lm "
cflags="-g -O2 -g -O2 -DEC_DEBUG_MINIMUM"
ccshared="-fPIC"
ldshared="gcc -shared"
linkforshared="-Xlinker -export-dynamic"
so=".so"
cc="gcc"

version=0.0.36

api_version=9
api_revision=0
binary_age=1
lt_version_info=9:0:1

elasticconfig_version=0.02

usage()
{
	cat <<EOF
elastic-config version $elasticconfig_version
Copyright (C) 1999-2000 Marco Pantaleoni. All rights reserved.
Usage: elastic-config [OPTIONS]
Options:
   --build  | --buildalias  | --buildtriplet
   --host   | --hostalias   | --hosttriplet
   --target | --targetalias | --targettriplet
   --prefix
   --exec-prefix
   --bindir
   --libdir
   --libs
   --cflags
   --ccshared
   --ldshared
   --linkforshared
   --so
   --cc
   --makemodule
   --makemoduleflags
   --makemodulelibs
   --api-full-version
   --api-version
   --api-revision
   --binary-age
   --version-info
   --version
EOF
	exit $1
}

if test $# -eq 0; then
	usage 1 1>&2
fi

while test $# -gt 0; do
  case "$1" in
  -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
  *) optarg= ;;
  esac

  case $1 in
    --build)
      echo_build=yes
      ;;
    --buildalias)
      echo_buildalias=yes
      ;;
    --buildtriplet)
      echo_buildtriplet=yes
      ;;
    --host)
      echo_host=yes
      ;;
    --hostalias)
      echo_hostalias=yes
      ;;
    --hosttriplet)
      echo_hosttriplet=yes
      ;;
    --target)
      echo_target=yes
      ;;
    --targetalias)
      echo_targetalias=yes
      ;;
    --targettriplet)
      echo_targettriplet=yes
      ;;
    --prefix=*)
      prefix=$optarg
      if test $exec_prefix_set = no ; then
        exec_prefix=$optarg
      fi
      ;;
    --prefix)
      echo_prefix=yes
      ;;
    --exec-prefix=*)
      exec_prefix=$optarg
      exec_prefix_set=yes
      ;;
    --exec-prefix)
      echo_exec_prefix=yes
      ;;
    --bindir)
      echo_bindir=yes
      ;;
    --libdir)
      echo_libdir=yes
      ;;
    --libs)
      echo_libs=yes
      ;;
    --cflags)
      echo_cflags=yes
      ;;
    --ccshared)
      echo_ccshared=yes
      ;;
    --ldshared)
      echo_ldshared=yes
      ;;
    --linkforshared)
      echo_linkforshared=yes
      ;;
    --so)
      echo_so=yes
      ;;
    --cc)
      echo_cc=yes
      ;;
    --makemodule | --mkmodule | --make-module | --mk-module)
      echo_makemodule=yes
      ;;
    --makemoduleflags | --mkmoduleflags | --make-module-flags | --mk-module-flags)
      echo_makemoduleflags=yes
      ;;
    --makemodulelibs | --mkmodulelibs | --make-module-libs | --mk-module-libs)
      echo_makemodulelibs=yes
      ;;
    --api-full-version)
      echo ${api_version}.${api_revision}
      ;;
    --api-version)
      echo $api_version
      ;;
    --api-revision)
      echo $api_revision
      ;;
    --binary-age)
      echo $binary_age
      ;;
    --version-info)
      echo $lt_version_info
      ;;
    --version)
      echo $version
      ;;
    *)
      usage 1 1>&2
      ;;
  esac
  shift
done

if test "$echo_build" = "yes"; then
	echo $build
fi

if test "$echo_buildalias" = "yes"; then
	echo $buildalias
fi

if test "$echo_buildtriplet" = "yes"; then
	echo $buildtriplet
fi

if test "$echo_host" = "yes"; then
	echo $host
fi

if test "$echo_hostalias" = "yes"; then
	echo $hostalias
fi

if test "$echo_hosttriplet" = "yes"; then
	echo $hosttriplet
fi

if test "$echo_target" = "yes"; then
	echo $target
fi

if test "$echo_targetalias" = "yes"; then
	echo $targetalias
fi

if test "$echo_targettriplet" = "yes"; then
	echo $targettriplet
fi

if test "$echo_prefix" = "yes"; then
	echo $prefix
fi

if test "$echo_exec_prefix" = "yes"; then
	echo $exec_prefix
fi

if test "$echo_bindir" = "yes"; then
	echo $bindir
fi

if test "$echo_libdir" = "yes"; then
	echo $libdir
fi

if test "$echo_libs" = "yes"; then
      my_libs=
      libdirs=-L${exec_prefix}/lib
      for i in $libs ; do
        if test $i != -L${exec_prefix}/lib ; then
          if test -z "$my_libs" ; then
            my_libs="$i"
          else
            my_libs="$my_libs $i"
          fi
        fi
      done

      echo $libdirs -lelastic $my_libs
fi

if test "$echo_cflags" = "yes"; then
      if test ${prefix}/include != /usr/include ; then
        includes=-I${prefix}/include
        for i in $cflags ; do
          if test $i = -I${prefix}/include ; then
            includes=""
          fi
        done
      fi
      echo $includes $cflags
fi

if test "$echo_ccshared" = "yes"; then
      echo $ccshared
fi

if test "$echo_ldshared" = "yes"; then
      echo $ldshared
fi

if test "$echo_linkforshared" = "yes"; then
      echo $linkforshared
fi

if test "$echo_so" = "yes"; then
      echo $so
fi

if test "$echo_cc" = "yes"; then
	echo $cc
fi

elastic_config_dir=`echo $0|sed 's%/[^/][^/]*$%%'`
if test -f ${elastic_config_dir}/elastic-config ; then
    elastic_config="${elastic_config_dir}/elastic-config"
else
    elastic_config="${bindir}/elastic-config"
fi
makemodule="${bindir}/makemodule"
makemoduleflags="-c ${elastic_config} --elastic-import=${libdir}/libelastic.a"
makemodulelibs=""

if test "$echo_makemodule" = "yes"; then
      echo $makemodule
fi

if test "$echo_makemoduleflags" = "yes"; then
      echo $makemoduleflags
fi

if test "$echo_makemodulelibs" = "yes"; then
      echo $makemodulelibs
fi
