#! /bin/sh
# 
# efltk-config
#
# original version by James Dean Palmer, adapted by Vincent Penne
#
# "$Id: efltk-config.in,v 1.9 2003/03/13 11:29:52 laza2000 Exp $"
#

MAJOR_VERSION=2
MINOR_VERSION=0
PATCH_VERSION=5
VERSION="$MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION"

### BEGIN efltk-config

# Calculate the prefix from the location of *this* file
prefix=`echo "$0" | sed 's/\/bin\/efltk-config//
s/\/efltk-config//'`

#prefix=/usr/pkg
exec_prefix=${prefix}
exec_prefix_set=no
bindir=${exec_prefix}/bin
includedir=${prefix}/include
libdir=${exec_prefix}/lib
srcdir=.

# compiler names
CXX="c++"
CC="gcc"

# flags for C++ compiler:
CFLAGS="-fexceptions -DFL_SHARED -I/usr/X11R7/include"
CXXFLAGS="-fexceptions -I/usr/X11R7/include -D_REENTRANT -I/usr/pkg/include/freetype2 -I/usr/pkg/include/libpng16 -I/usr/pkg/include -DFL_SHARED -I/usr/X11R7/include"

# program to make the archive:
LIBNAME="@LIBNAME@"
LIBCOMMAND="ar cr"
RANLIB="ranlib"
DSOLIBNAME="@DSOLIBNAME@"
DSOCOMMAND="${CXX} -Wl,-soname,${DSONAME} -shared  -o"

# flags for the linker
LD_PLUGIN_FLAGS="@LD_PLUGIN_FLAGS@"

# libraries to link with:
IMAGELIBS=" -lpng -lz  -ljpeg"

# programs to make archive and build DSOs
RANLIB="ranlib"
DSOCOMMAND="${CXX} -Wl,-soname,${DSONAME} -shared  -o"

usage ()
{
    echo "Usage: efltk-config [OPTIONS]
Options:
	[--prefix[=DIR]]  return/set where FLTK is installed
	[--exec-prefix[=DIR]]
	[--version]

options telling what we are doing :
	[--use-gl]        use GL
	[--use-xml]       use XML extension library
	[--use-odbc]      use ODBC database driver
	[--use-mysql]     use MySQL database driver
	[--use-images]    use extra image formats (PNG, Jpeg)
        [--multithread]   build a multithreaded program
	[--build-plugin]  build a plugin

options telling what information we request
	[--cflags]        return flags to compile C using FLTK
	[--cxxflags]      return flags to compile C++ using FLTK
	[--ldflags]       return flags to link against FLTK
	[--ldstaticflags] return flags to link against static FLTK library
                                          even if there are DSOs installed
	[--libs]          return FLTK libraries full path for dependencies

options compiling and linking an application:
	[-g]              compile the program with debugging information
	[--compile program.cpp]
        [--output program] if output is not set, basename is used as output

"
    exit $1
}

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

no_plugins=no
compile=
debug=
output=

# Parse command line options
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 $VERSION
      ;;
    --use-gl)
      use_gl=yes
      ;;
    --use-images)
      use_images=yes
      ;;
    --use-xml)
      use_xml=yes
      ;;
    --use-odbc)
      use_odbc=yes
      ;;
    --use-mysql)
      use_mysql=yes
      ;;
    --multithread)
      use_threads=yes
      ;;
    --build-plugin)
      build_plugin=yes
      ;;
    --cflags)
      echo_cflags=yes
      ;;
    --cxxflags)
      echo_cxxflags=yes
      ;;
    --ldflags)
      echo_ldflags=yes
      ;;
    --ldstaticflags)
      echo_ldstaticflags=yes
      ;;
    --libs)
      echo_libs=yes
      ;;
    --compile)
      compile=$2
      shift
      ;;
    -g)
      debug=-g3
      ;;
    -o)
      output=$2
      shift
      ;;
    *)
      echo_help=yes
      ;;
  esac
  shift
done

# Calculate needed libraries
LDLIBS=""
LDSTATIC=""
LIBS=""

if test "$use_gl" = "yes"; then
    LDLIBS="$LDLIBS -lefltk_gl "
    LDSTATIC="$LDSTATIC $prefix/lib/libefltk_gl.a "
    LIBS="$LIBS $prefix/lib/libefltk_gl.a"
fi

if test "$use_images" = "yes"; then
    LDLIBS="$LDLIBS -lefltk_images $IMAGELIBS"
    LDSTATIC="$LDSTATIC $prefix/lib/libefltk_images.a $IMAGELIBS"
    LIBS="$LIBS $prefix/lib/libefltk_images.a"
fi

if test "$use_xml" = "yes"; then
    LDLIBS="$LDLIBS -lefltk_xml"
    LDSTATIC="$LDSTATIC $prefix/lib/libefltk_xml.a"
    LIBS="$LIBS $prefix/lib/libefltk_xml.a"
fi

if test "$use_odbc" = "yes"; then
    LDLIBS="$LDLIBS -lefltk_odbc "
    LDSTATIC="$LDSTATIC $prefix/lib/libefltk_odbc.a "
    LIBS="$LIBS $prefix/lib/libefltk_odbc.a"
fi

if test "$use_mysql" = "yes"; then
    LDLIBS="$LDLIBS -lefltk_mysql "
    LDSTATIC="$LDSTATIC $prefix/lib/libefltk_mysql.a "
    LIBS="$LIBS $prefix/lib/libefltk_mysql.a"
    CXXFLAGS="$CXXFLAGS "
fi

if test "$build_plugin" = "yes"; then
    LDLIBS="$LDLIBS $LD_PLUGIN_FLAGS"
    LDSTATIC="$LDSTATIC $LD_PLUGIN_FLAGS"
fi

LDLIBS="$LDLIBS -lefltk -L/usr/pkg/lib -L/usr/lib -Wl,-R/usr/lib -Wl,-R/usr/pkg/lib -L/usr/X11R7/lib -Wl,-R/usr/X11R7/lib -L/usr/X11R7/lib  -lX11 -lXext -lm -Wl,-rpath,/usr/X11R7/lib -L/usr/X11R7/lib -lXft -liconv"
LDSTATIC="$LDSTATIC $prefix/lib/libefltk.a -L/usr/pkg/lib -L/usr/lib -Wl,-R/usr/lib -Wl,-R/usr/pkg/lib -L/usr/X11R7/lib -Wl,-R/usr/X11R7/lib -L/usr/X11R7/lib  -lX11 -lXext -lm -Wl,-rpath,/usr/X11R7/lib -L/usr/X11R7/lib -lXft -liconv"
LIBS="$LIBS $prefix/lib/libefltk.a"

if test "$use_threads" = "yes"; then
    LDLIBS="$LDLIBS  -pthread "
    LDSTATIC="$LDSTATIC  -pthread "
fi

# Answer to user requests
if test -n "$echo_help"; then usage 1
fi

if test -n "$compile"; then

    if test -n "$output"; then
	prog=$output
    else
    case $compile in
        *.cxx)
            prog=`basename $compile .cxx`
	    ;;
        *.cpp)
            prog=`basename $compile .cpp`
	    ;;
        *.cc)
            prog=`basename $compile .cc`
	    ;;
        *.C)
            prog=`basename $compile .C`
	    ;;
	*)
	    echo "ERROR: Unknown/bad C++ source file extension on \"$compile\"!"
	    exit 1
	    ;;
    esac
    fi
	    
    post=$prog

    echo $CXX $CXXFLAGS $debug -o $prog $compile $LDLIBS
    $CXX $CXXFLAGS $debug -o $prog $compile $LDLIBS
fi

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
    if test "$includedir" = "/usr/include"; then
	includes=
    else
      includes=-I`echo "$0" | sed 's/\/bin\/efltk-config/\/include/
s/\/efltk-config//'`
    fi
      echo $includes $CFLAGS
fi

if test "$echo_cxxflags" = "yes"; then
    if test "$includedir" = "/usr/include"; then
	includes=
    else
      includes=-I`echo "$0" | sed 's/\/bin\/efltk-config/\/include/
s/\/efltk-config//'`
    fi
      echo $includes $CXXFLAGS
fi

if test "$echo_ldflags" = "yes"; then
      my_libs=
      libdirs=-L${exec_prefix}/lib
      for i in $LDLIBS ; do
        if test $i != -L${exec_prefix}/lib ; then
          if test -z "$my_libs" ; then
            my_libs="$i"
          else
            my_libs="$my_libs $i"
          fi
        fi
      done
      echo $libdirs $my_libs
fi

if test "$echo_ldstaticflags" = "yes"; then
      echo $LDSTATIC
fi

if test "$echo_libs" = "yes"; then
      echo $LIBS
fi

# END of efltk-config
