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

export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

include /usr/share/dpkg/default.mk
include /usr/share/debhelper/dh_package_notes/package-notes.mk

built_binaries := $(shell dh_listpackages)

%:
	dh $@ --with xml-core

DPKG_GENSYMBOLS_CHECK_LEVEL=4
export DPKG_GENSYMBOLS_CHECK_LEVEL

configure_flags =
compat_configure_flags =

ifeq ($(filter %-doc,$(built_binaries)),)
configure_flags += -Dgtk_doc=false
else
configure_flags += -Dgtk_doc=true
endif

ifeq (linux,$(DEB_HOST_ARCH_OS))
configure_flags += -Dsession_tracking=logind
else
configure_flags += -Dsession_tracking=ConsoleKit
endif

ifneq ($(DEB_BUILD_ARCH),$(DEB_HOST_ARCH))
configure_flags += --cross-file=$(DEB_HOST_GNU_TYPE)-gobject-introspection.ini
endif

override_dh_auto_configure:
	dh_auto_configure -- \
		-Dexamples=false \
		-Dintrospection=true \
		-Dman=true \
		-Dtests=true \
		-Dgettext=true \
		-Dos_type=debian \
		-Dprivileged_group=sudo \
		$(configure_flags)

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 -euc 'export DBUS_SYSTEM_BUS_ADDRESS="$$DBUS_SESSION_BUS_ADDRESS"; exec "$$@"' \
		sh \
		dh_auto_test \
		-- \
		$(NULL)
endif

execute_before_dh_install:
	# on Debian use sudo group; on Ubuntu, also allow the admin group for
	# historical reasons
	if dpkg-vendor --is ubuntu; then \
		install -m644 debian/49-ubuntu-admin.rules debian/tmp/usr/share/polkit-1/rules.d/; \
	fi

override_dh_installsystemd:
	dh_installsystemd --no-start --restart-after-upgrade
