#!/usr/bin/make -f


PATCHFILE=`ls *diff `

BUILT_USING := $(shell dpkg-query -f '$${source:Package} (= $${source:Version}), ' -W sqwebmail )

ROOT=debian/sqwebmail-de
PATCHROOT=htmltree/en-us

%:
	dh $@

override_dh_auto_build:
	mkdir htmltree
	cp -a /usr/lib/courier/sqwebmail/html/en-us/ htmltree
	rm $(PATCHROOT)/ISPELLDICT
	echo -n default > $(PATCHROOT)/ISPELLDICT
	# patch files - except TIMEZONELIST
	filterdiff -x */TIMEZONELIST < $(PATCHFILE) | (cd $(PATCHROOT); patch -p1 )
	# add Europe/Berlin    Germany as top entry (replacing the * * entry)
	sed -i -e 's/^\*.*\*/Europe\/Berlin			Germany/' $(PATCHROOT)/TIMEZONELIST
	# check whether TIMEZONELIST has been properly altered -
	# there should now be two entries for Europe/Berlin
	# otherwise fail
	[ "$$(grep Europe/Berlin $(PATCHROOT)/TIMEZONELIST | wc -l)" = "2" ]

override_dh_clean:
	#Remove the patched html tree
	-rm -fr htmltree
	dh_clean

override_dh_auto_install:
	mkdir -p $(ROOT)/usr/lib/courier/sqwebmail/html/de-de
	cp -a htmltree/en-us/* $(ROOT)/usr/lib/courier/sqwebmail/html/de-de

override_dh_gencontrol:
	dh_gencontrol -- -VBuilt-Using="$(BUILT_USING)"
