[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: wildcard and globstar (was: GNU make troubleshooting)

From: Alejandro Colomar
Subject: Re: wildcard and globstar (was: GNU make troubleshooting)
Date: Sun, 16 Jul 2023 22:58:42 +0200
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0


On 2023-07-16 18:31, Dmitry Goncharov wrote:
> On Sun, Jul 16, 2023 at 10:49 AM Alejandro Colomar <alx@kernel.org> wrote:
>> I guess I'd need some kind of globstar support in GNU Make to be able
>> to use that
> Do you mean you need to find .mk files in subdirectories at different
> depth levels?
> mk:=$(wildcard */*/*.mk */*.mk *.mk)

Yeah, that's a working workaround.  The issues I have with it are that
the prefix has to be repeated, so the line get overly long, and that it's
less robust (e.g., if I add a 4th level).

However, after the suggestion from Torbjörn, I've picked this workaround
to reduce the code.  It ended up being as small as this:

MK := \
        $(srcdir)/Makefile \
        $(wildcard $(MAKEFILEDIR)/*.mk $(MAKEFILEDIR)/*/*.mk 
include $(MK)
$(MK):: ;

I added an include guard to the main Makefile, to prevent a loop.

I'm still interested in globstar support, though.  It would make that
line shorter and more robust.  Maybe you could add an option
--glob=globstar or similar to enable support.

> regards, Dmitry

On 2023-07-16 21:24, Torbjorn SVENSSON wrote:

[reordering your mail to answer to separate topics in it]

> On 2023-07-16 15:58, Alejandro Colomar wrote:

> I would have done something along these lines if I were in your shoes:
> MK := $(srcdir)/Makefile
> MK += $(shell $(FIND) $(MAKEFILEDIR) -type f -name '*.mk')

> Why are you wasting time doing grep when you can have find return just 
> those files that ends with .mk?

I'm probably just wasting microseconds, so that's not a big deal.

grep(1) provides a common interface, namely regex, that I can rely on
to do the most complex stuff.

find(1) has a brain-damaged design[1], and I never remember all the
details about a given feature, so I would waste minutes reading the
manual.  That's a meaningful waste.  I decided long ago that I
wouldn't use most of find(1)'s features (I only use the ones which
can't be replaced by external commands in a pipe easily).

[1]: <https://doc.cat-v.org/unix/find-history>

> Also, why need to sort the list when 
> it's only for make to define a rule?

I admit in other cases it's more merited.  In this one, it was that I
didn't really think it much.  It still has a (very small) benefit,
which is that when debugging the Makefile, the targets of the rule
will appear sorted, which might be slightly better, and anyway,
sorting a few dozens of files won't take much either.

> Or, a more cleaner solution would have been to define the MK-array in 
> the $(srcdir)/Makefile as you have it hard coded for the include 
> statements now.
> MK :=                           \
> $(MAKEFILEDIR)/check/_.mk       \
> $(MAKEFILEDIR)/check/catman.mk  \
> $(MAKEFILEDIR)/build/_.mk       \
> $(MAKEFILEDIR)/build/catman.mk  \
> $(MAKEFILEDIR)/build/html.mk    \
> $(MAKEFILEDIR)/build/pdf.mk     \
> $(MAKEFILEDIR)/build/pre.mk     \
> $(MAKEFILEDIR)/build/ps.mk      \
> $(MAKEFILEDIR)/build/src.mk     \
> $(MAKEFILEDIR)/dist.mk          \
> $(MAKEFILEDIR)/install/_.mk     \
> $(MAKEFILEDIR)/install/html.mk  \
> $(MAKEFILEDIR)/install/man.mk   \
> $(MAKEFILEDIR)/lint/_.mk        \
> $(MAKEFILEDIR)/lint/c.mk        \
> $(MAKEFILEDIR)/lint/man/_.mk    \
> $(MAKEFILEDIR)/lint/man/man.mk  \
> $(MAKEFILEDIR)/lint/man/mdoc.mk \
> $(MAKEFILEDIR)/make.mk          \
> $(MAKEFILEDIR)/verbose.mk
> include $(MK)

I didn't know I could include more than one file in a single include
statement.  I guess my C background didn't let me imagine that.  :)

I didn't consider that to be very clean, and so I've taken the parts
I like from your examples, which is the ability to include all files
from a variable, and set the variable with a wildcard.

Thank you both!


> $(srcdir)/Makefile $(MK):: ;
> Kind regards,
> Torbjörn

GPG key fingerprint: A9348594CE31283A826FBDD8D57633D441E25BB5

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

reply via email to

[Prev in Thread] Current Thread [Next in Thread]