#! /usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

get-orig-source:
	set -ex; tempdir=$$(mktemp -d); \
	udate=$$(curl -s -I https://foldoc.org/Dictionary| \
	sed -n 's/^[Ll]ast-[Mm]odified: //p'); \
	uver=$$(date -u -d "$$udate" +"%Y%m%d"); \
	fdir="$$tempdir/dict-foldoc-$$uver"; \
	mkdir "$$fdir"; \
	curl -s -f -o $$fdir/Dictionary https://foldoc.org/Dictionary; \
	tar czf dict-foldoc-$$uver.tar.gz -C $$tempdir .; \
	rm -rf $$tempdir

%:
	dh $@

override_dh_auto_build:
	dh_testdir

	cat Dictionary debian/Dictionary.debian > newdict
	set -ex ; \
	uver=$(DEB_VERSION_UPSTREAM) ; \
	udate=$$(LC_ALL=C date -d "$$uver" +"%d %B %Y"); \
	perl debian/condense newdict | \
	  /usr/bin/dictfmt -f --headword-separator %%% --break-headwords \
	  --allchars -u http://foldoc.org/Dictionary.gz \
	  -s "The Free On-line Dictionary of Computing ($$udate)" \
	  --utf8 --without-time foldoc
	# Ensure deterministic mtime for dictzip to inherit
	touch --date='@$(SOURCE_DATE_EPOCH)' foldoc.dict
	/usr/bin/dictzip -v foldoc.dict