# $Id: PKGBUILD 18501 2008-11-06 12:11:46Z pierre $
# Maintainer: Pierre Schmitz <pierre@archlinux.de>

pkgname=qt
pkgver=4.4.3
pkgrel=2
_qtcopyver=880178
pkgdesc="The QT gui toolkit."
arch=('i686' 'x86_64')
url="http://www.trolltech.com/products/qt"
license=('GPL3')
options=('!libtool' '!docs')
depends=('libpng' 'libxi' 'mesa' 'fontconfig' 'libxrandr' 'glib2' 'libtiff' 'libmng' 'sqlite3' 'dbus' 'libxcursor' 'libxinerama')
optdepends=('postgresql-libs' 'libmysqlclient' 'unixodbc')
makedepends=('inputproto' 'postgresql-libs' 'mysql' 'unixodbc' 'libxfixes')
provides=("qt4=${pkgver}")
replaces=('qt4')
conflicts=('qt4')
_pkgfqn=qt-x11-opensource-src-$pkgver
# svn export -r -${_qtcopyver} svn://anonsvn.kde.org/home/kde/trunk/qt-copy/patches/ qt-copy-patches-${_qtcopyver}
source=("ftp://ftp.trolltech.com/qt/source/${_pkgfqn}.tar.bz2"
        "ftp://ftp.archlinux.org/other/qt/qt-copy-patches-${_qtcopyver}.tar.bz2"
        'qt4-assistant.desktop' 'qt4-designer.desktop' 'qt4-linguist.desktop')
md5sums=('00e00c6324d342a7b0d8653112b4f08c'
         'd3a40d783528a86174b62ecfc136b031'
         'c95e1697bf2b923199c3b8cd7d485a17'
         '00333dca87e24767383217ba378b5980'
         '71f7ac8206c19da7ecf71cdb391f0452')

build() {
	unset QMAKESPEC
	export QT4DIR=$srcdir/$_pkgfqn
	export PATH=${QT4DIR}/bin:${PATH}
	export LD_LIBRARY_PATH=${QT4DIR}/lib:${LD_LIBRARY_PATH}

	cd $srcdir/$_pkgfqn
	for i in $srcdir/qt-copy-patches-${_qtcopyver}/*; do
		echo "applying $i"
		patch -p0 -i $i || return 1
	done

	# remove unwanted mkspecs
	cd mkspecs/
	find . -maxdepth 1 -regextype posix-egrep -type d ! -regex "./linux.*|./common|./features|./qws" -exec rm -rf "{}" \;
	cd qws
	find . -maxdepth 1 -regextype posix-egrep -type d ! -regex "./linux.*" -exec rm -rf "{}" \;
	cd ../../

	sed -i 's|-cp -P -f|-cp -L -f|' qmake/Makefile.unix
	sed -i "s|-O2|$CXXFLAGS|" mkspecs/common/g++.conf
	# fix postgres build
	sed -e '/pg_config --libs/d' -i configure
	# do not compile demos, examples and docs
	sed -i 's|CFG_NOBUILD_PARTS=""|CFG_NOBUILD_PARTS="demos examples docs"|' configure

	./configure -confirm-license \
		-prefix /usr \
		-docdir /usr/share/doc/qt \
		-plugindir /usr/lib/qt/plugins \
		-datadir /usr/share/qt \
		-translationdir /usr/share/qt/translations \
		-sysconfdir /etc \
		-examplesdir /usr/share/doc/qt/examples \
		-demosdir /usr/share/doc/qt/demos \
		-no-exceptions \
		-plugin-sql-{psql,mysql,sqlite,odbc} \
		-system-sqlite \
		-no-phonon \
		-dbus-linked \
		-webkit \
		-no-separate-debug-info \
		-nomake examples \
		-nomake docs \
		-nomake demos \
		-assistant-webkit \
		-system-libpng \
		-system-libjpeg \
		-system-zlib \
		-openssl-linked \
		-reduce-relocations \
		-xinerama \
		-xcursor \
		-xfixes \
		-optimized-qmake || return 1

	make || return 1
	make INSTALL_ROOT=$pkgdir install || return 1

	install -D -m644 tools/assistant/tools/assistant/images/assistant.png ${pkgdir}/usr/share/pixmaps/assistant.png
	install -D -m644 tools/linguist/linguist/images/appicon.png ${pkgdir}/usr/share/pixmaps/linguist.png
	install -D -m644 tools/designer/src/designer/images/designer.png ${pkgdir}/usr/share/pixmaps/designer.png
	install -d ${pkgdir}/usr/share/applications
	install -m644 ${srcdir}/qt4-{linguist,designer,assistant}.desktop ${pkgdir}/usr/share/applications/

	# cleanup and path fixes
	find $pkgdir/usr/lib -type f -name '*prl' -print -exec sed -i -e "/^QMAKE_PRL_BUILD_DIR/d" {} \;
	sed -i -e "s|-L$srcdir/${_pkgfqn}/lib||g" $pkgdir/usr/lib/pkgconfig/*.pc
	sed -i -e "s|$srcdir/${_pkgfqn}/bin/moc|/usr/bin/moc|g" $pkgdir/usr/lib/pkgconfig/*.pc
	sed -i -e "s|$srcdir/${_pkgfqn}/bin/uic|/usr/bin/uic|g" $pkgdir/usr/lib/pkgconfig/*.pc
}