Previous: Single Suffix Rules, Up: Portable Make

12.17 Timestamp Resolution and Make

Traditionally, file timestamps had 1-second resolution, and make used those timestamps to determine whether one file was newer than the other. However, many modern file systems have timestamps with 1-nanosecond resolution. Some make implementations look at the entire timestamp; others ignore the fractional part, which can lead to incorrect results. Normally this is not a problem, but in some extreme cases you may need to use tricks like ‘sleep 1’ to work around timestamp truncation bugs.

Commands like ‘cp -p’ and ‘touch -r’ typically do not copy file timestamps to their full resolutions (see Limitations of Usual Tools). Hence you should be wary of rules like this:

     dest: src
             cp -p src dest

as dest often appears to be older than src after the timestamp is truncated, and this can cause make to do needless rework the next time it is invoked. To work around this problem, you can use a timestamp file, e.g.:

     dest-stamp: src
             cp -p src dest
             date >dest-stamp