#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/autotools.mk
include /usr/share/cdbs/1/rules/patchsys-quilt.mk

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

pkg=wordnet
pkg-dev=$(pkg)-dev
pkg-sense=$(pkg)-sense-index

# DEB_INSTALL_DOCS_$(pkg) := --no-act
DEB_INSTALL_DOCS_$(pkg-dev) := --no-act
# DEB_INSTALL_DOCS_$(pkg-sense) := --no-act

## Work with the patch for DEFAULTPATH
## DEB_MAKE_ENVVARS := DEFAULTPATH="/usr/share/wordnet"
## DEB_MAKEMAKER_USER_FLAGS := -DDEFAULTPATH="/usr/share/wordnet"

#DEB_INSTALL_CHANGELOGS_$(pkg) := --no-act
#DEB_INSTALL_CHANGELOGS_$(pkg-dev) := --no-act
#DEB_INSTALL_CHANGELOGS_$(pkg-sense) := --no-act

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

build/goldendict-wordnet:: goldendict-wordnet.dsl.dz goldendict-wordnet_abrv.dsl
	convert debian/goldendict-wordnet.xpm goldendict-wordnet.bmp

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 > $@; \
		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 > $@; \
	fi
