Hi Paul,

On Wed, Sep 10, 2025 at 05:08:09PM -0400, Paul Smith wrote:
> On Wed, 2025-09-10 at 22:33 +0200, Alejandro Colomar wrote:
> >  alx@debian:~/tmp/bug$ cat Makefile | nl -ba
> >       1 MAKEFLAGS += --warn-undefined-variables
> >       2 
> >       3 foo := foo
> >       4 
> >       5 all:; echo $(foo)
> >       6 
> >       7 undefine foo
> >  alx@debian:~/tmp/bug$ make
> >  Makefile:5: warning: undefined variable 'foo'
> >  echo 
> > 
> > As I understand it, the variable foo is expanded immediately in the
> > definition of the recipe
> 
> No, you have it exactly backwards.  Variables in recipes are deferred
> and not expanded until the recipe is run.

Hmmm, I see.  Thanks!  Is there any way I can force simple expansion in
recipes?

The reason I want to be able to undefine the variable name is to not
need to come up with unique names in variables used within a recipe.
That's why I immediately undefine it; to be able to reuse the name,
making sure that old values are not used accidentally.

And it may also improve performance.

Maybe we could have something like '.IMMEDIATRECIPEEXPANSION:'.

> 
> See:
> https://www.gnu.org/software/make/manual/html_node/Reading-Makefiles.html
> 
> > Rule Definition
> > A rule is always expanded the same way, regardless of the form:
> > 
> > immediate : immediate ; deferred
> >         deferred
> >
> > That is, the target and prerequisite sections are expanded
> > immediately, and the recipe used to build the target is always
> > deferred. This is true for explicit rules, pattern rules, suffix
> > rules, static pattern rules, and simple prerequisite definitions.

Thanks!


Have a lovely night!
Alex

-- 
<https://www.alejandro-colomar.es>
Use port 80 (that is, <...:80/>).

Attachment: signature.asc
Description: PGP signature

Reply via email to