################################################################################
#
# kde4.cygclass - functions for building KDE 4.x packages
#
# Part of cygport - Cygwin packaging application
# Copyright (C) 2006-2015 Yaakov Selkowitz
# Provided by the Cygwin Ports project <http://sourceware.org/cygwinports/>
#
# cygport is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# cygport is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with cygport.  If not, see <http://www.gnu.org/licenses/>.
#
################################################################################

#****h* Cygclasses/kde4.cygclass
#  SYNOPSIS
#  inherit kde4
#  DESCRIPTION
#  The KDE project provides a full-featured X desktop with a wide variety
#  of applications, built on a library stack all based on the Qt C++ libraries.
#  Most packages are written in C++ and are built with CMake.
#
#  This cygclass manages the building of most KDE4-based packages.
#  INHERITS
#  cmake.cygclass, kde.org.cygclass, qt4.cygclass
#****

inherit cmake qt4 kde.org

#****v* kde4.cygclass/KDE4_EXTRAGEAR_VERSION
#  DESCRIPTION
#  KDE Extragear is a collection of software which is part of the KDE project
#  but which is not included in the main KDE Software Compilation modules.
#  Some of these applications are released in tandem with a KDE SC release but
#  use their own versioning system.  Such packages should use their own version
#  number as PV and define KDE4_EXTRAGEAR_VERSION to indicate with which
#  version of KDE SC they were released.
#  NOTE
#  If needed, this must be defined before inherit()ing kde4.cygclass.
#****
if defined KDE4_EXTRAGEAR_VERSION
then
	HOMEPAGE="http://extragear.kde.org/apps/${PN}/"
	SRC_URI="mirror://kde/stable/${KDE4_EXTRAGEAR_VERSION}/src/extragear/${P}-kde${KDE4_EXTRAGEAR_VERSION}.tar.bz2"
	SRC_DIR="${P}-kde${KDE4_EXTRAGEAR_VERSION}"
fi

export QTDIR=${QT4_QTDIR}
export QT_PLUGIN_PATH=${QT4_PLUGINSDIR}

#****C* kde4.cygclass/kde4_compile
#  SYNOPSIS
#  kde4_compile [OPTIONS]
#  DESCRIPTION
#  Runs cygcmake to configure the package with several Cygwin- and KDE-specific
#  options, then runs cygmake to compile.  Options, in the form of -DVARIABLE=VALUE,
#  are passed on to cygcmake.
#  NOTE
#  Source subdirectories which are declared with macro_optional_add_subdirectory()
#  in CMakeLists.txt can be disabled with '-DBUILD_foo=OFF' arguments.
#  REQUIRES
#  automoc4, cmake, libQtCore4-devel, libQtGui4-devel
#****
kde4_compile() {
	local skip skipargs

	# for backwards compatibility with KDE3
	for skip in ${DO_NOT_COMPILE}
	do
		skipargs+=" -DBUILD_${skip}=OFF"
	done

	cygcmake \
		-DKDE4_BUILD_TESTS=OFF \
		-DKDE4_ENABLE_FINAL=OFF \
		-DKDE4_ENABLE_FPIE=OFF \
		-DKDE4_INCLUDE_DIR=${CROSS_INCLUDEDIR-/usr/include}/kde4 \
		-DKDE4_USE_ALWAYS_FULL_RPATH=OFF \
		-DKDE_DISTRIBUTION_TEXT=Cygwin \
		-DQT_MOC_EXECUTABLE=${QT4_MOC} \
		-DQT_INCLUDE_DIR=${QT4_INCLUDEDIR} \
		-DQT_LIBRARY_DIR=${QT4_LIBDIR} \
		-DQT_UIC_EXECUTABLE=${QT4_UIC} \
		-D__KDE_HAVE_GCC_VISIBILITY=NO \
		${skipargs} \
		"${@}"

	cygmake
}

#****I* kde4.cygclass/kde4_install
#  SYNOPSIS
#  kde4_install [OPTIONS]
#  DESCRIPTION
#  Installs a KDE4 package with cyginstall into $D with some additional steps:
#  * Import libraries for libkdeinit4_* libraries are removed, as they are never used.
#  * README docs for subpackages in PKG_NAMES are installed into their own
#    subdirectories of /usr/share/doc/ under $D.
#  Options, if any, are passed on to cyginstall.
#****
kde4_install() {
	local kdepkg

	cyginstall "${@}"

	rm -f ${D}/usr/lib/libkdeinit4_* ${D}/usr/lib/kde4/lib/libkdeinit4_*

	for kdepkg in ${PKG_NAMES:-${PN}}
	do
		if [ -d ${S}/${kdepkg} ]
		then
			docinto /${kdepkg}
			dodoc ${S}/${kdepkg}/{AUTHORS,BUGS,ChangeLog,NEWS,README,TODO}
		elif [ -d ${S}/${kdepkg#${PN}-} ]
		then
			docinto /${kdepkg}
			dodoc ${S}/${kdepkg#${PN}-}/{AUTHORS,BUGS,ChangeLog,NEWS,README,TODO}
		fi
	done
}

#****o* kde4.cygclass/src_compile (kde4)
#  DEFINITION
src_compile() {
	cd ${B}
	kde4_compile
}
#****

#****o* kde4.cygclass/src_install (kde4)
#  DEFINITION
src_install() {
	cd ${B}
	kde4_install
}
#****

readonly -f kde4_compile kde4_install
