VPATH=../../sources/vector
-SVGS=$(shell find $(VPATH) -name "*.svg")
-PNGS=$(patsubst $(VPATH)/%.svg, %.png, $(SVGS))
-ROACH=$(filter roach/%, $(PNGS))
+TILE_DIRS=roach
+TILE_SVGS=$(shell find $(patsubst %, $(VPATH)/%, $(TILE_DIRS)) -name "*.svg")
+TILE_PNGS=$(patsubst $(VPATH)/%.svg, %.png, $(TILE_SVGS))
+ROACH=$(filter roach/%, $(TILE_PNGS))
ROACH_32=$(patsubst roach/%, roach_32/%, $(ROACH))
ROACH_21=$(patsubst roach/%, roach_21/%, $(ROACH))
ROACH_QUARTET=$(patsubst roach/%, roach_quartet/%, $(ROACH))
ROACH_NONET=$(patsubst roach/%, roach_nonet/%, $(ROACH))
-all: $(PNGS) $(ROACH_32) $(ROACH_21) $(ROACH_QUARTET) $(ROACH_NONET)
+all: $(TILE_PNGS) $(ROACH_32) $(ROACH_21) $(ROACH_QUARTET) $(ROACH_NONET)
-# Default rule
+# Tile rules
-%.png: %.svg
- @mkdir -p `dirname $@`
- @inkscape -z -e $@ -w 64 -h 64 $<
+define tile
+$(1)/%.png: $(1)/%.svg
+ @mkdir -p `dirname $$@`
+ @inkscape -z -e $$@ -w 64 -h 64 $$<
+endef
+
+$(foreach tiledir,$(TILE_DIRS),$(eval $(call tile,$(tiledir))))
# Smaller roaches
# Roach quartet
-roach_quartet/roach_%.png: roach_32/roach_*.png
+roach_quartet/roach_%.png: $(foreach i, 1 2 3 4, roach_32/roach_$(i).png)
@mkdir -p roach_quartet
@montage $(foreach i, -1 0 1 2 , roach_32/roach_$$(( ( $(i) + $(patsubst roach_quartet/roach_%.png,%, $@) ) % 4 + 1 )).png) -geometry +0+0 -background none $@
-roach_quartet/eyes_%.png: roach_32/eyes_*.png
+roach_quartet/eyes_%.png: $(foreach i, 1 2 3 4, roach_32/eyes_$(i).png)
@mkdir -p roach_quartet
@montage $(foreach i, -1 0 1 2 , roach_32/eyes_$$(( ( $(i) + $(patsubst roach_quartet/eyes_%.png,%, $@) ) % 4 + 1 )).png) -geometry +0+0 -background none $@
# Roach nonet
-roach_nonet/roach_%.png: roach_21/roach_*.png
+roach_nonet/roach_%.png: $(foreach i, 1 2 3 4, roach_21/roach_$(i).png)
@mkdir -p roach_nonet
@montage $(foreach i, -1 0 1 2 3 4 5 6 7 , roach_21/roach_$$(( ( $(i) + $(patsubst roach_nonet/roach_%.png,%, $@) ) % 4 + 1 )).png) -geometry +0+0 -background none - | convert - -background none -gravity southeast -splice 1x1 $@
-roach_nonet/eyes_%.png: roach_21/eyes_*.png
+roach_nonet/eyes_%.png: $(foreach i, 1 2 3 4, roach_21/eyes_$(i).png)
@mkdir -p roach_nonet
@montage $(foreach i, -1 0 1 2 3 4 5 6 7 , roach_21/eyes_$$(( ( $(i) + $(patsubst roach_nonet/eyes_%.png,%, $@) ) % 4 + 1 )).png) -geometry +0+0 -background none - | convert - -background none -gravity southeast -splice 1x1 $@