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.