#! /bin/sh

prefix=/usr
libdir=${exec_prefix}/lib
includedir=${prefix}/include
moduleconfdir=${prefix}/share/gmetadom

undefined()
{
	echo "Sorry, no '$moduleconfdir/$1.conf' was found."
	exit 1
}

usage()
{
    cat <<EOF
Usage: gmetadom-config [OPTION...]

Known values for OPTION are:

  --help		display this help and exit
  --version		output version information
  --prefix=DIR		change gmetadom prefix [default $prefix]
  --module=MOD          select a gmetadom module
  --cflags		print pre-processor and compiler flags
  --libs		print library linking information

Note that, before using options --cflags and --libs, the requested
module (and possibly the prefix) must be specified.

EOF

    exit $1
}

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

cflags=false
libs=false

module=""
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
	;;

    --module=*)
        module=$optarg
    	;;

    --module)
        for i in $moduleconfdir/*.conf; do
		echo $i | cut -d '.' -f1
	done
        ;;

    --version)
        if test x$module = x; then
		echo 0.0.3
	else
		if ! test -r $moduleconfdir/$module.conf; then
			undefined $module
		fi
		fgrep "version=" $moduleconfdir/$module.conf | cut -d '=' -f2
	fi
	exit 0
	;;

    --help)
	usage 0
	;;

    --cflags)
        if test x$module = x; then
		usage 1
	fi
	if ! test -r $moduleconfdir/$module.conf; then
		undefined $module
	fi
	echo -n "-I$includedir/gmetadom/$module "
	fgrep "cflags=" $moduleconfdir/$module.conf | cut -d '=' -f2
       	;;

    --libs)
        if test x$module = x; then
		usage 1
	fi
	if ! test -r $moduleconfdir/$module.conf; then
		undefined $module
	fi
	echo -n "-lgmetadom_$module "
	fgrep "libs=" $moduleconfdir/$module.conf | cut -d '=' -f2
       	;;

    *)
	usage 1
	;;
    esac
    shift
done

exit 0

