NULL =

private_icons_themes = \
	hicolor	\
	$(NULL)

private_icons = \
	hicolor_apps_16x16_im-aim.png \
	hicolor_apps_16x16_im-ekiga.png \
	hicolor_apps_16x16_im-facebook.png \
	hicolor_apps_16x16_im-gizmo.png \
	hicolor_apps_16x16_im-google-talk.png \
	hicolor_apps_16x16_im-icq.png \
	hicolor_apps_16x16_im-irc.png \
	hicolor_apps_16x16_im-jabber.png \
	hicolor_apps_16x16_im-msn.png \
	hicolor_apps_16x16_im-silc.png \
	hicolor_apps_16x16_im-sip.png \
	hicolor_apps_16x16_im-local-xmpp.png \
	hicolor_apps_16x16_im-gadugadu.png \
	hicolor_apps_16x16_im-groupwise.png \
	hicolor_apps_16x16_im-qq.png \
	hicolor_apps_16x16_im-meanwhile.png \
	hicolor_apps_16x16_im-mxit.png \
	hicolor_apps_16x16_im-myspace.png \
	hicolor_apps_16x16_im-sametime.png \
	hicolor_apps_16x16_im-skype.png \
	hicolor_apps_16x16_im-yahoo.png \
	hicolor_apps_16x16_im-zephyr.png \
	hicolor_apps_22x22_im-aim.png \
	hicolor_apps_22x22_im-ekiga.png \
	hicolor_apps_22x22_im-facebook.png \
	hicolor_apps_22x22_im-gizmo.png \
	hicolor_apps_22x22_im-google-talk.png \
	hicolor_apps_22x22_im-icq.png \
	hicolor_apps_22x22_im-irc.png \
	hicolor_apps_22x22_im-jabber.png \
	hicolor_apps_22x22_im-msn.png \
	hicolor_apps_22x22_im-silc.png \
	hicolor_apps_22x22_im-sip.png \
	hicolor_apps_22x22_im-local-xmpp.png \
	hicolor_apps_22x22_im-gadugadu.png \
	hicolor_apps_22x22_im-groupwise.png \
	hicolor_apps_22x22_im-qq.png \
	hicolor_apps_22x22_im-meanwhile.png \
	hicolor_apps_22x22_im-mxit.png \
	hicolor_apps_22x22_im-myspace.png \
	hicolor_apps_22x22_im-sametime.png \
	hicolor_apps_22x22_im-skype.png \
	hicolor_apps_22x22_im-yahoo.png \
	hicolor_apps_22x22_im-zephyr.png \
	hicolor_apps_24x24_im-aim.png \
	hicolor_apps_24x24_im-ekiga.png \
	hicolor_apps_24x24_im-gizmo.png \
	hicolor_apps_24x24_im-google-talk.png \
	hicolor_apps_24x24_im-icq.png \
	hicolor_apps_24x24_im-irc.png \
	hicolor_apps_24x24_im-jabber.png \
	hicolor_apps_24x24_im-msn.png \
	hicolor_apps_24x24_im-silc.png \
	hicolor_apps_24x24_im-sip.png \
	hicolor_apps_24x24_im-local-xmpp.png \
	hicolor_apps_24x24_im-gadugadu.png \
	hicolor_apps_24x24_im-groupwise.png \
	hicolor_apps_24x24_im-qq.png \
	hicolor_apps_24x24_im-meanwhile.png \
	hicolor_apps_24x24_im-mxit.png \
	hicolor_apps_24x24_im-myspace.png \
	hicolor_apps_24x24_im-sametime.png \
	hicolor_apps_24x24_im-yahoo.png \
	hicolor_apps_24x24_im-zephyr.png \
	hicolor_apps_32x32_im-aim.png \
	hicolor_apps_32x32_im-ekiga.png \
	hicolor_apps_32x32_im-gizmo.png \
	hicolor_apps_32x32_im-google-talk.png \
	hicolor_apps_32x32_im-icq.png \
	hicolor_apps_32x32_im-irc.png \
	hicolor_apps_32x32_im-jabber.png \
	hicolor_apps_32x32_im-msn.png \
	hicolor_apps_32x32_im-silc.png \
	hicolor_apps_32x32_im-sip.png \
	hicolor_apps_32x32_im-local-xmpp.png \
	hicolor_apps_32x32_im-gadugadu.png \
	hicolor_apps_32x32_im-groupwise.png \
	hicolor_apps_32x32_im-qq.png \
	hicolor_apps_32x32_im-meanwhile.png \
	hicolor_apps_32x32_im-mxit.png \
	hicolor_apps_32x32_im-myspace.png \
	hicolor_apps_32x32_im-sametime.png \
	hicolor_apps_32x32_im-yahoo.png \
	hicolor_apps_32x32_im-zephyr.png \
	hicolor_apps_48x48_im-aim.png \
	hicolor_apps_48x48_im-ekiga.png \
	hicolor_apps_48x48_im-facebook.png \
	hicolor_apps_48x48_im-gizmo.png \
	hicolor_apps_48x48_im-google-talk.png \
	hicolor_apps_48x48_im-icq.png \
	hicolor_apps_48x48_im-irc.png \
	hicolor_apps_48x48_im-jabber.png \
	hicolor_apps_48x48_im-msn.png \
	hicolor_apps_48x48_im-silc.png \
	hicolor_apps_48x48_im-sip.png \
	hicolor_apps_48x48_im-local-xmpp.png \
	hicolor_apps_48x48_im-gadugadu.png \
	hicolor_apps_48x48_im-groupwise.png \
	hicolor_apps_48x48_im-qq.png \
	hicolor_apps_48x48_im-meanwhile.png \
	hicolor_apps_48x48_im-mxit.png \
	hicolor_apps_48x48_im-myspace.png \
	hicolor_apps_48x48_im-sametime.png \
	hicolor_apps_48x48_im-skype.png \
	hicolor_apps_48x48_im-yahoo.png \
	hicolor_apps_48x48_im-zephyr.png \
	hicolor_apps_scalable_im-aim.svg \
	hicolor_apps_scalable_im-ekiga.svg \
	hicolor_apps_scalable_im-gizmo.svg \
	hicolor_apps_scalable_im-google-talk.svg \
	hicolor_apps_scalable_im-icq.svg \
	hicolor_apps_scalable_im-irc.svg \
	hicolor_apps_scalable_im-jabber.svg \
	hicolor_apps_scalable_im-msn.svg \
	hicolor_apps_scalable_im-silc.svg \
	hicolor_apps_scalable_im-sip.svg \
	hicolor_apps_scalable_im-local-xmpp.svg \
	hicolor_apps_scalable_im-gadugadu.svg \
	hicolor_apps_scalable_im-groupwise.svg \
	hicolor_apps_scalable_im-qq.svg \
	hicolor_apps_scalable_im-meanwhile.svg \
	hicolor_apps_scalable_im-mxit.svg \
	hicolor_apps_scalable_im-myspace.svg \
	hicolor_apps_scalable_im-sametime.svg \
	hicolor_apps_scalable_im-yahoo.svg \
	hicolor_apps_scalable_im-zephyr.svg \
	$(NULL)

EXTRA_DIST = \
	$(private_icons)	\
	local-xmpp.svg		\
	$(NULL)

include $(srcdir)/utils.mk

###############################################################################

gtk_update_icon_cache = gtk-update-icon-cache -f -t

update-icon-cache:
	@-if test -z "$(DESTDIR)"; then \
		echo "Updating Gtk icon cache."; \
		for theme in $(private_icons_themes); do \
			$(gtk_update_icon_cache) $(icondir)/$$theme; \
		done; \
	else \
		echo "*** Icon cache not updated.  After (un)install, run this:"; \
		for theme in $(private_icons_themes); do \
			echo "***   $(gtk_update_icon_cache) $(icondir)/$$theme"; \
		done; \
	fi

install-icons:
	for icon in $(private_icons); do \
		THEME=`echo $$icon | cut -d_ -f1`; \
		CONTEXT=`echo $$icon | cut -d_ -f2`; \
		SIZE=`echo $$icon | cut -d_ -f3`; \
		ICONFILE=`echo $$icon | cut -d_ -f4`; \
		mkdir -p $(DESTDIR)$(icondir)/$$THEME/$$SIZE/$$CONTEXT; \
		$(INSTALL_DATA) $(srcdir)/$$icon $(DESTDIR)$(icondir)/$$THEME/$$SIZE/$$CONTEXT/$$ICONFILE; \
	done

uninstall-icons:
	for icon in $(private_icons); do \
		THEME=`echo $$icon | cut -d_ -f1`; \
		CONTEXT=`echo $$icon | cut -d_ -f2`; \
		SIZE=`echo $$icon | cut -d_ -f3`; \
		ICONFILE=`echo $$icon | cut -d_ -f4`; \
		rm -f $(DESTDIR)$(icondir)/$$THEME/$$SIZE/$$CONTEXT/$$ICONFILE; \
	done

install-data-local:
	$(MAKE) install-icons
	$(MAKE) update-icon-cache

uninstall-local:
	$(MAKE) uninstall-icons
	$(MAKE) update-icon-cache

# Local copy of the "installed" icon. This is used to be able to run tp-account-widgets
# from source (see bgo #616159)
local_icons_dir = local-copy

# Generate the lists of destination paths
private_icons_local_install_paths = $(foreach obj, $(private_icons), $(local_icons_dir)/$(subst _,/,$(call reorder,_,1 3 2 4,$(obj))))

# For each destination path we'll need to compute back the original icon
# and create a rule that will ensure that the destination directory exists
# and then copy the original file
define icon_local_install_rule_template
$(local_icons_dir)/$$(subst _,/,$$(call reorder,_,1 3 2 4,$1)): $1
	$$(AM_V_GEN)mkdir -p $$(@D)
	$$(AM_V_GEN)cp $$^ $$@
endef

# Instantiate the template above for each icon
$(foreach icon,$(private_icons),$(eval $(call icon_local_install_rule_template,$(icon))))

install-icons-src: $(private_icons_local_install_paths)

all: install-icons-src

clean-local:
	-rm -rf $(local_icons_dir)
