#!/usr/bin/make -f
SHELL+= -e

DPKG_EXPORT_BUILDFLAGS = 1
DEB_BUILD_MAINT_OPTIONS=hardening=+pie,+bindnow
-include /usr/share/dpkg/buildflags.mk

D := $(CURDIR)/debian/binkd

build:
	dh_testdir
	cp mkfls/unix/install-sh mkfls/unix/configure mkfls/unix/Makefile.* .
	chmod u+x configure
	dh_auto_configure -- --with-debug --with-https --with-ntlm --with-bwlim --with-perl
	$(MAKE)
	touch $@

clean:
	dh_testdir
	[ ! -e Makefile ] || $(MAKE) clean
	-rm -f install-sh configure Makefile.in \
		Makefile Makefile.dep configure.in config.log binkd build
	dh_clean

binary-arch: build
	dh_testdir
	dh_testroot
	dh_prep

	dh_installdirs
	dh_installdocs todo.lst
	dh_installexamples
	dh_installchangelogs \!README.FIX
	dh_installman *.8

	cp binkd.cfg binkd.inc $D/etc/binkd/
	dh_systemd_enable
	dh_installinit --restart-after-upgrade
	dh_systemd_start --restart-after-upgrade

	dh_installlogrotate
	install binkd $D/usr/sbin/
	install --mode 755 debian/binkdlogstat $D/usr/sbin/

	dh_strip
	dh_compress
	dh_fixperms
	chown -R 64000:adm $D/var/log/binkd/
	chmod 750 $D/var/log/binkd/
	chown -R 64000:64000 $D/var/spool/ftn/ $D/etc/binkd/binkd.inc
	chmod 600 $D/etc/binkd/binkd.inc
	dh_shlibdeps
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary-indep:

binary:	binary-arch

build-arch: build
build-indep: build

get-orig-source:
	cd $(dir $(firstword $(MAKEFILE_LIST)))../ && \
	uscan --rename --force-download --watchfile debian/watch --destdir $(CURDIR)

.PHONY: binary binary-arch binary-indep build-arch build-indep clean get-orig-source
