#!/bin/bash

# QMAKESPEC is possibly also required on some systems
# See Qt/qmake docs for your system and Evolvotron README if you have any problems.
if [ -z "$QTDIR" ] ; then
  echo "QTDIR not defined"
  echo "You almost certainly need QTDIR defined and pointing at your QT installation"
  echo "If you know different, edit ./configure and remove this test."
  exit 1
fi

# TODO?: Should perhaps test "which qmake" here.
# If not found, add $(QTDIR)/bin to path.  But the ./BUILD script does that.
echo "Your qmake version is:"
qmake-qt4 --version 

echo
echo "Your gcc version is (unless qmake is set up to use a different one):"
gcc --version

echo
echo "Building built-in user documentation..."
if ! ./text_to_markup.py -html < USAGE > evolvotron.html ; then echo "Couldn't build evolvotron.html" ; fi
if ! ./text_to_markup.py -qml -s < USAGE > libevolvotron/usage_text.h ; then echo "Couldn't build libevolvotron/usage_text.h" ; fi
if ! test -s libevolvotron/usage_text.h ; then echo "\"Full built-in user documentation not available due to problem during build configuration\"" > libevolvotron/usage_text.h ; echo "Something went wrong, used built-in user documentation fallback plan"; fi
echo "...built built-in user documentation"

CONFIG_OPTS="$@"
VERSION_NUMBER=`./VERSION`

echo
echo "Running qmake-qt4 with CONFIG_OPTS=$CONFIG_OPTS VERSION_NUMBER=$VERSION_NUMBER..."

qmake-qt4 "CONFIG_OPTS=$CONFIG_OPTS" "VERSION_NUMBER=$VERSION_NUMBER" main.pro 

echo "...configuration completed - ready to do 'make' now"
