[Techtalk] Loop/wildcard-like syntax for GNU make?
Akkana Peck
akkana at shallowsky.com
Wed Apr 18 02:40:07 UTC 2007
Kelly Jones writes:
> Here's a Makefile that converts 3 GIFs to JPGs in a given directory:
Seems like a script or shell alias would be a better solution than a
Makefile, but I'll assume that this is part of some larger process
that needs to use make.
> 1.jpg: 1.gif
> /usr/local/bin/convert 1.gif 1.jpg
> 2.jpg: 2.gif
> /usr/local/bin/convert 2.gif 2.jpg
> 3.jpg: 3.gif
> /usr/local/bin/convert 3.gif 3.jpg
>
> How do I generalize this to apply to ALL the GIFs in a given
> directory? I tried:
>
> *.jpg: *.gif
> /usr/bin/local/bin/convert $1.gif $1.jpg
>
> but this obviously doesn't work (I didn't really expect it to). Neither does
>
> for $i (*.jpg) {
> $i.jpg: $i.gif
> /usr/bin/local/bin/convert $i.gif $i.jpg
> }
You could try something like this (disclaimer: I haven't tested it):
JPEGS = $(wildcard *.jpg)
GIFS = $(subst .jpg,.gif,$(JPEGS))
.jpg.gif:
/usr/bin/local/bin/convert $@ $<
all: $(GIFS)
You'll probably need to tweak that a bit. You can learn more about
making rules like .jpg.gif here:
http://www.gnu.org/software/make/manual/html_node/Suffix-Rules.html#Suffix-Rules
and the other bits (wildcard and subst) are also discussed in that
manual.
--
...Akkana
"Beginning GIMP: From Novice to Professional": http://gimpbook.com
More information about the Techtalk
mailing list