#!/usr/bin/make -f

#export DH_VERBOSE = 1

ifeq ($(shell dpkg-vendor --is Ubuntu && echo yes),yes)
    export EXTENSION_UUID=tiling-assistant@ubuntu.com
else
    export EXTENSION_UUID=tiling-assistant@leleat-on-github
endif

%:
	dh $@

override_dh_auto_build:
ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
	mkdir -p $(EXTENSION_UUID)
	jq -r '.uuid = "$(EXTENSION_UUID)" '\
	'| .name = "Ubuntu Tiling Assistant" '\
	'| .url = "https://launchpad.net/ubuntu/+source/gnome-shell-extension-tiling-assistant"' \
	      tiling-assistant@leleat-on-github/metadata.json > \
	      $(EXTENSION_UUID)/metadata.json
endif
	./update-locale.sh
	dh_auto_build

override_dh_install:
	set -e; for x in $(EXTENSION_UUID)/locale/*; do \
		install -d debian/tmp/usr/share/locale/$$(basename $$x)/LC_MESSAGES; \
		install -m644 $$x/LC_MESSAGES/*.mo debian/tmp/usr/share/locale/$$(basename $$x)/LC_MESSAGES; \
	done
	dh_install

ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
	extension_path=debian/gnome-shell-extension-ubuntu-tiling-assistant/usr/share/gnome-shell/extensions; \
	mv $(EXTENSION_UUID)/metadata.json \
	  $$extension_path/$(EXTENSION_UUID)/metadata.json
endif

override_dh_clean:
	dh_clean

ifeq ($(shell dpkg-vendor --derives-from Ubuntu && echo yes),yes)
	rm -rf $(EXTENSION_UUID)
endif

override_dh_gnome_clean:
