help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Replacing characters in a pattern rule


From: John Graham-Cumming
Subject: Re: Replacing characters in a pattern rule
Date: Wed, 07 Sep 2005 14:33:46 +0200
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.6) Gecko/20040208 Thunderbird/0.5 Mnenhy/0.6.0.104

natch wrote:
I have a list of directories (discovered automatically, but explicitly defined for this example):

DIRECTORIES := a b c

Some of these directories have index.html files in them. I wish to copy these into the local directory as

DIRECTORY_index.html

The straight forward solution is

INDEX_HTML_FILES := $(DIRECTORIES:%=%_index.html)

$(INDEX_HTML_FILES): %_index.html : %/index.html
   cp $< $@

Now, this words great for immediate subdirectories. However, I want this to work recursively, for example:

DIRECTORIES := a b c group/d group/e

I need both directory names in the file name, such as:

group_d_index.html    group_e_index.html

I can easily alter the copy command to be

   cp $< $(subst /,_,$@)

but I can't figure out how to generate the list of [ group_d_index.html group_e_index.html] files as a prerequisite. If I try and use the pattern expansion with a substitute command:

INDEX_HTML_FILES := $(subst /,_,$(DIRECTORIES:%=%_index.html))

Sounds like a great place to use $(eval).  You could do the following:

    DIRECTORIES := a b c group/d group/e

    define copier
    $(subst /,_,$1): $1 ; cp $$< $$@
    endef

    $(foreach d,$(DIRECTORIES),$(eval $(call copier,$d/index.html)))

John.
--
John Graham-Cumming
address@hidden

Home: http://www.jgc.org/
POPFile: http://getpopfile.org/

Sign up for my Spam and Anti-spam Newsletter
at http://www.jgc.org/

PGP key: http://www.jgc.org/pgp/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]