append assignment operator in target specific variable

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

append assignment operator in target specific variable

Hyunho Cho
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 <http://gnu.org/licenses/gpl.html>
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
[hidden email]
https://lists.gnu.org/mailman/listinfo/bug-make
Reply | Threaded
Open this post in threaded view
|

Re: append assignment operator in target specific variable

Martin Dorey-2
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+martin.dorey=[hidden email]> on behalf of Hyunho Cho <[hidden email]>
Sent: Sunday, May 19, 2019 08:52
To: [hidden email]
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
[hidden email]
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
[hidden email]
https://lists.gnu.org/mailman/listinfo/bug-make
Reply | Threaded
Open this post in threaded view
|

Re: append assignment operator in target specific variable

Henrik Carlqvist-2
In reply to this post by Hyunho Cho
> 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

Yes, the result will become 200 because foo is not expanded until it is
usead at the line "@echo foo : $(foo)". At that time, before building
"all" the entire Makefile will have been read and val was assigned to 200
at the last line in the Makefile.

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

Yes, because ":=" unlike "=" and "+=" is expanded at that very line.

regards Henrik

_______________________________________________
Bug-make mailing list
[hidden email]
https://lists.gnu.org/mailman/listinfo/bug-make