#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

export PYBUILD_NAME = legion-linux

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

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 --sourcedirectory=python/legion_linux --buildsystem=pybuild

override_dh_auto_test:
	# Upstream's python tests need the legion_laptop kernel module, which
	# cannot be loaded in a build chroot: skip them at build time.


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

execute_before_dh_auto_build:
	$(MAKE) -C $(CURDIR)/extra/service/legiond CFLAGS="$(CPPFLAGS) $(CFLAGS) -std=gnu2x -Wall -Wextra $(LDFLAGS)"
	sed -i s/_VERSION/$(UP_VERS)/ python/legion_linux/setup.cfg

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
	dh_installsystemd -p legiond --name=legiond-cpuset

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