B Johnson
B Johnson

Reputation: 2556

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. 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. I attempted to use the touch command to turn back the modification timestamp after the make modification, but without success. Does anyone have any ideas? Thanks.

Upvotes: 1

Views: 1796

Answers (2)

Zeke Hansell
Zeke Hansell

Reputation: 675

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

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. 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.

Upvotes: 1

Beta
Beta

Reputation: 99094

How about this:

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

Upvotes: 0

Related Questions