#!/bin/sh

# MN 2007
# compile QGIS 0.9+ with Cmake
# 32 and 64bit platform, incl. Python support
#
# http://wiki.qgis.org/qgiswiki/PythonBindings

MYHOSTTYPE=`uname -m`
QGISTARGET=/usr/local/lib/qgis/
if [ "$MYHOSTTYPE" = "x86_64" ] ; then
   QTDIR=/usr/lib64/qt4
   MYHOSTTYPE=${MYHOSTTYPE}-unknown-linux-gnu

else
   QTDIR=/usr/lib/qt4
   MYHOSTTYPE=${MYHOSTTYPE}-pc-linux-gnu
fi
GRASSBINS=$HOME/grass63/dist.${MYHOSTTYPE}

## nothing to change below

mkdir -p build
cd build
cmake -D SIP_BINARY_PATH:FILEPATH=/usr/bin/sip -D GRASS_PREFIX=${GRASSBINS} -D CMAKE_INSTALL_PREFIX=${QGISTARGET} -D QT_QMAKE_EXECUTABLE=${QTDIR}/bin/qmake ..

make
if [ $? -eq 1 ] ; then
         echo "an error occured"
         exit 1
fi

# must be root maybe:

make install

if [ $? -eq 1 ] ; then
         echo "an error occured"
         exit 1
fi

# fancy start script:
echo "#!/bin/sh 

export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH:${QGISTARGET}/lib:${GRASSBINS}/lib
${QGISTARGET}/bin/qgis \$@" > /usr/local/bin/qgis

chmod a+x /usr/local/bin/qgis

echo "Compile & Install done."
exit 0


