bug-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [bug #54727] foreach variable is not visible for a target specific v


From: Brian Vandenberg
Subject: Re: [bug #54727] foreach variable is not visible for a target specific variable definition in a recipe
Date: Thu, 4 Oct 2018 17:50:18 -0600

On Thu, Oct 4, 2018 at 7:53 AM Michael Builov <address@hidden> wrote:
>
> Follow-up Comment #3, bug #54727 (project make):
>
> It also possible to step on this "foreach + eval" bug not in a recipe.

Agreed, I reproduced with the following:

$ cat -n makefile
1  .RECIPEPREFIX := >
2  f:=g
3  asdf=$(foreach f,1,$(eval $1:$2:=$$f))
4  $(call asdf,A,M)
5  all:TMP:=$(call asdf,B,M)
6  all:A B
7  all A B:
8  >$(warning address@hidden: M := $(value M))
$ make --version | head -n1
GNU Make 4.1
$ make
makefile:8: A: M := 1
makefile:8: B: M := g
makefile:8: all: M :=

... however, by changing $$f => $f the problem goes away.  On the one
hand I agree it's inconsistent but on the other hand in these toy
examples "$$f" isn't needed.  In the original problem you were trying
to report is there any particular reason the $(foreach) variable's
expansion was delayed?

-brian

>
> Please consider the next example:
>
> ############
> # define global variable
> f := g
>
> # function for defining target-specific variables
> # $1 - target
> # $2 - variable
> def_target_specific = $(foreach f,1,$(eval $1: $2:=$$f))
>
> # calling in global context: M=1
> $(call def_target_specific,target_X,M)
>
> # calling in target-specific context: M=g
> all: TMP := $(call def_target_specific,target_Y,M)
>
> all: target_X target_Y
> target_X target_Y:; $(info $@: M=$M)
> ############
>
> result:
>
> target_X: M=1
> target_Y: M=g
>
>
>
> As we can see, the variable M has different values for target_X and target_Y,
> which is not expected.
>
> Outer foreach variables cannot be used inside the eval context, if the call
> comes from a target-specific variable definition.
>
>     _______________________________________________________
>
> Reply to this item at:
>
>   <https://savannah.gnu.org/bugs/?54727>
>
> _______________________________________________
>   Message sent via Savannah
>   https://savannah.gnu.org/
>
>
> _______________________________________________
> Bug-make mailing list
> address@hidden
> https://lists.gnu.org/mailman/listinfo/bug-make



reply via email to

[Prev in Thread] Current Thread [Next in Thread]