# Template file for 'hunspell-fr_FR'
pkgname=hunspell-fr_FR
version=7.0
revision=7
build_wrksrc="dictionaries"
short_desc="French dictionary for hunspell"
maintainer="Leah Neukirchen <leah@vuxu.org>"
license="MPL-1.1"
homepage="https://grammalecte.net/"
distfiles="https://grammalecte.net/oxt/lo-oo-ressources-linguistiques-fr-v${version}.oxt>linguistiques-fr-v${version}.zip"
checksum=e8a352abd550bfd773b09d6631e96af3dbcfefecc9b50d3b7bb6094e429cc64b
provides="hunspell-fr-libreoffice-24.2.2.2_2"
replaces="hunspell-fr-libreoffice>=0"

build_options="bdic"
desc_option_bdic="Enable Chromium's bdic format"

if [ "$XBPS_WORDSIZE" = 64 ]; then
	hostmakedepends=" qt6-webengine"
	build_options_default="bdic"
else
	case "$XBPS_MACHINE" in
	i686*)
		hostmakedepends=" qt5-webengine"
		build_options_default="bdic"
		;;
	esac
fi

if [ "$build_option_bdic" ]; then
	depends="hunspell-qtwebengine-dict"
fi

_vinstall_variant() {
	local _variant="$1" l
	local _all_locales="fr_FR fr_BE fr_CA fr_CH fr_LU fr_MC"
	vinstall fr-${_variant}.aff 644 usr/share/hunspell fr.aff
	vinstall fr-${_variant}.dic 644 usr/share/hunspell fr.dic
	for l in $_all_locales
	do
		ln -s fr.aff "${PKGDESTDIR}/usr/share/hunspell/${l}.aff"
		ln -s fr.dic "${PKGDESTDIR}/usr/share/hunspell/${l}.dic"
	done
	if [ "$build_option_bdic" ]; then
		vinstall fr-${_variant}.bdic 644 usr/share/hunspell-bdic fr.bdic
		for l in $_all_locales
		do
			ln -s fr.bdic \
				"${PKGDESTDIR}/usr/share/hunspell-bdic/${l}.bdic"
		done
	fi
}

do_build() {
	local variant
	PATH="/usr/lib/qt6/libexec:/usr/lib/qt5/bin:$PATH"
	if [ "$build_option_bdic" ]; then
		for variant in classique reforme1990 toutesvariantes; do
			qwebengine_convert_dict fr-${variant}.dic \
				fr-${variant}.bdic
		done
	fi
}

do_install() {
	_vinstall_variant classique
	vdoc README_dict_fr.txt
	vdoc $FILESDIR/README.voidlinux
}

hunspell-fr_FR-reforme1990_package() {
	short_desc+=" - Reforme 1990 Variant"
	if [ "$build_option_bdic" ]; then
		depends="hunspell-qtwebengine-dict"
	fi
	provides="${sourcepkg}-${version}_${revision}"
	replaces="${sourcepkg}>=0"
	pkg_install() {
		_vinstall_variant reforme1990
		vdoc README_dict_fr.txt
	}
}

hunspell-fr_FR-toutesvariantes_package() {
	short_desc+=" - All variant in one file"
	if [ "$build_option_bdic" ]; then
		depends="hunspell-qtwebengine-dict"
	fi
	provides="${sourcepkg}-${version}_${revision}"
	replaces="${sourcepkg}>=0"
	pkg_install() {
		_vinstall_variant toutesvariantes
		vdoc README_dict_fr.txt
	}
}
