#!/bin/sh
#
# Copyright 2004 Dagmar d'Surreal <rivyqntzne@tznvy.pbz>
# Available under the terms of the GNU GPL.
#

NAME="qt"
VERSION="3.3.5"
REVISION="1"

PKG_SOURCEURL='http://ftp.silug.org/mirrors/ftp.trolltech.com/qt/source/qt-x11-free-3.3.5.tar.bz2'
PKG_DESTDIRVAR=INSTALL_ROOT

PKG_PATCH[0]='qt-x11.diff'
PKG_PATCH[1]='qt.mysql.h.diff'
# Yes, we're faking it with these two.
PKG_PATCH[2]="qt.sh"
PKG_PATCH[3]="qt.csh"

. $DLG_ROOT/config
. $DLG_ROOT/SCRIPTS/dropline-functions.sh

prepare

applypatch 0 0 
applypatch 1 0 

analyzesource

# This bit gets *really* interesting.  The general idea is to make the
# arguments match what we have for the _rest_ of our packages.
cd $PKG_BUILDROOT
loggedcommand miscopts "sed -i -e 's/QMAKE_CFLAGS_DEBUG\t= -g/QMAKE_CFLAGS_DEBUG\t=/' mkspecs/linux-g++/qmake.conf"
if [ ! -z "$PKG_OPTLEVEL" ]; then
  loggedcommand miscopts "sed -i -e 's/QMAKE_CFLAGS_RELEASE\t= .*/QMAKE_CFLAGS_RELEASE\t= $PKG_OPTLEVEL/' mkspecs/linux-g++/qmake.conf"
fi
if [ ! -z "$PKG_ARCH" ]; then
  loggedcommand miscopts "sed -i -e 's/QMAKE_CFLAGS_RELEASE\t= .*/& -march=$PKG_ARCH/' mkspecs/linux-g++/qmake.conf"
fi
if [ ! -z "$PKG_CPU" ]; then
  loggedcommand miscopts "sed -i -e 's/QMAKE_CFLAGS_RELEASE\t= .*/& -march=$PKG_CPU/' mkspecs/linux-g++/qmake.conf"
fi

# Strictly speaking, this is not necessary.
FOOLD=$LD_LIBRARY_PATH
FOOBIN=$PATH
export LD_LIBRARY_PATH=$PKG_BUILDROOT/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
export PATH=$PKG_BUILDROOT/bin${PATH:+:$PATH}

cd $PKG_BUILDROOT
loggedcommand configure \
  echo yes \| ./configure -prefix /usr -docdir /usr/doc/qt-$VERSION \
  -plugindir /usr/lib/qt/plugins \
  -datadir /usr/share/qt \
  -translationdir /usr/share/qt/translations \
  -sysconfdir /etc/qt \
  -release -shared -qt-gif \
  -system-zlib -system-libpng -system-libmng -system-libjpeg \
  -no-exceptions \
  -plugin-sql-mysql \
  -thread -stl -xft \
  -plugin-imgfmt-png -plugin-imgfmt-jpeg -plugin-imgfmt-mng \
  -plugin-style-cde -plugin-style-compact -plugin-style-motif \
  -plugin-style-motifplus -plugin-style-platinum -plugin-style-sgi \
  -plugin-style-windows

make sub-src sub-tools
makeinstall

export PATH=$FOOBIN
export LD_LIBRARY_PATH=$FOOLD

spewdo "cp -v -r $PKG_SRCROOT/doc/man $PKG_STAGEROOT$PKG_PREFIX"
spewdo "cp -v -r $PKG_SRCROOT/examples $PKG_STAGEROOT$PKG_PREFIX/doc/qt-$VERSION"
spewdo "find $PKG_STAGEROOT$PKG_PREFIX/doc/qt-$VERSION/examples/ -type d -name .obj -exec rm -r {} \;"
spewdo "find $PKG_STAGEROOT$PKG_PREFIX/doc/qt-$VERSION/examples/ -type d -name .moc -exec rm -r {} \;"
tidydocumentation
analyzebinaries

# This gets the /etc/profile.d hooks in place so that the proper variables
# are set in the user's environment to handle the Qt installation.
findpatch shellfile ${PKG_PATCH[2]}
findpatch cshellfile ${PKG_PATCH[3]}
if [ ! -e $shellfile ]; then
  exit 1
elif [ ! -e $cshellfile ]; then
  exit 1
fi
spewdo "createdir $PKG_STAGEROOT$PKG_SYSCONFDIR/profile.d/"
spewdo "chmod 755 $PKG_STAGEROOT$PKG_SYSCONFDIR/profile.d/"
spewdo "install -m 755 $shellfile $PKG_STAGEROOT$PKG_SYSCONFDIR/profile.d/"
spewdo "install -m 755 $cshellfile $PKG_STAGEROOT$PKG_SYSCONFDIR/profile.d/"

finalizepackage
packagize
cleanup
