#!/usr/bin/make -f
# There are some problems with sanitize=+all and getgroups(2), as checked in
# runit-2.1.2/src/chkshgrp.c.
# -- Dmitry Bogatov <KAction@gnu.org>  Sun, 24 Dec 2017 00:13:54 +0300
export DEB_BUILD_MAINT_OPTIONS = hardening=+all qa=+canary
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk
export CFLAGS  += $(shell getconf LFS_CFLAGS)
export LDFLAGS += $(shell getconf LFS_LDFLAGS)

%:
	dh $@ --sourcedirectory=runit-$(DEB_VERSION_UPSTREAM)/src \
	      --with bash_completion,runit,buildinfo

override_dh_auto_configure:
	echo $(CC) $(CFLAGS) > runit-$(DEB_VERSION_UPSTREAM)/src/conf-cc
	echo $(CC) > runit-$(DEB_VERSION_UPSTREAM)/src/conf-ld

override_dh_auto_build:
	$(MAKE) debian/contrib/shutdown
	dh_auto_build

override_dh_installsystemd:
	dh_installsystemd --name runit

override_dh_installman-arch:
	dh_installman
	mv debian/runit-init/usr/share/man/man8/runit-init.8 \
           debian/runit-init/usr/share/man/man8/init.8

override_dh_runit: runscripts/getty
	dh_runit

debian/runscripts/getty-%/run: debian/runscripts/getty.run.x
	mkdir -p $(@D)
	$< $* > $@
debian/runscripts/getty-%/finish: debian/runscripts/getty.finish.x
	mkdir -p $(@D)
	$< $* > $@

GETTY_SERVICE_DIRS = $(foreach n, 1 2 3 4 5 6, debian/runscripts/getty-tty$n)
runscripts/getty: $(GETTY_SERVICE_DIRS:%=%/run) $(GETTY_SERVICE_DIRS:%=%/finish)

override_dh_clean:
	rm -fr $(GETTY_SERVICE_DIRS)
	dh_clean
override_dh_installchangelogs:
	dh_installchangelogs
	dh_installchangelogs -p runit -p runit-init \
	    runit-$(DEB_VERSION_UPSTREAM)/package/CHANGES

.PHONY: runscripts/getty
