[BUG] undefined variable used in recipe before undefine directive

Alejandro Colomar <[email protected]> Wed, 10 Sep 2025 22:33:41 +0200
Newsgroups gmane.comp.gnu.make.bugs
Message-ID <dozwj4skpmjnrsm2latffegxp2qr2dwpi3b52l753q4h53zhop@xt4bga7ws3y3>
Hi,

I think this looks like a bug, unless I'm forgetting some details about
how variables are expanded within recipes.

	alx@debian:~/tmp/bug$ ls
	Makefile
	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, and make(1) shouldn't care if I undefine it
after the definition of the recipe, right?  make(1) should create the
recipe with the contents of the variable, and not with the variable
itself.

Am I missing anything?

I'm using Debian Sid:

	$ make --version | head -n1
	GNU Make 4.4.1



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-----

iQIzBAABCgAdFiEES7Jt9u9GbmlWADAi64mZXMKQwqkFAmjB4J4ACgkQ64mZXMKQ
wqnC3A/7BHyulS2MpDwpSNTeKyFuSrVEsPLAzXwdiQXFcer3cZXP9msJgLpFBy0e
I5nFaaHsuopY3W8fADyDBYT7qoAMRCd4uFak05GQcqNgpMyMrYkDsTR5kAXfZ9mV
Pyhlad3LlkuHyKkEkmFxkiaPFuHqqfzbEiiHktJND1bbzGJUSfyozxSGvZpgUFVI
Wmzf8TLlLRVktjvlqS2GZlLB6BRuNxXgKKXTQE5HaBGd64gRfXOI0F/5KZMQLXXV
KsgcY6O2enLusvHU0SYPBeywxwj6wBpiCg5B9LA7Gum8G3M15Qcp4GF+hKBmWYGM
CkGESBtUS1qfU8UDqM53EkaygWC7ZFjICC/vWZ/lWSyMO84PBJEEc5Rve3NxiV13
NRMdvetIN4PyBR+dziW5tmGktmic7/IJEDH0qjQ9IfESq8E4w5m2Zn9u1IJxDkiq
fDqah3W3eCQLOF3gDkSlS0W/Bs0x0bjs46GFQ3FfBnklXzGS34poRyTo1mz/pve/
s7aUVtQh2qkzS4WePufhXbd8/TFA9IAeVmg9PPzukFIlmlXsFzz+ms5x7ae9A87m
x6WofPgTjAHGJGbCkZ0vUv9jW0IWUqZzoJ60rioio38t3Ye1OsnnFL6JpsI0KTDy
ArWu9jNeFGdU4ZXl+0TqQdFxYfV8dO/TJYvuG3izzIJbI30q5b0=
=u5fx
-----END PGP SIGNATURE-----