#! /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_installman:
	dh_installman
	# Remove too outdated manpages
	rm -f debian/tmp/usr/share/man/de/man1/file.1.gz
	rm -f debian/tmp/usr/share/man/de/man8/lilo.8.gz
	# Remove intro.{2,3} manpages from manpages-de-dev,
	# they are included in manpages-de
	rm debian/manpages-de-dev/usr/share/man/de/man2/intro.2
	rm debian/manpages-de-dev/usr/share/man/de/man3/intro.3
