#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

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

PY3REQUESTED := $(shell py3versions -r)
PY3DEFAULT := $(shell py3versions -d)
# Run setup.py with the default python3 last so that the scripts use
# #!/usr/bin/python3 and not #!/usr/bin/python3.X.
PY3 := $(filter-out $(PY3DEFAULT),$(PY3REQUESTED)) python3

override_dh_auto_clean:
	dh_clean
	rm -rf build *.egg-info .pybuild
	find -name \*.pyc -print0 | xargs -0r rm -f
	find -name __pycache__ -print0 | xargs -0r rm -rf
	-$(shell python3 ./bin/update-apparmor-policy ./data/apparmor-easyprof-ubuntu.json)

override_dh_auto_build:
	dh_auto_build
	set -ex; for python in $(PY3); do \
		$$python setup.py build; \
	done

override_dh_auto_install:
	# setuptools likes to leave some debris around, which confuses things.
	find build -name \*.pyc -print0 | xargs -0r rm -f
	find build -name __pycache__ -print0 | xargs -0r rm -rf
	find build -name \*.egg-info -print0 | xargs -0r rm -rf
	dh_auto_install
	set -ex; for python in $(PY3); do \
		$$python setup.py install --install-layout=deb \
		--root=$(CURDIR)/debian/tmp; \
	done

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	set -ex; for python in $(PY3); do \
		$$python setup.py test; \
	done
	./run-pep8
endif
