#!/bin/sh

prefix=/usr/X11R6
exec_prefix=${prefix}
exec_prefix_set=no

lib_dps=""
lib_dpstk=""
lib_psres=""
lib_all="yes"

usage()
{
	cat <<EOF
Usage: dgs-config [OPTIONS] [LIBRARIES]
Options:
	[--prefix[=DIR]]
	[--exec-prefix[=DIR]]
	[--version]
	[--libs]
	[--cflags]
Libraries:
	dps
	dpstk
	psers
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
      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
      ;;
    --version)
      echo 0.5.8
      exit 0
      ;;
    --cflags)
      if test "${prefix}/include" != /usr/include ; then
        includes="-I${prefix}/include"
      fi 
      echo_cflags=yes
      ;;
    --libs)
      echo_libs=yes
      ;;
    dps)
      lib_dps=yes
      lib_all=no
      ;;
    dpstk)
      lib_dpstk=yes
      lib_all=no
      ;;
    psres)
      lib_psres=yes
      lib_all=no
      ;;
    *)
      usage 1 1>&2
      ;;
  esac
  shift
done

if test "$echo_prefix" = "yes"; then
	echo $prefix
fi
if test "$echo_exec_prefix" = "yes"; then
	echo $exec_prefix
fi
if test "$echo_cflags" = "yes"; then
	echo $includes " -I/usr/X11R6/include"
fi
if test "$echo_libs" = "yes"; then
	libsp=""
	libsa=""
	lib=""
	if test "$lib_all" = "yes"; then
		lib="-ldpstk -ldps -lpsres"
		libsp=" -lSM -lICE"
		libsa="-lX11  -lm"
	else
	    if test "$lib_dpstk" = "yes"; then
		lib_dps="yes"
		lib_dpstk=-ldpstk
	    else
		lib_dpstk=""
	    fi

	    if test "$lib_dps" = "yes"; then
		lib_dps=-ldps
		libsp=" -lSM -lICE"
		libsa="-lX11  -lm"
	    else
		lib_dps=""
	    fi
	    
	    if test "$lib_psres" = "yes"; then
		lib_psres=-lpsres
	    else
		lib_psres=""
	    fi
	    lib="$lib_dpstk $lib_dps $lib_psres"
	fi
	echo $libsp -L${exec_prefix}/lib $lib $libsa
fi
