#!/usr/bin/make -f

EXTENSION := $(shell awk -F\" '/"uuid": / { print $$4 }' */metadata.json)

%:
	dh ${@}

execute_after_dh_auto_clean:
	rm -f *.zip

override_dh_auto_build:
	./scripts/build.sh

override_dh_auto_install:
	mkdir -p debian/gnome-shell-extension-just-perfection/usr/share/gnome-shell/extensions
	unzip *.zip -d debian/gnome-shell-extension-just-perfection/usr/share/gnome-shell/extensions/$(EXTENSION)

	# compiling schema
	glib-compile-schemas debian/gnome-shell-extension-just-perfection/usr/share/gnome-shell/extensions/$(EXTENSION)/schemas

	# removing unused files
	rm -f debian/gnome-shell-extension-just-perfection/usr/share/gnome-shell/extensions/$(EXTENSION)/LICENSE
	rm -f debian/gnome-shell-extension-just-perfection/usr/share/gnome-shell/extensions/$(EXTENSION)/CHANGELOG.md

execute_after_dh_fixperms:
	find debian/gnome-shell-extension-just-perfection -type f -name "*.json" -exec chmod 0644 {} +;
	find debian/gnome-shell-extension-just-perfection -type f -name "*.xml" -exec chmod 0644 {} +;

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