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: natch
Subject: Re: Replacing characters in a pattern rule
Date: Wed, 07 Sep 2005 14:14:33 -0400
User-agent: Mozilla Thunderbird 1.0.6 (Windows/20050716)

John Graham-Cumming wrote:

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.

That solution looks beautiful. Unfortunately, I'm forced to use Make 3.79.1 which doesn't understand eval. Any other suggestions?

-
natc





reply via email to

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