SUMMARY="Librares that help developers build software on top of Qt"
DESCRIPTION="KDE (the K Desktop Environment) is a powerful, open-source \
graphical desktop environment. It combines ease of use, contemporary \
functionality, and outstanding graphical design."
HOMEPAGE="http://www.kde.org"
SOURCE_URI="http://download.kde.org/stable/4.13.2/src/kdelibs-4.13.2.tar.xz"
CHECKSUM_SHA256="559809c602b80ff1091a4fb67e8c98b0ebb91c3cd437d1583068ddde19efda0e"
SOURCE_DIR="kdelibs-4.13.2"
LICENSE="GNU LGPL v2.1"
COPYRIGHT="2014 KDE e.V."
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="
	kdelibs4$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:kbuildsycoca4$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:kde4_config$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:kded4$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:kdeinit4$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:kdeinit4_shutdown$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:kdeinit4_wrapper$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:kmailservice$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:kross$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:kshell4$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:ktelnetservice$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:kwrapper4$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkcmutils$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkdeclarative$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkdecore$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkdefakes$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkio$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkdeui$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkrosscore$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkdeinit4_kded4$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkdeinit4_kbuildsycoca4$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkdeinit4_kconf_update$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkdeinit4_kio_http_cache_cleaner$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkdeinit4_klauncher$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkdewebkit$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkdnssd$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkemoticons$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkfile$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkidletime$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkimproxy$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkmediaplayer$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libknewstuff2$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libknewstuff3$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libknotifyconfig$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkntlm$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkparts$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkprintutils$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkrossui$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libktexteditor$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkunitconversion$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libkutils$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libplasma$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libsolid$secondaryArchSuffix = $portVersion compat >= 4.13
	lib:libthreadweaver$secondaryArchSuffix = $portVersion compat >= 4.13
	"
REQUIRES="
	haiku$secondaryArchSuffix
	libqt4$secondaryArchSuffix >= 4.8
	lib:libz$secondaryArchSuffix
	lib:libbz2$secondaryArchSuffix
	lib:liblzma$secondaryArchSuffix
	lib:libssl$secondaryArchSuffix
	lib:libcrypto$secondaryArchSuffix
	lib:libqca$secondaryArchSuffix
	lib:libintl$secondaryArchSuffix
	lib:libpcre$secondaryArchSuffix
	lib:libgif$secondaryArchSuffix
	lib:libpng$secondaryArchSuffix
	lib:libjpeg$secondaryArchSuffix
	lib:libjasper$secondaryArchSuffix
	lib:libattica$secondaryArchSuffix
	lib:libdbusmenu_qt$secondaryArchSuffix
	shared_mime_info$secondaryArchSuffix
	strigi$secondaryArchSuffix
	"
PROVIDES_devel="
	kdelibs4${secondaryArchSuffix}_devel = $portVersion compat >= 4.13
	cmd:checkXML$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:kconfig_compiler$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:makekdewidgets$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:meinproc4$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:meinproc4_simple$secondaryArchSuffix = $portVersion compat >= 4.13
	cmd:preparetips$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkcmutils$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkdeclarative$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkdecore$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkdefakes$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkio$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkdeui$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkrosscore$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkdewebkit$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkdnssd$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkemoticons$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkfile$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkidletime$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkimproxy$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkmediaplayer$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libknewstuff2$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libknewstuff3$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libknotifyconfig$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkntlm$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkparts$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkprintutils$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkrossui$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libktexteditor$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkunitconversion$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libkutils$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libplasma$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libsolid$secondaryArchSuffix = $portVersion compat >= 4.13
	devel:libthreadweaver$secondaryArchSuffix = $portVersion compat >= 4.13
	"
REQUIRES_devel="
	haiku$secondaryArchSuffix
	libqt4${secondaryArchSuffix}_devel >= 4.8
	kdelibs4${secondaryArchSuffix} == $portVersion base
	lib:libxml2$secondaryArchSuffix
	lib:libxslt$secondaryArchSuffix
	lib:libexslt$secondaryArchSuffix
	"
BUILD_REQUIRES="
	libqt4${secondaryArchSuffix}_devel >= 4.8
	devel:libz$secondaryArchSuffix
	devel:libbz2$secondaryArchSuffix
	devel:liblzma$secondaryArchSuffix
	devel:libssl$secondaryArchSuffix
	devel:libcrypto$secondaryArchSuffix
	devel:libqca$secondaryArchSuffix
	devel:libintl$secondaryArchSuffix
	devel:libpcre$secondaryArchSuffix
	devel:libxml2$secondaryArchSuffix
	devel:libxslt$secondaryArchSuffix
	devel:libexslt$secondaryArchSuffix
	devel:libgif$secondaryArchSuffix
	devel:libpng$secondaryArchSuffix
	devel:libjpeg$secondaryArchSuffix
	devel:libjasper$secondaryArchSuffix
	devel:libattica$secondaryArchSuffix
	devel:libdbusmenu_qt$secondaryArchSuffix
	docbook_xml_dtd
	docbook_xsl_stylesheets
	shared_mime_info$secondaryArchSuffix
	strigi${secondaryArchSuffix}_devel
	"
BUILD_PREREQUIRES="
	haiku${secondaryArchSuffix}_devel
	cmd:cmake
	cmd:pkg_config$secondaryArchSuffix
	cmd:automoc4
	cmd:perl
	cmd:flex
	cmd:bison$secondaryArchSuffix
	cmd:xmllint
	cmd:ninja
	cmd:g++$secondaryArchSuffix
	cmd:find
	"

PATCHES="kdelibs4-4.13.2.patch"

BUILD()
{
	mkdir -p build
	cd build
	cmake -Wno-dev -DCMAKE_INSTALL_PREFIX=$prefix \
		-DDOCBOOKXML_CURRENTDTD_DIR=/system/data/xml/docbook/xml-dtd-4.5 \
		-DDOCBOOKXSL_DIR=/system/data/xml/docbook/xsl-stylesheets-1.78.1 \
		-DKDE4_AUTH_HELPER_BACKEND_NAME=Fake -DKDE4_BUILD_TESTS=Off \
		-DCMAKE_BUILD_TYPE=Release -GNinja ..
	ninja $jobArgs
}

INSTALL()
{
	cd build
	ninja install
	
	# Cleanup after CMake
	mkdir -p $includeDir
	cp -R $prefix/include/* $includeDir/
	rm -rf $prefix/include/
	
	mkdir -p $libDir
	mv $prefix/lib/*.so* $libDir/
	mv $prefix/lib/kde4/ $libDir
	rm -f $prefix/lib/*.so*
	
	mkdir -p $binDir
	find $prefix/bin/ -maxdepth 1 -type f -exec mv -t $binDir {} \+
	find $prefix/bin/ -maxdepth 1 -type f -exec rm -f {} \;
	
	mkdir -p $dataDir/cmake/Modules/
	cp -R $prefix/lib/cmake/* $dataDir/cmake/Modules/
	rm -rf $prefix/lib/cmake/
	cp -R $prefix/share/apps/cmake/modules/* $dataDir/cmake/Modules/
	rm -rf $prefix/share/apps/cmake/
	
	mkdir -p $documentationDir
	mv $prefix/share/man $documentationDir

	mkdir -p $documentationDir/KDE/ksgmltools2/
	cp -R $prefix/share/apps/ksgmltools2/* $documentationDir/KDE/ksgmltools2/
	rm -rf $prefix/share/apps/ksgmltools2/
		
	# etc contains only XDG stuff we don't support
	rm -rf $prefix/etc/
	
	devCommands="checkXML kconfig_compiler makekdewidgets meinproc4 \
		meinproc4_simple preparetips"

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

	prepareInstalledDevelLibs \
		libkcmutils \
		libkdeclarative \
		libkdecore \
		libkdefakes \
		libkio \
		libkdeui \
		libkrosscore \
		libkdewebkit \
		libkdnssd \
		libkemoticons \
		libkfile \
		libkidletime \
		libkimproxy \
		libkmediaplayer \
		libknewstuff2 \
		libknewstuff3 \
		libknotifyconfig \
		libkntlm \
		libkparts \
		libkprintutils \
		libkrossui \
		libktexteditor \
		libkunitconversion \
		libkutils \
		libplasma \
		libsolid \
		libthreadweaver

	packageEntries devel \
		$developDir \
		$devPackageCommands \
		$dataDir/cmake/ \
		$documentationDir
}
