#!/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/unity-launcher-toggle                 --install-data=/opt/extras.ubuntu.com/unity-launcher-toggle                 --install-lib=/opt/extras.ubuntu.com/unity-launcher-toggle

override_dh_python2:
	dh_python2 /opt/extras.ubuntu.com/unity-launcher-toggle


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