#!/usr/bin/make -f
export CHANGELOG_VERSION=$(shell dpkg-parsechangelog -SVersion)

%: cdist/version.py
	dh $@ --with python3 --buildsystem=python_distutils

# Upstream build system assumes git checkout. Since Debian source packages
# should be buildable from tarballs, we have to reimplement some of upstream
# build trickery.

cdist/version.py:
	echo "VERSION = '$(CHANGELOG_VERSION)'" > $@

build::
	$(MAKE) man
	find docs/man/ -name \*.1 -o -name \*.7 > debian/manpages

override_dh_auto_install:
	python3 setup.py install --root=debian/cdist --install-layout=deb
	find debian/cdist -name .gitignore -delete

override_dh_fixperms:
	dh_fixperms
	# Make lintian happy. If something have shebang, then `chmod +x'.
	find debian/cdist -type f -execdir \
		/bin/sh -c '(head -n1 {} | grep -qF "#!") && chmod +x {}' \;

override_dh_auto_clean:
	dh_auto_clean
	$(MAKE) clean
	rm -rf ./build
	find -name docbook-xsl.css -delete
