#!/bin/sh

matrix_lib=""
plplot_libs="    -Llib -lplplotd ${matrix_lib:+-l${matrix_lib}d}  -L/usr/X11R6/lib -lX11 -lm "
plplot_cflags=" -I. -I/usr/X11R6/include"
plplot_cxx_lib="-lplcxxd"

prefix=/usr/local
version=5.0.4

usage()
{
	cat <<EOF
Usage: plplot-config [OPTIONS]
Options:
	[--prefix[=DIR]]
	[--version]
	[--libs]
	[--cflags]
        [--with-c++]
	[--help]
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
    --prefix=*)
      prefix=$optarg
      ;;
    --prefix)
      echo_prefix=yes
      ;;
    --version)
      echo $version
      ;;
    --cflags)
      echo_cflags=yes
      ;;
    --libs)
      echo_libs=yes
      ;;
    --with-c++)
      echo_cxx=yes
      ;;
    --help|*)
      usage 1 1>&2
      ;;
  esac
  shift
done

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

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

if test "$echo_libs" = "yes"; then
  my_plplot_libs=
  libdirs=-L${prefix}/lib
  for i in $plplot_libs ; do
    if test $i != -L${prefix}/lib ; then
      if test -z "$my_plplot_libs" ; then
        my_plplot_libs="$i"
      else
        my_plplot_libs="$my_plplot_libs $i"
      fi
    fi
  done
  if test "$echo_cxx" = "yes" ; then
    my_plplot_libs="$my_plplot_libs $plplot_cxx_lib"
  fi
  echo $libdirs $my_plplot_libs
fi      

