制作类似支持自动删除临时文件和正则表达式模式规则的工具?

发布于 2024-09-15 17:29:42 字数 890 浏览 6 评论 0原文

我正在搜索类似 make 的构建工具,它支持(除了通常的 make 功能之外):

  1. 自动删除临时创建的文件(例如在 GNU make 中)
  2. 规则模式中的正则表达式(例如 烹饪

关于1: 默认情况下,GNU make 会删除临时文件。例如,有以下规则:

%.c: %.y
          some-comand

%.o: %.c
          some-comand

如果您有一个文件 foo.y 并调用 make foo.o,则 make 派生必须首先创建 foo.c,然后创建 foo.o。准备好后删除临时文件 foo.c。

库克并不支持这一点。

关于2: 使仅支持后缀模式样式规则。例如这样(等效符号):.

%.o: %.c
          some-comand

co: some-comand

在模式规则中允许正则表达式当然更强大。伪代码示例:

foo.+bar.o: foo.+bar.c
          some-comand

foo\1bar.o: foo(.+)bar.c
          some-comand

如果需要 fooXXXbar.o 并且 fooYYYbar.c 存在(或者 make 知道如何创建它),则第一个规则匹配(并且执行其命令)。第二个规则匹配,如果例如 fooXXXbar.o 是需要并且 fooXXXbar.c 存在。

您知道支持这些功能的版本吗?

I am searching a make like build tool that supports (besides usual make features):

  1. Automatic deletion of temporary created files (like in GNU make for example)
  2. Regular expressions in rule patterns (like e.g. in Cook

About 1:
By default GNU make deletes temporary files. For example have these rules:

%.c: %.y
          some-comand

%.o: %.c
          some-comand

If you have a file foo.y and call make foo.o then make derives that is has to create first foo.c and then foo.o. After it is ready it delete the temporary file foo.c.

Cook does not support this.

About 2:
Make just support suffix pattern style rules. For example like this (equivalent notations):

%.o: %.c
          some-comand

.c.o:
some-comand

Allowing regular expressions in rules of patterns is of course more powerful. Pseudo-code examples:

foo.+bar.o: foo.+bar.c
          some-comand

foo\1bar.o: foo(.+)bar.c
          some-comand

The first rule matches (and its command is executed) if for example fooXXXbar.o is needed and fooYYYbar.c exists (or make knows how to create it. The second rule matches, if for example fooXXXbar.o is needed and fooXXXbar.c exists.

Do you know a build that supports these features?

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

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

发布评论

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

评论(3

猫性小仙女 2024-09-22 17:29:42

除了 GNUMake 之外,我不太熟悉任何构建工具;它不处理正则表达式,但它可以处理这些情况。第二条规则很简单:

foo%bar.o: foo%bar.c
    @echo trying to make $@, found $^

第一条规则需要一些努力:

PPP = $(firstword $(filter-out foobar.c, $(wildcard foo*bar.c)))

ifneq ($(PPP),)
foo%bar.o: $(PPP)
    @echo found $^
else
WAR = $(warning no match to the regex)
foo%bar.o:
    $(WAR)
endif

I'm not really familiar with any build tool but GNUMake; it doesn't handle regexes, but it can handle these cases. The second rule is easy:

foo%bar.o: foo%bar.c
    @echo trying to make $@, found $^

The first one requires some kludgery:

PPP = $(firstword $(filter-out foobar.c, $(wildcard foo*bar.c)))

ifneq ($(PPP),)
foo%bar.o: $(PPP)
    @echo found $^
else
WAR = $(warning no match to the regex)
foo%bar.o:
    $(WAR)
endif
郁金香雨 2024-09-22 17:29:42

GNU Make 显然有 1,并且需要 2(其维护者似乎同意),但是有不是它的完整设计,更不用说补丁了。

您可以使用 $(call)、$(eval) 甚至 $(shell) 等函数在 GNU make 中模拟此功能,
和/或生成辅助 Makefile 并包含它们,但结果很难阅读。

GNU Make obviously has 1, and needs 2 (its maintainers seem to agree), but there isn't a full design for it, let alone a patch.

You can emulate this functionality in GNU make by using functions such as $(call), $(eval) or even $(shell),
and/or generating auxiliary Makefiles and including them, but the results are quite hard to read.

暗地喜欢 2024-09-22 17:29:42

.SECONDEXPANSION 扩展可以提供很大帮助。例如:

  .SECONDEXPANSION:

  1.o another.o dir/3rd.o: $(call munge,$@)
    gcc blah blah -o $@
    ∶

基本上,$munge 应该返回给定目标的源。您可以定义函数来执行几乎任何操作,甚至可以通过 $(shell...) 调用 perl(尽管 $shell 会在一定程度上损害性能)。一个简单的可能是:

munge = $(patsubst %.o,%.cpp,$(notdir $1))

.SECONDEXPANSION expansion can help quite a lot. For example:

  .SECONDEXPANSION:

  1.o another.o dir/3rd.o: $(call munge,$@)
    gcc blah blah -o $@
    ∶

Basically, $munge should return the source given the target. You can define your function to do practically anything, even calling perl via $(shell...) (though $shell hurts performance somewhat). A simple one might be:

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