与现有目标和缺失的依赖关系建立依赖关系
我有一个 makefile,例如:
A : B
echo "made A"
B : D
echo "made B"
这里,B 存在,但 D 不存在(有时,它存在,有时不存在)
现在,如果我执行 make,它会对我大喊:
make: *** No rule to make target 'D', needed by 'B'. Stop.
有什么方法可以正确运行,即:
- B 和D 不存在:失败
- B 存在,D 存在并且比 B 更新,应用配方
- B 存在,D 存在但较旧:如果 B 存在且 D 不存在,则不执行任何操作
- :不要重建 B(您不能)但您可以使用 B 来构建 A
使用以 D 作为目标的空行将始终执行构建 B 的配方,但如果没有 D,则不能,因此不需要它!
有什么办法吗?
使用空规则的解决方案
D :
我找到了最后 ,这样丢失D就不会失败。所以现在一切都OK了,除了如果D丢失则重做B,这可以在B配方中进行测试:
B : D
if [ D ] ; then echo "doing B with D"; fi
但它确实看起来很黑客......
I have a makefile such as :
A : B
echo "made A"
B : D
echo "made B"
Here, B exists but D doesn't (sometimes, it does, sometimes it doesn't)
Now if I execute make, it shouts at me :
make: *** No rule to make target 'D', needed by 'B'. Stop.
Is there any way to behave correctly i.e. :
- B and D don't exist : fail
- B exists, D does and is newer than B , apply recipe
- B exists, D exists but is older : don't do anything
- if B exists and D doesn't : don't rebuild B (you can't) but you can use B to build A
Using an empty line with D as target would always execute recipe to build B, but without D it cannot, so it's not wanted !
Is there any way ?
I found the solution of using an empty rule
D :
at the end, so that missing D will not fail. So now all is OK except B is redone if D is missing, which can be tested in B recipe :
B : D
if [ D ] ; then echo "doing B with D"; fi
But it really seems hackish ...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以通过将 B 标记为中间来避免从较旧的 D 重新生成 B:
然后您可以删除 D 的空规则,并且匹配“正确”行为的四个标准。
You can get around the re-generation of B from an older D by marking B as intermediate:
You can then remove the empty rule for D, and your four criteria for "correct" behaviour are matched.