Create rule in makefile for just a set of files
Question
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?
Solution
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).
OTHER TIPS
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 $< $@
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow