Reputation: 3494
I have the following targets in my makefile to generate icons for my Android app:
base_icon := icon-base.png
Icon-ldpi.png: $(base_icon)
convert $< -resize 36x36 -unsharp 1x4 $@
Icon-mdpi.png: $(base_icon)
convert $< -resize 48x48 -unsharp 1x4 $@
Icon-hdpi.png: $(base_icon)
convert $< -resize 72x72 -unsharp 1x4 $@
Icon-xhdpi.png: $(base_icon)
convert $< -resize 96x96 -unsharp 1x4 $@
Icon-xxhdpi.png: $(base_icon)
convert $< -resize 144x144 -unsharp 1x4 $@
Icon-xxxhdpi.png: $(base_icon)
convert $< -resize 192x192 -unsharp 1x4 $@
icons_android: \
Icon-ldpi.png \
Icon-mdpi.png \
Icon-hdpi.png \
Icon-xhdpi.png \
Icon-xxhdpi.png \
Icon-xxxhdpi.png
How can I make this more elegant without repeating the convert instructions over and over again?
What I was looking for was having some sort of a parameterized target:
Icon-%.png: $(base_icon)
convert $< -resize $(size) -unsharp 1x4 $@
But I am not certain how to lookup the $(size)
for the given icon. Is there some sorts of a map that I can define in a Makefile and lookup in the target?
Upvotes: 0
Views: 430
Reputation: 471
Try following example, although it's not perfect,
base_icon := icon-base.png
define icon_template
Icon-$(1).png: $$(base_icon)
convert $$< -resize $(2) -unsharp 1x4 $$@
icons_android: Icon-$(1).png
endef
$(eval $(call icon_template,ldpi,36x36))
$(eval $(call icon_template,mdpi,48x48))
$(eval $(call icon_template,hdpi,72x72))
Upvotes: 1