bug-make
[Top][All Lists]
Advanced

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

Re: append assignment operator in target specific variable


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
 

reply via email to

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