Makefile 中的目标替换
在典型的回归中,有一个“基本”类别和一个测试用例“abc.c”。要在“basic”类别中运行测试“abc”,用户必须键入:
make basic_abc
然后命令应该是:
basic_abc: abc.c
gcc -g -o abc abc.c
如何编写一条规则,将在我的 $@ 中删除“basic_”。这样我就可以在所有测试中使用该规则。 在伪语言中,如何通过模式替换得到上述规则
basic_abc: $(patsubst .*_, " ", $@).c
gcc -g -o $(patsubst .*_, " ", $@) $(patsubst .*_, " ", $@).c
In a typical regression, there is a CATEGORY which is "basic" and a test-case "abc.c". To run a test "abc" in category "basic", the user has to key in:
make basic_abc
Then the command should be:
basic_abc: abc.c
gcc -g -o abc abc.c
How can I write a rule, that WILL CHOP "basic_" in my $@. So that I can use the rule for all tests. In pseudo language, how can I get the above rule with pattern substitution
basic_abc: $(patsubst .*_, " ", $@).c
gcc -g -o $(patsubst .*_, " ", $@) $(patsubst .*_, " ", $@).c
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
你的意思是这样吗?
不过,Make 已经知道如何编译 .c 文件。从你的问题来看,
basic_x
依赖于编译的x
似乎更有意义,并在配方中的一堆测试用例上运行它,但也许我误解了你的设置。Do you mean like this?
Make already knows how to compile a .c file, though. From your question it would seem to make more sense for
basic_x
to depend on the compiledx
, and run it on a bunch of test cases in the recipe, but maybe I misunderstand your setup.