On Sat, 2024-01-27 at 20:27 +0100, Basile Starynkevitch wrote: > > It would be great if you could provide examples where these would > > be > > useful, especially examples that are not already covered by the > > output > > of the -p option to GNU Make. > > make -p don't show (unfortunately) the line number in makefiles. > Alternatively, a runtime option for make -p (perhaps > --show-line-numbers) would be nice.
It definitely DOES show line numbers. For example for a variable definition: # makefile (from 'Makefile', line 361) PACKAGE_NAME = GNU Make and for a rule definition: all: alloca.h # ... # recipe to execute (from 'Makefile', line 490): $(MAKE) $(AM_MAKEFLAGS) all-recursive > > I'm not saying we shouldn't introduce these, although I think you > > misunderstand how tricky it would be to use them (for example, if > > you set: > > > > FOO = $(__LINE__) > > This would be expanded at Makefile parsing time. Not at function > invocation time. I'm not sure what you mean by "this". It would be helpful to my understanding if you used the example I provided and showed what value you expected BAR to have: 1 or 3? Then I could be sure I understood what you meant. Macros and functions in recursive variable assignments ("=") are not expanded when the variable is defined. They are expanded when the variable is referenced. For example if you have: bar = 1 FOO = $(bar) bar = 2 all: ; @echo $(FOO) then the output will be "2", not "1", because $(bar) is not expanded when FOO is defined, it's expanded when $(FOO) is expanded (in the recipe, in this example). Are you suggesting that $(__LINE__) would somehow be a special case and NOT work like this? So if I have: bar = 1 FOO = $(bar) $(__LINE__) bar = 2 all: ; @echo $(FOO) the output I got would be "2 2" instead of "2 4"? In other words, make would parse the value of FOO looking for references to the special variables __LINE__ and __FILE__ and expand only those, but not other macros or functions? > If I started to implement it, I would add > > FT_ENTRY ("__LINE__", 0, 0, 0, func__LINE__), > > in GNU make's src/function.c file. This would almost certainly not do what you want. > So my intuition is that this feature is easy to implement. I don't think you're correct about that. But any discussion of the implementation details is premature: the behavior must be defined first. -- Paul D. Smith <psm...@gnu.org> Find some GNU make tips at: https://www.gnu.org http://make.mad-scientist.net "Please remain calm...I may be mad, but I am a professional." --Mad Scientist