#!/usr/bin/make -f
export DH_VERBOSE=1

include /usr/share/dpkg/pkg-info.mk
FLAKE8 := $(shell flake8 --version 2> /dev/null)

%:
	dh $@ --with python3,bash-completion --buildsystem=pybuild

override_dh_auto_build:
	dh_auto_build
	make -C apt-hook build

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	python3 -m pytest
ifdef FLAKE8
	# required for Trusty: flake8 does not install a __main__  for -m
	# invocation
	python3 $(shell which flake8) uaclient
else
	python3 -m flake8 uaclient
endif
endif

override_dh_auto_install:
	dh_auto_install --destdir=debian/ubuntu-advantage-tools
	flist=$$(find $(CURDIR)/debian/ -type f -name version.py) && sed -i 's,@@PACKAGED_VERSION@@,$(DEB_VERSION),' $${flist:-did-not-find-version-py-for-replacement}
	make -C apt-hook DESTDIR=$(CURDIR)/debian/ubuntu-advantage-tools install

override_dh_auto_clean:
	dh_auto_clean
	make clean
