#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1

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

# Prevent setuptools/distribute from accessing the internet.
export http_proxy = http://127.0.9.1:9

# This has to be exported to make some magic below work.
export DH_OPTIONS
export PYBUILD_NAME=python3-openvpn-connector-setup
export PYBUILD_INTERPRETERS=python3

%:
	dh $@ --with python3 --buildsystem=pybuild

override_dh_auto_build:
	python3 setup.py build

# We need to enforce the xz compression algorithm, due to issues with aptly
# https://github.com/aptly-dev/aptly/issues/989
override_dh_builddeb:
	dh_builddeb -- -Zxz

override_dh_auto_install:
	python3 setup.py install --root=$(CURDIR)/debian/python3-openvpn-connector-setup/ --install-layout=deb
	find $(CURDIR)/debian/python3-openvpn-connector-setup/ -type d -name __pycache__ | xargs rm -rf

#	# Install the cockpit-openvpn-connector files
	make -C $(CURDIR)/cockpit-openvpn-connector DESTDIR=$(CURDIR)/debian/cockpit-openvpn-connector PREFIX=/usr install
	install -m644 $(CURDIR)/cockpit-openvpn-connector/VERSION $(CURDIR)/debian/cockpit-openvpn-connector/usr/share/cockpit/openvpn-connector/VERSION

#	# Hack to avoid issues with lacking egg-info in python3-dbus debian package (Debian < 11, Ubuntu < 20.04)
	find $(CURDIR)/debian/python3-openvpn-connector-setup/ -type f -name requires.txt | xargs rm -vf

override_dh_auto_clean:
	python3 setup.py clean -a
	find . -path '*/__pycache__/*' -delete
	find . -type d -name '__pycache__' -empty -delete

