# Template file for 'libreoffice'
pkgname=libreoffice
version=26.2.5.2
revision=1
build_helper="gir"
build_style=configure # hack, avoid sourcing common/.../gnu-configure-args.sh
metapackage=yes
make_build_target="build"
# Use order in configure.ac
_xdeps="zlib-devel libjpeg-turbo-devel clucene-devel expat-devel xmlsec1-devel
 nss-devel nspr-devel librevenge-devel libodfgen-devel libepubgen-devel
 libwpd-devel libwpg-devel libwps-devel libvisio-devel libcdr-devel
 libmspub-devel libmwaw-devel libetonyek-devel libfreehand-devel
 libe-book-devel libabw-devel libpagemaker-devel libqxp-devel libzmf-devel
 libstaroffice-devel lcms2-devel libcppunit-devel freetype-devel libxslt-devel
 libgcrypt-devel libxml2-devel python3-devel libcurl-devel boost-devel-minimal
 libeot-devel libmd4c-devel sqlite-devel libzstd-devel liblzma-devel
 mdds frozen glm unixodbc-devel libldap-devel sane-devel icu-devel liborcus-devel
 graphite-devel harfbuzz-devel libargon2-devel redland-devel hunspell-devel
 zxcvbn-c-devel zxing-cpp-devel box2d-devel hyphen-devel mythes-devel
 CoinMP-devel lpsolve-devel libexttextcat-devel libnumbertext-devel
 libepoxy-devel cairo-devel liblangtag-devel libpng-devel tiff-devel
 libwebp-devel fontconfig-devel libcmis-devel
 gobject-introspection libgirepository-devel libglib-devel"
hostmakedepends="automake flex gperf hyphen icu libtool openldap which gettext
 tar xz perl-Archive-Zip pkg-config sane unzip zip python3-setuptools
 fontforge python3-lxml qt6-base gnupg glib-devel afdko
 $(vopt_if java 'openjdk17 apache-ant beanshell rhino hsqldb1.8.0')"
makedepends="$_xdeps openssl-devel libXrender-devel libbluetooth-devel
 gpgmepp-devel libXinerama-devel libXt-devel libX11-devel libICE-devel
 libSM-devel libopenjpeg2-devel abseil-cpp-devel poppler-cpp-devel
 gtk+3-devel gtk4-devel gst-plugins-base1-devel
 qt6-base-devel qt6-multimedia-devel
 kf6-kio-devel kf6-frameworkintegration-devel
 libmariadbclient-devel postgresql-libs-devel
 $(vopt_if firebird 'libfbclient3-devel libatomic_ops-devel')"
# Add the previously installed default languages as well
depends="libreoffice-common>=${version}_${revision}
 libreoffice-base>=${version}_${revision}
 libreoffice-calc>=${version}_${revision}
 libreoffice-draw>=${version}_${revision}
 libreoffice-fonts>=${version}_${revision}
 libreoffice-gnome>=${version}_${revision}
 libreoffice-impress>=${version}_${revision}
 libreoffice-math>=${version}_${revision}
 libreoffice-postgresql>=${version}_${revision}
 libreoffice-writer>=${version}_${revision}
 libreoffice-xtensions>=${version}_${revision}
 libreoffice-i18n-en-US>=${version}_${revision}
 libreoffice-i18n-de>=${version}_${revision}
 libreoffice-i18n-es>=${version}_${revision}
 libreoffice-i18n-fr>=${version}_${revision}
 libreoffice-i18n-it>=${version}_${revision}
 libreoffice-i18n-pl>=${version}_${revision}
 libreoffice-i18n-pt>=${version}_${revision}"
checkdepends="gdb"
short_desc="Productivity suite"
maintainer="Đoàn Trần Công Danh <congdanhqx@gmail.com>"
license="GPL-3.0-or-later"
homepage="https://www.libreoffice.org/"

_basever=${version%.beta*}
_basever=${_basever%.*}
# Source, dictionary, help and translations
_baseurl="https://download.documentfoundation.org/libreoffice/src/${_basever}"
# _baseurl="https://downloadarchive.documentfoundation.org/libreoffice/old/${version}/src/"
# Please don't remove this mirror, it's faster for me
# _baseurl="https://download.nus.edu.sg/mirror/tdf/libreoffice/src/${_basever}"
# _baseurl="https://mirrors.nju.edu.cn/tdf/libreoffice/src/${_basever}"
# _baseurl="https://mirrors.tuna.tsinghua.edu.cn/libreoffice/src/${_basever}"
_addurl="https://dev-www.libreoffice.org/src"
_exturl="https://dev-www.libreoffice.org/extern"

# Additional distfiles and checksums can be found in
# the file 'download.lst' after configure was run.
distfiles="
 ${_baseurl}/${pkgname}-${version}.tar.xz
 ${_baseurl}/${pkgname}-help-${version}.tar.xz
 ${_baseurl}/${pkgname}-translations-${version}.tar.xz"
checksum="8ec785ee1fd1a1d9b9d8eba1c8ff7556695ca8f02e1f7a26bef8cd540f669fea
 73fbe02eb53408e11121da9a170bc4a9c2250b5baaa8851c65b3f70e88841703
 44f1dbdefe0dab21293297cacb8af8d6a7bece4ce95ded7f25c24837bd067fb7"
replaces="libreoffice-firebird<6.2.4.2_1"

_distfile_add() {
	local url="$_addurl"
	if [ "$1" = -e ]; then
		url="$_exturl"
		shift
	fi
	distfiles+=" ${url}/${1}"
	checksum+=" ${2}"
	skip_extraction+=" ${1}"
}
_distfile_add a7983f859eafb2677d7ff386a023bc40-xsltml_2.1.2.zip \
	75823776fb51a9c526af904f1503a7afaaab900fba83eda64f8a41073724c870
_distfile_add language-subtag-registry-2026-06-14.tar.bz2 \
	e74af13fd11fbcb24a5910d0f50e45d8505d86267bde2bb2d1d45aed966bc3bb
_distfile_add pdfium-7471.tar.bz2 \
	7144b0fa78fd408997e7b84ffd3c257db602e392a1bb1584828d80e60b6b27c5
_distfile_add -e officeotron-0.8.5.jar \
	0c2a4227394ac78147387f1c1ff1063e87f2151ffc91f1eb97bb17c2650fa708
_distfile_add skia-m142-f4ed99d2443962782cf5f8b4dd27179f131e7cbe.tar.xz \
	45ae58e84fa2d1e261bfc980e1c5b7bbfaf83887e3813795bd343d3786f4d0bc
_distfile_add -e odfvalidator-0.9.0-RC2-SNAPSHOT-jar-with-dependencies-2726ab578664434a545f8379a01a9faffac0ae73.jar \
	d55495ab3a86544650587de2a72180ddf8bfc6376d14ddfa923992dbc86a06e0
_distfile_add ba2930200c9f019c2d93a8c88c651a0f-flow-engine-0.9.4.zip \
	233f66e8d25c5dd971716d4200203a612a407649686ef3b52075d04b4c9df0dd
_distfile_add d8bd5eed178db6e2b18eeed243f85aa8-flute-1.1.6.zip \
	1b5b24f7bc543c0362b667692f78db8bab4ed6dafc6172f104d0bd3757d8a133
_distfile_add eeb2c7ddf0d302fba4bfc6e97eac9624-libbase-1.1.6.zip \
	75c80359c9ce343c20aab8a36a45cb3b9ee7c61cf92c13ae45399d854423a9ba
_distfile_add 3bdf40c0d199af31923e900d082ca2dd-libfonts-1.1.6.zip \
	e0531091787c0f16c83965fdcbc49162c059d7f0c64669e7f119699321549743
_distfile_add 3404ab6b1792ae5f16bbd603bd1e1d03-libformula-1.1.7.zip \
	5826d1551bf599b85742545f6e01a0079b93c1b2c8434bf409eddb3a29e4726b
_distfile_add db60e4fde8dd6d6807523deb71ee34dc-liblayout-0.2.10.zip \
	e1fb87f3f7b980d33414473279615c4644027e013012d156efa538bc2b031772
_distfile_add 97b2d4dba862397f446b217e2b623e71-libloader-1.1.6.zip \
	3d853b19b1d94a6efa69e7af90f7f2b09ecf302913bee3da796c15ecfebcfac8
_distfile_add 8ce2fcd72becf06c41f7201d15373ed9-librepository-1.1.6.zip \
	abe2c57ac12ba45d83563b02e240fa95d973376de2f720aab8fe11f2e621c095
_distfile_add f94d9870737518e3b597f9265f4e9803-libserializer-1.1.6.zip \
	05640a1f6805b2b2d7e2cb9c50db9a5cb084e3c52ab1a71ce015239b4a1d4343
_distfile_add ace6ab49184e329db254e454a010f56d-libxml-1.1.7.zip \
	7d2797fe9f79a77009721e3f14fa4a1dec17a6d706bdc93f85f1f01d124fab66
_distfile_add 39bb3fcea1514f1369fcfc87542390fd-sacjava-1.3.zip \
	085f2112c51fa8c1783fac12fbd452650596415121348393bb51f0f7e85a9045
_distfile_add frozen-1.2.0.tar.gz \
	ed8339c017d7c5fe019ac2c642477f435278f0dc643c1d69d3f3b1e95915e823
_distfile_add dragonbox-1.1.3.tar.gz \
	09d63b05e9c594ec423778ab59b7a5aa1d76fdd71d25c7048b0258c4ec9c3384
_distfile_add Java-WebSocket-1.6.0.tar.gz \
	f3ce29efde338707241d47ab4784b19a1e3658bfa0564b5bc5f80c27e5118728
_distfile_add fast_float-8.2.2.tar.gz \
	e64b5fff88e04959154adbd5fb83331d91f2e04ac06454671cdfcbdff172b158
_distfile_add -e verapdf-cli-1.29.0.jar \
	bdeef807f7e883fe3ff4e0a4712dc216064ca670d5c857fbc94408266719f0f4

build_options="java firebird"
desc_option_java="Enable Java support"
desc_option_firebird="Enable Firebird SDBC support"

CXXFLAGS="-DGLM_ENABLE_EXPERIMENTAL -DU_USING_ICU_NAMESPACE=1"

case "$XBPS_TARGET_MACHINE" in
	i686*)	# Broken unit tests
		CXXFLAGS+=" -DDISABLE_CVE_TESTS=1"
		;;
	x86_64*|ppc64*) build_options_default="java" ;;
	# aarch64*) build_options_default="java" ;;
	armv[56]*) broken="untested" ;;
esac

if [ -z "$CROSS_BUILD" ]; then
	build_options_default+=" firebird"
else
	hostmakedepends+=" $_xdeps"
fi

# Move files listed in a <name>_list.txt into $PKGDESTDIR
_split() {
	local list file dir destdir
	destdir="${DESTDIR}/all"
	list=${wrksrc}/file-lists/${1}_list.txt
	# skip non-existing file lists
	[ -f ${list} ] || msg_error "There is no ${1}_list.txt file!\n"
	grep -v -e '^%dir' -e '^$' "$list" | sort -u |
	while read file; do
		dir="${file%/*}"
		[ -d "${PKGDESTDIR}/${dir}" ] || vmkdir "${dir}"
		mv ${destdir}/${file} ${PKGDESTDIR}/${dir}/
	done
	# Move appdata file, if any
	file=usr/share/metainfo/libreoffice-${1}.appdata.xml
	if [ -f ${destdir}/${file} ]; then
		dir="${file%/*}"
		[ -d "${PKGDESTDIR}/${dir}" ] || vmkdir "${dir}"
		mv ${destdir}/${file} ${PKGDESTDIR}/${dir}/
	fi
}

unset _languages
_add_lang() {
	local pkglang tmp
	local deps=
	local lang=$1
	local name=$2
	pkglang="${lang//-/_}"
	shift 2
	while case "$1" in
		-h*)	tmp=${1#-h}; deps="$deps hunspell-${tmp:-$pkglang}" ;;
		-H*)	tmp=${1#-H}; deps="$deps hyphen-${tmp:-$pkglang}" ;;
		-m*)	tmp=${1#-m}; deps="$deps mythes-${tmp:-$pkglang}" ;;
		-l*)	pkglang=${1#-l} ;;
		-vh=*)	deps="$deps virtual?hunspell-${1#-vh=}" ;;
		*)	false ;;
	esac; do shift; done
	_languages="$_languages ${pkglang//_/-}"
	eval "libreoffice-i18n-${lang}_package() {
		short_desc+=\" - ${name} language pack\"
		depends='$deps'
		pkg_install() {
			_split lang_${pkglang}
		}
	}"
}

_add_lang ab		"Abkhazian"
_add_lang af		"Afrikaans" -h -H
_add_lang am		"Amharic"
# _add_lang an		"Aragonese"
_add_lang ar		"Arabic" -h -m
_add_lang as		"Assamese" -h -H
_add_lang ast		"Asturian"
# _add_lang az		"Azerbaijani"
_add_lang be		"Belarusian" -h -H
_add_lang bg		"Bulgarian" -h -H -m
_add_lang bn		"Bengali" -h
_add_lang bn-IN		"Bengali (India)" -hbn
_add_lang bo		"Tibetan" -h
_add_lang br		"Breton" -h
_add_lang brx		"Bodo"
_add_lang bs		"Bosnian" -h
_add_lang ca		"Catalan" -hca_ES -H -m
_add_lang ca-valencia	"Catalan (Valencian)" -hca_ES -Hca -mca
_add_lang ckb		"Central Kurdish" -h
_add_lang cs		"Czech" -h -H -m
_add_lang cy		"Welsh (Cymraeg)"
_add_lang da		"Danish" -hda_DK -H -m
_add_lang de		"German" -h -H -m
_add_lang dgo		"Dogri proper"
_add_lang dsb		"Lower Sorbian"
_add_lang dz		"Dzongkha"
_add_lang el		"Greek" -hel_GR -H
_add_lang en-GB		"English (UK)" -hen -vh=en_GB -Hen -men
_add_lang en-US		"English (US)" -hen -Hen -men
_add_lang en-ZA		"English (South Africa)" -hen -vh=en_GB -Hen -men
_add_lang eo		"Esperanto" -h -H -m
_add_lang es		"Spanish" -h -H -m
_add_lang et		"Estonian" -h -H
_add_lang eu		"Basque"
_add_lang fa		"Persian (Farsi)" -h
_add_lang 'fi'		"Finnish"
_add_lang fr		"French" -hfr_FR -H -m
_add_lang fur		"Friulian"
_add_lang fy		"Frisian"
_add_lang ga		"Irish"
_add_lang gd		"Scottish Gaelic" -h
_add_lang gl		"Galician" -h -H -m
_add_lang gu		"Gujarati" -h
_add_lang gug		"Guaraní (Paraguay)" -h -m
_add_lang he		"Hebrew" -h
_add_lang hi		"Hindi" -h
_add_lang hr		"Croatian" -h -H
_add_lang hsb		"Upper Sorbian"
_add_lang hu		"Hungarian" -h -H -m
_add_lang hy		"Armenian"
_add_lang id		"Indonesian" -h -H -m
_add_lang is		"Icelandic" -h -H -m
_add_lang it		"Italian" -hit_IT -Hit_IT -mit_IT
_add_lang ja		"Japanese"
# _add_lang jv		"Bedjond"
_add_lang ka		"Georgian"
_add_lang kab		"Kabyle"
_add_lang kk		"Kazakh"
# _add_lang kl		"Aklanon"
_add_lang km		"Khmer"
_add_lang kmr-Latn	"Kurmanji - Northern Kurdish (Latin)" -hkmr
_add_lang kn		"Kannada" -h -H
_add_lang ko		"Korean" -h
_add_lang kok		"Konkani"
_add_lang ks		"Kashmiri"
# _add_lang ky		"Aka-Kol"
_add_lang lb		"Luxembourgish"
_add_lang lo		"Lao" -h
_add_lang lt		"Lithuanian" -h -H
_add_lang lv		"Latvian" -h -H -m
_add_lang mai		"Maithili"
_add_lang mk		"Macedonian"
_add_lang ml		"Malayalam"
_add_lang mn		"Mongolian" -h -H
_add_lang mni		"Meithei (Manipuri)"
_add_lang mr		"Marathi" -h -H -m
_add_lang my		"Burmese"
_add_lang nb		"Norwegian (Bokmal)" -hno -Hno -mno
_add_lang ne		"Nepali" -h -m
_add_lang nl		"Dutch" -hnl_NL -Hnl_NL
_add_lang nn		"Nynorsk" -hno -Hno -mno
_add_lang nr		"Ndebele (South)"
_add_lang nso		"Northern Sotho"
_add_lang oc		"Occitan" -h
_add_lang om		"Oromo"
_add_lang or		"Oriya" -h -H
_add_lang pa-IN		"Punjabi (India)" -hpa -Hpa
_add_lang pl		"Polish" -h -H -m
_add_lang pt		"Portuguese" -hpt_PT -Hpt_PT -mpt_PT
_add_lang pt-BR		"Portuguese (Brazil)" -h -H -m
_add_lang ro		"Romanian" -hro_RO -H -m
_add_lang ru		"Russian" -hru_RU -H -m
_add_lang rw		"Kinyarwanda"
_add_lang sa-IN		"Sanskrit (India)" -hsa -Hsa
# _add_lang sah		"Yakut"
_add_lang sat		"Santali"
_add_lang sat-Olck	"Santali (Ol Chiki)"
_add_lang sd		"Sindhi"
_add_lang si		"Sinhala" -h
_add_lang sid		"Sidamo"
_add_lang sk		"Slovak" -h -H -m
_add_lang sl		"Slovenian" -h -H -m
_add_lang sq		"Albanian" -h -H
_add_lang sr		"Serbian" -h -H
_add_lang sr-Latn	"Serbian (Latin)" -hsr -Hsr
_add_lang ss		"Swati"
_add_lang st		"Southern Sotho"
_add_lang sv		"Swedish" -h -H -m
_add_lang sw-TZ		"Swahili (Tanzania)"
_add_lang szl		"Silesian"
_add_lang ta		"Tamil" -h
_add_lang te		"Telugu" -h -H
_add_lang tg		"Tajik"
_add_lang th		"Thai" -h -H -m
# _add_lang ti		"Tigrinya/Tigrigna"
_add_lang tl		"Tagalog"
_add_lang tn		"Tswana"
_add_lang tr		"Turkish" -h
_add_lang ts		"Tsonga"
_add_lang tt		"Tatar"
_add_lang ug		"Uyghur"
_add_lang uk		"Ukrainian" -h -H -m
# _add_lang ur		"Urdu"
_add_lang uz		"Uzbek"
_add_lang ve		"Venda"
_add_lang vec		"Venetian"
_add_lang vi		"Vietnamese" -h
_add_lang xh		"Xhosa"
_add_lang zh-CN		"Simplified Chinese (People's Republic of China)"
_add_lang zh-TW		"Traditional Chinese (Taiwan)"
_add_lang zu		"Zulu" -H

post_extract() {
	local pkg f dir fname
	local srcdistdir=${XBPS_SRCDISTDIR}/${pkgname}-${version} pkg
	mkdir -p ${wrksrc}/external/tarballs
	for pkg in ${skip_extraction} libreoffice-{help,translations}-${version}.tar.xz ; do
		case "$pkg" in
		*.dll)
			# The dll needs to be copied instead of symlinked
			cp -v ${srcdistdir}/${pkg} ${wrksrc}/external/tarballs/
			;;
		*)
			# ... the other files can be symlinked
			ln -svf ${srcdistdir}/${pkg} ${wrksrc}/external/tarballs/
			;;
		esac
	done
	for f in ${FILESDIR}/*.patch; do
		fname=${f##*/}
		dir=${fname%%-*}
		if [ -d "${wrksrc}/external/${dir}" ]; then
			cp "$f" "${wrksrc}/external/${dir}/${fname}.1"
		fi
	done
}

post_patch() {
	vsed -i bin/distro-install-desktop-integration \
		-e "/gzip -f/d" \
		-e "s|.1.gz|.1|g"
	chmod +x bin/unpack-sources

	if [ "$XBPS_BUILD_ENVIRONMENT" = void-packages-ci ]; then
		vsed -i "s/bootstrap: check-if-root compilerplugins/bootstrap: compilerplugins/" Makefile.in
	fi
}

do_configure() {
	local opts
	local bopts=--with-lang=en-US

	# the build system tries to call curl or wget, we can catch any invocations here and add them to distfiles
	ln -sf /bin/false ${XBPS_WRAPPERDIR}/curl
	ln -sf /bin/false ${XBPS_WRAPPERDIR}/wget
	ln -sf /bin/false ${XBPS_WRAPPERDIR}/git

	export QT6DIR=/usr/lib/qt6

	# Separate autogen.sh and configure because we need
	# to patch configure for musl support
	NOCONFIGURE=1 ./autogen.sh

	# standard options
	opts="--prefix=/usr"
	opts+=" --sysconfdir=/etc"
	opts+=" --sbindir=/usr/bin"
	opts+=" --bindir=/usr/bin"
	opts+=" --mandir=/usr/share/man"
	opts+=" --infodir=/usr/share/info"
	opts+=" --localstatedir=/var"
	# libreoffice options
	opts+=" --with-vendor='VoidLinux'"
	opts+=" --with-help"
	opts+=" --disable-odk"
	opts+=" --disable-online-update"
	opts+=" --enable-python=system"
	opts+=" --enable-gtk3"
	opts+=" --enable-introspection"
	opts+=" --enable-gtk4"
	# opts+=" --enable-qt5"
	opts+=" --enable-qt6"
	opts+=" --enable-kf6"
	# opts+=" --enable-gtk3-kde5"
	opts+=" --disable-dependency-tracking"
	opts+=" --enable-release-build"
	opts+=" --enable-split-app-modules"
	opts+=" --disable-dconf"
	opts+=" --disable-epm"
	# New strategy: enable all libs and headers, then disable what's missing
	opts+=" --with-system-libs"
	bopts+=" --with-system-libs"
	opts+=" --with-system-headers"
	bopts+=" --with-system-headers"
	case "$XBPS_TARGET_MACHINE" in
	x86_64)	# opts+=" --enable-ext-mariadb-connector"
		# opts+=" --enable-ext-ct2n"
		opts+=" --enable-ext-nlpsolver"
		# opts+=" --enable-ext-languagetool"
		;;
	esac
	opts+=" --without-fonts"
	opts+=" --enable-build-opensymbol"
	# opts+=" --disable-fetch-external"

	# skia sucks
	if [ "$XBPS_TARGET_ENDIAN" = "be" ]; then
		opts+=" --disable-skia"
	fi

	if [ "$build_option_java" ]; then
		opts+=" --with-java"
		opts+=" --with-jdk-home=/usr/lib/jvm/openjdk17"
		# also disables hamcrest
		opts+=" --without-junit"
	else
		opts+=" --without-java"
	fi

	# You can native compile firebird then cross-compile libreoffice.
	if [ "$build_option_firebird" ]; then
		export FIREBIRD_CFLAGS=-I$XBPS_CROSS_BASE/usr/include/firebird
		export FIREBIRD_LIBS=-lfbclient
		opts+=" --enable-firebird-sdbc"
	else
		opts+=" --disable-firebird-sdbc"
	fi

	opts+=" --with-tls=nss"
	opts+=" --with-system-hsqldb"
	opts+=" --with-hsqldb-jar=/usr/share/java/hsqldb-1.8.0.jar"
	# https://github.com/tdf/libcmis/pull/43 changes ABI
	# opts+=" --without-system-libcmis"
	# bopts+=" --without-system-libcmis"
	opts+=" --without-system-libtommath"
	bopts+=" --without-system-libtommath"
	opts+=" --without-system-jfreereport"
	bopts+=" --without-system-jfreereport"
	opts+=" --without-system-dragonbox"
	bopts+=" --without-system-dragonbox"
	opts+=" --without-system-libfixmath"
	bopts+=" --without-system-libfixmath"
	opts+=" --without-system-fast-float"
	bopts+=" --without-system-fast-float"
	opts+=" --without-myspell-dicts"
	opts+=" --without-system-java-websocket"
	bopts+=" --without-system-java-websocket"
	# finish configuring build
	opts+=" --with-external-dict-dir=/usr/share/hunspell"
	opts+=" --with-external-hyph-dir=/usr/share/hyphen"
	opts+=" --with-external-thes-dir=/usr/share/mythes"
	opts+=" --with-parallelism=${XBPS_MAKEJOBS}"

	if [ "$CROSS_BUILD" ]; then
		opts+=" --host=$XBPS_CROSS_TRIPLET"
		opts+=" --with-boost=${XBPS_CROSS_BASE}/usr"
		opts+=" --x-libraries=${XBPS_CROSS_BASE}/usr/lib"
		export QT6INC=$XBPS_CROSS_BASE/usr/include/qt6
		export QT6LIB=$XBPS_CROSS_BASE/usr/lib
		export KF6INC=$XBPS_CROSS_BASE/usr/include
		export KF6LIB=$XBPS_CROSS_BASE/usr/lib
		# CXXFLAGS+=" -I$XBPS_CROSS_BASE/${py3_inc}"
		export PYTHON_CFLAGS="-I${XBPS_CROSS_BASE}/${py3_inc}"
		export PYTHON_LIBS="-L$XBPS_CROSS_BASE/usr/lib -lpython${py3_ver}"
		LDFLAGS_FOR_BUILD="$CFLAGS_FOR_BUILD $LDFLAGS_FOR_BUILD"
	fi

	./configure ${opts} --with-lang="${_languages}" \
		--with-build-platform-configure-options="$bopts"
}

do_build() {
	make ${makejobs} ${make_build_target}
	make ${makejobs} -C libreofficekit
}

do_check() {
	: "need firebird running" \
	LO_JAVA_DIR="${wrksrc}/instdir/program/classes" \
	LD_LIBRARY_PATH=/usr/lib/jvm/openjdk17/lib/server \
	make ${makejobs} check
}

do_install() {
	make DESTDIR="${DESTDIR}/all" PREFIXDIR=/usr distro-pack-install

	# Remove useless directory usr/lib32
	rm -rf ${DESTDIR}/usr/lib32
	grep libreoffice.program.libavmediagtk file-lists/common_list.txt \
		>>file-lists/gnome_list.txt
	vsed -i -e '/libavmediaqt6/d' \
		-e '/libavmediagtk/d' \
		-e '/liblibreofficekitgtk/d' \
		file-lists/common_list.txt
}

libreoffice-common_package() {
	short_desc+=" - Common files"
	depends="libreoffice-i18n-en-US>=${version}_${revision}
	 $(vopt_if java 'rhino hsqldb1.8.0')"
	skiprdeps=/usr/lib/libreoffice/program/libofficebean.so
	replaces="libreoffice-epub>=0"
	pkg_install() {
		_split common
	}
}

libreoffice-base_package() {
	short_desc+=" - Database frontend"
	depends="libreoffice-writer>=${version}_${revision}"
	pkg_install() {
		_split base
	}
}

libreoffice-calc_package() {
	short_desc+=" - Spreadsheet"
	depends="libreoffice-writer>=${version}_${revision}"
	pkg_install() {
		_split calc
	}
}

libreoffice-draw_package() {
	short_desc+=" - Drawing application"
	depends="sane libreoffice-impress>=${version}_${revision}"
	pkg_install() {
		_split draw
	}
}

libreoffice-fonts_package() {
	short_desc+=" - Fonts"
	# libreoffice-fonts used to bundle those fonts
	depends="
	 amiri-font
	 culmus
	 dejavu-fonts-ttf
	 font-adobe-source-code-pro
	 source-sans-pro
	 font-adobe-source-serif-pro
	 font-alef
	 font-crosextra-caladea-ttf
	 font-crosextra-carlito-ttf
	 font-emoji-one-color
	 font-kacst
	 font-liberation-narrow-ttf
	 liberation-fonts-ttf
	 font-libertine-graphite-ttf
	 font-reem-kufi-ttf
	 font-sil-gentium-basic
	 font-sil-scheherazade
	 noto-fonts-ttf
	 noto-fonts-ttf-extra
	"
	metapackage=yes
	pkg_install() {
		vmkdir usr/lib/libreoffice/share
		mv ${DESTDIR}/all/usr/lib/libreoffice/share/fonts \
			${PKGDESTDIR}/usr/lib/libreoffice/share/
	}
}

libreoffice-gnome_package() {
	short_desc+=" - GNOME integration"
	pkg_install() {
		_split gnome
	}
}

libreoffice-impress_package() {
	short_desc+=" - Presentation application"
	depends="libreoffice-writer>=${version}_${revision}"
	pkg_install() {
		_split impress
	}
}

libreoffice-qt6_package() {
	short_desc+=" - Qt6 integration"
	pkg_install() {
		cat > ${wrksrc}/file-lists/qt6_list.txt <<-EOF
		%dir /usr/lib/libreoffice/program
		/usr/lib/libreoffice/program/libvclplug_qt6lo.so
		/usr/lib/libreoffice/program/libavmediaqt6.so
		EOF
		_split qt6
	}
}

libreoffice-kde_package() {
	short_desc+=" - KDE integration"
	depends="libreoffice-qt6>=${version}_${revision}"
	pkg_install() {
		cat > ${wrksrc}/file-lists/kde_list.txt <<-EOF
		%dir /usr/lib/libreoffice/program
		%dir /usr/share/metainfo
		/usr/lib/libreoffice/program/libvclplug_kf6lo.so
		/usr/share/metainfo/org.libreoffice.kde.metainfo.xml
		EOF
		_split kde
	}
}

libreoffice-libgtk_package() {
	short_desc="GTK+3 widget wrapping LibreOffice functionality"
	pkg_install() {
		local _gir_wrkdir
		cat > ${wrksrc}/file-lists/libgtk_list.txt <<-EOF
		%dir /usr/lib/libreoffice/program
		/usr/lib/libreoffice/program/liblibreofficekitgtk.so
		EOF
		_split libgtk
		ln -sf libreoffice/program/liblibreofficekitgtk.so \
			"${PKGDESTDIR}/usr/lib/liblibreofficekitgtk.so"
		vmkdir usr/share/gir-1.0
		vmkdir usr/lib/girepository-1.0
		_gir_wrkdir=workdir/CustomTarget/sysui/share/libreoffice
		vinstall "${_gir_wrkdir}/LOKDocView-0.1.typelib" 644 \
			usr/lib/girepository-1.0
		vinstall "${_gir_wrkdir}/LOKDocView-0.1.gir" 644 \
			usr/share/gir-1.0
	}
}

libreoffice-kit_package() {
	short_desc+=" - development files"
	pkg_install() {
		vmkdir usr/include
		vcopy ${wrksrc}/include/LibreOfficeKit usr/include
	}
}

libreoffice-math_package() {
	short_desc+=" - Equation editor"
	depends="libreoffice-writer>=${version}_${revision}"
	pkg_install() {
		_split math
	}
}

libreoffice-postgresql_package() {
	short_desc+=" - Connector for PostgreSQL"
	depends="libreoffice-base>=${version}_${revision}"
	pkg_install() {
		_split postgresql
	}
}

libreoffice-writer_package() {
	short_desc+=" - Word processor"
	pkg_install() {
		_split writer
	}
}

# Use a name which makes this catch-all subpackage the last one
libreoffice-xtensions_package() {
	short_desc+=" - Extensions"
	depends="libreoffice-common>=${version}_${revision}
	 $(vopt_if java beanshell)"
	pkg_install() {
		# Remove empty files
		find ${DESTDIR}/all -size 0 -delete
		# Remove useless files
		for f in segments.gen segments_3 _0.cfs help.tree help.key_ help.db_; do
			find ${DESTDIR}/all -name "${f}" -delete
		done
		# Move the remaining files to this subpackage
		vmkdir usr
		mv -v ${DESTDIR}/all/usr/* ${PKGDESTDIR}/usr/
		rm -rvf ${DESTDIR}/all
	}
}
