#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Run pip install without internet access
export PIPFLAGS=--no-build-isolation --no-index --no-deps --progress-bar off --upgrade --ignore-installed

# Enable installation of python packages
export PIP_BREAK_SYSTEM_PACKAGES=1

version := $(shell dpkg-parsechangelog -S Version | sed -rne 's,([^-\+]+)+(\+dfsg)*.*,\1,p'i)
source := $(shell dpkg-parsechangelog -S Source)
upstreampck := $(source)_$(version).orig.tar.gz

PACKAGE = $(firstword $(shell dh_listpackages))
TMP     = $(CURDIR)/debian/$(PACKAGE)

%:
	dh ${@} --with python3

# We want cuda_plugin.so to retain its name:
override_dh_python3:
	dh_python3 --no-ext-rename

clean:
	@ echo CLEAN
	rm -f ../$(upstreampck)
	tar czf ../$(upstreampck) --exclude=.git --exclude=debian --exclude=.pc .
	dh_testdir
	dh_auto_clean
	dh_clean


override_dh_auto_install:
	dh_auto_install -- DESTDIR="$(CURDIR)/debian/criu" PREFIX="/usr" LIBEXECDIR="/usr/lib" PYTHON="python3"
	# Fix for pip 22.0.2 on Ubuntu 22.04
	if [ -x "$(CURDIR)/debian/criu/usr/local/bin/crit" ]; then \
		mkdir -p "$(CURDIR)/debian/criu/usr/bin/"; \
		mv "$(CURDIR)/debian/criu/usr/local/bin/crit" "$(CURDIR)/debian/criu/usr/bin/"; \
	fi

override_dh_auto_test:
	# disabled: doesn't work yet

override_dh_strip:
	dh_strip --ddeb-migration='criu-dbg (<< 1.8-2~)'
