### this file is sourced not run
PKGVER=4.8.7
PKGBUILD=1
PKGARCH=x86_64

# source: post BLFS 7.8 2016-01-06
TARBALL=qt-everywhere-opensource-src-$PKGVER.tar.gz
MD5SUM=d990ee66bf7ab0c785589776f35ba6ad
SRC_URL=http://download.qt-project.org/official_releases/qt/4.8/$PKGVER/$TARBALL
BUNDLE=

# updated webkit
WK_PKGVER=2.3.4
WK_TARBALL=qtwebkit-$WK_PKGVER.tar.gz
WK_MD5SUM=42ef76d0cf7d0c611ef83418e9f297ff
WK_SRC_URL=http://download.kde.org/stable/qtwebkit-2.3/$WK_PKGVER/src/$TARBALL

SLACKREQ='libX11 alsa-lib mesa dbus glib libjpeg-turbo libpng libtiff openssl \
sqlite3 cups gtk2 gst-plugins-base'
SLACKDESC="qt4: qt $PKGVER (Qt GUI framework)  
qt4:  
qt4: Qt is a cross-platform application framework that is widely used for 
qt4: developing application software with a graphical user interface (GUI) (in 
qt4: which cases Qt is classified as a widget toolkit), and also used for 
qt4: developing non-GUI programs such as command-line tools and consoles for 
qt4: servers. One of the major users of Qt is KDE.  
qt4: 
qt4: 
qt4: 
qt4: This package installs in /opt/qt4-$PKGVER with symlnk to /opt/qt4
"

### default pkg_download
### prepare
pkg_prepare() {
	# qt4
	pkg_check $SRC_DIR $TARBALL $MD5SUM &&
	tar -C tmp -xf $SRC_DIR/$TARBALL &&
	
	# webkit
	SRC_URL=$WK_SRC_URL &&
	pkg_check $SRC_DIR $WK_TARBALL $WK_MD5SUM &&
	mkdir -p $(ls -d tmp/qt*)/qtwebkit &&
	tar -C tmp/qt*/qtwebkit -xf $SRC_DIR/$WK_TARBALL &&
	cd tmp/qt*/qtwebkit &&
	patch -Np1 -i ../../pkg/qtwebkit-2.3.4-gcc5-1.patch
}

### default pkg_package
### build
pkg_build() {
	cd /tmp/qt*
	export QT4DIR=/opt/qt4
	mkdir -pv /opt/qt-$PKGVER &&
	ln -sfvn qt-$PKGVER $QT4DIR &&	

	export QMAKESPEC=linux-g++-64 # CBLFS
	./configure -prefix $QT4DIR  \
			-libdir $QT4DIR/$LIBDIR \
			-plugindir $QT4DIR/$LIBDIR/plugins \
			-importdir $QT4DIR/$LIBDIR/imports \
			-headerdir $QT4DIR/include \
			-datadir $QT4DIR/$LIBDIR \
			-translationdir $QT4DIR/share/translations \
			-docdir $QT4DIR/share/doc/qt \
			-demosdir $QT4DIR/share/demos \
			-examplesdir $QT4DIR/share/examples \
			-reduce-relocations \
			-no-separate-debug-info \
			-sysconfdir /etc/xdg \
            -confirm-license     \
            -opensource          \
            -release             \
            -dbus-linked         \
            -openssl-linked      \
            -plugin-sql-sqlite   \
            -no-phonon           \
            -no-phonon-backend   \
            -no-nis              \
            -no-openvg           \
            -nomake demos        \
            -nomake examples     \
            -no-icu              \
            -no-webkit           \
            -no-exceptions       \
            -optimized-qmake     &&

	make $MAKEFLAGS &&
	make install &&

	find $QT4DIR/$LIBDIR/pkgconfig -name "*.pc" -exec perl -pi -e "s, -L$PWD/?\S+,,g" {} \; &&
	for file in $QT4DIR/$LIBDIR/libQt*.prl; do
		 sed -r -e '/^QMAKE_PRL_BUILD_DIR/d'    \
				-e 's/(QMAKE_PRL_LIBS =).*/\1/' \
				-i $file
	done &&
	unset file &&
	rm -rf /include &&	
	
	# desktop icons
	install -v -Dm644 src/gui/dialogs/images/qtlogo-64.png \
					  /usr/share/pixmaps/qt4logo.png       &&
	install -v -Dm644 tools/assistant/tools/assistant/images/assistant-128.png \
					  /usr/share/pixmaps/assistant-qt4.png &&
	install -v -Dm644 tools/designer/src/designer/images/designer.png \
					  /usr/share/pixmaps/designer-qt4.png  &&
	install -v -Dm644 tools/linguist/linguist/images/icons/linguist-128-32.png \
					  /usr/share/pixmaps/linguist-qt4.png  &&
	install -v -Dm644 tools/qdbus/qdbusviewer/images/qdbusviewer-128.png \
					  /usr/share/pixmaps/qdbusviewer-qt4.png &&
	install -dm755 /usr/share/applications &&
	
	# desktop files
	install -m644 /tmp/pkg/assistant-qt4.desktop /usr/share/applications &&
	install -m644 /tmp/pkg/designer-qt4.desktop /usr/share/applications &&
	install -m644 /tmp/pkg/linguist-qt4.desktop /usr/share/applications &&
	install -m644 /tmp/pkg/qdbusviewer-qt4.desktop /usr/share/applications &&
	install -m644 /tmp/pkg/qtconfig-qt4.desktop /usr/share/applications &&
	
	# profile
	mkdir -p /etc/profile.d
	cat > /etc/profile.d/qt4.sh << EOF &&
QT4DIR=$QT4DIR
export QT4DIR
EOF
	chmod +x /etc/profile.d/qt4.sh &&

	pkg_build_slackdesc &&
	
	# multilib
	mv -v $QT4DIR/bin/qmake{,-64} &&
	mv -v $QT4DIR/bin/uic{,-64} &&
	mv -v $QT4DIR/bin/uic3{,-64} &&
	mv -v $QT4DIR/bin/moc{,-64} &&
	mv -v $QT4DIR/include/Qt/qconfig{,-64}.h &&
	mv -v $QT4DIR/include/QtCore/qconfig{,-64}.h
	ln -sfv /usr/bin/multiarch_wrapper $QT4DIR/bin/qmake &&
	ln -sfv /usr/bin/multiarch_wrapper $QT4DIR/bin/uic &&
	ln -sfv /usr/bin/multiarch_wrapper $QT4DIR/bin/uic3 &&
	ln -sfv /usr/bin/multiarch_wrapper $QT4DIR/bin/moc &&
	cp -v /tmp/pkg/qconfig.h $QT4DIR/include/Qt/qconfig.h &&
	cp -v /tmp/pkg/qconfig.h $QT4DIR/include/QtCore/qconfig.h
	
	# now buld webkit
	export QTDIR=$QT4DIR &&
	export PATH=$PATH:$QT4DIR/bin &&
	cd /tmp/qt*/qtwebkit &&
	Tools/Scripts/build-webkit --qt            \
							   --no-webkit2    \
							   --prefix=$QT4DIR &&
	make -C WebKitBuild/Release install
}
