# Template file for 'calligra'
pkgname=calligra
version=26.04.1
revision=2
build_style=cmake
configure_args="-DCALLIGRA_SHOULD_BUILD_UNMAINTAINED=ON
 -DKDE_INSTALL_QTPLUGINDIR=lib/qt6/plugins
 -DKDE_INSTALL_QMLDIR=lib/qt6/qml
 -DBUILD_TESTING=OFF"
hostmakedepends="perl pkg-config extra-cmake-modules gettext pstoedit
 qt6-base qt6-declarative-host-tools
 kf6-kconfig kf6-kcoreaddons kf6-kdoctools kf6-kcmutils"
makedepends="ecm-devel eigen boost-headers zlib-devel
 openssl-devel imath-devel gsl-devel poppler-devel libgit2-devel
 kf6-karchive-devel kf6-kcompletion-devel kf6-kconfig-devel
 kf6-kconfigwidgets-devel kf6-kcoreaddons-devel kf6-kcrash-devel
 kf6-kdoctools-devel kf6-kguiaddons-devel kf6-ki18n-devel
 kf6-kiconthemes-devel kf6-kitemviews-devel kf6-kjobwidgets-devel
 kf6-kcmutils-devel kf6-kio-devel kf6-knotifications-devel
 kf6-knotifyconfig-devel kf6-sonnet-devel kf6-ktextwidgets-devel
 kf6-kwidgetsaddons-devel kf6-kwindowsystem-devel kf6-kxmlgui-devel
 kf6-kdbusaddons-devel
 qt6-base-devel qt6-svg-devel qt6-declarative-devel
 qtkeychain-qt6-devel kdiagram6-devel qca-qt6-devel poppler-qt6-devel
 libokular-devel phonon-devel
 lcms2-devel fontconfig-devel freetype-devel librevenge-devel
 libodfgen-devel libwpd-devel libwpg-devel libwps-devel
 libvisio-devel libetonyek-devel"
depends="calligra-filters calligra-libs calligra-plugins calligra-karbon
 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}/release-service/${version}/src/calligra-${version}.tar.xz"
checksum=193ce06bf7dc3225a8961123aa131c245d49519154bf095804dacaee06197685

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

if [ "$XBPS_WORDSIZE$XBPS_WORDSIZE" = "64$XBPS_TARGET_WORDSIZE" ]; then
	makedepends+=" qt6-webengine-devel"
fi

CXXFLAGS="-DKDE_NO_DEBUG_OUTPUT"

if [ "$CROSS_BUILD" ]; then
	hostmakedepends+=" calligra-devtools"
	configure_args+=" -DMODERN_ICONV_RUN=1"
fi

post_patch() {
	if [ "$XBPS_WORDSIZE$XBPS_WORDSIZE" != "64$XBPS_TARGET_WORDSIZE" ]; then
		msg_normal "Applying no-webengine.patch\n"
		patch -sNp1 -i ${FILESDIR}/no-webengine.patch
	fi
}

# cmake doesn't detect the functions correctly
pre_build() {
	if [ "$XBPS_TARGET_LIBC" = musl ]; then
		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
	fi
}

do_install() {
	vdoc README.md
}

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() {
	metapackage=yes
	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() {
	metapackage=yes
	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() {
	metapackage=yes
	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/bin/rng2cpp
		vbin build/bin/recordsxml2cpp
	}
}

calligra-gemini_package() {
	short_desc+=" - QML interface for Calligra Words and Stage"
	depends="kf6-kirigami"
	if [ "$XBPS_WORDSIZE$XBPS_WORDSIZE" = "64$XBPS_TARGET_WORDSIZE" ]; then
		depends+=" qt6-webengine"
	fi
	pkg_install() {
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/components/cmake_install.cmake
		DESTDIR=$PKGDESTDIR \
		cmake -P ${wrksrc}/build/gemini/cmake_install.cmake
	}
}
