#!/bin/sh

thisdir=$(dirname "$0")
if test "$thisdir" = "." ; then
  thisdir=$PWD
fi
prefix=/usr
exec_prefix=${prefix}
includedir=${prefix}/include/
libdir=${prefix}/lib/
sharedir=${prefix}/share/apps/cmake/modules/
libversion=-3.3
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=-3.3
  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)
	--cmakelibs (return the whole Tulip libs in cmake style)
	--lib_tulip (return the Tulip core lib)
	--cmakelib_tulip (return the Tulip core lib in cmake style)
    --lib_ogl (return the Tulip OpenGL lib)
	--cmakelib_ogl (return the Tulip OpenGL lib in cmake style)
	--cmakelib_qt (return the Tulip Qt lib in cmake style)
	--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)
		--cmakepluginpath (return the path for installation of Tulip plugins with cmake)
        --qtincludes (return the Qt includes)
        --qtlibs (return the Qt libs needed by Tulip)
        --sharepath (return the path where share data are installed)
	
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.3.0
      ;;
    --cxxflags)
      echo -I${includedir} -DQT_MINOR_REL=5
      ;;
    --glincludes)
      echo -I/usr/include
      ;;
    --gllibs)
      echo /usr/lib/libGL.so /usr/lib/libGLU.so /usr/lib/libGLEW.so 
      ;;
    --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 /usr/lib/libQtCore.so /usr/lib/libQtGui.so /usr/lib/libQtOpenGL.so /usr/lib/libQtXml.so /usr/lib/libQtNetwork.so 
      ;;
    --qtincludes)
      echo -I/usr/lib/qt4/include
      ;;
    --sharepath)
      echo ${sharedir}
      ;;
    *)
      usage
      ;;
  esac
  shift
done

exit 0
