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

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

ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
  export CC := $(DEB_HOST_GNU_TYPE)-gcc
endif

D := $(CURDIR)/debian/openbsd-inetd

clean:
	dh_testdir
	rm -f debian/.stamp-*
	rm -f inetd *.o
	dh_clean

build: build-arch build-indep
build-arch: debian/.stamp-build
build-indep: debian/.stamp-build
debian/.stamp-build:
	dh_testdir
	$(MAKE) -f Makefile.debian
	touch $@

binary-arch: checkroot build
	dh_testdir
	dh_prep

	dh_installdirs usr/sbin/ usr/share/man/man5/ lib/systemd/system/
	dh_installdocs
	dh_installman inetd.8
	dh_installchangelogs ChangeLog
	dh_link
	install --mode=755 inetd $D/usr/sbin/
	cp debian/inetd.service $D/lib/systemd/system/
	dh_systemd_enable
	dh_installinit --restart-after-upgrade
	dh_systemd_start --restart-after-upgrade
	dh_strip
	dh_compress
	dh_fixperms
	dh_shlibdeps
	dh_installdeb
	dh_gencontrol
	dh_md5sums
	dh_builddeb

binary:	binary-arch

binary-indep:

checkroot:
	test root = "`whoami`"

.PHONY: binary binary-arch binary-indep build build-arch build-indep clean checkroot
