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