#!/usr/bin/make -f
include /usr/share/gnome-pkg-tools/1/rules/uploaders.mk
-include /usr/share/gnome-pkg-tools/1/rules/gnome-get-source.mk

GS_CONFIGURE_FLAGS = --libdir=/usr/lib \
		--disable-silent-rules

DISTRO_ID = debian
ifeq (yes,$(shell dpkg-vendor --derives-from Ubuntu && echo yes))
	DISTRO_ID = ubuntu
else ifeq (yes,$(shell dpkg-vendor --derives-from Tanglu && echo yes))
	DISTRO_ID = tanglu
endif

# Install target dir
INSTALLDIR = $(CURDIR)/debian/tmp

%:
	dh $@ --with gnome,autoreconf

override_dh_auto_configure:
	dh_auto_configure -- $(GS_CONFIGURE_FLAGS)

override_dh_auto_build:
	cp debian/ubuntu-one.png src/plugins
	dh_auto_build

override_dh_auto_install:
	dh_auto_install --destdir=$(INSTALLDIR)
	rm -f $(INSTALLDIR)/usr/lib/gs-plugins-*/libgs_plugin_fedora*

override_dh_installgsettings:
	sed 's/@DISTRO@/$(DISTRO_ID)/g' debian/gnome-software.gsettings-override.in > debian/gnome-software.gsettings-override
	dh_installgsettings

override_dh_install:
	rm -f debian/tmp/usr/lib/gs-plugins-*/*.a
	rm -f debian/tmp/usr/lib/gs-plugins-*/*.la
	dh_install --list-missing
	# Change the name and icon for Unity sessions
	sed -i 's/Name=Software/Name=Ubuntu Software/' debian/ubuntu-software/usr/share/ubuntu/applications/org.gnome.Software.desktop
	sed -i 's/Icon=org.gnome.Software/Icon=ubuntusoftware/' debian/ubuntu-software/usr/share/ubuntu/applications/org.gnome.Software.desktop

# Hack to include some translations, we can drop that once we get a langpack update
# Includes the strings from the locales that have translations on launchpad but
# de/it/pt are not needed because their translation is the original english string
override_dh_translations:
	dh_translations
	echo "Name[es]=Software de Ubuntu" >> debian/ubuntu-software/usr/share/ubuntu/applications/org.gnome.Software.desktop
	echo "Name[fr]=Logiciels Ubuntu" >> debian/ubuntu-software/usr/share/ubuntu/applications/org.gnome.Software.desktop
	echo "Name[zh_CN]=Ubuntu 软件" >> debian/ubuntu-software/usr/share/ubuntu/applications/org.gnome.Software.desktop

override_dh_makeshlibs:
	dh_makeshlibs -Xlibgs_plugin

override_dh_auto_test:
	# DISABLED

override_dh_clean:
	rm -f debian/gnome-software.gsettings-override
	dh_clean
