[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Matching subdirectories in patterns?
From: |
CHEN Cheng |
Subject: |
Re: Matching subdirectories in patterns? |
Date: |
Thu, 24 Sep 2009 09:25:53 +0800 |
User-agent: |
Mutt/1.5.17 (2007-11-01) |
On Wed, Sep 23, 2009 at 11:44:49AM -0500, Roy Stogner wrote:
>
> I'm writing a Makefile for use in building LaTeX documents generated
> by other users. For use with pdflatex, some format conversion of
> figures is necessary. Because the Makefile is intended for reuse in
> many different projects, figure names are not known in advance for
> generating target names.
>
> Creating targets which turn a flat directory "rawfigs/" full of source
> figures into a directory "figs/" full of converted results isn't too
> complicated. The solution I'm using (or rather, the hack I'm using,
> since I don't care that it will break for filenames containing
> spaces):
>
> vectorsources := $(shell find rawfigs/ ../common/rawfigs/ -name '*.dia' -o
> -name '*.eps' -o -name '*.ps' -o -name '*.pdf')
> vectorfigs := $(shell echo ' ' $(vectorsources) ' ' | sed -e 's>
> \(../common/\)*raw> >g' -e 's/\.[^. ]* /.pdf /g')
>
> This generates a list vectorfigs which, for each source image, creates
> a target pdf image with the same filename in a different directory. A
> set of pattern rules then tells make how to build those targets, e.g.:
>
> figs/%.pdf: rawfigs/%.eps
> mkdir -p $(dir $@)
> epstopdf $? -o=$@
>
>
> However, this doesn't work when rawfigs/ isn't a flat directory. If a
> user has rawfigs/subdir1/fig.eps, the target figs/subdir1/fig.pdf is
> correctly added to the vectorfigs list, but when asked to generate it,
> make dies with a "no rule to make target" error. It appears that the
> pattern character % doesn't match the directory separator character /
> in a target.
>
> Does anyone have any suggestions? Is there a way to create a pattern
> rule (or a patterned vpath directive, perhaps) where the pattern
> matches subdirectories?
IIUC, a generic pattern rule may help:
all : vpath/subdir/test.o
%.o : %.c
mkdir -p $(dir $(subst vpath,vpath.new,$@))
gcc -c -o $(subst vpath,vpath.new,$@) $<
HTH,
Cheng