#!/usr/bin/make -f
# Sample debian/rules that uses debhelper.
# GNU copyright 1997 to 1999 by Joey Hess.

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

# This is the debhelper compatability version to use.

package         = iesperanto
apackage        = aspell-eo

ISPELLDIR       = $(CURDIR)/debian/${package}/usr/lib/ispell
ISPELLVARDIR    = $(CURDIR)/debian/${package}/var/lib/ispell
ISPELLSHAREDIR  = $(CURDIR)/debian/${package}/usr/share/ispell
ISPELLOVRDIR    = $(CURDIR)/debian/${package}/usr/share/lintian/overrides

ASPELLDATADIR   = $(CURDIR)/debian/${apackage}/usr/lib/aspell
ASPELLSHAREDIR  = $(CURDIR)/debian/${apackage}/usr/share/aspell
ASPELLOVRDIR    = $(CURDIR)/debian/${apackage}/usr/share/lintian/overrides
ASPELLVARDIR    = $(CURDIR)/debian/${apackage}/var/lib/aspell
ASPELL6BASENAME = aspell6-eo
ASPELL6DIR      = $(CURDIR)/debian/$(ASPELL6BASENAME)
ASPELLPROC      = /usr/share/aspell-lang/proc    # Location of proc script
ASPELLDATA      = eo.dat eo.multi

OOOTMP          = ooo-tmp

MUNCHED_WORDS   = kerno.txt \
komputo.txt \
etnoland.txt \
kancero.txt \
movado.txt \
personoj.txt

include /usr/share/quilt/quilt.make

configure: configure-stamp
configure-stamp:
	dh_testdir
	# Add here commands to configure the package.

	touch $@

build: build-arch build-indep
build-arch: build-stamp
build-indep: build-stamp
build-stamp: patch configure-stamp
	dh_testdir

	cat $(MUNCHED_WORDS) | sort -uf > kune.txt
	sed -f debian/cx2latin3.sed kune.txt > kune.txt.latin3
	sed -f debian/cx2latin3.sed eo.aff > eo.aff.latin3
#	buildhash kune.txt eo.aff eo.hash

# ----  Creating myspell dict
	cp README debian/README.ispell
	cp legumin.l3 debian/legumin.l3.ispell
	( echo `cat  kune.txt.latin3 | wc -l`; cat kune.txt.latin3 ) > eo.dic
	ispellaff2myspell --charset=latin3 --myheader=debian/eo_ALL.header eo.aff.latin3 > eo.aff.myspell

	touch $@

aspelltgz: clean build
	mkdir -p $(ASPELL6DIR)
	install -m 644 debian/aspell/Copyright $(ASPELL6DIR)
	install -m 644 debian/aspell/info $(ASPELL6DIR)
	install -m 644 debian/aspell/eo.dat $(ASPELL6DIR)
	install -m 644 debian/README.ispell debian/legumin.l3.ispell $(ASPELL6DIR)
	install -m 644 debian/README.aspell $(ASPELL6DIR)/README
	install -m 644 eo.aff.myspell $(ASPELL6DIR)/eo_affix.dat
	cat eo.dic | sed 1d | LC_COLLATE=C sort -u | \
		aspell --local-data-dir=$(ASPELL6DIR) --lang=eo  clean > $(ASPELL6DIR)/eo.wl
	( cd $(ASPELL6DIR) && \
		ln -sf $(ASPELLPROC) proc && \
		perl proc && \
		./configure && \
		make dist )
	mv $(ASPELL6DIR)/$(ASPELL6BASENAME)*.tar.bz2 ..

clean: clean-patched unpatch
clean-patched:
	dh_testdir
	dh_testroot
	rm -f build-stamp configure-stamp

	# Add here commands to clean up after the build process.

	rm -f eo.hash kune.txt kune.txt.cnt kune.txt.stat
	rm -f eo.aff.latin3 kune.txt.latin3 eo.aff.myspell eo.dic
	rm -f debian/legumin.l3.ispell debian/README.ispell
	rm -rf $(OOOTMP)

	if [ -d $(ASPELL6DIR) ]; then \
		rm $(ASPELL6DIR)/* && rmdir $(ASPELL6DIR); fi

	dh_clean

install: build
	dh_testdir
	dh_testroot
	dh_prep
	dh_installdirs

	# Add here commands to install the package into debian/${package}.

	mkdir -p $(ISPELLDIR) $(ISPELLSHAREDIR) $(ISPELLVARDIR) $(OOOTMP)

#	install -m 644 eo.hash $(ISPELLDIR)/esperanto.hash
	install -m 644 kune.txt $(ISPELLSHAREDIR)/esperanto.mwl
	( cd $(ISPELLSHAREDIR) && gzip -9 esperanto.mwl )
	install -m 644 eo.aff $(ISPELLDIR)/esperanto.aff
	installdeb-ispell -piesperanto
# ------------- myspell/hunspell
	cp eo.aff.myspell $(OOOTMP)/eo.aff
	cp eo.dic $(OOOTMP)
	installdeb-myspell --srcdir=$(OOOTMP) -pmyspell-eo --dico-no-alt-links
	installdeb-hunspell -pmyspell-eo
# ------------- aspell
	mkdir -p $(ASPELLDATADIR) $(ASPELLSHAREDIR) $(ASPELLVARDIR)
	( cd debian/aspell && install -m 644 $(ASPELLDATA) $(ASPELLDATADIR))
	install -m 644 eo.aff.myspell $(ASPELLDATADIR)/eo_affix.dat
	cat eo.dic | sed 1d | prezip -s | gzip -9 -c > $(ASPELLSHAREDIR)/eo.cwl.gz
	installdeb-aspell -p$(apackage)

# Build architecture-independent files here.
binary-indep: build install
	dh_testdir
	dh_testroot
	dh_installdocs
	dh_installexamples
	dh_installmenu
#	dh_installman
#	dh_undocumented
	dh_installchangelogs
	dh_link
	dh_strip
	dh_compress
	dh_fixperms
#	dh_makeshlibs
	dh_installdeb
#	dh_perl
	dh_shlibdeps
	dh_gencontrol
	dh_md5sums
	dh_builddeb

# Build architecture-dependent files here.
binary-arch: build install

binary: binary-indep binary-arch
.PHONY: build clean clean-patched binary-indep binary-arch binary install patch unpatch configure

