在 makefile 中为一组文件创建规则

发布于 2024-09-27 02:11:13 字数 210 浏览 1 评论 0原文

我正在编写一个 Makefile,并且我想使用带有通配符的通用规则,例如

%: bkp/%
    cp $< $@

但我希望此规则仅对一些特定文件有效。我想用列表定义一个变量,例如

file_list = foo.c bar.c zzz.c

并配置规则,使其仅对该变量中列出的文件有效。我该怎么做?

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

%: bkp/%
    cp 
lt; $@

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别挽留 2024-10-04 02:11:13

你想要一个静态模式规则

file_list = foo.c bar.c zzz.c

$(file_list): %: bkp/%
        cp 
lt; $@

语法非常类似于您使用的隐式模式规则。是的,它通常更安全(更可预测)。

You want a static pattern rule:

file_list = foo.c bar.c zzz.c

$(file_list): %: bkp/%
        cp 
lt; $@

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

悲欢浪云 2024-10-04 02:11:13

当然,5分钟后我自己找到了答案...:)

我们需要的是静态模式规则。

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

所以这个例子可以用以下方法解决

$(file_list) : % : bkp/%
    cp 
lt; $@

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 
lt; $@
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文