make in and off handles directory targets in the same way as file targets. Thus, it is easy to write such rules:
outDir/someTarget: Makefile outDir touch outDir/someTarget outDir: mkdir -p outDir
The only problem is that the timestamp of directories depends on what is done with the files inside. For the above rules, this leads to the following result:
$ make mkdir -p outDir touch outDir/someTarget $ make touch outDir/someTarget $ make touch outDir/someTarget $ make touch outDir/someTarget
This is definitely not what you want. Whenever you touch a file, you also touch the directory. And since the file depends on the directory, the file is therefore outdated and has to be rebuilt.
However, you can easily break this loop by telling make to ignore the directory timestamp . This is done by declaring the catalog as pre-order for order only:
This correctly gives:
$ make mkdir -p outDir touch outDir/someTarget $ make make: 'outDir/someTarget' is up to date.
TL; DR:
Write a rule to create a directory:
$(OUT_DIR): mkdir -p $(OUT_DIR)
And the goals for the content inside depend only on the directory order:
$(OUT_DIR)/someTarget: ... | $(OUT_DIR)
cmaster Jun 28 '18 at 12:28 2018-06-28 12:28
source share