#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/gnome-pkg-tools/1/rules/uploaders.mk

DEB_COMPRESS_EXCLUDE := copyright

THEMES := $(shell ls icons)

binary-install/gnome-themes-extras::
	IUTIL=$$(pkg-config --variable=program_path icon-naming-utils)/icon-name-mapping ; \
	  cd $(CURDIR)/debian/gnome-themes-extras/usr/share/icons/ && \
	  for theme in $(THEMES); do \
	    cd $$theme && \
	    for size in */; do \
	      cd $$size && \
	      for context in actions animations apps categories devices emblems mimetypes places status; do \
	        test -d $$context && \
	        $$IUTIL -c $$context ; \
	      done ; \
	      cd .. ; \
	    done ; \
	    cd .. ; \
	  done

updatepo:
	podir=$$(mktemp -d) && \
		svn co svn://svn.gnome.org/svn/gnome-themes-extras/trunk/po $$podir && \
		rm -f po/*.po && \
		mv $$podir/*.po po/ && \
		rm -rf $$podir

build: $(THEMES:%=icons/%/index.theme) $(THEMES:%=themes/%/index.theme) debian/postinst debian/prerm

icons/%/index.theme: themefiles/%.icons
	intltool-merge -d po $< $@
themes/%/index.theme: themefiles/%.theme
	intltool-merge -d po $< $@
debian/%: debian/%.in
	sed 's/@THEMES@/$(THEMES)/' $< > $@

clean-icons:
# Eliminate all Illustrator nonstandard stuff
	find icons -type f -name \*.svg -exec perl -pi -e \
	 's/adobe-blending-mode:[a-z]+\;//;s/xmlns:graph="&ns_graphs;"//;undef $$/;s/\<a:midPointStop.*?\/\>//sg;s/\<midPointStop.*?\/\>//sg' \{} \;

clean::
# Clean generated index.theme files
	rm -f icons/*/index.theme themes/*/index.theme debian/postinst debian/prerm

