SUMMARY="A project management application of the Calligra Suite"
DESCRIPTION="Plan is a project management application. It is intended for \
managing moderately large projects with multiple resources.

To enable you to model your project adequately, Plan offers different \
types of task dependencies and timing constraints. The usual use case \
is to define your tasks, estimate the effort needed to perform each task, \
allocate resources and then let Plan schedule the tasks according to \
network and resource availability."
HOMEPAGE="https://www.calligra.org/"
COPYRIGHT="2010-2021 KDE Organisation"
LICENSE="GNU LGPL v2
	GNU GPL v2"
REVISION="1"
SOURCE_URI="https://download.kde.org/stable/calligra/$portVersion/calligraplan-$portVersion.tar.xz"
CHECKSUM_SHA256="9a97414f2207941a70d93ff096617365d35379cc93a09cfc19ee532d2905a9d8"
SOURCE_FILENAME="calligraplan-$portVersion.tar.xz"
PATCHES="calligraplan-$portVersion.patchset"
ADDITIONAL_FILES="
	calligraplan.rdef.in
	calligraplanwork.rdef.in
	"

ARCHITECTURES="all ?x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

libVersion="17.0.0"

PROVIDES="
	calligraplan$secondaryArchSuffix = $portVersion
	lib:libkdeinit5_calligraplan$secondaryArchSuffix = $libVersion
	lib:libkdeinit5_calligraplanwork$secondaryArchSuffix = $libVersion
	lib:libplankernel$secondaryArchSuffix = $libVersion
	lib:libplankundo2$secondaryArchSuffix = $libVersion
	lib:libplanmain$secondaryArchSuffix = $libVersion
	lib:libplanmodels$secondaryArchSuffix = $libVersion
	lib:libplanodf$secondaryArchSuffix = $libVersion
	lib:libplanplugin$secondaryArchSuffix = $libVersion
	lib:libplanprivate$secondaryArchSuffix = $libVersion
	lib:libplanstore$secondaryArchSuffix = $libVersion
	lib:libplanui$secondaryArchSuffix = $libVersion
	lib:libplanwidgets$secondaryArchSuffix = $libVersion
	lib:libplanwidgetutils$secondaryArchSuffix = $libVersion
	lib:libplanworkfactory$secondaryArchSuffix = $libVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libboost_system$secondaryArchSuffix
	lib:libetonyek_0.1$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libKChart$secondaryArchSuffix
	lib:libkdeinit5_kded5$secondaryArchSuffix
	lib:libkdeinit5_klauncher$secondaryArchSuffix
	lib:libKF5Activities$secondaryArchSuffix
	lib:libKF5Archive$secondaryArchSuffix
	lib:libKF5Auth$secondaryArchSuffix
	lib:libKF5Bookmarks$secondaryArchSuffix
	lib:libKF5Codecs$secondaryArchSuffix
	lib:libKF5Completion$secondaryArchSuffix
	lib:libKF5ConfigCore$secondaryArchSuffix
	lib:libKF5ConfigGui$secondaryArchSuffix
	lib:libKF5ConfigWidgets$secondaryArchSuffix
	lib:libKF5CoreAddons$secondaryArchSuffix
	lib:libKF5Crash$secondaryArchSuffix
	lib:libKF5DBusAddons$secondaryArchSuffix
	lib:libKF5DocTools$secondaryArchSuffix
	lib:libKF5Emoticons$secondaryArchSuffix
	lib:libKF5GuiAddons$secondaryArchSuffix
	lib:libKF5Holidays$secondaryArchSuffix
	lib:libKF5I18n$secondaryArchSuffix
	lib:libKF5IconThemes$secondaryArchSuffix
	lib:libKF5ItemModels$secondaryArchSuffix
	lib:libKF5ItemViews$secondaryArchSuffix
	lib:libKF5JobWidgets$secondaryArchSuffix
	lib:libKF5JS$secondaryArchSuffix
	lib:libKF5JSApi$secondaryArchSuffix
	lib:libKF5KCMUtils$secondaryArchSuffix
	lib:libKF5KDELibs4Support$secondaryArchSuffix
	lib:libKF5KHtml$secondaryArchSuffix
	lib:libKF5KIOCore$secondaryArchSuffix
	lib:libKF5KrossCore$secondaryArchSuffix
	lib:libKF5Notifications$secondaryArchSuffix
	lib:libKF5NotifyConfig$secondaryArchSuffix
	lib:libKF5Parts$secondaryArchSuffix
	lib:libKF5Service$secondaryArchSuffix
	lib:libKF5Solid$secondaryArchSuffix
	lib:libKF5SonnetCore$secondaryArchSuffix
	lib:libKF5TextWidgets$secondaryArchSuffix
	lib:libKF5ThreadWeaver$secondaryArchSuffix
	lib:libKF5UnitConversion$secondaryArchSuffix
	lib:libKF5Wallet$secondaryArchSuffix
	lib:libKF5WidgetsAddons$secondaryArchSuffix
	lib:libKF5WindowSystem$secondaryArchSuffix
	lib:libKF5XmlGui$secondaryArchSuffix
	lib:libKGantt$secondaryArchSuffix
	lib:libKPropertyCore3$secondaryArchSuffix
	lib:libKPropertyWidgets3$secondaryArchSuffix
	lib:libKReport3$secondaryArchSuffix
	lib:libqca_qt5$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5WebKitWidgets$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	extra_cmake_modules$secondaryArchSuffix >= 5.77
	devel:eigen$secondaryArchSuffix
	devel:libboost_system$secondaryArchSuffix
	devel:libetonyek_0.1$secondaryArchSuffix
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libKChart$secondaryArchSuffix
	devel:libkdeinit5_kded5$secondaryArchSuffix
	devel:libkdeinit5_klauncher$secondaryArchSuffix
	devel:libKF5Activities$secondaryArchSuffix
	devel:libKF5Archive$secondaryArchSuffix
	devel:libKF5Auth$secondaryArchSuffix
	devel:libKF5Bookmarks$secondaryArchSuffix
	devel:libKF5Codecs$secondaryArchSuffix
	devel:libKF5Completion$secondaryArchSuffix
	devel:libKF5ConfigCore$secondaryArchSuffix
	devel:libKF5ConfigGui$secondaryArchSuffix
	devel:libKF5ConfigWidgets$secondaryArchSuffix
	devel:libKF5CoreAddons$secondaryArchSuffix
	devel:libKF5Crash$secondaryArchSuffix
	devel:libKF5DBusAddons$secondaryArchSuffix
	devel:libKF5DesignerPlugin$secondaryArchSuffix
	devel:libKF5DocTools$secondaryArchSuffix
	devel:libKF5Emoticons$secondaryArchSuffix
	devel:libKF5GuiAddons$secondaryArchSuffix
	devel:libKF5Holidays$secondaryArchSuffix
	devel:libKF5I18n$secondaryArchSuffix
	devel:libKF5IconThemes$secondaryArchSuffix
	devel:libKF5ItemModels$secondaryArchSuffix
	devel:libKF5ItemViews$secondaryArchSuffix
	devel:libKF5JobWidgets$secondaryArchSuffix
	devel:libKF5JSApi$secondaryArchSuffix
	devel:libKF5KCMUtils$secondaryArchSuffix
	devel:libKF5KDELibs4Support$secondaryArchSuffix
	devel:libKF5KHtml$secondaryArchSuffix
	devel:libKF5KIOCore$secondaryArchSuffix
	devel:libKF5KrossCore$secondaryArchSuffix
	devel:libKF5Notifications$secondaryArchSuffix
	devel:libKF5NotifyConfig$secondaryArchSuffix
	devel:libKF5Parts$secondaryArchSuffix
	devel:libKF5Service$secondaryArchSuffix
	devel:libKF5Solid$secondaryArchSuffix
	devel:libKF5SonnetCore$secondaryArchSuffix
	devel:libKF5TextWidgets$secondaryArchSuffix
	devel:libKF5ThreadWeaver$secondaryArchSuffix
	devel:libKF5UnitConversion$secondaryArchSuffix
	devel:libKF5Wallet$secondaryArchSuffix
	devel:libKF5WidgetsAddons$secondaryArchSuffix
	devel:libKF5WindowSystem$secondaryArchSuffix
	devel:libKF5XmlGui$secondaryArchSuffix
	devel:libKGantt$secondaryArchSuffix
	devel:libKPropertyCore3$secondaryArchSuffix
	devel:libKReport3$secondaryArchSuffix
	devel:liblangtag$secondaryArchSuffix
	devel:liblcms2$secondaryArchSuffix
	devel:libqca$secondaryArchSuffix >= 2
	devel:libQt5Core$secondaryArchSuffix >= 5.14
	devel:libQt5WebKitWidgets$secondaryArchSuffix
	devel:libz$secondaryArchSuffix
	"
BUILD_PREREQUIRES="
	cmd:cmake
	cmd:g++$secondaryArchSuffix
	cmd:lrelease$secondaryArchSuffix >= 5
	cmd:make
	cmd:perl
	cmd:pkg_config$secondaryArchSuffix
	cmd:python
	"

BUILD()
{
	# disable docs generation
	sed -e '/add_subdirectory(doc)/ s/^#*/#/' -i CMakeLists.txt
	sed -e '/kdoctools_install(po)/ s/^#*/#/' -i CMakeLists.txt

	mkdir -p build
	cd build

	cmake .. \
		-DCMAKE_INSTALL_PREFIX=$appsDir/Calligra \
		-DCMAKE_INSTALL_BINDIR=$appsDir/Calligra \
		-DCMAKE_INSTALL_LIBDIR=$libDir \
		-DCMAKE_INSTALL_DATAROOTDIR=$dataDir \
		-DKDE_INSTALL_INCLUDEDIR=$includeDir \
		-DKDE_INSTALL_PLUGINDIR=$addOnsDir/Qt5 \
		-DECM_MKSPECS_INSTALL_DIR=$dataDir/Qt5/mkspecs \
		-DECM_DIR=/system/data/cmake/Modules/ECM/cmake \
		-DICONV_INCLUDE_DIR=/system/$relativeIncludeDir \
		-DKDE_INSTALL_DATAROOTDIR=$dataDir \
		-DCMAKE_CXX_FLAGS="-DKDE_NO_DEBUG_OUTPUT" \
		-DRELEASE_BUILD=ON

	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	cd $appsDir/Calligra
	mv calligraplan Plan
	mv calligraplanwork PlanWork

	rm -rf $appsDir/Calligra/etc

	mkdir -p "$dataDir/deskbar/menu/Applications/Calligra"

	local APP_SIGNATURE="application/x-vnd.calligra-plan"
	local MAJOR="`echo "$portVersion" | cut -d. -f1`"
	local MIDDLE="`echo "$portVersion" | cut -d. -f2`"
	local MINOR="`echo "$portVersion" | cut -d. -f3`"
	local LONG_INFO="$SUMMARY"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/calligraplan.rdef.in > $sourceDir/build/calligraplan.rdef

	addResourcesToBinaries $sourceDir/build/calligraplan.rdef $appsDir/Calligra/Plan
	addAppDeskbarSymlink $appsDir/Calligra/Plan "Calligra/Plan"

	local APP_SIGNATURE="application/x-vnd.calligra-planwork"
	sed \
		-e "s|@APP_SIGNATURE@|$APP_SIGNATURE|" \
		-e "s|@MAJOR@|$MAJOR|" \
		-e "s|@MIDDLE@|$MIDDLE|" \
		-e "s|@MINOR@|$MINOR|" \
		-e "s|@LONG_INFO@|$LONG_INFO|" \
		$portDir/additional-files/calligraplanwork.rdef.in > $sourceDir/build/calligraplanwork.rdef

	addResourcesToBinaries $sourceDir/build/calligraplanwork.rdef $appsDir/Calligra/PlanWork
	addAppDeskbarSymlink $appsDir/Calligra/PlanWork "Calligra/PlanWork"
}

TEST()
{
	cd build
	make test
}
