#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

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

clean:
	@ echo CLEAN
	rm -f ../$(upstreampck)
	tar czf ../$(upstreampck) --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~)'
