#!/bin/sh
#
# Configure script for myththemes
#

prefix="/usr/local"
sysroot=""

qmake="qmake"

for opt do
  case "$opt" in
  --prefix=*) prefix=`echo $opt | cut -d '=' -f 2`
  ;;
  --sysroot=*) sysroot=`echo $opt | cut -d '=' -f 2`
  ;;
  --qmake=*) qmake=`echo $opt | cut -d '=' -f 2`
  ;;
  esac
done

if test x"$1" = x"-h" -o x"$1" = x"--help" ; then
cat << EOF

Usage:   configure [options]
Options: [defaults in brackets after descriptions]
Generic options:
  --prefix=PREFIX          MythTV install location PREFIX [$prefix]
  --sysroot=SYSROOT        sysroot location SYSROOT [$sysroot]
  --qmake=QMAKE            use specified qmake [$qmake]
  --help                   print this message
EOF
exit 1
fi

# bring in mythtv config
if [ -e $sysroot$prefix/include/mythtv/mythconfig.mak ] ; then
  rm mythconfig.mak 2> /dev/null
  ln -s $sysroot$prefix/include/mythtv/mythconfig.mak mythconfig.mak
else
  echo "ERROR: mythconfig.mak not found at $sysroot$prefix/include/mythtv/mythconfig.mak"
  echo "Did you make AND install MythTV first?"
  echo "Are you using the correct prefix ($prefix) and sysroot ($sysroot)?"
  echo "Bailing out!!"
  exit
fi

is_qmake4()
{
    $1 --version 2>&1 | grep -q "Qt version 4"
}
 
if ! is_qmake4 $qmake; then
    if is_qmake4 qmake-qt4; then
        qmake=qmake-qt4
    else
        echo "qmake for Qt4 not found. Please specify the correct qmake with --qmake="
        exit 1
    fi
fi

${qmake} QMAKE=$(which ${qmake}) myththemes.pro
