如何强制重新编译 Makefile 中的单个文件?
这个想法是,一个项目有一个包含 __DATE__
和 __TIME__
的文件。在不显式更改其修改日期的情况下重新编译它可能会很酷。
编辑: $(shell touch -c ..) 如果只是笨拙的话可能是一个很好的解决方案。
The idea is that a project has a single file with __DATE__
and __TIME__
in it. It might be cool to have it recompiled without explicitly changing its modification date.
edit: $(shell touch -c ..) might be a good solution if only clumsy.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
标准习惯用法是让目标文件(而不是源文件!)依赖于一个不存在且没有规则或依赖项的目标(该目标通常称为 FORCE),就像这样
如果名为“的文件,这将中断不过,“FORCE”是以某种方式被创造出来的。使用 GNU make,您可以使用特殊目标 .PHONY,它没有此限制,但需要您有明确的规则来重建该文件:
请参阅 http://www.gnu.org/software/make/manual/html_node/Phony-Targets.html 的更多细节。
The standard idiom is to have the object file (not the source file!) depend on a target which doesn't exist and has no rules or dependencies (this target is conventionally called FORCE), like this
This will break if a file named "FORCE" gets created somehow, though. With GNU make you can instead use the special target .PHONY, which doesn't have this limitation, but does require you to have an explicit rule to rebuild that file:
See http://www.gnu.org/software/make/manual/html_node/Phony-Targets.html for more details.
一种方法是在运行
make
之前删除相应的目标文件(.o
或.obj
)。这将触发重新编译(和重新链接),而不更改源文件修改日期。One way to do this is to delete the corresponding object file (
.o
or.obj
) before runningmake
. This will trigger a recompile (and relink) without changing the source file modification date.