#!/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,-z,defs -Wl,--as-needed

export DH_VERBOSE=1

# Use recursive variables since this variable must not be expanded until 
# files have been installed.
LIBMOZJS = $(shell objdump -p debian/tmp/usr/lib/libgjs.so | awk '$$1=="NEEDED" && $$2~/^libmozjs/ { print $$2 }' | sed s/\\.so\\./-/ )

%:
	dh $@ --with gnome,gir

override_dh_auto_configure:
	dh_auto_configure -- \
		--libdir=\$${prefix}/lib \
		--libexecdir=\$${prefix}/lib/gjs \
		--enable-installed-tests \
		--with-xvfb-tests \
		--with-dbus-tests

override_dh_girepository:
	dh_girepository -l $(CURDIR) /usr/lib/gjs/girepository-1.0

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

override_dh_missing:
	dh_missing --fail-missing

override_dh_auto_test:
ifeq (, $(filter nocheck, $(DEB_BUILD_OPTIONS)))
	DEB_HOST_ARCH=$(DEB_HOST_ARCH) debian/test.sh
endif

override_dh_makeshlibs:
	dh_makeshlibs -Xusr/lib/gjs-1.0/ -V'libgjs0g (>= $(DEB_UPSTREAM_VERSION)), libgjs0-$(LIBMOZJS)' -- -c4

override_dh_gencontrol:
	echo gjs:Provides=libgjs0-$(LIBMOZJS) >> debian/libgjs0g.substvars
	dh_gencontrol
