#!/usr/bin/make -f
# -*- makefile -*-

include /usr/share/dpkg/architecture.mk

# export DH_VERBOSE = 1
PYVERS = $(shell py3versions -vs)

# Hardening
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

CONFIGURE_FLAGS += -DCMAKE_POSITION_INDEPENDENT_CODE=ON
CONFIGURE_FLAGS += -DOPENDHT_PROXY_SERVER=ON
CONFIGURE_FLAGS += -DOPENDHT_PROXY_CLIENT=ON
CONFIGURE_FLAGS += -DOPENDHT_PUSH_NOTIFICATIONS=ON
CONFIGURE_FLAGS += -DOPENDHT_PYTHON=ON
CONFIGURE_FLAGS += -DOPENDHT_C=ON
CONFIGURE_FLAGS += -DOPENDHT_TESTS_NETWORK=OFF

%:
	dh $@ --without autoreconf --with python3

override_dh_auto_configure:
	dh_auto_configure -- ${CONFIGURE_FLAGS}

clean-python%:
	( [ -d "obj-$(DEB_BUILD_GNU_TYPE)"/python ] && \
	    cd "obj-$(DEB_BUILD_GNU_TYPE)"/python && \
	    python$* setup.py clean ) || true

build-python%:
	cd "obj-$(DEB_BUILD_GNU_TYPE)"/python && \
	  python$* setup.py build

install-python%:
	cd "obj-$(DEB_BUILD_GNU_TYPE)"/python && \
	  python$* setup.py install \
	    --root=$(CURDIR)/debian/tmp \
	    --install-layout=deb

execute_after_dh_auto_clean: $(PYVERS:%=clean-python%)
	$(RM) $(CURDIR)/python/opendht.cpp
execute_after_dh_auto_build: $(PYVERS:%=build-python%)
execute_after_dh_auto_install: $(PYVERS:%=install-python%)
	rm -f $(CURDIR)/debian/tmp/usr/share/man/man1/dhtnode.1
execute_after_dh_install:
	rm -f $(CURDIR)/debian/libopendht-dev/usr/include/opendht/opendht_c.h

override_dh_installsystemd:
	dh_installsystemd -popendht-tools --name=dhtnode-http --no-enable --no-start
	dh_installsystemd --remaining-packages

# Skip dh_dwz set as it fail on debian/dhtnode/usr/bin/dhtnode in version 2.4.10
override_dh_dwz:
	#dh_dwz

override_dh_missing:
	echo dh_missing disabled

