#!/usr/bin/make -f
%:
ifneq ($(shell dh -l | grep -xF translations),)
	dh $@ --with python2,translations
else
	dh $@ --with python2
endif

override_dh_auto_install:
	dh_auto_install -- --install-scripts=/opt/extras.ubuntu.com/easy-stopwatch/bin                 --install-data=/opt/extras.ubuntu.com/easy-stopwatch                 --install-lib=/opt/extras.ubuntu.com/easy-stopwatch

override_dh_python2:
	dh_python2 /opt/extras.ubuntu.com/easy-stopwatch


override_dh_install:
	dh_install
	mkdir -p debian/easy-stopwatch/opt/extras.ubuntu.com/easy-stopwatch/bin
	if [ -x debian/easy-stopwatch/opt/extras.ubuntu.com/easy-stopwatch/easy-stopwatch ]; then mv debian/easy-stopwatch/opt/extras.ubuntu.com/easy-stopwatch/easy-stopwatch debian/easy-stopwatch/opt/extras.ubuntu.com/easy-stopwatch/bin; fi
	if [ -f debian/easy-stopwatch/opt/extras.ubuntu.com/easy-stopwatch/share/applications/easy-stopwatch.desktop ]; then \
		mkdir -p debian/easy-stopwatch/usr/share/applications; \
		mv debian/easy-stopwatch/opt/extras.ubuntu.com/easy-stopwatch/share/applications/easy-stopwatch.desktop debian/easy-stopwatch/usr/share/applications/extras-easy-stopwatch.desktop; \
		rmdir --ignore-fail-on-non-empty debian/easy-stopwatch/opt/extras.ubuntu.com/easy-stopwatch/share/applications; \
		sed -i 's|Exec=[^ ]*|Exec=/opt/extras.ubuntu.com/easy-stopwatch/bin/easy-stopwatch|' debian/easy-stopwatch/usr/share/applications/extras-easy-stopwatch.desktop; \
		sed -i 's|Icon=/usr/|Icon=/opt/extras.ubuntu.com/easy-stopwatch/|' debian/easy-stopwatch/usr/share/applications/extras-easy-stopwatch.desktop; \
	fi
	grep -RlZ 'import gettext' debian/easy-stopwatch/* | xargs -0 -r sed -i 's|\(import\) gettext$$|\1 locale|'
	grep -RlZ 'from gettext import gettext as _' debian/easy-stopwatch/* | xargs -0 -r sed -i 's|from gettext \(import gettext as _\)|from locale \1|'
	grep -RlZ "gettext.textdomain('easy-stopwatch')" debian/easy-stopwatch/* | xargs -0 -r sed -i "s|gettext\(\.textdomain('easy-stopwatch')\)|locale\.bindtextdomain('easy-stopwatch', '/opt/extras.ubuntu.com/easy-stopwatch/share/locale')\nlocale\1|" 
	sed -i "s|__easy_stopwatch_data_directory__ =.*|__easy_stopwatch_data_directory__ = '/opt/extras.ubuntu.com/easy-stopwatch/share/easy-stopwatch/'|" debian/easy-stopwatch/opt/extras.ubuntu.com/easy-stopwatch/easy_stopwatch*/easy_stopwatchconfig.py
	sed -i 's|        sys.path.insert(0, opt_path)|\0\n    os.putenv("XDG_DATA_DIRS", "%s:%s" % ("/opt/extras.ubuntu.com/easy-stopwatch/share/", os.getenv("XDG_DATA_DIRS", "")))|' debian/easy-stopwatch/opt/extras.ubuntu.com/easy-stopwatch/bin/easy-stopwatch
	if [ -d debian/easy-stopwatch/opt/extras.ubuntu.com/easy-stopwatch/share/glib-2.0/schemas ]; then glib-compile-schemas debian/easy-stopwatch/opt/extras.ubuntu.com/easy-stopwatch/share/glib-2.0/schemas; fi