简体   繁体   English

makefile修改时间的技巧?

[英]makefile modification time trickery?

So I have a makefile, and in that makefile is a rule that first performs a precompile transform and modifies the source file and then compiles it into the proper target. 因此,我有一个makefile,在该makefile中是一条规则,该规则首先执行预编译转换并修改源文件,然后将其编译为适当的目标。 I would like to know if there is a way to trick/coerce make into thinking that the source was not actually modified, so that make will only recompile when a user modifies, not when the make rule modifies the source. 我想知道是否有一种欺骗/强迫make的方式,以为实际上并未修改源,因此make仅在用户修改时才重新编译,而在make规则修改源时才重新编译。 I attempted to use the touch command to turn back the modification timestamp after the make modification, but without success. 我尝试使用touch命令在进行修改后返回修改时间戳,但是没有成功。 Does anyone have any ideas? 有人有什么想法吗? Thanks. 谢谢。

One possible way to accomplish what you want is to create a secondary target -- that is a zero length file which acts like a flag to say whether you've done what you want to do or not, and have the rule which does the precompile transform based on that file. 完成目标的一种可能方法是创建一个辅助目标 -长度为零的文件,其作用类似于标志,以表明您是否已完成要完成的工作,并具有执行预编译的规则根据该文件进行转换。

I guess I have a question about what you are trying to do. 我想我对您要做什么有疑问。 Why do the transform in-place , rather than have the transform create an intermediate file which then gets compiled. 为什么要就地进行转换,而不是让转换创建一个中间文件然后进行编译。

In-place transformations can be problematic, especially if the transform process is not idempotent. 就地转换可能会出现问题,尤其是在转换过程不是幂等的情况下。

Edit 1 编辑1

Based on your question, I would say you could do this: 根据您的问题,我会说您可以这样做:

target.flag: target.original-file
    touch target.save -r target.original-file
    <do transformation>
    touch target.original-file -r target.save
    rm target.save
    touch target.flag

Using touch with the "-r" option says to grab the access date from the specified file. 将touch与“ -r”选项一起使用表示从指定文件中获取访问日期。 So you would be saving the date of the original file on temporary file. 因此,您将原始文件的日期保存在临时文件中。 Then do the transformation, then use touch to grab the date from the temporary file and put it back on the now transformed file. 然后进行转换,然后使用touch从临时文件中获取日期,并将其放回到现在转换的文件上。

How about this: 这个怎么样:

foo.target: foo.source
    $(TRANSFORM) $<
    $(COMPILE) $<

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM