#!/usr/bin/make -f

VERSION = $(shell dpkg-parsechangelog --show-field Version)

%:
	dh $@ --with python3 --buildsystem=pybuild

override_dh_auto_build:
	@if ! grep -q 'VERSION = "$(VERSION)"' diffoscope/__init__.py; then \
		echo "Version in debian/changelog doesn't match diffoscope version"; \
		exit 1; \
	fi
	dh_auto_build -O--buildsystem=pybuild

override_dh_python3:
	dh_python3 --recommends=python-debian --recommends=rpm-python --recommends=tlsh --recommends=guestfs

override_dh_gencontrol:
	TOOLS="$$(bin/diffoscope --list-tools=debian | tail -n 1 | \
		sed -e 's/\(^\| \)\(coreutils\|diffutils\|e2fsprogs\|findutils\|gzip\|tar\)\(,\|$$\)//g')"; \
		[ -n "$$TOOLS" ] || { echo '--list-tools failed' >&2; exit 1; }; \
		echo "diffoscope:Recommends=$$TOOLS" >> debian/diffoscope.substvars
	dh_gencontrol -O--buildsystem=pybuild

debian/diffoscope.1: debian/diffoscope.1.rst
	rst2man $< $@

override_dh_installman: debian/diffoscope.1
	dh_installman -O--buildsystem=pybuild

override_dh_clean:
	rm -f debian/diffoscope.1
	dh_clean -O--buildsystem=pybuild

diffoscope/presenters/icon.py: favicon.png
	(echo '# Generated from favicon.png'; \
	 echo 'FAVICON_BASE64 = """'; \
	 base64 $<; \
	 echo '""".replace("\\n", "")'; \
	) > $@

favicon.png: logo.svg
	inkscape -w 32 -h 32 -e $@ $<
