#!/usr/bin/make -f

%:
	dh $@

override_dh_auto_build:
	$(MAKE) programs \
		INC_USRLOCAL=/usr \
		FINALBINDIR=/usr/lib/ipsec \
		FINALLIBEXECDIR=/usr/lib/ipsec \
		INC_RCDEFAULT=/etc/init.d \
		PUBDIR=/usr/sbin \
		MANTREE=/usr/share/man \
		CONFDIR=$(CURDIR)/debian \
		USE_LDAP=true \
		USE_LIBCURL=true \
		USE_XAUTHPAM=true \
		USE_FIPSCHECK=false \
		USE_LIBCAP_NG=false \
		USE_LABELED_IPSEC=false \
		USE_ADNS=false \
		USE_DNSSEC=true

override_dh_auto_install:
	# Add here commands to install the package into debian/tmp.
	$(MAKE) install \
		INC_USRLOCAL=/usr \
		FINALBINDIR=/usr/lib/ipsec \
		FINALLIBEXECDIR=/usr/lib/ipsec \
		INC_RCDEFAULT=/etc/init.d \
		PUBDIR=$(CURDIR)/debian/libreswan/usr/sbin \
		MANTREE=$(CURDIR)/debian/libreswan/usr/share/man \
		DESTDIR=$(CURDIR)/debian/libreswan
	rm -rf $(CURDIR)/debian/libreswan/usr/local
	rm -f $(CURDIR)/debian/libreswan/etc/init.d/ipsec?*

	# delete var/lock/subsys and var/run to satisfy lintian
	rm -rf $(CURDIR)/debian/libreswan/var/lock
	rm -rf $(CURDIR)/debian/libreswan/var/run

	# there is no sysconfig in debian
	rm -rf $(CURDIR)/debian/libreswan/etc/sysconfig

	# fix some manpage issues
	for oldname in `find $(CURDIR)/debian/libreswan/usr/share/man -name "ipsec_ipsec*"`; \
	do \
	    newname=`echo "$$oldname" | sed 's/ipsec_ipsec_/ipsec_/'`; \
	    if [ -f "$$newname" ]; then \
		rm -f "$$oldname"; \
	    else \
		mv "$$oldname" "$$newname"; \
	    fi; \
	done

	chmod 600 $(CURDIR)/debian/libreswan/etc/ipsec.secrets
	chmod 644 $(CURDIR)/debian/libreswan/etc/ipsec.conf
	chmod 700 $(CURDIR)/debian/libreswan/etc/ipsec.d/policies

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

override_dh_fixperms:
	dh_fixperms -X etc/ipsec.secrets -X etc/ipsec.d

override_dh_auto_test:
	 echo "Skip dh_auto_test"
