#!/usr/bin/make -f
include /usr/share/dpkg/default.mk

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

export GIR_SONAME = 1
export GIR_API_VERSION = 1.0
export GIR_FORMAT = 1.2

MANPAGES := debian/dh_girepository.1
$(MANPAGES): debian/dh_girepository
	pod2man -c "gobject-introspection" -r "$(DEB_VERSION)" $< $@

%:
	dh $@ --builddir=_build

debian/extra-substvars:
	DEB_HOST_ARCH=$(DEB_HOST_ARCH) debian/extra-substvars.py >> debian/extra-substvars

debian/libgirepository-1.0-1.symbols: debian/libgirepository-1.0-1.symbols.in debian/extra-substvars
	set -e; \
	libffiN=$$(sed -ne 's/^gobjectintrospection:libffiN=//p' debian/extra-substvars); \
	sed -e "s/@libffiN@/$$libffiN/" < $< > $@

override_dh_clean:
	dh_clean -Xorg.gtk.test.gschema.xml.orig -Xorg.gtk.test.gschema.override.orig

override_dh_auto_configure:
	dh_auto_configure -- \
		-Dgir_dir_prefix=lib/${DEB_HOST_MULTIARCH} \
		-Dgtk_doc=true \
		-Dcairo=enabled \
		-Ddoctool=enabled \
		-Dpython=python3

execute_before_dh_auto_build: $(MANPAGES)

execute_after_dh_auto_install:
	sed -i -e 's|^girdir=\(.*\)|girdir=$${datadir}/gir-1.0|' \
		debian/tmp/usr/lib/*/pkgconfig/*.pc

execute_before_dh_makeshlibs: debian/libgirepository-1.0-1.symbols

execute_after_dh_shlibdeps:
	perl -w debian/dh_girepository -v

execute_before_dh_python3:
	dh_python3 -pgobject-introspection /usr/lib/$(DEB_HOST_MULTIARCH)/gobject-introspection/giscanner/

override_dh_gencontrol:
	dh_gencontrol -- -Tdebian/extra-substvars
