Re: Optimizing directory creation

Tim Murphy <[email protected]> Thu, 30 Apr 2026 23:00:18 +0100
Newsgroups gmane.comp.gnu.make.general
Message-ID <CACJSg6kz9ajRmqWMqru5cBkE7BUgkaqsVF8mY-j6fGimM1tr7w@mail.gmail.com>
On Thu, 30 Apr 2026 at 20:26, Heime <[email protected]> wrote:

> On Friday, May 1st, 2026 at 6:59 AM, Tim Murphy <[email protected]>
> wrote:
>
> > What was effective for me was a variable that one appended the director=
y
> to and then at the end of the makefile a for loop that ran something like
> $(eval $$(shell mkd=C4=B1r -p ... ) on batches of about 20 directories at=
 a time.
>
> Right.  Followed by the rules to make your targets after making the
> directories
> present in the variable.
>
>
You have it right but I just want to correct something else where you've
not got quite the right sense and it might help you.

What you have to remember about make is that its' declarative so make reads
the whole makefile before starting to try to run rules.

What this means is that you can use $(shell mkdir blah) anywhere in the
makefile - at the top or the bottom  and it will still happen before the
first rule is expanded.

e.g. the "mkdir happens before "echo hello" in both these makefiles:

$(shell mkdir bob/a)
bob/a:
    echo "Hello" > $@

...and...

bob/a:
    echo "Hello" > $@
$(shell mkdir bob/a)

I don't present this as the most elegant pattern - it just works for me in
some situations.  David's one is quite nice.

Best regards,

Tim