#!/usr/bin/make -f

#optipng makes png's indexed which GRUB2 doesn't understand
export NO_PNG_PKG_MANGLE=1

%:
	dh $@ --with=python3

check:
	# Sanity-check before upload.
	find -name debian -prune -o -name \*.py -print | xargs py3compile
	find -type f \( -name \*.pyc -o -name \*.pyo \) -print0 | xargs -0r rm -f
	find -type d -name __pycache__ -print0 | xargs -0r rm -rf

	# Check the syntax of any shell scripts.
	set -e; for x in $$(find -type f -print0 | xargs -0 file -i | grep "text/x-shellscript" | cut -d':' -f1); do \
			sh -n $$x; \
	done
	# Check the syntax of any Python scripts.
	./tests/run-pyflakes

	# Check that we can build all the GRUB binaries (don't actually ship these though)
	# build without the MINGW32 binary as it would require apt-get source to work on binary build
	PATCHES=/dev/null ./tests/grub-binaries

override_dh_clean: check
	dh_clean
	cd $(CURDIR)/po; make clean

override_dh_auto_clean:
	set -ex; for python in $(shell py3versions -r); do \
		$$python setup.py build; \
	done;

override_dh_auto_build:
	set -ex; for python in $(shell py3versions -r); do \
		$$python setup.py build; \
	done;

override_dh_auto_install:
	set -ex; for python in $(shell py3versions -r); do \
		$$python setup.py install --root=$(CURDIR)/debian/tmp --install-layout=deb; \
	done;

override_dh_python3:
	dh_python3 --shebang=/usr/bin/python3
