Re: [BUG] undefined variable used in recipe before undefine directive
Alejandro Colomar <[email protected]> Wed, 10 Sep 2025 23:38:36 +0200
| Newsgroups | gmane.comp.gnu.make.bugs |
|---|---|
| Message-ID | <pr4vxih34ko3yfkznqlhiv2gkscyg4ncofunwaizcavdvxx7lv@geg24ko2v43z> |
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/>).
signature.asc
(application/pgp-signature, 833 B)
-----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmjB79UACgkQ64mZXMKQ wqnjjxAAmClybkPPf97QtkmLYzkDNgdCp9L+Y9f8yf5hER2fsRR/inIJiIkGOxpf JVNVfyEi1A9v9JYB/HL45l4otm60+0Zm/mflGssT2J/Tppxs9zv7NdDnaXwdkmGm atsJfXxf3hgO59NLvVG6guzFC0r7ekTw0iV/oRNPC88rb4sLHaaToS+7LLa05ocw jDU7e7QJNKuhvFclLSLCXnblvgpjbNDAXXqReKCvnCdl+/HM/sWDtjCRO/JyRywJ K6nADvgj2e07d6Ig7h1kFA7kE6EWfweFNXuK0UmdV4o3C1XsbI/o6YyDRPcEAaNz a5CZG1MSgYXF3F1VT2XLTMGEdOjHOj8KMka4P1YA2BcF7Z+k7g78GgpwncqtWmS9 h+oFulsHOP+NcNme2NNTC0dbu2dJf4xaxUAFrWW8H+i+UcFp8mYYcdzytn6+opVa ZwZoQ5CJBhPfWcxuuymFsRGyrGqbICP9JMwRKAIt6zM6gxqE1fS61jHCYJoEM990 jVxCXHgp+ewW08ldOoFJ3Dwn1rd5fWHMd+z8Cgtc0QKhVwuIqcxBkKlpHh3+3bqT MBbzbEKz5ZkAB74UXI7hypOUnjndq/13hhjkJ53FwpRmAP/zlOiOaeAC4My2IB/i AmnJf9/Jl+12h19QajqM8ARY3OKcN0M07edgR8/bwWxismwLej4= =CCzh -----END PGP SIGNATURE-----