|
From: | Martin Dorey |
Subject: | Re: append assignment operator in target specific variable |
Date: | Sun, 19 May 2019 19:30:16 +0000 |
Here's my understanding of the OP's three samples being run:
$ cat Makefile.1
foo :=
val := 100
all : foo += $(val)
all : ; @echo foo : $(foo)
val := 200
$ make -f Makefile.1
foo : 200
$ cat Makefile.2
foo :=
val := 100
all : foo := $(val)
all : ; @echo foo : $(foo)
val := 200
$ make -f Makefile.2
foo : 100
$ cat Makefile.3
foo :=
val := 100
foo += $(val)
val := 200
$(info $(foo))
$ make -f Makefile.3
100
make: *** No targets. Stop.
$
The contention is that Make has behaved incorrectly in the first sample, seemingly deferring the evaluation of $(val) in the target-specific assignment to foo, until after val changed from 100 to 200, despite foo previously having been defined as a "simple"
variable, ie with :=, per:
... which teaches:
> For the append operator, ‘+=’,
the right-hand side is considered immediate if the variable was previously set as a simple variable (‘:=’
or ‘::=’), and deferred otherwise.
That seemed like a plausible contention to me... until I found:
... which teaches:
> Note that this [target-specific] variable is actually distinct from any “global” value: the two variables do not have to have
the same flavor (recursive vs. simple).
We
can demonstrate that that's what's going on with a fourth sample:
$
cat Makefile.4
foo :=
val := 100
all : foo += $(val)
all : ; @echo foo : $(foo) is a $(flavor foo) variable
val := 200
$ make -f Makefile.4
foo : 200 is a recursive variable
$
The initial := assignment to foo makes no difference. The desired effect seems achievable by making the initial assignment target-specific too:
$ cat Makefile.6
val := 100
all : foo :=
all : foo += $(val)
all : ; @echo foo : $(foo) is a $(flavor foo) variable
val := 200
$ make -f Makefile.6
foo : 100 is a simple variable
$
I hope that dispels the mystery.
From: Bug-make <bug-make-bounces+address@hidden> on behalf of Hyunho Cho <address@hidden>
Sent: Sunday, May 19, 2019 08:52 To: address@hidden Subject: append assignment operator in target specific variable ***** EXTERNAL EMAIL *****
GNU Make 4.2.1 Built for x86_64-pc-linux-gnu Copyright (C) 1988-2016 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <https://nam04.safelinks.protection.outlook.com/?url="">> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. 1. "foo" is simple variable. so result have to be 100 but is 200 foo := val := 100 all : foo += $(val) all : @echo foo : $(foo) val := 200 result is : 200 ------------------------------------------------------- 2. If i change '+=' operator to ':=' then result is 100 foo := val := 100 all : foo := $(val) all : @echo foo : $(foo) val := 200 result is : 100 ---------------------------------- foo := val := 100 foo += $(val) val := 200 $(info $(foo)) result is : 100 _______________________________________________ Bug-make mailing list address@hidden https://nam04.safelinks.protection.outlook.com/?url=""> |
[Prev in Thread] | Current Thread | [Next in Thread] |