#!/usr/bin/make -f

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		--libdir=/usr/lib \
		-Dfirewalld=true \
		-Dinstalled_tests=false

# Tests do not appear to work outside of a graphical GNOME shell environment
override_dh_auto_test:

execute_after_dh_fixperms:
	chmod +x debian/gnome-shell-extension-gsconnect/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/nativeMessagingHost.js
	chmod +x debian/gnome-shell-extension-gsconnect/usr/share/gnome-shell/extensions/gsconnect@andyholmes.github.io/service/daemon.js

# Use debian/postinst to install the Chrome conffile
# and debian/postrm to remove it since dpkg's automatic
# conffile handling doesn't handle the special /etc/opt/ directory
# https://bugs.debian.org/888549
execute_after_dh_auto_install:
	mkdir -p debian/gnome-shell-extension-gsconnect-browsers/usr/share/gnome-shell-extension-gsconnect
	mv debian/tmp/etc/opt/chrome/native-messaging-hosts/org.gnome.shell.extensions.gsconnect.json \
		debian/gnome-shell-extension-gsconnect-browsers/usr/share/gnome-shell-extension-gsconnect/org.gnome.shell.extensions.gsconnect.json
	rm -rf debian/tmp/etc/opt

override_dh_gencontrol:
	dh_gencontrol -- \
		-Vgnome:MinimumVersion=$(shell python3 -c "import json; print(min(int(x) for x in json.load(open('obj-$(DEB_HOST_GNU_TYPE)/data/metadata.json', 'rt'))['shell-version']))") \
		-Vgnome:MaximumVersion=$(shell python3 -c "import json; print(1+max(int(x) for x in json.load(open('obj-$(DEB_HOST_GNU_TYPE)/data/metadata.json', 'rt'))['shell-version']))")