The standard way is to create directories by the very first command of the rule that generates files in the directory. For example, if you have target $(BUILD)/file.o
, then just put the proper mkdir
command in the commands section:
$(BUILD)/temp_directory/%.c: ...
@mkdir -p $(@D)
generate-c-file > $@
The object files that depend on .c
files don't need that directory creation, because if the .c
file is generated, the directory is there as well.
Directories are seldom a separate entity that should be tracked via special dependency, so not having any of them as a target is reasonable.
And it is -j
-compatible as well: the OS will take care of two processing creating the same directory--via internal filesystem locks.