简体   繁体   中英

GNU make: How to modify a file without re-executing rules?

Suppose I want to make an extremely minor (ie commenting, whitespace cleanup, etc) change to a file but I don't want Make to go through the time-consuming (>24hrs) rebuild process. Is there a way to do this?

I know you can do the opposite (ie rebuild without editing a file) using "touch", but that doesn't really help here.

You can also do the opposite with touch as well. One way I do it that's pretty easy is:

 $ cp -a foo.c foo.c.bak
 $ <fix up foo.c>
 $ touch foo.c -r foo.c.bak

Since cp -a should preserve the modification timestamp. Another way something similar can be done is to note the modification timestamp (eg stat -c "%y" foo.c or something like that) and use the -m and -t arguments to touch instead of copying the file.

After editing the file, you can change the "modification time" to whatever you want with

touch -m -r filename

Where filename is the name of a file with the time you want to copy (another untouched file from the build). See http://www.computerhope.com/unix/utouch.htm

touch is still the answer you just need to use it backwards.

  1. Copy the file (preserving modification times, -p ).
  2. Edit the original file.
  3. Use touch to reset the modification/etc. times back to what they were before (touch -r file.copy file).

That should be enough to do what you want.

And remember you can always ask make -q to see whether it thinks it will have any work to do to make sure you got it right.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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