GNU Make 构建过时且比某个时间戳更新的文件
我正在使用 GNU Make 3.81 来构建给定的 C 项目。 GNU 的正常行为是检查目标是否存在并且任何先决条件比目标新,则执行目标命令。
如果先决条件比目标新且比给定时间戳新,是否可以重建目标?例如,仅当文件更新于 2011 年 10 月 2 日时,它才会构建。
I am using GNU Make 3.81 for building a given C project. The normal behavior of GNU is to check, if the target exists and any prerequisite is newer than the target, the target commands are executed.
Is it possible to rebuild the target if the prerequisites are newer than the target AND newer than a given timestamp? Lets say, that it builds only if the files are newer than Oct 2, 2011, for example.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
无法直接使用 make 来完成此操作,但您可以在规则的操作中使用 shell 来完成此操作:
请注意使用
\
使if
命令成为单个命令。您还可以使用else
来处理目标已过期且先决条件也已过时的情况。There's no way to do it directly with make, but you could do it with the shell in the action for the rule:
Note the use of
\
to make theif
command a single command. You could also use anelse
to deal with the case where the target is out of date and the prereq is also old.make
将重新生成比任何先决条件更新的所有目标,因此您的和条件将难以实现。如果您想在构建目录中引入纪元,只需使用
touch -d
将所有文件的修改时间戳设置为纪元时间即可。不是一个漂亮的解决方案,而是一个可行的解决方案。make
will re-make all targets that are newer than any of its prerequisites, so your and condititon will be hard to implement.If you want to introduce an epoch into your build directory, you can simply set the modification timestamps of all files to the epoch time with
touch -d
. Not a pretty, but a working solution.