#!/usr/bin/make -f
#export DH_VERBOSE=1

# For DEB_HOST_MULTIARCH and DEB_VERSION_UPSTREAM
include /usr/share/dpkg/default.mk

# On older distros +pie will add -fPIE -pie to the library linkage, which breaks
# it, -fPIC is enough
export DEB_BUILD_MAINT_OPTIONS = hardening=+all,-pie

ifeq (,$(findstring terse,$(DEB_BUILD_OPTIONS)))
	WAF = python3 ./waf -v
else
	WAF = python3 ./waf
endif

ifneq (,$(filter hurd,$(DEB_HOST_ARCH_OS)))
        STATIC_LIBS="-lpcap"
else
        STATIC_LIBS=""
endif

%:
	dh $@ --parallel

override_dh_auto_configure:
	$(WAF) configure --prefix=/usr --libdir=/usr/lib/$(DEB_HOST_MULTIARCH)

override_dh_auto_build:
	$(WAF) build --enable-static-library

override_dh_auto_install:
	$(WAF) install --destdir=$(CURDIR)/debian/tmp --enable-static-library
	install -d debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig
	sed -e "s/@VERSION@/$(DEB_VERSION_UPSTREAM)/" \
                -e "s|@DEB_HOST_MULTIARCH@|$(DEB_HOST_MULTIARCH)|g" \
                -e "s|@STATIC_LIBS@|$(STATIC_LIBS)|g" \
                debian/norm.pc.in > \
		debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/norm.pc

override_dh_auto_clean:
	$(WAF) distclean
	find waflib -name "*.pyc" -delete
