#!/usr/bin/make -f
#export DH_VERBOSE=1

%:
	dh $@

CONFIG_ARGS = --libexecdir=lib --bindir=/usr/bin --sbindir=/usr/sbin
ifeq ($(DEB_HOST_ARCH_OS),linux)
        CONFIG_ARGS += -Dpam=true
else
        CONFIG_ARGS += -Dpam=false
endif

override_dh_auto_configure:
	dh_auto_configure -- $(CONFIG_ARGS)

override_dh_install:
	dh_install
	# Make openrc's flavour of start-stop-daemon available to openrc-run
	mv  $(CURDIR)/debian/openrc/usr/sbin/start-stop-daemon  $(CURDIR)/debian/openrc/usr/lib/rc/sbin
	# These are symlinks for compatibility reasons, and we don't want
	# them in Debian.
	for file in runscript rc service ; do \
		rm -f $(CURDIR)/debian/openrc/usr/sbin/$${file} ; \
	done

	# Use Debian's default pam config.
	rm -rf $(CURDIR)/debian/openrc/etc/pam.d/

	# These need to be removed, the same way as other stuff above
	for file in service.8 service.8.gz start-stop-daemon.8 start-stop-daemon.8.gz ; do \
		rm -f $(CURDIR)/debian/openrc/usr/share/man/man8/$${file} ; \
	done

	# These are Gentoo specific stuff, we don't want them
	set -e && for i in sysctl.d local.d ; do \
		rm -rf $(CURDIR)/debian/openrc/etc/$${i} ; \
	done

	# We don't want Gentoo init scripts apart from agetty, savecache and
	# cgroups: #960182, #960183
	find $(CURDIR)/debian/openrc/etc/init.d/ $(CURDIR)/debian/openrc/etc/conf.d/ \
		\! -type d \! \( -name agetty -o -name savecache -o -name cgroups -o -name rc -o -name rcS \) -delete

	for dir in boot default sysinit shutdown; do \
		rm -f $(CURDIR)/debian/openrc/etc/runlevels/$${dir}/* ; \
	done