#!/bin/sh

# This script was borrowed from GNet

gnet_cflags=""
gnet_libs=""

prefix=/usr
exec_prefix=${prefix}
exec_prefix_set=no
cflags="-I${exec_prefix}/lib/emcast/include"
libs="-L${exec_prefix}/lib"


usage()
{
	cat <<EOF
Usage: emcast-config [OPTIONS] [LIBRARIES]
Options:
	[--prefix[=DIR]]
	[--exec-prefix[=DIR]]
	[--version]
	[--libs]
	[--cflags]
Libraries:
	emcast
        btp
EOF
	exit $1
}

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

lib_emcast=no
lib_btp=no
mod_specified=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
      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 0.3.2
      ;;
    --cflags)
      echo_cflags=yes
      ;;
    --libs)
      echo_libs=yes
      ;;
    emcast)
      lib_emcast=yes
      mod_specified=yes
      ;;
    btp)
      lib_btp=yes
      mod_specified=yes
      ;;
    *)
      usage 1 1>&2
      ;;
  esac
  shift
done

if test "$mod_specified" = "no"; then
    lib_emcast=yes
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
    # Include ${prefix}/include if it's in a non-standard place
    if test ${prefix}/include != /usr/include ; then
      cflags="-I${prefix}/include $cflags"
    fi
      emcast_cflags=""
      emcast_libs="-lemcast"
      btp_cflags="-I${prefix}/include/btp $gnet_cflags"
      btp_libs="-lbtp $gnet_libs"

    if test "$lib_emcast" = "yes"; then
      cflags="$cflags -I${prefix}/include/emcast"
    fi
    if test "$lib_btp" = "yes"; then
      cflags="$cflags -I${prefix}/include/btp $gnet_cflags"
    fi

    echo $cflags
fi

if test "$echo_libs" = "yes"; then
    if test "$lib_emcast" = "yes"; then
      libs="$libs -lemcast"
    fi
    if test "$lib_btp" = "yes"; then
      libs="$libs -lbtp $gnet_libs"
    fi
    echo $libs
fi      
