Bonjour Basile,
On Thu, 18 Jun 2026, 11:00 Basile STARYNKEVITCH, <[email protected]>
wrote:
> What are the good ways to understand a GNU makefile behavior (on Linux
> only)?
>
> GNU make has $(error ...) and $(warning ...) but no $(message ...) or
> $(note ...)
>
There is $(info) and I think that's fairly close to what you want but it
doesn't have the line number or filename.
You can probably get the filename from $(MAKEFILE_LIST) like this:
$(info $(MAKEFILE_LIST): The message)
...which could give output like this:
make -f test.mk
test.mk: The message
The only problem here could be that you might want the last element of
MAKEFILE_LIST if you have a complicated structure with included makefiles
I think the line number is more difficult but what could be very cool is a
function that would return the current line number. I can't think of a way
to do that at the moment but I'd be glad to be corrected.
It is possible to create functions in C and load them into make
dynamically. This is useful because it's a thing you can do without having
to convince the make maintainers to add your code. The problem is I'm not
sure if these dynamically loadable modules have access to the appropriate
symbols which would let you show the line number and you might be able to
just assume they exist but it's a bit fragile.
A builtin line number function could possibly be so useful that it would
get accepted as it might be useful in more than one situation so don't
consider that option closed - it's just a bit harder.
One useful tool for debugging make is the --print-database option. This
shows you how your makefile would look if it was deconstructed to the
simplest form. It's sort of like a dump of makes internal data
structures. If you're having problems this can sometimes show you that the
thing you think your doing is not what's actually being understood by make.
Bon chance!
Tim Murphy