Create rule in makefile for just a set of files

牧云@^-^@ 提交于 2019-12-18 03:06:06

问题


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:


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).




回答2:


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 $< $@


来源:https://stackoverflow.com/questions/3878383/create-rule-in-makefile-for-just-a-set-of-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!