#!/usr/bin/make -f
# coding: koi8-r
# [debian/rules] for rus-ispell
#
# COPYRIGHT C 2005-2011 Martin-Eric Racine <martin-eric.racine@iki.fi>
#
# LICENSE
# This package is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License or (at
# your option) any later version.
#

%:
	dh $@

ILANGUAGE=russian
LANG_COUNTRY=ru_RU
DICT_LANG=ru
DICTIONARIES=base.koi abbrev.koi computer.koi for_name.koi geography.koi science.koi

# Explicitely declare the encoding to ensure that 'grep' and 'tr' work as expected.
LANG=C
LC_ALL=C
export LANG LC_ALL

override_dh_auto_build:
	# Generate ispell dictionary.
	grep -h '[£³]' $(DICTIONARIES) | tr '\243\263' '\305\345' > yo_subst.koi
	cat $(DICTIONARIES) yo_subst.koi |./sortkoi8 | uniq > $(ILANGUAGE).dict
	sed -e "s/^\#[ye]//;s/^\#koi/wordchars/" $(ILANGUAGE).aff.koi > $(ILANGUAGE).aff
	# Generate traditional ispell hash needed by i2myspell.
	buildhash $(ILANGUAGE).dict $(ILANGUAGE).aff $(ILANGUAGE).hash 
	# Generate gzipped munched wordlist for ispell 3.3 dictionary.
	gzip -c --best $(ILANGUAGE).dict > $(ILANGUAGE).mwl.gz
	# Generate myspell dictionary (KOI8-R).
	i2myspell -d ./$(ILANGUAGE).dict > $(LANG_COUNTRY).dic
	i2myspell ./$(ILANGUAGE) KOI8-R áâ÷çäå³öúéêëìíîïðòóôõæèãþûýÿùøüàñ \
	                              ÁÂ×ÇÄÅ£ÖÚÉÊËÌÍÎÏÐÒÓÔÕÆÈÃÞÛÝßÙØÜÀÑ | \
	                              sed 's/ - / 0 /' > $(LANG_COUNTRY).aff
	# Generate aspell dictionary; build-depends on aspell because of prezip.
	cp $(LANG_COUNTRY).aff $(DICT_LANG)_affix.dat
	cat $(LANG_COUNTRY).dic | sed 1d | LC_COLLATE=C sort -u | prezip > $(DICT_LANG).cwl
	gzip $(DICT_LANG).cwl
	echo "add $(DICT_LANG).rws" > $(DICT_LANG).multi
	echo "add $(DICT_LANG).multi" > $(ILANGUAGE).alias

# Make sure dh_clean does not remove this upstream file
override_dh_clean:
	dh_clean -Xold/README.orig

override_dh_auto_clean:
	# Clean ispell files.
	rm -f *.cnt *.hash *.stat yo_subst.koi *.utf8
	# Also delete aff and dict, since we build them here.
	rm -f $(ILANGUAGE).aff $(ILANGUAGE).dict $(ILANGUAGE).mwl.gz
	# Clean myspell files.
	rm -f $(LANG_COUNTRY).aff $(LANG_COUNTRY).dic x
	# Clean aspell files.
	rm -f *.alias *_affix.dat *.multi *.*wl*

override_dh_auto_install:
	installdeb-ispell --package=i$(ILANGUAGE)
	installdeb-hunspell --package=myspell-$(DICT_LANG)
	installdeb-myspell --package=myspell-$(DICT_LANG)
	installdeb-aspell --package=aspell-$(DICT_LANG)
#EOF
