同时从两个变量自动生成 makefile 中的规则

发布于 2024-08-02 21:42:25 字数 424 浏览 1 评论 0原文

我有一些搜索模式不太适合作为结果文件名的一部分。因此,我将正则表达式和相应的文件名部分拆分为两个不同的变量,如下所示。如何自动执行以下操作,以便我不必手动列出所有文件,也不必手动输入运行 grep 的规则?

SEARCH_RE   = test  a/b/c  a.*b
SEARCH_FILE = test  abc    ab

ALL = result.test result.abc result.ab

all: $(ALL)

result.test:
        grep test  inputfile > result.test

result.abc:
        grep a/b/c inputfile > result.abc

result.ab
        grep a.*b  inputfile > result.ab

I have some search patterns that fits poorly as part of a file name for the result. I therefore split the regular expression and the corresponding file name part into two different variables like below. How can I automate the following so that I do not have to manually list files for ALL and also do not have to manually enter the rules running grep?

SEARCH_RE   = test  a/b/c  a.*b
SEARCH_FILE = test  abc    ab

ALL = result.test result.abc result.ab

all: $(ALL)

result.test:
        grep test  inputfile > result.test

result.abc:
        grep a/b/c inputfile > result.abc

result.ab
        grep a.*b  inputfile > result.ab

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

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

发布评论

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

评论(2

轻许诺言 2024-08-09 21:42:26

我建议

ALL = $(addprefix result.,$(SEARCH_FILE))

至于编写规则,我认为您想要的那种查找可以在 Make 中完成,但实际上不应该这样做——这将是一个可怕的混乱。我建议这样做:

result.test: TARG = test
result.abc: TARG = a/b/c
result.ab: TARG = a.*b

$(ALL):
    grep $(TARG) inputfile > $@

I recommend

ALL = $(addprefix result.,$(SEARCH_FILE))

As for writing the rules, the kind of lookup I think you want can be done in Make, but really shouldn't be-- it would be a horrible kludge. I'd suggest doing it this way:

result.test: TARG = test
result.abc: TARG = a/b/c
result.ab: TARG = a.*b

$(ALL):
    grep $(TARG) inputfile > $@
岁月如刀 2024-08-09 21:42:26

我不知道如何创建规则,但是 ALL 目标很简单:

ALL = $(patsubst %,result.%,$(SEARCH_FILE))

I don't know how to create the rules, but the ALL target is easy enough:

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