#!/bin/sh

thisdir=$(dirname "$0")
if test "$thisdir" = "." ; then
  thisdir=$PWD
fi
prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include
libdir=${exec_prefix}/lib
libversion=
libextension=so
plugincxxflags="-fPIC -DPIC"
pluginldflags=-shared
pluginpath=${libdir}/tlp

WINNT=$(sh -c 'uname -s | grep -q MINGW32_NT; echo $?')
MACOSX=$(sh -c 'uname -s | grep -q Darwin; echo $?')
LINUX=$(sh -c 'uname -s | grep -q Linux; echo $?')

# check for MacOS or Windows installation
if [ $MACOSX -eq 0 ] ; then
  libextension=dylib
  pluginldflags="-bundle -Wl,-bind_at_load -flat_namespace"
  if [ -d $(dirname $thisdir)/lib ] ; then
# MacOS bundle
    includedir=$(dirname $thisdir)/include
    libdir=$(dirname $thisdir)/lib
    pluginpath=${libdir}/tlp
  fi
fi
if [ $WINNT -eq 0 ] ; then
  libversion=-
  libextension=dll
  plugincxxflags=-DPIC
  if [ -f "$thisdir/uninst-Tulip.exe" ] ; then
#   Windows installation
    drive=`echo ${thisdir} | awk -F / '{print $2}'`
    thisdir=${thisdir/\/$drive\//$drive:/}
    includedir=${thisdir}/include
    libdir=${thisdir}
    pluginpath=${libdir}/lib/tlp
  else
    pluginpath=${libdir}/bin
    libdir=${exec_prefix}/bin
  fi
fi

usage()
{
    cat <<EOF
Usage: tulip-config [OPTIONS]
Options:
	--version (return the current version of Tulip)
	--libs (return the whole Tulip libs)
	--lib_tulip (return the Tulip core lib)
        --lib_ogl (return the Tulip OpenGL lib)
	--cxxflags (return the Tulip needed cxx flags)
	--glincludes (return the OpenGL includes)
	--gllibs (return the OpenGL libs)
	--plugincxxflags (return the Tulip plugin cxx flags)
	--pluginextension (return the plugin file extension)
	--pluginldflags (return the plugin loader flags)
        --pluginpath (return the path for installation of Tulip plugins)
        --qtincludes (return the Qt includes)
        --qtlibs (return the Qt libs needed by Tulip)
	
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
    --version)
      echo 3.1.2
      ;;
    --cxxflags)
      echo -I${includedir}  -DQT_NO_DEBUG -DQT_MINOR_REL=7
      ;;
    --glincludes)
      echo -I/usr/include
      ;;
    --gllibs)
      echo -L/usr/lib -lGLEW -lGLU -lGL
      ;;
    --libs)
      echo -L${libdir} -ltulip${libversion} -ltulip-ogl${libversion} -ltulip-qt4${libversion}
      ;;
    --lib_tulip)
      echo -L${libdir} -ltulip${libversion}
      ;;
    --lib_ogl)
      echo -L${libdir} -ltulip-ogl${libversion}
      ;;
    --plugincxxflags)
      echo ${plugincxxflags}
      ;;
    --pluginldflags)
      echo ${pluginldflags}
      ;;
    --pluginextension)
      echo ${libextension}
      ;;
    --pluginpath)
      echo ${pluginpath}
      ;;
    --qtlibs)
      echo -L/usr/lib/x86_64-linux-gnu -lQtCore -lQtGui -lQtOpenGL -lQtXml -lQtNetwork
      ;;
    --qtincludes)
      echo -I/usr/share/qt4/include -I/usr/share/qt4/include/Qt -I/usr/share/qt4/include/QtDesigner
      ;;
    *)
      usage
      ;;
  esac
  shift
done

exit 0
