#!/usr/bin/make -f
-include /usr/share/gnome-pkg-tools/1/rules/gnome-get-source.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_LDFLAGS_MAINT_APPEND = -Wl,-O1 -Wl,-z,defs -Wl,--as-needed
export CARGO_HOME = $(CURDIR)/debian/cargo-home
NULL =

%:
	dh $@ --with gnome,gir

override_dh_autoreconf:
	dh_autoreconf --as-needed

override_dh_auto_configure:
	mkdir -p $(CARGO_HOME)
	dh_auto_configure -- \
		--enable-pixbuf-loader \
		--enable-installed-tests \
		--enable-introspection \
		--enable-vala \
		--enable-gtk-doc \
		GDK_PIXBUF_QUERYLOADERS=/usr/lib/$(DEB_HOST_MULTIARCH)/gdk-pixbuf-2.0/gdk-pixbuf-query-loaders \
		$(NULL)

override_dh_makeshlibs:
	dh_makeshlibs -- -c4

override_dh_install:
	find debian/tmp -name '*.a' -print -delete
	find debian/tmp -name '*.la' -print -delete
	rm -f debian/tmp/usr/bin/rsvg-view-3
	dh_install
	sed -e "s/#MULTIARCH#/$(DEB_HOST_MULTIARCH)/g" debian/librsvg2-common.postinst.in > \
		debian/librsvg2-common.postinst

override_dh_installchangelogs:
	dh_installchangelogs -XChangeLog

override_dh_missing:
	dh_missing --fail-missing

override_dh_clean:
	dh_clean
	rm -fr $(CARGO_HOME)

# Skip rsvg-tests which contain the reftests; they are tightly coupled to
# specific versions of pixman, cairo, pango, and freetype. This list of
# tests comes from the test_programs variable in tests/Makefile.am.
# See also https://gitlab.gnome.org/GNOME/librsvg/issues/511 and
# https://gitlab.gnome.org/GNOME/librsvg/issues/512 for an attempt to
# mitigate this problem upstream.
export TESTS = "api loading crash render-crash dimensions errors infinite-loop"

override_dh_auto_test-arch:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	mkdir -p $(CURDIR)/debian/locales
	localedef -i en_US -f UTF-8 $(CURDIR)/debian/locales/en
	localedef -i en_US -f UTF-8 $(CURDIR)/debian/locales/en_US
	localedef -i de_DE -f UTF-8 $(CURDIR)/debian/locales/de
	LOCPATH=$(CURDIR)/debian/locales dh_auto_test -- TESTS=$(TESTS)
	find debian -name '*.log' \
		-not -name config.log \
		-not -name test-suite.log \
		-print0 | xargs -0 tail -v -c1M
endif

override_dh_auto_test-indep:
	@:
