# Template file for 'calligra'
pkgname=calligra
version=3.2.1
revision=24
build_style=cmake
configure_args="-Wno-dev -DCALLIGRA_SHOULD_BUILD_UNMAINTAINED=ON
 -DMEINPROC5_EXECUTABLE=/usr/bin/meinproc5 -DBUILD_TESTING=OFF"
hostmakedepends="perl pkg-config extra-cmake-modules gettext
 qt5-qmake qt5-host-tools calligra-devtools kcoreaddons kwallet"
makedepends="ecm-devel eigen3.2
 exiv2-devel kactivities5-devel gsl-devel qt5-declarative-devel
 kcmutils-devel kdelibs4support-devel kdiagram-devel
 kholidays-devel khtml-devel knotifyconfig-devel kross-devel lcms2-devel
 libetonyek-devel libgit2-devel libodfgen-devel kwallet-devel
 libopenexr-devel libspnav-devel libvisio-devel libwpg-devel libwps-devel
 poppler-qt5-devel qca-qt5-devel threadweaver-devel marble5-devel
 knotifyconfig-devel sonnet-devel kcodecs-devel
 kauth-devel kparts-devel kxmlgui-devel kconfigwidgets-devel kconfig-devel
 ktextwidgets-devel kservice-devel kcrash-devel kio-devel kiconthemes-devel"
depends="calligra-filters calligra-libs calligra-plugins calligra-karbon
 calligra-kexi calligra-stage calligra-sheets calligra-extras
 calligra-words calligra-handbook calligra-gemini calligra-plan"
short_desc="Illustration application"
maintainer="John <me@johnnynator.dev>"
license="GPL-2.0-or-later, LGPL-2.0-or-later, GFDL-1.2-or-later"
homepage="https://www.calligra-suite.org/"
distfiles="${KDE_SITE}/calligra/${version}/calligra-${version}.tar.xz"
checksum=b1f8a6eb8208543a2f908caa83d089075fcd1e530d00e19f5362b2f9cc371147

replaces="calligra-braindump>=0 calligra-flow>=0"

build_options="webengine"
desc_option_webengine="Use Qt5 WebEngine for Calligra Gemini"

if [ "$XBPS_TARGET_ENDIAN" = "le" ]; then
	# webengine does not cross-build from 64bit to 32bit, use webkit
	if [ "$XBPS_WORDSIZE" = "$XBPS_TARGET_WORDSIZE" ]; then
		build_options_default="webengine"
	fi
fi

CXXFLAGS="-DKDE_NO_DEBUG_OUTPUT"

if [ "$CROSS_BUILD" ]; then
	configure_args+=" -DMODERN_ICONV_RUN=1 -DDESKTOPTOJSON_EXECUTABLE=/usr/bin/desktoptojson"
fi

post_patch() {
	[ "$build_option_webengine" ] && return 0

	msg_normal "Applying gemini-webkit.patch\n"
	patch -sNp1 -i ${FILESDIR}/gemini-webkit.patch
}

# cmake doesn't detect the functions correctly
pre_build() {
	case $XBPS_TARGET_MACHINE in
		*-musl) cat >> build/filters/words/msword-odf/wv2/src/config.h <<-EOF
		#define HAVE_FUNC_ISNAN 1
		#define HAVE_FUNC_ISINF 1
		#define HAVE_FUNC_ISFINITE 1
		EOF
		;;
	esac
}

do_install() {
	vdoc README
}

calligra-filters_package() {
	short_desc+=" - filters"
	depends="pstoedit"
	pkg_install() {
		DESTDIR=$PKGDESTDIR \
			cmake -P ${wrksrc}/build/filters/cmake_install.cmake
	}
}

calligra-libs_package() {
	short_desc+=" - libraries"
	pkg_install() {
		for d in interfaces libs pics servicetypes; do
			DESTDIR=$PKGDESTDIR \
			cmake -P ${wrksrc}/build/${d}/cmake_install.cmake
		done
	}
}

calligra-plugins_package() {
	short_desc+=" - plugins"
	pkg_install() {
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/plugins/cmake_install.cmake
	}
}

calligra-karbon_package() {
	short_desc+=" - Create scalable vector drawings"
	pkg_install() {
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/karbon/cmake_install.cmake
	}
}

calligra-kexi_package() {
	build_style=meta
	depends="kexi"
	short_desc+=" - Develop desktop db apps (transitional dummy package)"
}

calligra-stage_package() {
	short_desc+=" - Write presentation documents"
	pkg_install() {
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/stage/cmake_install.cmake
	}
}

calligra-krita_package() {
	build_style=meta
	short_desc+=" - Edit and paint images (transitional dummy package)"
	depends="krita>=${version}_${revision}"
}

calligra-sheets_package() {
	short_desc+=" - Write spreadsheet documents"
	pkg_install() {
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/sheets/cmake_install.cmake
	}
}

calligra-words_package() {
	short_desc+=" - Word Processor"
	depends="calligra-plugins"
	pkg_install() {
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/words/cmake_install.cmake
	}
}

calligra-handbook_package() {
	build_style=meta
	short_desc+=" - Documentation (removed temporarily)"
	#pkg_install() {
	#	DESTDIR=$PKGDESTDIR \
	#	cmake -P ${wrksrc}/build/doc/calligra/cmake_install.cmake
	#}
}

calligra-extras_package() {
	short_desc+=" - Extras"
	pkg_install() {
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/extras/cmake_install.cmake
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/data/cmake_install.cmake
	}
}

calligra-devtools_package() {
	short_desc+=" - Developer tools"
	pkg_install() {
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/devtools/cmake_install.cmake
		vbin build/devtools/rng2cpp/rng2cpp
		vbin build/filters/sheets/excel/sidewinder/recordsxml2cpp
	}
}

calligra-gemini_package() {
	short_desc+=" - QML interface for Calligra Words and Stage"
	depends="qt5-quickcontrols kirigami2"
	if [ "$build_option_webengine" ]; then
		depends+=" qt5-webengine"
	else
		depends+=" qt5-webkit"
	fi
	pkg_install() {
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/components/cmake_install.cmake
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/gemini/cmake_install.cmake
	}
}
