#! /bin/sh

prefix=/usr/local
exec_prefix=${prefix}
includedir=${prefix}/include

usage()
{
    cat <<EOF
Usage: libglade-config [OPTION] [LIBRARIES]

Known values for OPTION are:

  --prefix=DIR		change libglade prefix [default $prefix]
  --libs		print library linking information
  --cflags		print pre-processor and compiler flags
  --check		just check for library.
  --help		display this help and exit
  --version		output version information

Possible widget libraries:
  gtk (included by default)
  gnome
  bonobo
  gnomedb
EOF

    exit $1
}

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

cflags=false
libs=false

lib_gtk=yes
lib_gnome=no
lib_bonobo=no
lib_gnomedb=no

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
	;;

    --version)
	echo libglade 0.17
	exit 0
	;;

    --help)
	usage 0
	;;

    --cflags)
	echo_cflags=yes
       	;;

    --libs)
	echo_libs=yes
       	;;

    --check)
	;;

    gtk)
	lib_gtk=yes
	;;
    gnome)
	lib_gnome=yes
	;;
    bonobo)
	lib_gnome=yes   # bonobo implies gnome
	lib_bonobo=yes
	;;
    gnomedb)            # gnomedb implies gnome
        lib_gnome=yes
        lib_gnomedb=yes
        ;;

    *)
	usage 1 1>&2
	exit 1
	;;
    esac
    shift
done

# This is uncommented when we have no GNOME support ...
if test "$lib_gnome" = "yes"; then
  echo "*** GNOME support was not compiled into libglade" 1>&2
  exit 1
fi

# This is uncommented when we have no BONOBO support ...
if test "$lib_bonobo" = "yes"; then
  echo "*** Bonobo support was not compiled into libglade" 1>&2
  exit 1
fi

# This is uncommented when we have no GNOME-DB support ...
if test "$lib_gnomedb" = "yes"; then
  echo "*** GNOME-DB support was not compiled into libglade" 1>&2
  exit 1
fi

if test "$echo_cflags" = "yes"; then
    cflags="-I/usr/local/include/gnome-xml -I${prefix}/include/libglade-1.0"
    if test "$lib_bonobo" = "yes"; then
	cflags="$cflags "
    elif test "$lib_gnomedb" = "yes"; then
        cflags="$cflags "
    elif test "$lib_gnome" = "yes"; then
	cflags="$cflags "
    else
	cflags="$cflags -I/usr/local/include/gtk-1.2 -I/usr/local/include/glib-1.2 -I/usr/X11R6/include"
    fi
    echo $cflags
fi

if test "$echo_libs" = "yes"; then
    libs=""
    libsa=""
    if test "$lib_gtk" = "yes"; then
	libs="-lglade"
	libsa="-L/usr/local/lib -L/usr/X11R6/lib -lgtk -lgdk -Wl,-E -lgmodule -lglib -lintl -liconv -lXi -lXext -lX11 -lm"
    fi
    if test "$lib_gnome" = "yes"; then
	libs="-lglade-gnome $libs"
	libsa=" "
    fi
    if test "$lib_bonobo" = "yes"; then
	libs="-lglade-bonobo $libs"
	libsa=" "
    fi
    if test "$lib_gnomedb" = "yes"; then
	libs="-lglade-gnomedb $libs"
	libsa=" "
    fi
    echo -L${exec_prefix}/lib $libs -L/usr/local/lib -lxml -lz $libsa
fi

exit 0
