是否可以匹配 make 文件中的集?
我有一个 make 文件,它使用模式匹配来使用如下规则自动编译:
%.o : %.c
gcc -c $<
但是,在这个项目中,我有许多源文件,它们的扩展名不同。有没有办法像正则表达式一样匹配 make 文件中的集合。
伪示例:
%.o : %.[cC]
gcc -c $<
不可能简单地更改源文件的大小写,因为它用于混合来自其他几个模块的现有项目的模块测试。
I have a make file that uses pattern matching to automate compilation using a rule like this:
%.o : %.c
gcc -c lt;
However in this project I have a number of source files which differ in case of their extension. Is there a way to match sets in make files like in regular expressions.
Pseudo-example:
%.o : %.[cC]
gcc -c lt;
It is not possible to simply change the case of the source files as this is used for module testing of an existing project which mixes modules from several other.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我找到了解决方案。事实证明,makefile 有几个问题。
首先,我发布的示例实际上正如班塔尔指出的那样起作用。但是我的问题是我的源文件不在根目录中,而是在我添加到 vpath 的 src/ 子目录中。老实说,我认为这与我的问题无关,因为我相信 make 会自动扫描其 vpath 来查找源文件。结果 vpath 不适用于规则检查。
为了使其工作,请执行以下操作:
接下来,当我正在研究如何完成它的示例时, make 有时会在我背后构建源文件。如果您这样做:
...并且没有构建 .o 文件的规则,则 make 将使用隐式 inbuild 规则构建它。相当混乱。可以使用 -r 标志禁用它。
第三次使用 gcc 编译 .C 文件而不使用任何额外选项将导致链接器错误,因为 gcc 默认将 .C 文件解释为 C++ 文件。为了编译为 C 文件,请使用 -x 标志。
希望这对某人有帮助。
I found the solution. It turns out that the makefile had several issues.
First the example I posted actually works as Banthar pointed out. However my problem was that my sourcefiles weren't in the root directory but in a src/ subdirectory which I had added to vpath. I honestly thought it was irrelevant to my question as I believed make would automatically scan its vpath for source files. Turns out vpath does not apply to rule checking.
To make it work do:
Next as I was working through examples of how to get it done make would sometimes build sourcefiles behind my back. If you do:
... and not have rule to build the .o file make will build it using implicit inbuild rules. Quite confusing. It can be disabled using the -r flag.
Third compiling .C files using gcc without any extra options will result in linker errors because gcc interprets .C files as C++ files as default. In order to compiles as C files use -x flag.
Hope this helps someone.
我能看到的最简单的选择就是简单地链接不匹配的情况:
然后让规则链接完成其余的工作。
The easiest option I can see is simply to link non-matching cases:
and let rule chaining do the rest.