#!/bin/sh

prefix=/usr
exec_prefix=/usr
libdir=/usr/lib
includedir=/usr/include

exec_prefix_flag=no
debug_flag=no
static_flag=no

usage()
{
  cat <<EOF
Usage: itpp-config [OPTION]

Known values for OPTION are:

  --prefix        output libitpp installation prefix
  --exec-prefix   output libitpp installation exec prefix
  --debug         output debugging pre-processor, compiler and linker
                  flags (should be used in front of --cflags and --libs)
  --static        output linker flags for static linking
                  (needs to be used in front of --libs)
  --cflags        output pre-processor and compiler flags
  --libs          output linker flags
  --help          display this help and exit
  --version       output version information
EOF
  exit $1
}

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

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

  case $1 in
    --prefix=*)
      prefix="$optarg"
      if test "x$exec_prefix_flag" = xno; then
        exec_prefix="$optarg"
      fi
      ;;
    --prefix)
      echo "$prefix"
      ;;
    --exec-prefix=*)
      exec_prefix="$optarg"
      exec_prefix_flag=yes
      ;;
    --exec-prefix)
      echo "$exec_prefix"
      ;;
    --version)
      echo "4.0.0"
      ;;
    --help)
      usage 0
      ;;
    --debug)
      debug_flag=yes
      ;;
    --static)
      static_flag=yes
      ;;
    --cflags)
      cflags_str="-I${includedir}"
      if test "x$debug_flag" = xyes; then
        cflags_str="${cflags_str} "
      else
        cflags_str="${cflags_str} -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32"
      fi
      echo "${cflags_str}"
      ;;
    --cflags-deb*)
      echo "-I${includedir} "
      ;;
    --cflags-opt*)
      echo "-I${includedir} -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m32"
      ;;
    --libs)
      libs_str="-L${libdir}"
      if test "x$debug_flag" = xno; then
        libs_str="${libs_str} -litpp"
      else
        libs_str="${libs_str} -litpp"
      fi
      if test "x$static_flag" = xyes; then
        libs_str="${libs_str} -L/usr/lib/atlas -lfftw3 -llapack -latlas -lblas"
      fi
      echo "${libs_str}"
      ;;
    --libs-deb*)
      echo "${libs_str} -litpp -L/usr/lib/atlas -lfftw3 -llapack -latlas -lblas"
      ;;
    --libs-opt*)
      echo "-L${libdir} -litpp -L/usr/lib/atlas -lfftw3 -llapack -latlas -lblas"
      ;;
    *)
      usage 1
      ;;
  esac
  shift
done
