英文:
make runs target even though file already exists
问题
我有一个像这样的 Makefile
bin:
mkdir -p bin
bin/kustomize: bin
curl -fsSL "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s bin
当我运行 make bin/kustomize
时,它每次都试图下载,即使它已经存在。我希望 make 不会运行该目标。
当我移除对 bin
的依赖时,它按照我的期望工作。
英文:
I have a Makefile like this
bin:
mkdir -p bin
bin/kustomize: bin
curl -fsSL "https://raw.githubusercontent.com/kubernetes-sigs/kustomize/master/hack/install_kustomize.sh" | bash -s bin
When I run make bin/kustomize
it tries to download it, every time, even though it is already there. I would expect that make doesn't want to run that target.
When I remove the dependency to bin
, it works as I expect.
答案1
得分: 1
您的 bin/
是一个目录,而不是一个普通文件。
在您的 规则 中,GNU make 的依赖关系:
bin/kustomize: bin
表示文件 bin/kustomize
应该在 bin/
的修改时间发生变化时重新构建。
但是在目录内覆盖文件条目(从技术上讲,将名称与inode关联起来)会更改目录的修改时间。
如HolyBlackCat所评论的,您可能需要一个仅顺序的先决条件。
如果您希望在内容更改时触发构建规则(而不仅仅是使用修改时间),可以考虑使用其他构建工具,也许是omake。
更复杂的GNU makefile示例在RefPerSys开源推理引擎中。
英文:
Your bin/
is a directory, not a plain file.
The GNU make dependency in your rule
bin/kustomize: bin
says that file bin/kustomize
should be reconstructed every time the modification time of bin/
is changing.
But overwriting a file entry (technically associating a name to an an inode) inside a directory is changing the directory modification time.
As commented by HolyBlackCat you want an order-only prerequisite
Should you want the building rules to fire when a content is changed (and not just using modification time), consider using other builder software, maybe omake
An example of a more complex GNU makefile is inside the RefPerSys open source inference engine.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论