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:

https://www.gnu.org/software/make/manual/html_node/Reading-Makefiles.html

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

https://www.gnu.org/software/make/manual/html_node/Target_002dspecific.html

... 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 <[email protected]> on behalf of 
Hyunho Cho <[email protected]>
Sent: Sunday, May 19, 2019 08:52
To: [email protected]
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=http%3A%2F%2Fgnu.org%2Flicenses%2Fgpl.html&amp;data=01%7C01%7CMartin.Dorey%40hitachivantara.com%7Cea80ac5cd7064c04a19d08d6dc72e3fa%7C18791e1761594f52a8d4de814ca8284a%7C0&amp;sdata=kbwD%2Fs52Jf4iNxE1bejr3j6lRU6oF4mbSqbT7m55mPY%3D&amp;reserved=0>
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
[email protected]
https://nam04.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.gnu.org%2Fmailman%2Flistinfo%2Fbug-make&amp;data=01%7C01%7CMartin.Dorey%40hitachivantara.com%7Cea80ac5cd7064c04a19d08d6dc72e3fa%7C18791e1761594f52a8d4de814ca8284a%7C0&amp;sdata=sNY5pGiW%2FojhW82Kv4Grdq32btCypaRLonzCp7VpmJA%3D&amp;reserved=0
_______________________________________________
Bug-make mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/bug-make

Reply via email to