#!/usr/bin/make -f

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

export DEB_BUILD_MAINT_OPTIONS=hardening=+bindnow

export PYBUILD_NAME=cryptography37
export CARGO_HOME=$(CURDIR)/debian/.cargo

PYTHON3_SUPPORTED_VERSIONS:=$(shell py3versions -s 2>/dev/null | sed 's/python3.//g')

%:
	dh $@ --buildsystem=pybuild


override_dh_auto_clean:
	dh_auto_clean
	rm -rf cryptography/hazmat/bindings/__pycache__ \
	       cryptography/hazmat/primitives/__pycache__

override_dh_auto_build:
	for version in $(PYTHON3_SUPPORTED_VERSIONS); do \
		python3.$${version} setup.py build; \
		mkdir -p $(CURDIR)/.pybuild/cpython3_3.$${version}_cryptography37/build/; \
		cp -r build/lib.linux-*/cryptography $(CURDIR)/.pybuild/cpython3_3.$${version}_cryptography37/build/; \
	done

override_dh_auto_test:

override_dh_python3:
	dh_python3 --depends=cffi
	find .
	sed -Ei -e '/^cffi/d' debian/python3-cryptography37/usr/lib/python3*/dist-packages/cryptography-37*.egg-info/requires.txt
	-rm debian/python3-cryptography37/usr/lib/python3.*/dist-packages/cryptography/hazmat/bindings/_openssl.abi3.so \
	   debian/python3-cryptography37/usr/lib/python3.*/dist-packages/cryptography/hazmat/bindings/_padding.abi3.so
	-rmdir -p debian/python3-cryptography37/usr/lib/python3.*/dist-packages/cryptography/hazmat/bindings
	mv debian/python3-cryptography37/usr/lib/python3/dist-packages/cryptography debian/python3-cryptography37/usr/lib/python3/dist-packages/cryptography37
	mv debian/python3-cryptography37/usr/lib/python3/dist-packages/cryptography-$(DEB_VERSION_UPSTREAM).egg-info debian/python3-cryptography37/usr/lib/python3/dist-packages/cryptography37-$(DEB_VERSION_UPSTREAM).egg-info
