#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

include /usr/share/openstack-pkg-tools/pkgos.make

PYTHON3S:=$(shell py3versions -vr)

UP_VERS=$(shell echo $(DEB_VERSION_UPSTREAM) | sed -e 's/~git.*//' -e 's/~/.0/' -e 's/+dfsg[[:digit:]]*//' -e 's/+ds[[:digit:]]*//')

%:
	dh $@ --with python3 $(MAX_PARALLEL)


execute_after_dh_auto_clean:
	rm -f $(CURDIR)/extra/service/legiond/legiond
	rm -f $(CURDIR)/extra/service/legiond/legiond-cli
	rm -rf python/legion_linux/build python/legion_linux/legion_linux.egg-info
	sed -i s/$(UP_VERS)/_VERSION/ python/legion_linux/setup.cfg

execute_before_dh_auto_build:
	$(MAKE) -C $(CURDIR)/extra/service/legiond
	sed -i s/_VERSION/$(UP_VERS)/ python/legion_linux/setup.cfg

execute_before_dh_auto_install:
	# Python stuff
	set -e ; set -x ; cd python/legion_linux ; for i in $(PYTHON3S) ; do \
		python$$i setup.py install --install-layout=deb --root $(CURDIR)/debian/python3-legion-linux ; \
	done

execute_before_dh_install:
	dh_install -plenovolegionlinux-dkms kernel_module/Makefile kernel_module/*.c usr/src/legion-laptop-$(UP_VERS)/

override_dh_dkms:
	dh_dkms -V$(UP_VERS)

override_dh_installsystemd:
	dh_installsystemd
	dh_installsystemd -p legiond --name=legiond-onresume
	dh_installsystemd -p legiond --name=legiond

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