出现“make:Nothing to be do for 'target'”的错误
让我用一个例子来说明一下。
mkdir test
cd test
touch target
make target
这将导致: make: Nothing to be do for 'target'.
所以 make 告诉我没有什么可做的。这是因为 make 没有找到 make target
的规则,而是因为 target
已经存在 make 告诉我无事可做。
现在,我不想那样。我希望 make 在找不到 target
的规则时给出错误,即使 target
已经存在。
我已尝试以下操作:
echo '.DEFAULT:
echo make: *** No rule to make target `$@'. Stop.
false'> Makefile
但这不会在创建多个目标时停止 make 。
Let me illustrate it with an example.
mkdir test
cd test
touch target
make target
This will result in: make: Nothing to be done for 'target'.
So make tells me there is nothing to do. This is because make did not find a rule to make target
, but because the target
already exists make tells me there is nothing to do.
Now, I don't want that. I want make to give me an error when it cannot find a rule for target
, even though the target
already exists.
I have tried the following:
echo '.DEFAULT:
echo make: *** No rule to make target `$@'. Stop.
false'> Makefile
But this does not stop the make when making multiple targets.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
问题是, make 假设目标名称也是一个将由给定命令构建的文件。
但有时这不是真的(例如想想“干净”)。
要告诉 make 某些目标不构建此文件,您需要将它们设置为“虚假”。将以下行放入您的 Makefile 中:
The problem is, that make assumes the target name is also a file which will be build by the given commands.
But sometimes this is not true (e.g. think of "clean").
To tell make that some targets don't build this file, you need to make them "phony". Put the following line into your Makefile:
如果你仔细想想,你最终会陷入先有鸡还是先有蛋的情况(或无限倒退)。假设您设法制定了一条规则,规定“您必须有一条规则来创建目标 目标 才合法”,那么您将拥有对于某些其他文件X,表示“目标依赖于X”的规则。是这样写的:
但是随后您会回到起点:您还需要一个规则来创建X。你怎么能这么做呢?您可能有一个不依赖于任何内容的规则,并在需要时神奇地创建文件X:
如果没有这样的规则,您就会陷入无限倒退。
因此,
make
旨在确保文件存在且是最新的。如果文件存在并且没有规则(隐式或显式)来指定它的制作方式,则该文件是最新的。你想要做的事情是不可能的。If you think about it, you would end up with a chicken-and-egg situation (or infinite regress). Suppose you managed to have a rule that said 'You must have a rule to create target before it is legitimate', then you'd have a rule that says 'target depends on X' for some other file X. That's written:
But then you'd be back to the starting point: you'd also want a rule to create X. How can you do that? You might have a rule that depends on nothing and magically creates the file X when it is needed:
Without a rule like that, you have an infinite regress.
So,
make
is designed to ensure that files exist and are up to date. If a file exists and there are no rules - implicit or explicit - to specify how it is made, then the file is up to date. What you are seeking to do is not possible.实际上,这听起来像是一个完全合理的(如果被误导了;-))请求。不过,您必须使用带有空配方的规则显式列出每个源文件。
给你:
布丁的证明:
请注意,
Makefile: ;
行是必需的。毕竟,make 尝试做的第一件事就是重建 Makefile。还要注意,包罗万象的模式规则是非终结的。这可能会对性能造成巨大影响。正如手册中所说的匹配任何规则“它们非常有用,但 make 可能需要很多时间来考虑它们。”
Actually this sounds like a perfectly reasonable (if misguided ;-)) request. You will have to explicitly list every source file with a rule with an empty recipe though.
Here you go:
The proof of the pudding:
Note that the line
Makefile: ;
is necessary. After all, the first thing make tries to do is rebuild the Makefile.Note also that the catch-all pattern rule is non-terminal. This can be a massive performance hit. As the manual says about match anything rules "They are very useful, but it can take a lot of time for make to think about them."