19
Dynamic directory creation in GNU Make?
(programming.dev)
Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!
Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.
Hope you enjoy the instance!
Rules
Follow the wormhole through a path of communities !webdev@programming.dev
Oh right, that was not the whole Makefile, only the part that caused problems. As @fruitcantfly@programming.dev pointed out, it breaks down with more
SOURCEfiles and populates the newly created directories with only the firstSOURCEfile. After some more poking and reading I found a method that works by usingdefine:I feel like this is an abuse of Make, but it works. When is it a good idea to delegate the building process to other tools?
Yes, I didn't notice that, I should have tested it more thoroughly!
Make works best when there's a simple relation between target filename and the dependency filenames, and when the output filenames are known ahead of time (or are easily derived from a list of inputs).
You can use Make to achieve what you want though, even when the relations are complex. The idiomatic pattern is to dynamically create your dependency lists and include them at runtime. Make supports this as a first-class feature and will handle re-evaluating any rules that are changed every time an included Makefile is (re-)generated.
For example:
(I've tested this one and it seems to work)
But if you want to avoid any complex use of Make then you can push a lot of the logic into your script and then just create a timestamp file for each input as a dummy output to represent the fact that the script was run on each input. eg.
This is a much simpler Makefile, but now you need to create the output filename, make the output directory and redirect the script output inside the script itself. The other drawback is that it's harder to use the output file as an input to another rule. You can use the timestamp file as an input but you won't have the actual filename available to send to a command without some more scripting.