#!/usr/bin/make -f
%:
	dh $@

P=ttf-ancient-fonts
V=2.58
U=http://users.teilar.gr/~g1951d/
Z=Aegean.zip \
  Textfonts.zip \
  Symbola.zip \
  Aegyptus.zip \
  Akkadian.zip \
  Anatolian.zip \
  Maya.zip \
  Unidings.zip \
  Musica.zip \
  Analecta.zip \

override_dh_install:
	dh_install -pfonts-ancient-scripts -XSymbola
	dh_install --remaining-packages

get-orig-source:
	for f in $(Z) ; do \
		wget -O $$f $(U)$$f ; \
		# Some files are duplicated so we need -o \
		unzip -o -d $(P)-$(V).orig $$f ; \
		rm -f $$f ; \
	done
	# We prefer UTF-8 LF text files, convert them using iconv, tr
	find $(P)-$(V).orig -iname '*.txt' -print0 | xargs -0 -I_ sh -c "iconv -f UTF-16 -t UTF-8 _ | tr -d '\r' > _.tmp && mv _.tmp _"
	# PDFs are produced using Microsoft Word and no
	# Word files (source code) are published for them
	# so we have to remove them as per DFSG item 2.
	rm -f $(P)-$(V).orig/*.pdf
	tar zcf $(P)_$(V).orig.tar.gz $(P)-$(V).orig
	rm -rf $(P)-$(V).orig
