#!/usr/bin/make -f

DEBIAN_VERSION ?= $(shell LANG=C dpkg -l base-files | awk '($$1=="ii"){print $$3}' | cut -d. -f1)

%:
	dh $@

override_dh_clean:
	dh_clean
	-rm man/check-support-status.*1
	-rm check-support-status

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp
	# compile and install catalogs
	for po in po/*.po ; do \
		bn="$$(basename "$$po")" ; \
		[ "$$bn" = 'messages.po' ] && continue ; \
		mkdir -p "debian/debian-security-support/usr/share/locale/$${bn%%.po}/LC_MESSAGES" ; \
		msgfmt \
			-o "debian/debian-security-support/usr/share/locale/$${bn%%.po}/LC_MESSAGES/debian-security-support.mo" \
			"$$po" ; \
	done

override_dh_install:
	mkdir -p debian/debian-security-support/usr/share/debian-security-support/
	cp security-support-ended.deb$(DEBIAN_VERSION) debian/debian-security-support/usr/share/debian-security-support/security-support-ended
	cp security-support-limited debian/debian-security-support/usr/share/debian-security-support/security-support-limited
	dh_install --fail-missing

override_dh_installman:
	for man in man/check-support-status.txt.* ; do \
		[ -f "$$man" ] || continue ; \
		lang="$$(basename "$$man" | sed -e 's/^check-support-status\.txt\.//')" ; \
		a2x --format=manpage --no-xmllint "$$man" ; \
		mv man/check-support-status.1 "man/check-support-status.$$lang.1" ; \
	done
	a2x --format=manpage --no-xmllint man/check-support-status.txt
	# ignore an empty manpage created during build
	-rm debian/debian-security-support/usr/share/man/man1/check-support-status.1p
	dh_installman
