#!/bin/bash

function header {
    echo -e "\033[0;34m==>\033[0;0;1m $1 \033[0;0m"
}
function middle {
    echo -e "\033[0;33m==>\033[0;0;1m $1 \033[0;0m"
}


header "Last.fm Configure"
middle "Checking for qmake..."

qmake-qt4 -v &> /dev/null
if [[ $? == 127 ]]
then
    qmake -v &> /dev/null
    if [[ $? == 0 ]]
    then
        QMAKE=qmake
    fi
else
    QMAKE=qmake-qt4
fi

if [[ $? == 127 ]]
then
          ##########################################################################80-->
	echo "Sorry, qmake was not found, is Qt4 installed? You will want to install your "
	echo "distribution's packages of qt4 _and_ qt4-devel."
	exit
fi

middle "Checking the installed version of Qt is correct..."

# valid qmake output
# QMake version 2.01a
# Using Qt version 4.2.2 in /opt/qt/4.2.2/lib

$QMAKE -v | grep -q '^Using Qt version 4.[3-9]' &> /dev/null

if [[ $? > 0 ]]
then
	      ##########################################################################80-->
	echo "Your version of Qt seems to be too old, we require Qt 4.3 or above."
	echo
	echo "It is possible you have Qt3 and Qt4 both installed. Locate your qt4 installation"
	echo "and ensure it is placed first in the path, eg:"
	echo
	echo "	PATH=/opt/qt4/bin:\$PATH ./configure"
	echo
	echo "However this configure script is very basic, perhaps we got it wrong.."
	echo "Try typing the following, perhaps it will build for you :)"
	echo
	echo "	qmake -config release && make"
	exit
fi

middle "Generating Makefiles..."

$QMAKE -config release

#HACK because build system is b0rked
mkdir -p build/fplib/release

echo "Good, your configure is finished. Now type 'make'"
echo "If you have problems during the build, consult the README file."
