#! /usr/bin/make -f
# Stolen from the manpages Debian package and heavily hacked to accomodate
# manpages-de's needs by Daniel Kobras <kobras@debian.org>.

#export DH_VERBOSE=1

MIRRORURL:=http://ftp.de.debian.org/debian
CONTENTS_ARCHLIST:=amd64 i386
CONTENTS=$(foreach arch,$(CONTENTS_ARCHLIST),/tmp/manpages-de.build/Contents-$(arch).gz)

HTTP_GET=$(shell which curl)
ifeq (,$(HTTP_GET))
HTTP_GET=$(shell which wget)
endif
ifeq (,$(HTTP_GET))
HTTP_GET=$(shell which GET)
endif

#
# Convenience rules. Never used in an automated build. Call by hand before
# building a new release.
#

/tmp/manpages-de.build/Contents-%:
ifeq (,$(HTTP_GET))
	@echo "Cannot retrieve Contents files without curl, wget, or GET"; \
	     exit 1
else
	@echo "Retrieving up-to-date $(CONTENTS)"
	test -d /tmp/manpages-de.build || mkdir /tmp/manpages-de.build
	cd /tmp/manpages-de.build; \
		$(HTTP_GET) "$(MIRRORURL)/dists/unstable/`basename $@`"
endif

debian/manpages-de.prune: debian/manpages-de.prune.in $(CONTENTS)
	cp debian/manpages-de.prune.in debian/manpages-de.prune
	zgrep -vhE '[^,]doc/manpages-de(-dev)?$$' \
	           /tmp/manpages-de.build/Contents-*.gz | \
		grep -E '/man/de(\.[^/]+)?/' | while read file rest; do \
			echo "$${file%.gz}"; \
		done | sort -u >> debian/manpages-de.prune

update-prune: debian/manpages-de.prune

#
# Standard rules to follow
#

%:
	dh $@

override_dh_auto_build:
	# Add warning about outdated manpages
	python debian/add-outdated-warning.py

override_dh_installman:
	dh_installman --language=de --package=manpages-de `find man[145678] -maxdepth 1 -type f`
	dh_installman --language=de --package=manpages-de-dev `find man[23] -maxdepth 1 -type f`
	# Remove manpages from debian/manpages-de.prune
	python debian/prune-manpages.py
