#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,-O1 -Wl,--as-needed
binaries := $(shell dh_listpackages)

ifeq ($(DEB_HOST_ARCH_OS),linux)
	CONFFLAGS += \
		--enable-wayland-backend=yes \
		--enable-wayland-compositor=yes \
		--enable-evdev-input=yes
endif

ifeq (,$(filter %-doc,$(binaries)))
CONFFLAGS += --disable-gtk-doc
else
CONFFLAGS += --enable-gtk-doc
endif

%:
	dh $@ --with gir,gnome

override_dh_autoreconf:
	dh_autoreconf --as-needed

override_dh_auto_configure:
	dh_auto_configure -- \
		--enable-x11-backend=yes \
		--enable-gdk-backend=yes \
		--enable-egl-backend=yes \
		--disable-docs \
		--enable-installed-tests \
		--enable-introspection=yes \
		$(CONFFLAGS)

override_dh_install:
	find debian -name '*.la' -delete
	dh_install

override_dh_missing:
	dh_missing --fail-missing

override_dh_compress:
	dh_compress -X.c

override_dh_gnome:
	dh_gnome --no-gnome-versions

override_dh_makeshlibs:
	dh_makeshlibs -V -- -c4

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
# Don't run the tests on s390x since it hangs the build on Launchpad
# Don't run on armel since it hung with
# https://buildd.debian.org/status/logs.php?pkg=clutter-1.0&ver=1.26.2%2Bdfsg-5
ifneq (,$(filter armel s390x,$(DEB_HOST_ARCH)))
# Ignore test failures on architectures where they fail
else ifneq (,$(filter hppa hurd-i386 kfreebsd-i386 kfreebsd-amd64 mips mipsel mips64el powerpc ppc64 sparc64,$(DEB_HOST_ARCH)))
	-dbus-run-session -- xvfb-run -a dh_auto_test
else
	dbus-run-session -- xvfb-run -a dh_auto_test
endif
endif

override_dh_strip:
	dh_strip --dbgsym-migration='libclutter-1.0-dbg (<< 1.26.2+dfsg-2~)'
