gnu make dependency checking with directories and symbolic links
Note: The googlefood category is just for things that I needed to know but couldn’t find on google. This will probably be uninteresting for 99.9% of the world, so feel free to skip this.
When using gnu make:
- file dependency checks that involve symbolic links check only the modification time of the file the symlink points to. The creation time of the symbolic link itself is irrelevant.
- File dependency checks that involve directories as pre-requisites will trigger if either:
- the directory itself is newer
- any file within the top level of the directory is newer
- Directories within directories or files within non-toplevel subdirectories will not trigger.
Example in a Makefile
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<tt> all: slink dir # This rule is triggered if 'filename' is newer than file 'slink' # where 'file-symlinked-to-filename' is a symlink to 'filename' # The creation and modification times of 'file-symlinked-to-filename' itself are ignored slink: file-symlinked-to-filename @echo Rebuild slink touch slink # This rule is triggered if 'directory' is newer than file 'filedir' # 'directory' is newer if mtime(directory) > mtime(filedir) # 'directory' is newer if mtime(directory/any-file) > mtime(filedir) # 'directory' is NOT newer if mtime(directory/dir2) > mtime(filedir) # 'directory' is NOT newer if mtime(directory/*/any-file) > mtime(filedir) filedir: directory @echo Rebuild filedir touch filedir </tt> |
February 5th, 2008 at 10:15 am
The reason for #2 is that a directories modification time is reset by the OS whenever its contents change. This makes sense if you think of a directory as a special file that contains a listing of other files.
May 9th, 2011 at 7:56 am
Passing -L to make will cause make to look at the modification time of the symbolic link itself.