[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #54727] foreach variable is not visible for a target specific varia
From: |
Michael Builov |
Subject: |
[bug #54727] foreach variable is not visible for a target specific variable definition in a recipe |
Date: |
Wed, 26 Sep 2018 07:47:03 -0400 (EDT) |
User-agent: |
Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:62.0) Gecko/20100101 Firefox/62.0 |
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/