#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,-O1 -Wl,-z,defs
export DPKG_GENSYMBOLS_CHECK_LEVEL = 4

ifeq ($(DEB_HOST_ARCH_OS),linux)
ENABLE_SELINUX := -Dselinux=true
else
ENABLE_SELINUX := -Dselinux=false
endif

ifeq ($(shell dpkg-vendor --is Ubuntu && echo yes), yes)
# Not in main repository
ENABLE_CLOUD += -Dcloudproviders=false
else
ENABLE_CLOUD += -Dcloudproviders=true
endif

# Avoid test failures on buildd environments
export HOME=$(CURDIR)/debian/build
# Put these back to their defaults if we are not running with a clean
# environment, so that they are based on the temporary $HOME above
unexport XDG_CACHE_HOME
unexport XDG_CONFIG_DIRS
unexport XDG_CONFIG_HOME
unexport XDG_DATA_DIRS
unexport XDG_DATA_HOME

# The tests assume this directory exists and is writable
export XDG_RUNTIME_DIR=$(CURDIR)/debian/tmp-xdg-runtime-dir
# Let's get failing tests' stdout and stderr so we have some information when
# a build fails
export VERBOSE=1

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		-Ddocs=true \
		-Dpackagekit=true \
		-Dtests=all \
		$(ENABLE_CLOUD) \
		$(ENABLE_SELINUX)

override_dh_auto_test:
	touch $(CURDIR)/debian/.debhelper/generated/_source/home/.gtk-bookmarks
	GTK_A11Y=none dbus-run-session -- xvfb-run --auto-servernum dh_auto_test
