gnu make dependency checking with directories and symbolic links
Friday, January 11th, 2008Note: The googlefood category is just for things that I needed to know but couldn’t find on google.
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
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