#!/usr/bin/make -f
# -*- makefile -*-  
# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1

export INSTALL_PREFIX  = /usr
export INSTALL_DESTDIR = /debian/gis-weather$(INSTALL_PREFIX)

%:
	dh $@ --with python3 --buildsystem=pybuild

override_dh_auto_install:
	install -dm 0755 $(CURDIR)$(INSTALL_DESTDIR)/bin/
	echo '#!/bin/sh\nexec python3 /usr/share/gis-weather/gis-weather.py' > $(CURDIR)$(INSTALL_DESTDIR)/bin/gis-weather
	install -dm 0755 $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/
	echo deb > $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/package
	cp $(CURDIR)/gis-weather.py $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/
	cp $(CURDIR)/icon.png $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/
	cp -a $(CURDIR)/dialogs $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/
	cp -a $(CURDIR)/i18n $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/
	cp -a $(CURDIR)/services $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/
	cp -a $(CURDIR)/themes $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/
	cp -a $(CURDIR)/utils $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/
	grep -rl '^#!/' $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/ | xargs chmod 0755
	grep -rl '^#!/' $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/ | xargs sed -i '/^#!/s/env.*py.*/python3/'
	dos2unix -v -o $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/dialogs/settings_dialog.py
	find $(CURDIR)$(INSTALL_DESTDIR)/share/gis-weather/themes -type f -perm 0755 -print -exec chmod 0644 {} \;
	install -dm 0755 $(CURDIR)$(INSTALL_DESTDIR)/share/applications/
	echo '[Desktop Entry]\nName=Gis Weather\nComment=Weather widget\nCategories=GNOME;Utility;\nExec=gis-weather\nIcon=gis-weather\nTerminal=false\nType=Application' > $(CURDIR)$(INSTALL_DESTDIR)/share/applications/gis-weather.desktop
	install -Dm 0755 $(CURDIR)/icon.png $(CURDIR)$(INSTALL_DESTDIR)/share/pixmaps/gis-weather.png

override_dh_missing:
	dh_missing --fail-missing
