保存$^的先决顺序
鉴于此makefile
.SUFFIXES: .mmd .tmp .html
a.html : h.tmp a.tmp
b.html : h.tmp b.tmp
c.html : h.tmp c.tmp C.tmp
.tmp.html:
cat $^ > $@
.mmd.tmp:
Markdown.pl $< > $@
,其中h.mmd
是每个HTML文件开始时要插入的标题。
命令make?.html
产生该
$ touch h.mmd
$ make ?.html
Markdown.pl h.mmd > h.tmp
cat a.tmp h.tmp > a.html
cat b.tmp h.tmp > b.html
cat c.tmp h.tmp C.tmp > c.html
先决条件已按字母顺序排序。我可以保留依赖项中指定的顺序,以便cat
命令在指定的顺序中包含每个部分吗?
Given this makefile
.SUFFIXES: .mmd .tmp .html
a.html : h.tmp a.tmp
b.html : h.tmp b.tmp
c.html : h.tmp c.tmp C.tmp
.tmp.html:
cat $^ > $@
.mmd.tmp:
Markdown.pl lt; > $@
where h.mmd
is a header to be inserted at the start of each html file.
The command make ?.html
produces this
$ touch h.mmd
$ make ?.html
Markdown.pl h.mmd > h.tmp
cat a.tmp h.tmp > a.html
cat b.tmp h.tmp > b.html
cat c.tmp h.tmp C.tmp > c.html
The prerequisites have been sorted alphabetically. Can I preserve the order specified in the dependency lines so that the cat
command includes each part in the specified order?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
它与字母顺序或排序无关。先决条件未分类,$^的值也没有重新安排,除了一个例外:
在所有隐式规则中,隐式依赖性始终是先决条件列表中的第一个元素,无论您以后是否稍后是否将其添加为其他不同的先决条件地点。
查看是否将后缀规则转换为模式规则(但两者都相同)可能会更简单:一个后缀规则类似:
与模式规则相同:
因此,如果您有:
因为目标
c.html
是c
,匹配的先决条件c.tmp
即使以不同的顺序列出了它们,即使它们以不同的顺序列出明确的先决条件列表。因此,其输出将是:注意:未排序,但匹配的先决条件首先出现。
没有办法“关闭此”。如@redgrittybrick所建议的那样,唯一的解决方案是根本不列出先决条件模式。您可以使用他们的想法:
或继续使用后缀规则:
两者都会给出相同的结果:
It doesn't have anything to do with alphabetical order or sorting. The prerequisites are not sorted and the value of $^ is not rearranged, with one exception:
In all implicit rules the implicit dependency is always the first element in the prerequisite list, regardless of whether you added it later as an explicit prerequisite in a different location.
It might be simpler to see if you convert your suffix rule into a pattern rule (but both work the same): A suffix rule like:
is the same thing as a pattern rule like:
So if you have:
because the pattern match for a target
c.html
isc
, the matching prerequisitec.tmp
will always be the first prerequisite even though they're listed in different order in the explicit prerequisites list. So the output of this will be:Note: not sorted, but the matching prerequisite appears first.
There is no way to "turn this off". The only solution, as suggested by @RedGrittyBrick, is to not list the prerequisite pattern at all. You can use their idea of:
Or continue to use a suffix rule like:
and both will give the same result:
我不正确地理解这一点,但是对我有用的一种方法是进行单行更改以替换后缀规则
.tmp.html:
使用模式规则%。html:html:
保留订单的
这是一个答案,尽管不完整,因为...
我理解:
我不明白的是:
I don't properly understand this but one way that worked for me was to make a one-line change to replace the suffix rule
.tmp.html:
with a pattern rule%.html:
which preserves order
So that is an answer, albeit incomplete because ...
What I understand:
What I don't understand: