Follow-up Comment #2, bug #54727 (project make):
> By the time we expand the recipe all target-specific variables for that
recipe have already been assigned: it's not possible for the recipe to add
more target-specific variables to it's target and have those take effect.
But this is works:
$ echo 'all:; $(eval $$@: x:=1)$(info $x)' | make -f -
result:
1
To ensure that the real target-specific variable is being used, please try the
following makefile:
######
x:=g
all: a b
a:; $(eval $$@: x:=t)$(info $@: $x)
b:; $(info $@: $x)
######
result:
a: t
b: g
> If you try to define a new target inside a recipe you'll get a fatal error.
Yes, it is expected, and I fully agree with this behavior.
$ echo 'all:; $(eval x:)' | make -f -
result:
'*** prerequisites cannot be defined in recipes. Stop.'
--------
Creating/assigning values to the target-specific variables in the recipes can
be used to avoid pollution of the global namespace.
Let's look at an example of a rule that generates several files ('b' and 'c')
at once (it can be GNU bison).
######
all: a b c
a: b c
a: done:=
b c:; $(if $(done),,$(eval a: done:=1)touch b c)
######
The command to generate the 'b' and 'c' files will only be executed once, even
if make is run with the -j option.
_______________________________________________________
Reply to this item at:
<https://savannah.gnu.org/bugs/?54727>
_______________________________________________
Message sent via Savannah
https://savannah.gnu.org/
_______________________________________________
Bug-make mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-make