Makefile 中的目标替换

发布于 2024-12-29 00:44:35 字数 441 浏览 2 评论 0原文

在典型的回归中,有一个“基本”类别和一个测试用例“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 技术交流群。

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

发布评论

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

评论(1

橘虞初梦 2025-01-05 00:44:35

你的意思是这样吗?

.PHONY: basic_%
basic_%: %.c
        gcc -g -o $* 
lt;

不过,Make 已经知道如何编译 .c 文件。从你的问题来看, basic_x 依赖于编译的 x 似乎更有意义,并在配方中的一堆测试用例上运行它,但也许我误解了你的设置。

Do you mean like this?

.PHONY: basic_%
basic_%: %.c
        gcc -g -o $* 
lt;

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 compiled x, and run it on a bunch of test cases in the recipe, but maybe I misunderstand your setup.

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