#!/usr/bin/make -f

override_dh_installchangelogs:
	dh_installchangelogs doc/ChangeLog

override_dh_installdocs:
	dh_installdocs -A doc/SCOWL-README

override_dh_md5sums:
	dh_md5sums -Xvar/lib/aspell

DICT_LANG := en
DEB_DESTDIR := debian/aspell-$(DICT_LANG)

override_dh_auto_configure:
	mv en-common.cwl en-common.cwl.orig
	(prezip-bin -d < en-common.cwl.orig ; cat debian/extrawords.txt) | LC_ALL=C sort -u | prezip-bin -z > en-common.cwl

%.gz: %
	gzip -9 -n < "$<" > "$@"

override_dh_auto_build:

override_dh_auto_install: $(patsubst %,%.gz,$(wildcard *.cwl))
	mv *.cwl.gz $(DEB_DESTDIR)/usr/share/aspell
	for f in *.cwl; do \
	    WL=$${f%.cwl}; \
	    > "$(DEB_DESTDIR)/var/lib/aspell/$$WL.rws"; \
	    dh_link "var/lib/aspell/$$WL.rws" "usr/lib/aspell/$$WL.rws"; \
	    echo "$$WL" >> "$(DEB_DESTDIR)/usr/share/aspell/$(DICT_LANG).contents"; \
	done

	> $(DEB_DESTDIR)/var/lib/aspell/$(DICT_LANG).compat

	installdeb-aspell

execute_before_dh_clean:
	mv en-common.cwl.orig en-common.cwl || :

%:
	dh $@
