#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

export DEB_BUILD_MAINT_OPTIONS := hardening=+all

PY3V := $(shell py3versions -vr)

%:
	dh $@ --with bash-completion,python3

override_dh_autoreconf:
	dh_autoreconf
	# autoreconf updates the timestamps on the Makefiles,
	# update them on the pre-generated man pages to make
	# sure they are newer and the build system doesn't try
	# to re-generate them.
	touch doc/man/*.1 doc/man/*.3 doc/man/*.8

# Disable tests, they fail on the buildds
override_dh_auto_test:
	# Uncomment the following line to run the tests suite,
	# it doesn't support running in parallel.
	#dh_auto_test --no-parallel

override_dh_auto_install:
	dh_auto_install
	for pv in $(PY3V); do \
	  PYTHON=python$${pv} PYTHON_CONFIG=python$${pv}-config \
	    dh_auto_configure -- --enable-python-bindings; \
	  cd extras/bindings/swig/python; \
	  make clean; \
	  make install DESTDIR="$(CURDIR)/debian/tmp"; \
	  mv "$(CURDIR)/debian/tmp/usr/lib/python$${pv}/site-packages" \
	     "$(CURDIR)/debian/tmp/usr/lib/python$${pv}/dist-packages"; \
	  find "$(CURDIR)/debian/tmp/usr/lib/python$${pv}" -type l -delete; \
	  mv "$(CURDIR)/debian/tmp/usr/lib/python$${pv}/dist-packages/_lttng.so.0.0.0" \
	     "$(CURDIR)/debian/tmp/usr/lib/python$${pv}/dist-packages/_lttng.so"; \
	  cd $(CURDIR); \
	done

override_dh_installinit:
	dh_installinit --name=lttng-sessiond

override_dh_installsystemd:
	dh_installsystemd --name=lttng-sessiond

override_dh_makeshlibs:
	dh_makeshlibs -V
