# Contributor: Leo <thinkabit.ukim@gmail.com>
# Maintainer: Will Sinatra <wpsinatra@gmail.com>
pkgname=words
pkgver=2.1
pkgrel=2
pkgdesc="Collection of international 'words' file for /usr/share/dict"
url="https://ftp.gnu.org/gnu/aspell/dict/0index.html"
arch="noarch"
license="GPL-2.0-or-later"
makedepends="aspell-utils"
subpackages="
	words-en
	words-gb
	words-it
	words-es
	words-fi:fir
	words-fr
	words-de
	"
source="https://ftp.gnu.org/gnu/aspell/dict/en/aspell6-en-2017.08.24-0.tar.bz2
	https://ftp.gnu.org/gnu/aspell/dict/fi/aspell6-fi-0.7-0.tar.bz2
	https://ftp.gnu.org/gnu/aspell/dict/fr/aspell-fr-0.50-3.tar.bz2
	https://ftp.gnu.org/gnu/aspell/dict/de-alt/aspell6-de-alt-2.1-1.tar.bz2
	https://ftp.gnu.org/gnu/aspell/dict/it/aspell6-it-2.2_20050523-0.tar.bz2
	https://ftp.gnu.org/gnu/aspell/dict/de/aspell-de-0.50-2.tar.bz2
	https://ftp.gnu.org/gnu/aspell/dict/es/aspell6-es-1.11-2.tar.bz2
	"
builddir="$srcdir"

for _pkg in $subpackages; do
	depends="$depends ${_pkg%%:*}"
done

build() {
	preunzip ./*/*.cwl
	for wl in ./*/*.wl; do
		iconv -f ISO-8859-1 -t UTF-8 $wl | \
		cut -d '/' -f 1 | LC_ALL=C sort -df > ./${wl##*/}.utf8
	done
	rm ./*/*.wl

	# locale specific sort for other languages?
	# sort specified from FS#47262
	cat en-common.wl.utf8 en_US* | sort -u | LC_ALL=C sort -df > us-merged
	cat en-common.wl.utf8 en_GB* | sort -u | LC_ALL=C sort -df > gb-merged
	cat de-only.wl.utf8   de_*   | sort -u | LC_ALL=C sort -df > de-merged
}

package() {
	install -Dm644 us-merged "$pkgdir/usr/share/dict/american-english"
	install -Dm644 gb-merged "$pkgdir/usr/share/dict/british-english"
	ln -s american-english   "$pkgdir/usr/share/dict/usa"
	ln -s british-english    "$pkgdir/usr/share/dict/british"

	install -Dm644 de-merged       "$pkgdir/usr/share/dict/ngerman"
	install -Dm644 de-alt.wl.utf8  "$pkgdir/usr/share/dict/ogerman"
	ln -s ngerman "$pkgdir/usr/share/dict/german"

	install -Dm644 fr-40-only.wl.utf8 "$pkgdir/usr/share/dict/french"

	install -Dm644 es.wl.utf8 "$pkgdir/usr/share/dict/spanish"
	install -Dm644 fi.wl.utf8 "$pkgdir/usr/share/dict/finnish"
	install -Dm644 it.wl.utf8 "$pkgdir/usr/share/dict/italian"
}

en() {
	depends=""
	pkgdesc="American English dictionary in /usr/share/dict"

	amove usr/share/dict/usa
	amove usr/share/dict/american-english
}

gb() {
	depends=""
	pkgdesc="British English dictionary in /usr/share/dict"

	amove usr/share/dict/british
	amove usr/share/dict/british-english
}

it() {
	depends=""
	pkgdesc="Italian dictionary in /usr/share/dict"

	amove usr/share/dict/italian
}

es() {
	depends=""
	pkgdesc="Spanish dictionary in /usr/share/dict"

	amove usr/share/dict/spanish
}

fir() {
	depends=""
	pkgdesc="Finnish dictionary in /usr/share/dict"

	amove usr/share/dict/finnish
}

fr() {
	depends=""
	pkgdesc="French dictionary in /usr/share/dict"

	amove usr/share/dict/french
}

de() {
	depends=""
	pkgdesc="German dictionary in /usr/share/dict"

	amove usr/share/dict/german
	amove usr/share/dict/ngerman
	amove usr/share/dict/ogerman
}

sha512sums="2530f6bff61456ccf4e0e8383ab8583a1421b6001f156b4419385a272a54217b01e93d7aed8acff15f1e49afbb13bb81fd66002662ce7233c465ec0737fdfedc  aspell6-en-2017.08.24-0.tar.bz2
d1f27bc8e36033cba6ddaa978f2facfe8d134ab70124ec80d5397dba2b533b512755312feaf2afa838f68e4449479953a8b951264fbbfc28cdfd9457f67f67f7  aspell6-fi-0.7-0.tar.bz2
bb5d1faada9283521096a19a8f5abada2a19cc02717f6dde57846ef46a4df253113b10a2bb72d2b0e32e4a3ab24b541a5acd9f4595b908d2f6cd2fc448d8bc3b  aspell-fr-0.50-3.tar.bz2
823324bc299e9adbbe5308681a5f74ee2a76a32816e8abc9d19c3da0c4eae756eaf1a3c76e2d75449b51010854ab869379073b1fe377e505662187d6c38230b4  aspell6-de-alt-2.1-1.tar.bz2
2a2ccdbb8bb52e8e08525a40f985c1a2987c00d5e9fd39f57b8dc8689f3503f63751efe9ae4bec45fc5efea64666cd64abbda3e437ad0819f15b5a96987cda5a  aspell6-it-2.2_20050523-0.tar.bz2
79b0c9776c4a9b8bb0c5b3902bd1aa5daf6262b2a02753165d2fdb056b9bb0efcf5c4290d85bf98103cca29cf7aa81f99f725ea0faf5ab98b36ce080bdf8afbc  aspell-de-0.50-2.tar.bz2
5d0159f24d6bff43db682a4beb25e82dd362c205acf7c9e0d728808c0e54a8a566befe26316f384099c72e6c429713f8ad7d2dc66a8f04a15e1d5a9cfe2290d8  aspell6-es-1.11-2.tar.bz2"
