#! /bin/bash

#
# This is a completely home made bash script that make som fixes to the Makefile.
# I created this script because of a Qt bug which resulted in  compilation errors and
# because of qmake's install options doesn't work very well.
# Im solving those problems with simple sed commands.
#

echo "Starting configure script..."

# Start with generating the source and header files from setupbase.ui and msgbox.ui
${QTDIR}/bin/uic netgodialogbase.ui -o netgodialogbase.h
${QTDIR}/bin/uic netgodialogbase.ui -i netgodialogbase.h -o netgodialogbase.cpp
${QTDIR}/bin/uic setupbase.ui -o setupbase.h
${QTDIR}/bin/uic setupbase.ui -i setupbase.h -o setupbase.cpp
${QTDIR}/bin/uic msgbox.ui -o msgbox.h
${QTDIR}/bin/uic msgbox.ui -i msgbox.h -o msgbox.cpp

# Fixing the 'double const'-bug to avoid compilation errors.
sed -i 's/static const unsigned char const/static const unsigned char/g' setupbase.cpp netgodialogbase.cpp msgbox.cpp

# Do 'qmake' to generate a Makefile.
${QTDIR}/bin/qmake
echo "Generating Makefile..."

# Remove the line in the Makefile that tries to 'strip' my bash script (results in errors).
sed -i '/-strip "$(INSTALL_ROOT)\/usr\/bin\/netgo"/d' Makefile

# Remove the line that tries to do 'rmdir /usr/bin'. Funny qmake :)
sed -i '/-$(DEL_DIR) "$(INSTALL_ROOT)\/usr\/bin\/"/d' Makefile

# Change the minumun version from 3.3 to 3.2 for the GUI (this is harmless).
sed -i 's/<!DOCTYPE UI><UI version="3.3" stdsetdef="1">/<!DOCTYPE UI><UI version="3.2" stdsetdef="1">/' *.ui

echo "Setting up install options in Makefile..."
echo
echo "Good - your configure finished. Start make now"
echo
