XMLS = xmlstarlet ed -P -N svg=http://www.w3.org/2000/svg
LAYER_ON = -u //*/svg:g[@inkscape:label=\"$(1)\"]/@style -v display:inline
LAYER_OFF = -u //*/svg:g[@inkscape:label=\"$(1)\"]/@style -v display:none
S2P = inkscape --without-gui
SIZE = --export-width=$(1) --export-height=$(2)
#S2P = imagemagick -background none
#SIZE = -resize $(1)x$(2)

TMP = tmp
RES = res

DIR = $(TMP) $(RES) $(RES)/drawable $(RES)/drawable-ldpi \
    	$(RES)/drawable-mdpi $(RES)/drawable-hdpi $(RES)/drawable-xhdpi

png = bingo.png  box.png  floor.png  goal.png   splash.png  \
	    wall.png  worker.png  worker_select.png

pngx = icon.png  icon_debug.png  next.png  prev.png  reset.png  undo.png \
	   lock.png unlock.png unlocking.png

all:  $(DIR)\
	$(addprefix $(RES)/drawable/,$(png)) \
	$(addprefix $(RES)/drawable-ldpi/,$(pngx)) \
	$(addprefix $(RES)/drawable-mdpi/,$(pngx)) \
	$(addprefix $(RES)/drawable-hdpi/,$(pngx)) \
	$(addprefix $(RES)/drawable-xhdpi/,$(pngx))

$(DIR) :
	mkdir -p $@

$(RES)/drawable/%.png : $(TMP)/%.svg
	$(S2P) --export-png=$@ --file=$<

$(RES)/drawable-ldpi/%.png : $(TMP)/%.svg
	$(S2P) $(call SIZE,36,36) --export-png=$@ --file=$< 

$(RES)/drawable-mdpi/%.png : $(TMP)/%.svg
	$(S2P) $(call SIZE,48,48) --export-png=$@ --file=$<

$(RES)/drawable-hdpi/%.png : $(TMP)/%.svg
	$(S2P) $(call SIZE,72,72) --export-png=$@ --file=$<

$(RES)/drawable-xhdpi/%.png : $(TMP)/%.svg
	$(S2P) $(call SIZE,96,96) --export-png=$@ --file=$<

$(TMP)/%.svg : %.svg
	cp $< $@

$(TMP)/icon.svg : icon.svg
	$(XMLS) $(call LAYER_OFF,"Debug") $< > $@

$(TMP)/icon_debug.svg : icon.svg
	$(XMLS) $(call LAYER_ON,"Debug") $< > $@

$(TMP)/worker.svg : worker.svg
	$(XMLS) $(call LAYER_OFF,"Hands") $< > $@

$(TMP)/worker_select.svg : worker.svg
	$(XMLS) $(call LAYER_ON,"Hands") $< > $@

$(TMP)/floor.svg : floor.svg
	$(XMLS) $(call LAYER_OFF,"Goal") $< > $@

$(TMP)/goal.svg : floor.svg
	$(XMLS) $(call LAYER_ON,"Goal") $< > $@

$(TMP)/lock.svg : lock.svg
	$(XMLS) $(call LAYER_ON,"lock") $< > $@

$(TMP)/unlock.svg : lock.svg
	$(XMLS) $(call LAYER_ON,"unlock") $< > $@

$(TMP)/unlocking.svg : lock.svg
	$(XMLS) $(call LAYER_ON,"unlocking") $< > $@

$(TMP)/prev.svg : buttons.svg
	$(XMLS) $(call LAYER_ON,"Prev Smooth") $< > $@

$(TMP)/next.svg : buttons.svg
	$(XMLS) $(call LAYER_ON,"Next Smooth") $< > $@

$(TMP)/reset.svg : buttons.svg
	$(XMLS) $(call LAYER_ON,"Reset Smooth") $< > $@

$(TMP)/undo.svg : buttons.svg
	$(XMLS) $(call LAYER_ON,"Undo Smooth") $< > $@



#		def cfg = 'imagemagick -background none -resize '+w+'x'+h+' - ' + png
#		def sizes = [ 'ldpi':[36,36],
#					  'mdpi':[48,48],
#					  'hdpi':[72,72],
#					 'xhdpi':[96,96] ]

#		def sizes2= [ 'ldpi':[22,36],
#					  'mdpi':[29,48],
#					  'hdpi':[43,72],
#					 'xhdpi':[58,96] ]
		
