#!/usr/bin/make -f
# -*- makefile -*-
#
#  # Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
export LIBDIR=$${DESTDIR}/usr/lib/${DEB_HOST_MULTIARCH}
export PYTHONLIBDIR=$${DESTDIR}/usr/lib/$(shell pyversions -d)
export BASHCOMPLETIONDIR=$${DESTDIR}/usr/share/bash-completion/completions
export INITDIR=$${DESTDIR}/etc/init.d
export SYSCONFDIR=$${DESTDIR}/etc/default
#export SHLIBDIR=$${DESTDIR}/lib/${DEB_HOST_MULTIARCH}
#export LIBBASE=lib/${DEB_HOST_MULTIARCH}

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# The build system doesn't use CPPFLAGS, pass them to CFLAGS to enable the
# missing (hardening) flags. dpkg_buildflags is necessary because $(shell ..)
# doesn't use local environment variables.
dpkg_buildflags = DEB_BUILD_MAINT_OPTIONS=$(DEB_BUILD_MAINT_OPTIONS) dpkg-buildflags
export DEB_CFLAGS_MAINT_APPEND = $(shell $(dpkg_buildflags) --get CPPFLAGS)

%:
	dh $@ --with python2

override_dh_install:
	dh_install
	mv $(CURDIR)/debian/policycoreutils/usr/share/bash-completion/completions/semanage-bash-completion.sh \
		$(CURDIR)/debian/policycoreutils/usr/share/bash-completion/completions/semanage
	mv $(CURDIR)/debian/policycoreutils/usr/share/bash-completion/completions/setsebool-bash-completion.sh \
		$(CURDIR)/debian/policycoreutils/usr/share/bash-completion/completions/setsebool

# Remove upstream initscripts and use Debian ones
	rm -rf $(CURDIR)/debian/policycoreutils/etc/init.d/restorecond
	rm -rf $(CURDIR)/debian/policycoreutils/etc/init.d/mcstrans

# Remove system-config-selinux for now, it needs some adjustements for debian
	rm -rf $(CURDIR)/debian/policycoreutils/usr/share/system-config-selinux/
	rm -rf $(CURDIR)/debian/policycoreutils/usr/bin/sepolgen

override_dh_fixperms:
	dh_fixperms -Xusr/sbin/seunshare

override_dh_installinit:
	dh_installinit --name=mcstrans
	dh_installinit --name=restorecond

override_dh_installpam:
	dh_installpam --name=newrole
	dh_installpam --name=run_init
