SUMMARY="A comprehensive C++ application development framework"
DESCRIPTION="Qt is a cross-platform application framework that is widely \
used for developing software with a graphical user interface, and also used \
for developing non-GUI programs such as command-line tools and consoles for \
servers."
HOMEPAGE="http://github.com/qt-haiku/qt4" 
SOURCE_URI="https://github.com/qt-haiku/qt4/archive/v4.8.6-haiku-3.tar.gz"
CHECKSUM_SHA256="8afb8b1ae32223a34decbc9b794dc66399c799ccca7e01301b4f5882e2d212cb"
SOURCE_DIR="qt4-4.8.6-haiku-3"
LICENSE="GNU LGPL v2.1"
COPYRIGHT="2014 Digia Plc and/or its subsidiary(-ies)."
REVISION="1"
ARCHITECTURES="x86 ?x86_64"
if [ $effectiveTargetArchitecture != x86_gcc2 ]; then
    # x86_gcc2 is fine as primary target architecture as long as we're building
    # for a different secondary architecture.
    ARCHITECTURES="$ARCHITECTURES x86_gcc2"
else
    ARCHITECTURES="$ARCHITECTURES !x86_gcc2"
fi
SECONDARY_ARCHITECTURES="x86"

PROVIDES="
	libqt4$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qtconfig$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qsystray$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qdbus$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libphonon$secondaryArchSuffix = 4.4.0 compat >= 4
	lib:libQt3Support$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtCLucene$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtCore$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtDBus$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtDeclarative$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtDesigner$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtDesignerComponents$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtGui$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtHelp$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtMultimedia$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtNetwork$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtScript$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtScriptTools$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtSql$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtSvg$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtTest$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtWebKit$secondaryArchSuffix = 4.9.4 compat >= 4
	lib:libQtXml$secondaryArchSuffix = $portVersion compat >= 4.8
	lib:libQtXmlPatterns$secondaryArchSuffix = $portVersion compat >= 4.8
	"

REQUIRES="
	haiku$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libicuuc$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libpng$secondaryArchSuffix
	lib:libtiff$secondaryArchSuffix
	"

BUILD_REQUIRES="
	icu${secondaryArchSuffix}_devel
	devel:libz$secondaryArchSuffix
	devel:libcrypto$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libpng$secondaryArchSuffix
	devel:libtiff$secondaryArchSuffix
	dbus${secondaryArchSuffix}_devel
	"

BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:pkg_config$secondaryArchSuffix
	cmd:which
	cmd:make
	cmd:g++$secondaryArchSuffix
	cmd:ld$secondaryArchSuffix
	cmd:perl
	cmd:find
	cmd:awk
	"

if [ $targetArchitecture = x86_gcc2 ]; then
	BUILD_PREREQUIRES="$BUILD_PREREQUIRES cmd:g++"
fi

PROVIDES_devel="
	libqt4${secondaryArchSuffix}_devel = $portVersion compat >= 4.8
	cmd:assistant$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:designer$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:lconvert$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:linguist$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:lrelease$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:lupdate$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:moc$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:pixeltool$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qcollectiongenerator$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qdbuscpp2xml$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qdbusviewer$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qdbusxml2cpp$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qdoc3$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qhelpconverter$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qhelpgenerator$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qmake$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qmlplugindump$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qmlviewer$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qt3to4$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:qttracereplay$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:rcc$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:uic$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:uic3$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:xmlpatterns$secondaryArchSuffix = $portVersion compat >= 4.8
	cmd:xmlpatternsvalidator$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libphonon$secondaryArchSuffix = 4.4.0 compat >= 4
	devel:libQt3Support$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtCLucene$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtCore$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtDBus$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtDeclarative$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtDesigner$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtDesignerComponents$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtGui$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtHelp$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtMultimedia$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtNetwork$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtScript$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtScriptTools$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtSql$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtSvg$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtTest$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtWebKit$secondaryArchSuffix = 4.9.4 compat >= 4
	devel:libQtXml$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtXmlPatterns$secondaryArchSuffix = $portVersion compat >= 4.8
	devel:libQtUiTools$secondaryArchSuffix = $portVersion compat >= 4.8
	"

# if libssl and libcrypto are not in REQUIRES_devel,
# qmake will decide that there is no system OpenSSL support
# and thus build Qt apps without any SSL support.
REQUIRES_devel="
	libqt4$secondaryArchSuffix == $portVersion base
	haiku$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	"

BUILD()
{
	# not an autotools configure
	./configure \
		-prefix $prefix \
		-bindir $binDir \
		-libdir $libDir \
		-headerdir $includeDir \
		-docdir $docDir/Qt \
		-datadir $dataDir/Qt \
		-translationdir $dataDir/Qt/translations \
		-sysconfdir $settingsDir \
		-demosdir $dataDir/Qt/demos \
		-examplesdir $dataDir/Qt/examples \
		-importdir $dataDir/Qt/imports \
		-plugindir $addOnsDir/Qt \
		-no-pch -no-opengl -no-largefile \
		-fast -nomake examples -nomake demos -release -opensource \
		-confirm-license -no-iconv -phonon -no-phonon-backend \
		-multimedia -no-audio-backend -dbus

	make $jobArgs

	pushd src/3rdparty/haiku-tools/qsystray
	if [ $targetArchitecture = x86 ]; then
		make -f Makefile.gcc4
	else
		export PATH="/bin:$PATH"
		make -f Makefile.gcc2
	fi
	popd

	pushd haiku
	./do-res.sh
	popd
}

INSTALL()
{
	make install
	fixPkgconfig
	mv -f $libDir/libQtDBus.la $developLibDir

	cd src/3rdparty/haiku-tools/qsystray
	if [ $targetArchitecture = x86 ]; then
		cp -af qsystray $binDir
	else
		cp -af qsystray_gcc2 $binDir/qsystray
	fi

	prepareInstalledDevelLibs libphonon \
		libQt3Support libQtCLucene \
		libQtCore libQtDeclarative \
		libQtDesigner libQtDesignerComponents \
		libQtGui libQtHelp \
		libQtMultimedia libQtNetwork \
		libQtScript libQtScriptTools \
		libQtSql libQtSvg \
		libQtTest libQtWebKit \
		libQtXml libQtXmlPatterns \
		libQtUiTools

	# UGLY HACK -- REMOVE ME WHEN QMAKE/CMAKE/ETC IS FIXED
	cd $libDir
	for i in lib*.so.4.*;do
		ln -fs $i $(echo $i | cut -f1,2 -d.)
	done

	devCommands="assistant designer lconvert linguist lrelease lupdate
		moc pixeltool qdbuscpp2xml qdbusviewer qdbusxml2cpp
		qcollectiongenerator qdoc3 qhelpconverter qhelpgenerator qmake
		qmlplugindump qmlviewer qt3to4 qttracereplay rcc uic uic3 xmlpatterns
		xmlpatternsvalidator"

	for i in $devCommands; do
		devPackageCommands="$devPackageCommands $binDir/$i"
	done

	DIR_QT_DEVELOP_DESKBAR="${dataDir}/deskbar/menu/Applications/Qt"
	mkdir -p ${DIR_QT_DEVELOP_DESKBAR}
	addAppDeskbarSymlink $binDir/assistant "Qt/Qt Assistant"
	addAppDeskbarSymlink $binDir/designer "Qt/Qt Designer"
	addAppDeskbarSymlink $binDir/qdbusviewer "Qt/Qt D-Bus Viewer"
	addAppDeskbarSymlink $binDir/linguist "Qt/Qt Lingist"
	addAppDeskbarSymlink $binDir/qmlviewer "Qt/QML Viewer"
	addAppDeskbarSymlink $binDir/qhelpconverter "Qt/Qt Help Converter"

	packageEntries devel \
		$developDir \
		$devPackageCommands \
		${DIR_QT_DEVELOP_DESKBAR} \
		$dataDir/Qt/mkspecs

	# move tests to demo/example package when it exists
	rm -rf $prefix/tests
	rm -rf $dataDir/Qt/demos $dataDir/Qt/examples
}
