SUMMARY="The integrated work applications suite"
DESCRIPTION="Calligra Suite is a collection of office applications linked \
together by a common base.  This common base assures that all office \
application can work together and also share a common look and feel."
HOMEPAGE="https://www.calligra.org/"
COPYRIGHT="2010-2020 KDE Organisation"
LICENSE="GNU LGPL v2
	GNU GPL v2"
REVISION="5"
SOURCE_URI="https://download.kde.org/stable/calligra/$portVersion/calligra-$portVersion.tar.xz"
CHECKSUM_SHA256="b1f8a6eb8208543a2f908caa83d089075fcd1e530d00e19f5362b2f9cc371147"
SOURCE_FILENAME="calligra-$portVersion.tar.xz"
PATCHES="calligra-$portVersion.patchset"
ADDITIONAL_FILES="
	karbon.rdef.in
	sheets.rdef.in
	stage.rdef.in
	words.rdef.in
	template_icons.zip
	"

ARCHITECTURES="all !x86_gcc2"
SECONDARY_ARCHITECTURES="x86"

libVersion="17.0.0"

PROVIDES="
	calligra$secondaryArchSuffix = $portVersion
	lib:libbasicflakes$secondaryArchSuffix = $libVersion
	lib:libcalligrasheetscommon$secondaryArchSuffix = $libVersion
	lib:libcalligrasheetsodf$secondaryArchSuffix = $libVersion
	lib:libcalligrastageprivate$secondaryArchSuffix = $libVersion
	lib:libflake$secondaryArchSuffix = $libVersion
	lib:libkarboncommon$secondaryArchSuffix = $libVersion
	lib:libkarbonui$secondaryArchSuffix = $libVersion
	lib:libkdeinit5_calligrasheets$secondaryArchSuffix = $libVersion
	lib:libkdeinit5_calligrastage$secondaryArchSuffix = $libVersion
	lib:libkdeinit5_calligrawords$secondaryArchSuffix = $libVersion
	lib:libkdeinit5_karbon$secondaryArchSuffix = $libVersion
	lib:libkoformula$secondaryArchSuffix = $libVersion
	lib:libkomain$secondaryArchSuffix = $libVersion
	lib:libkomsooxml$secondaryArchSuffix = $libVersion
	lib:libkoodf$secondaryArchSuffix = $libVersion
	lib:libkoodf2$secondaryArchSuffix = $libVersion
	lib:libkoodfreader$secondaryArchSuffix = $libVersion
	lib:libkopageapp$secondaryArchSuffix = $libVersion
	lib:libkoplugin$secondaryArchSuffix = $libVersion
	lib:libkostore$secondaryArchSuffix = $libVersion
	lib:libkotext$secondaryArchSuffix = $libVersion
	lib:libkotextlayout$secondaryArchSuffix = $libVersion
	lib:libkovectorimage$secondaryArchSuffix = $libVersion
	lib:libkoversion$secondaryArchSuffix = $libVersion
	lib:libkowidgets$secondaryArchSuffix = $libVersion
	lib:libkowidgetutils$secondaryArchSuffix = $libVersion
	lib:libkowv2$secondaryArchSuffix = $libVersion
	lib:libkplatokernel$secondaryArchSuffix = $libVersion
	lib:libkplatomodels$secondaryArchSuffix = $libVersion
	lib:libkplatoui$secondaryArchSuffix = $libVersion
	lib:libkundo2$secondaryArchSuffix = $libVersion
	lib:libpigmentcms$secondaryArchSuffix = $libVersion
	lib:librtfreader$secondaryArchSuffix = $libVersion
	lib:libwordsprivate$secondaryArchSuffix = $libVersion
	"
REQUIRES="
	haiku$secondaryArchSuffix
	lib:libboost_system$secondaryArchSuffix
	lib:libetonyek_0.1$secondaryArchSuffix
	lib:libfontconfig$secondaryArchSuffix
	lib:libfreetype$secondaryArchSuffix
	lib:libgsl$secondaryArchSuffix
	lib:libiconv$secondaryArchSuffix
	lib:libIex_3_0$secondaryArchSuffix
	lib:libIlmThread_3_0$secondaryArchSuffix
	lib:libImath_3_0$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:liblcms2$secondaryArchSuffix
	lib:libodfgen_0.1$secondaryArchSuffix
	lib:libOpenEXR_3_0$secondaryArchSuffix
	lib:libOpenEXRUtil_3_0$secondaryArchSuffix
	lib:libphonon4qt5$secondaryArchSuffix
	lib:libpoppler_qt5$secondaryArchSuffix
	lib:libqca_qt5$secondaryArchSuffix
	lib:libQt5Core$secondaryArchSuffix
	lib:libQt5WebKitWidgets$secondaryArchSuffix
	lib:librevenge_0.0$secondaryArchSuffix
	lib:libvisio_0.1$secondaryArchSuffix
	lib:libwpd_0.10$secondaryArchSuffix
	lib:libwpg_0.3$secondaryArchSuffix
	lib:libwps_0.4$secondaryArchSuffix
	lib:libz$secondaryArchSuffix
	"

PROVIDES_okular_plugins="
	calligra${secondaryArchSuffix}_okular_plugins = $portVersion
	lib:libkookulargenerator_odp$secondaryArchSuffix = $libVersion
	lib:libkookulargenerator_odt$secondaryArchSuffix = $libVersion
	"

REQUIRES_okular_plugins="
	calligra$secondaryArchSuffix == $portVersion base
	lib:libOkular5Core$secondaryArchSuffix
	$REQUIRES
	"

BUILD_REQUIRES="
	haiku${secondaryArchSuffix}_devel
	extra_cmake_modules$secondaryArchSuffix >= 5.77
	devel:eigen$secondaryArchSuffix
	devel:libboost_system$secondaryArchSuffix >= 1.70.0
	devel:libetonyek_0.1$secondaryArchSuffix
	devel:libfontconfig$secondaryArchSuffix
	devel:libfreetype$secondaryArchSuffix
	devel:libgsl$secondaryArchSuffix
	devel:libiconv$secondaryArchSuffix
	devel:libIex_3_0$secondaryArchSuffix
	devel:libIlmThread_3_0$secondaryArchSuffix
	devel:libImath_3_0$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:libodfgen_0.1$secondaryArchSuffix
	devel:libOkular5Core$secondaryArchSuffix
	devel:libOpenEXR_3_0$secondaryArchSuffix
	devel:libOpenEXRUtil_3_0$secondaryArchSuffix
	devel:libphonon4qt5$secondaryArchSuffix
	devel:libpoppler$secondaryArchSuffix >= 104
	devel:libpoppler_qt5$secondaryArchSuffix >= 1.26
	devel:libqca$secondaryArchSuffix >= 2
	devel:libQt5Core$secondaryArchSuffix >= 5.15
	devel:libQt5WebKitWidgets$secondaryArchSuffix
	devel:librevenge_0.0$secondaryArchSuffix
	devel:libvisio_0.1$secondaryArchSuffix
	devel:libwpd_0.10$secondaryArchSuffix
	devel:libwpg_0.3$secondaryArchSuffix
	devel:libwps_0.4$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
	"

PATCH()
{
	unzip -o $sourceDir/../../additional-files/template_icons.zip -d $sourceDir
}

BUILD()
{
	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 \
		-DPRODUCTSET="karbon sheets words stage okular" \
		-DCMAKE_CXX_FLAGS="-DKDE_NO_DEBUG_OUTPUT" \
		-DRELEASE_BUILD=ON \
		-DBUILD_UNMAINTAINED=ON \
		-DWITH_Okular5=ON

	make $jobArgs
}

INSTALL()
{
	cd build
	make install

	cd $appsDir/Calligra
	mv calligrasheets Sheets
	mv calligrawords Words
	mv calligrastage Stage
	mv karbon Karbon

	rm -rf $appsDir/Calligra/etc

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

	local APP_SIGNATURE="application/x-vnd.calligra-sheets"
	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/sheets.rdef.in > $sourceDir/build/sheets.rdef

	addResourcesToBinaries $sourceDir/build/sheets.rdef $appsDir/Calligra/Sheets
	addAppDeskbarSymlink $appsDir/Calligra/Sheets "Calligra/Sheets"

	local APP_SIGNATURE="application/x-vnd.calligra-words"
	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/words.rdef.in > $sourceDir/build/words.rdef

	addResourcesToBinaries $sourceDir/build/words.rdef $appsDir/Calligra/Words
	addAppDeskbarSymlink $appsDir/Calligra/Words "Calligra/Words"

	local APP_SIGNATURE="application/x-vnd.calligra-stage"
	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/stage.rdef.in > $sourceDir/build/stage.rdef

	addResourcesToBinaries $sourceDir/build/stage.rdef $appsDir/Calligra/Stage
	addAppDeskbarSymlink $appsDir/Calligra/Stage "Calligra/Stage"

	local APP_SIGNATURE="application/x-vnd.calligra-karbon"
	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/karbon.rdef.in > $sourceDir/build/karbon.rdef

	addResourcesToBinaries $sourceDir/build/karbon.rdef $appsDir/Calligra/Karbon
	addAppDeskbarSymlink $appsDir/Calligra/Karbon "Calligra/Karbon"

	packageEntries okular_plugins \
		$addOnsDir/Qt5/okular \
		$libDir/libkookularGenerator_odp.so \
		$libDir/libkookularGenerator_odp.so.${libVersion%.*.*} \
		$libDir/libkookularGenerator_odp.so.${libVersion} \
		$libDir/libkookularGenerator_odt.so \
		$libDir/libkookularGenerator_odt.so.${libVersion%.*.*} \
		$libDir/libkookularGenerator_odt.so.${libVersion}
}

TEST()
{
	make test
}
