#!/bin/sh

DIFS=' 
'

prefix="/usr/pkg"
exec_prefix="/usr/pkg"

ganglia_prefix="$prefix"
ganglia_exec_prefix="$exec_prefix"
ganglia_bindir="/usr/pkg/bin"
ganglia_libdir="/usr/pkg/lib"
ganglia_includedir="/usr/pkg/include"
ganglia_datarootdir="/var/db/ganglia"
ganglia_cflags="-O2 -I/usr/pkg/include -I/usr/include -I/usr/pkg/include/freetype2 -Dz_off_t=long -I/usr/X11R7/include -I/usr/pkg/include/glib-2.0 -I/usr/pkg/include/gio-unix-2.0 -I/usr/pkg/lib/glib-2.0/include -I/usr/pkg/include/harfbuzz -I/usr/pkg/include/libxml2 -I/usr/pkg/include/apr-1 -fno-strict-aliasing -Wall"
ganglia_ldflags="-L/usr/pkg/lib -Wl,-R/usr/pkg/lib -L/usr/lib -Wl,-R/usr/lib -L/usr/X11R7/lib -Wl,-R/usr/X11R7/lib -lpthread  -Wl,-R/usr/pkg/lib -L/usr/pkg/lib -lapr-1 -lrt -lcrypt -lpthread"
ganglia_libs="-lkvm -lz -lpcre -lexpat -lconfuse -lpthread "
ganglia_version="3.7.2"

help=no
version=no

usage="ganglia-config"
usage="$usage [--help] [--version] [--all]"
usage="$usage [--prefix] [--exec-prefix] [--bindir] [--libdir] [--includedir] [--datarootdir]"
usage="$usage [--cflags] [--ldflags] [--libs]"
if [ $# -eq 0 ]; then
    echo "ganglia-config:Error: Invalid option" 1>&2
    echo "ganglia-config:Usage: $usage" 1>&2
    exit 1
fi
output=''
output_extra=''
all=no
prev=''
OIFS="$IFS" IFS="$DIFS"
for option
do
    if [ ".$prev" != . ]; then
        eval "$prev=\$option"
        prev=''
        continue
    fi
    case "$option" in
        -*=*) optarg=`echo "$option" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
           *) optarg='' ;;
    esac
    case "$option" in
        --help|-h)
            echo "Usage: $usage"
            echo "Report bugs to ganglia-developers@lists.sourceforge.net"
            exit 0
            ;;
        --version|-v)
            echo "Ganglia $ganglia_version"
            exit 0
            ;;
        --all)
            all=yes
            ;;
        --prefix)
            output="$output $ganglia_prefix"
            ;;
        --exec-prefix)
            output="$output $ganglia_exec_prefix"
            ;;
        --bindir)
            output="$output $ganglia_bindir"
            ;;
        --libdir)
            output="$output $ganglia_libdir"
            ;;
        --includedir)
            output="$output $ganglia_includedir"
            ;;
	--datarootdir)
	    output="$output $ganglia_datarootdir"
	    ;;
        --cflags)
            output="$output -I$ganglia_includedir"
            output_extra="$output_extra $ganglia_cflags"
            ;;
        --ldflags)
            output="$output -L$ganglia_libdir"
            output_extra="$output_extra $ganglia_ldflags"
            ;;
        --libs)
            output="$output -lganglia"
            output_extra="$output_extra $ganglia_libs"
            ;;
        * )
            echo "ganglia-config:Error: Invalid option" 1>&2
            echo "ganglia-config:Usage: $usage" 1>&2
            exit 1;
            ;;
    esac
done
IFS="$OIFS"
if [ ".$prev" != . ]; then
    echo "ganglia-config:Error: missing argument to --`echo $prev | sed 's/_/-/g'`" 1>&2
    exit 1
fi
if [ ".$output" != . ]; then
    if [ ".$all" = .yes ]; then
        output="$output $output_extra"
    fi
    echo $output
fi

