#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

%:
	dh $@ --with systemd

# this should track the definition of USERCOMPILE in mk/userland.mk:46
# but without -fstack-protector-all for arches that lack stack-protector
ifneq (,$(filter $(DEB_HOST_ARCH), hppa alpha ia64))
export USERCOMPILE = -fexceptions -fno-strict-aliasing -fPIE -DPIE
endif

ifeq ($(DEB_HOST_ARCH_OS),linux)
  ENABLE_SELINUX = USE_LABELED_IPSEC=true USE_LINUX_AUDIT=true
  ENABLE_LIBCAP_NG = USE_LIBCAP_NG=true
else
  ENABLE_SELINUX = USE_LABELED_IPSEC=false USE_LINUX_AUDIT=false
  ENABLE_LIBCAP_NG = USE_LIBCAP_NG=false
endif

override_dh_auto_build:
	dh_auto_build -- programs \
		ARCH=$(DEB_HOST_ARCH) \
		IPSECVERSION=$(DEB_VERSION_UPSTREAM_REVISION) \
		PREFIX=/usr \
		FINALLIBEXECDIR=/usr/libexec/ipsec \
		FINALMANDIR=/usr/share/man \
		USE_LDAP=true \
		$(ENABLE_LIBCAP_NG) \
		$(ENABLE_SELINUX)

override_dh_auto_install-arch:
	# Add here commands to install the package into debian/libreswan
	$(MAKE) install \
		ARCH=$(DEB_HOST_ARCH) \
		IPSECVERSION=$(DEB_VERSION_UPSTREAM_REVISION) \
		PREFIX=/usr \
		FINALLIBEXECDIR=/usr/libexec/ipsec \
		FINALMANDIR=/usr/share/man \
		USE_LDAP=true \
		$(ENABLE_LIBCAP_NG) \
		$(ENABLE_SELINUX) \
		DESTDIR=$(CURDIR)/debian/libreswan

override_dh_auto_test:
	 echo "Skip dh_auto_test"

override_dh_strip:
	dh_strip --dbg-package=libreswan-dbg
