#!/usr/bin/make -f

%:
	dh $@ --with autoreconf

override_dh_auto_configure:
	dh_auto_configure -- --with-tclconfig=/usr/lib/tcl8.5 --with-tkconfig=/usr/lib/tk8.5

override_dh_auto_clean:
	dh_auto_clean
	if [ -d contrib/wordnet_structures -a -e contrib/wordnet_structures/Makefile ] ; then cd contrib/wordnet_structures; make clean; fi
	rm -rf autom4te.cache
	rm -rf src/grind/grind-wnparse.[ch] src/grind/grind-wnlex.c
	# Make sure that really all Makefiles in doc are deleted
	rm -f `find doc -name Makefile`
	rm -f goldendict-wordnet.dsl goldendict-wordnet.dsl.dz
	rm -f goldendict-wordnet_abrv.dsl goldendict-wordnet.bmp

override_dh_auto_install-indep: goldendict-wordnet.dsl.dz goldendict-wordnet_abrv.dsl
	dh_auto_install

override_dh_install-arch:
	dh_install
	find debian -name "*.la" -delete

goldendict-wordnet_abrv.dsl: debian/goldendict-wordnet_abrv.dsl
	perl -e 'print "\xff\xfe"' > $@
	iconv -t utf-16le $< >> $@

goldendict-wordnet.dsl.dz: goldendict-wordnet.dsl
	dictzip -k $<

goldendict-wordnet.dsl:
	set -e; \
	if dpkg-architecture -qDEB_BUILD_ARCH|grep -q 'mips\|arm\|s390'; then \
		if test "$$FORCE_GOLDENDICT_BUILD" -gt 0; then \
			ruby debian/wn-for-goldendict.rb > $@ || ($(RM) $@; false); \
		else \
			echo "Building of goldendict-wordnet dictionary was skipped"; \
			echo "to build this package use environment variable"; \
			echo "FORCE_GOLDENDICT_BUILD=1" ; \
			touch $@; \
		fi; \
	else \
		ruby debian/wn-for-goldendict.rb > $@ || ($(RM) $@; false); \
	fi

