#!/bin/sh

. ../configure.inc

HAVE_ROAR=false

while [ "$1" != '' ]
do
 case "$1" in
  --inst-dir)
   INSTALL_DIR="$2"
   shift;
  ;;
  --pkg-config)
   PKG_CONFIG="$2"
   shift;
  ;;
  --force-have-roar)
   HAVE_ROAR=true
  ;;
  --help|-h)
    cat << EOF
Usage: ./configure [OPTIONS]...

Options:
  --help               - Show this help
  --inst-dir DIR       - Install dir
  --force-have-roar    - Force to assume libroar is ok
  --pkg-config PKGCONF - Set filename for pkg-config
EOF
    exit 0
   ;;
  *)
    echo 'Unknown option. Try ./configure --help'
    exit 2
 esac
 shift;
done

on_error () {
 exit 1;
}

check_cc;
check_pkg_config;

echo -n 'testing for gtk... '

if [ "$PKG_CONFIG" != '' ]
then
 GTK_LIBS=`$PKG_CONFIG  gtk+-2.0 --libs 2> /dev/null`
 GTK_CFLAFS=`$PKG_CONFIG --cflags gtk+-2.0 2> /dev/null`
else
 GTK_LIBS=`gtk-config gtk+-2.0 --libs 2> /dev/null`
 GTK_CFLAFS=`gtk-config gtk+-2.0 --cflags 2> /dev/null`
fi

if [ "$GTK_LIBS" = '' -a "$GTK_CFLAFS" = '' ]
then
 echo no.
 on_error;
else
 echo yes
fi

echo -n 'testing for audacious version... '
if $PKG_CONFIG --atleast-version=1.5.1 audacious 2> /dev/null
then
 echo '>= 1.5.1'
else
 echo 'too old'
 on_error;
fi

echo -n 'testing for audacious... '
XMMS_LIBS=`$PKG_CONFIG audacious  --libs 2> /dev/null`
XMMS_CFLAGS=`$PKG_CONFIG audacious  --cflags 2> /dev/null`

if [ "$XMMS_LIBS" = '' -a "$XMMS_CFLAGS" = '' ]
then
 echo no.
 on_error;
else
 echo yes
fi

echo -n 'testing for audacious plugin dir... '
if [ "$INSTALL_DIR" = '' ]
then
 INSTALL_DIR="`$PKG_CONFIG --variable=output_plugin_dir audacious 2> /dev/null`"

 if [ "$INSTALL_DIR" = '' ]
 then
  echo not found.
  on_error;
 else
  echo "$INSTALL_DIR"
 fi
else
  echo "$INSTALL_DIR"
fi

check_libroar;

rm -f tests tests.c

echo creating Makefile.conf...
{
 echo "CC=$CC"
 echo
 echo "GTK_LIBS=$GTK_LIBS"
 echo "GTK_CFLAFS=$GTK_CFLAFS"
 echo
 echo "XMMS_LIBS=$XMMS_LIBS"
 echo "XMMS_CFLAGS=$XMMS_CFLAGS"
 echo
 echo "INSTALL_DIR=$INSTALL_DIR"
} > Makefile.conf

#ll
