# Template file for 'calligra'
pkgname=calligra
version=3.1.0
revision=12
build_style=cmake
configure_args="-Wno-dev -DCALLIGRA_SHOULD_BUILD_UNMAINTAINED=ON"
hostmakedepends="automoc4 perl pkg-config extra-cmake-modules"
makedepends="akonadi-contacts-devel akonadi5-devel ecm-devel eigen3.2
 exiv2-devel kactivities5-devel gsl-devel
 kcmutils-devel kcontacts-devel kdelibs4support-devel kdiagram-devel
 kholidays-devel khtml-devel knotifyconfig-devel kross-devel lcms2-devel
 libetonyek-devel libgit2-devel libodfgen-devel libokular-devel
 libopenexr-devel libspnav-devel libvisio-devel libwpg-devel libwps-devel
 poppler-qt5-devel qca-qt5-devel threadweaver-devel marble5-devel"
short_desc="Illustration application"
maintainer="John <johnz@posteo.net>"
license="GPL-2.0-or-later, LGPL-2.0-or-later, GFDL-1.2-or-later"
homepage="http://www.calligra-suite.org/"
distfiles="${KDE_SITE}/calligra/${version}/calligra-${version}.tar.xz"
checksum=6818cd6e64136321be217eb57cc7d6ac7c7035191fdb1ee336ebe60bc114e870

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

subpackages="calligra-filters calligra-libs calligra-plugins calligra-karbon
 calligra-kexi calligra-stage calligra-krita calligra-sheets calligra-extras
 calligra-words calligra-handbook calligra-gemini calligra-devtools"
depends="${subpackages/calligra-devtools/} calligra-plan"

CXXFLAGS="-DKDE_NO_DEBUG_OUTPUT"

if [ "$CROSS_BUILD" ]; then
	hostmakedepends+=" qt5-qmake qt5-host-tools calligra-devtools kcoreaddons"
	configure_args+=" -DMODERN_ICONV_RUN=1 -DDESKTOPTOJSON_EXECUTABLE=/usr/bin/desktoptojson"
fi

# 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() {
		cd ${wrksrc}/build/filters
		make DESTDIR=$PKGDESTDIR install
	}
}
calligra-libs_package() {
	short_desc+=" - libraries"
	pkg_install() {
		for d in interfaces libs pics servicetypes; do
			cd ${wrksrc}/build/${d}
			make DESTDIR=$PKGDESTDIR install
		done
	}
}
calligra-plugins_package() {
	short_desc+=" - plugins"
	pkg_install() {
		cd ${wrksrc}/build/plugins
		make DESTDIR=$PKGDESTDIR install
	}
}
calligra-karbon_package() {
	short_desc+=" - Create scalable vector drawings"
	pkg_install() {
		cd ${wrksrc}/build/karbon
		make DESTDIR=$PKGDESTDIR install
	}
}
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() {
		cd ${wrksrc}/build/stage
		make DESTDIR=$PKGDESTDIR install
		#cd ../doc/stage
		#make DESTDIR=$PKGDESTDIR install
	}
}
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() {
		cd ${wrksrc}/build/sheets
		make DESTDIR=$PKGDESTDIR install
		#cd ../doc/sheets
		#make DESTDIR=$PKGDESTDIR install
	}
}
calligra-words_package() {
	short_desc+=" - Word Processor"
	depends="calligra-plugins"
	pkg_install() {
		cd ${wrksrc}/build/words
		make DESTDIR=$PKGDESTDIR install
	}
}
calligra-handbook_package() {
	build_style=meta
	noarch=yes
	short_desc+=" - Documentation (removed temporarily)"
	#pkg_install() {
	#	cd ${wrksrc}/build/doc/calligra
	#	make DESTDIR=$PKGDESTDIR install
	#}
}
calligra-extras_package() {
	short_desc+=" - Extras"
	pkg_install() {
		cd ${wrksrc}/build/extras
		make DESTDIR=$PKGDESTDIR install
		cd ${wrksrc}/build/data
		make DESTDIR=$PKGDESTDIR install
	}
}
calligra-devtools_package() {
	short_desc+=" - Developer tools"
	pkg_install() {
		cd ${wrksrc}/build/devtools
		make DESTDIR=$PKGDESTDIR install
		vbin rng2cpp/rng2cpp
		vbin ../filters/sheets/excel/sidewinder/recordsxml2cpp
	}
}
calligra-gemini_package() {
	short_desc+=" - QML interface for Calligra Words and Stage"
	depends="qt5-quickcontrols kirigami2 qt5-webengine"
	pkg_install() {
		cd ${wrksrc}/build/components
		make DESTDIR=$PKGDESTDIR install
		cd ${wrksrc}/build/gemini
		make DESTDIR=$PKGDESTDIR install
	}
}
