views:

33

answers:

2

I am writing a Makefile, and I want to use a generic rule with wildcards, like

%: bkp/%
    cp $< $@

But I wanted this rule to be valid only for a few specific files. I wanted to define a variable with the list, for example

file_list = foo.c bar.c zzz.c

and configure the rule so it is only valid for files that are listed in this variable. How do I do that?

+1  A: 

You want a static pattern rule:

file_list = foo.c bar.c zzz.c

$(file_list): %: bkp/%
        cp $< $@

The syntax is very similar to the implicit pattern rule you were using. And yes, it's generally safer (more predictable).

j_random_hacker
+1  A: 

Of course, 5 minutes later I found the answer myself... :)

What we need is a static pattern rule.

http://www.gnu.org/software/make/manual/make.html#Static-Pattern

So the example would be solved with

$(file_list) : % : bkp/%
    cp $< $@
dividebyzero
`file_list` -> `$(file_list)` and I'll +1.
j_random_hacker
Oops! Thanks! :)
dividebyzero