While it is possible to have a directory as a dependency, there are a few things to be aware of. Consider this:
directory: @mkdir -p directory directory/file : directory commands-to-make-the-file
This will do what you think. However, it executes commands-to-make-the-file when the file older than the directory , which might not be what you want.
You need to consider scenarios in which the directory timestamp is updated. This happens whenever files are added or removed from the directory, but this does not happen when an existing file is modified.
So, some unrelated actions that update the directory will make the file obsolete, perhaps unnecessarily, which will cause commands to recreate it.
source share