#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

%:
	dh $@ --with gir,gnome --no-parallel

override_dh_autoreconf:
	dh_autoreconf --as-needed

ifeq ($(DEB_HOST_ARCH_OS),linux)
CONFFLAGS = \
	--enable-egl-device \
	--enable-wayland \
	--enable-native-backend
else
CONFFLAGS += \
	--disable-wayland-egl-platform \
	--disable-wayland-egl-server \
	--disable-kms-egl-platform \
	--disable-wayland \
	--disable-native-backend
endif

override_dh_auto_configure:
	dh_auto_configure -- \
		--libexecdir="\$${prefix}/lib/mutter" \
		--enable-startup-notification \
		--enable-compile-warnings \
		$(CONFFLAGS)

# See https://bugs.debian.org/874077
# Ignore test failures on Debian and on s390x
override_dh_auto_test:
ifneq (,$(findstring $(DEB_HOST_ARCH),"s390x"))
	-xvfb-run dh_auto_test
else ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
	xvfb-run dh_auto_test
else
	-xvfb-run dh_auto_test
endif

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

override_dh_missing:
	dh_missing --fail-missing

override_dh_girepository:
	dh_girepository /usr/lib/$(DEB_HOST_MULTIARCH)/mutter

override_dh_makeshlibs:
	dh_makeshlibs -V

override_dh_shlibdeps:
	dh_shlibdeps -Llibmutter-3-0 -l/usr/lib/$(DEB_HOST_MULTIARCH)/mutter

override_dh_strip:
	dh_strip --dbgsym-migration='mutter-dbg (<< 3.18.3-2~)'

override_dh_auto_clean:
	dh_auto_clean
	rm -f src/gtk-primary-selection-protocol.c
	rm -f src/gtk-primary-selection-server-protocol.h
	rm -f src/gtk-shell-protocol.c
	rm -f src/gtk-shell-server-protocol.h
	rm -f src/gtk-text-input-protocol.c
	rm -f src/gtk-text-input-server-protocol.h
	rm -f src/keyboard-shortcuts-inhibit-unstable-v1-protocol.c
	rm -f src/keyboard-shortcuts-inhibit-unstable-v1-server-protocol.h
	rm -f src/linux-dmabuf-unstable-v1-protocol.c
	rm -f src/linux-dmabuf-unstable-v1-server-protocol.h
	rm -f src/pointer-constraints-unstable-v1-protocol.c
	rm -f src/pointer-constraints-unstable-v1-server-protocol.h
	rm -f src/pointer-gestures-unstable-v1-protocol.c
	rm -f src/pointer-gestures-unstable-v1-server-protocol.h
	rm -f src/relative-pointer-unstable-v1-protocol.c
	rm -f src/relative-pointer-unstable-v1-server-protocol.h
	rm -f src/tablet-unstable-v2-protocol.c
	rm -f src/tablet-unstable-v2-server-protocol.h
	rm -f src/xdg-foreign-unstable-v1-protocol.c
	rm -f src/xdg-foreign-unstable-v1-server-protocol.h
	rm -f src/xdg-output-unstable-v1-protocol.c
	rm -f src/xdg-output-unstable-v1-server-protocol.h
	rm -f src/xdg-shell-protocol.c
	rm -f src/xdg-shell-server-protocol.h
	rm -f src/xdg-shell-unstable-v6-protocol.c
	rm -f src/xdg-shell-unstable-v6-server-protocol.h
	rm -f src/xwayland-keyboard-grab-unstable-v1-protocol.c
	rm -f src/xwayland-keyboard-grab-unstable-v1-server-protocol.h

