#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# This has to be exported to make some magic below work.
export DH_OPTIONS

LC_ALL = C
LOCALE_PATH = $(CURDIR)/debian/locale
export LC_ALL LOCALE_PATH

locale: locale-stamp
locale-stamp:
	mkdir $(LOCALE_PATH)
	localedef -i uk_UA -f KOI8-U $(LOCALE_PATH)/uk_UA
	localedef -i uk_UA -f UTF-8 $(LOCALE_PATH)/uk_UA.UTF-8
	touch locale-stamp
	
build: build-arch build-indep

build-arch: build-arch-stamp
build-arch-stamp: locale
	LC_ALL=C.UTF-8 LOCPATH=$(LOCALE_PATH) $(MAKE) ispell
	touch build-arch-stamp

build-indep: build-indep-stamp
build-indep-stamp: locale
	LOCPATH=$(LOCALE_PATH) $(MAKE) ASPELL_ENC=utf-8 ASPELL_ENC_NAME=utf-8 myspell aspell uk.cwl.gz ukrainian
	touch build-indep-stamp

clean:
	dh clean
	rm -rf debian/locale

install: install-indep install-arch
install-indep: build-indep
	dh_testdir
	dh_testroot
	dh_prep -i 
	dh_installdirs -i
	cp dist/myspell-uk-*/uk_UA.aff debian/myspell-uk/usr/share/hunspell
	cp dist/myspell-uk-*/uk_UA.dic debian/myspell-uk/usr/share/hunspell
	LOCPATH=$(LOCALE_PATH) LC_ALL=uk_UA.UTF-8 sort -d ukrainian | uniq > debian/wukrainian/usr/share/dict/ukrainian
	cp uk.cwl.gz debian/aspell-uk/usr/share/aspell
	dh_install --sourcedir=dist/aspell-uk-* -paspell-uk

install-arch: build-arch
	dh_testdir
	dh_testroot
	dh_prep -s 
	dh_installdirs -s
	dh_install --sourcedir=dist/ispell-uk-* -piukrainian

binary-arch: install-arch
	dh_testdir
	dh_testroot
	dh_installchangelogs -a
	dh_installdocs -a
	installdeb-ispell -p iukrainian
	dh_link -a
	dh_compress -a
	dh_fixperms -a
	dh_installdeb -a
	dh_gencontrol -a
	dh_md5sums -a
	dh_builddeb -a

binary-indep: install-indep
	dh_testdir
	dh_testroot
	dh_installchangelogs -i
	dh_installdocs -i
	installdeb-myspell -p myspell-uk
	installdeb-wordlist -p wukrainian
	installdeb-aspell -p aspell-uk
	dh_link -i
	dh_compress -i
	dh_fixperms -i
	dh_installdeb -i
	dh_gencontrol -i
	dh_md5sums -i
	dh_builddeb -i

binary: binary-arch binary-indep
.PHONY: build build-arch build-indep clean binary-indep binary-arch binary install install-indep install-arch locale
