#!/usr/bin/make -f
# -*- makefile -*-

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

%:
	dh $@ --with gir

DPKG_GENSYMBOLS_CHECK_LEVEL=4
export DPKG_GENSYMBOLS_CHECK_LEVEL

ifeq (linux,$(DEB_HOST_ARCH_OS))
  SYSTEMD_CONFIG_FLAG = --enable-libsystemd-login
else
  SYSTEMD_CONFIG_FLAG = --disable-libsystemd-login
endif

override_dh_auto_configure:
	dh_auto_configure -- \
		--disable-silent-rules \
		--enable-gtk-doc \
		--enable-man-pages \
		--enable-introspection \
		$(SYSTEMD_CONFIG_FLAG) \
		--disable-examples \
		--with-systemdsystemunitdir=/lib/systemd/system \
		--libexecdir=\$${prefix}/lib/policykit-1

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# on buildds we can't rely on actually having a system bus
	dbus-run-session -- sh -c 'DBUS_SYSTEM_BUS_ADDRESS=$$DBUS_SESSION_BUS_ADDRESS make check'
endif

override_dh_install:
	# on Debian use sudo group; on Ubuntu, also allow the admin group for
	# historical reasons
	if dpkg-vendor --is ubuntu; then \
	    sed 's/@admin@/"unix-group:sudo", "unix-group:admin"/' debian/admin.rules.in > debian/tmp/etc/polkit-1/rules.d/40-ubuntu-admin.rules; \
	elif dpkg-vendor --is debian; then \
	    sed 's/@admin@/"unix-group:sudo"/' debian/admin.rules.in > debian/tmp/etc/polkit-1/rules.d/40-debian-sudo.rules; \
	fi
	find debian/tmp -name '*.la' -print -delete
	dh_install

override_dh_missing:
	dh_missing --fail-missing

override_dh_installsystemd:
	dh_installsystemd --no-start
