conditionals not working for conditional variables in sub-make?

2009-05-07 Thread Szekeres István
Please see the makefile attached.
by running it it outputs:
VAR=foo VAR2=bar VAR3=foo

but I think VAR2 should be foo.

Bug or do I misunderstand something?

thanks,
Istvan



ifeq ($(VAR),foo)
VAR2=foo
else
VAR2=bar
endif

VAR3=$(VAR)

all: 
make var1 
make var2

var1: VAR=foo
var1: do-echo

var2: VAR=bar
var2: do-echo

do-echo:
@echo VAR=$(VAR) VAR2=$(VAR2) VAR3=$(VAR3)

___
Bug-make mailing list
Bug-make@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-make


RE: conditionals not working for conditional variables in sub-make?

2009-05-07 Thread Martin Dorey
You misunderstand something.
 
 it outputs:
 VAR=foo VAR2=bar VAR3=foo
 
That's only a small fraction of what I see, with make-3.81.  This is what I see:
 
mart...@whitewater:~/tmp/bug-make-2009-05-07$ make
make var1 
make[1]: Entering directory `/home/martind/tmp/bug-make-2009-05-07'
VAR=foo VAR2=bar VAR3=foo
make[1]: Leaving directory `/home/martind/tmp/bug-make-2009-05-07'
make var2
make[1]: Entering directory `/home/martind/tmp/bug-make-2009-05-07'
VAR=bar VAR2=bar VAR3=bar
make[1]: Leaving directory `/home/martind/tmp/bug-make-2009-05-07'
mart...@whitewater:~/tmp/bug-make-2009-05-07$
 
Perhaps you want the all rule to say:
 
all: var1 var2
 
Then I see the desired output:
 
mart...@whitewater:~/tmp/bug-make-2009-05-07$ make
VAR=foo VAR2=bar VAR3=foo
mart...@whitewater:~/tmp/bug-make-2009-05-07$
 
-Original Message-
From: bug-make-bounces+mdorey=bluearc@gnu.org 
[mailto:bug-make-bounces+mdorey=bluearc@gnu.org] On Behalf Of Szekeres 
István
Sent: Thursday, May 07, 2009 02:57
To: bug-make@gnu.org
Subject: conditionals not working for conditional variables in sub-make?
 
Please see the makefile attached.
by running it it outputs:
VAR=foo VAR2=bar VAR3=foo
 
but I think VAR2 should be foo.
 
Bug or do I misunderstand something?
 
thanks,
Istvan
 
___
Bug-make mailing list
Bug-make@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-make


Re: conditionals not working for conditional variables in sub-make?

2009-05-07 Thread Szekeres István
Hi,

2009/5/7 Martin Dorey mdo...@bluearc.com:
 That's only a small fraction of what I see, with make-3.81.  This is what I
 see:
 [...]
 VAR=foo VAR2=bar VAR3=foo

But here VAR2 should be foo As VAR=foo, the ifeq then-branch
should set it to foo, but it goes into the else branch - which I think
it shouldn't do.

 Perhaps you want the all rule to say:

 all: var1 var2

No, it is different. I definitely want the sub-make because I want too
runs with VAR substituted to foo in the first run and to bar in the
second. As you can see the VAR variable picks up the right value
(do-echo outputs foo and then bar) but the ifeq does not pick up the
value, basically the ifeq(foo,foo) goes into the else branch.


___
Bug-make mailing list
Bug-make@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-make


RE: conditionals not working for conditional variables in sub-make?

2009-05-07 Thread Martin Dorey
 But here VAR2 should be foo!

No, it shouldn't, for exactly the same reason that VAR2 isn't foo here:

mart...@whitewater:~/tmp/bug-make-2009-05-07$ make var1
VAR=foo VAR2=bar VAR3=foo
mart...@whitewater:~/tmp/bug-make-2009-05-07$

Despite the number of exclamation marks, it's not clear why you think VAR2 
should be foo.  Do you think VAR was foo when make was started?  Or do you 
think that make reevaluates all the code at global scope in the context of 
every target?

-Original Message-
From: Szekeres István [mailto:szeke...@iii.hu] 
Sent: Thursday, May 07, 2009 12:58
To: Martin Dorey
Cc: bug-make@gnu.org
Subject: Re: conditionals not working for conditional variables in sub-make?

Hi,

2009/5/7 Martin Dorey mdo...@bluearc.com:
 That's only a small fraction of what I see, with make-3.81.  This is what I
 see:
 [...]
 VAR=foo VAR2=bar VAR3=foo

But here VAR2 should be foo As VAR=foo, the ifeq then-branch
should set it to foo, but it goes into the else branch - which I think
it shouldn't do.

 Perhaps you want the all rule to say:

 all: var1 var2

No, it is different. I definitely want the sub-make because I want too
runs with VAR substituted to foo in the first run and to bar in the
second. As you can see the VAR variable picks up the right value
(do-echo outputs foo and then bar) but the ifeq does not pick up the
value, basically the ifeq(foo,foo) goes into the else branch.


___
Bug-make mailing list
Bug-make@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-make


RE: conditionals not working for conditional variables in sub-make?

2009-05-07 Thread Martin Dorey
 VAR become foo when the var1 rule was executed.
 it reevaluates because of the explicit make commands in the all rule.

Think about the order in which those two things happen.

The second one happens before the first and hence doesn't see the first's 
effect.

A thought experiment might help you to see the light.  Imagine in the all 
rule, that instead of running make var1, you ran 
a-script-which-happens-to-invoke-make-var1.

-Original Message-
From: Szekeres István [mailto:szeke...@iii.hu] 
Sent: Thursday, May 07, 2009 14:40
To: Martin Dorey
Cc: bug-make@gnu.org
Subject: Re: conditionals not working for conditional variables in sub-make?

2009/5/7 Martin Dorey mdo...@bluearc.com:
 But here VAR2 should be foo!

 No, it shouldn't, for exactly the same reason that VAR2 isn't foo here:

 mart...@whitewater:~/tmp/bug-make-2009-05-07$ make var1
 VAR=foo VAR2=bar VAR3=foo
 mart...@whitewater:~/tmp/bug-make-2009-05-07$

 Despite the number of exclamation marks, it's not clear why you think VAR2 
 should be foo.

See Target specific variables in the make info. In my example the
var1 rule sets VAR to foo (correctly), the var2 rule sets it to
bar (correctly).

  Do you think VAR was foo when make was started?

No. VAR become foo when the var1 rule was executed.

 Or do you think that make reevaluates all the code at global scope in the 
 context of every target?

No, it reevaluates because of the explicit make commands in the all rule.

The var1 rule sets VAR to foo, and VAR3 is set to $(VAR) globally,
and this works correctly, you can see this even in your own output:


   mart...@whitewater:~/tmp/bug-make-2009-05-07$ make
   make var1
   make[1]: Entering directory `/home/martind/tmp/bug-make-2009-05-07'
   VAR=foo VAR2=bar VAR3=foo

VAR is foo and VAR3 is also foo, correct.

   make[1]: Leaving directory `/home/martind/tmp/bug-make-2009-05-07'
   make var2
   make[1]: Entering directory `/home/martind/tmp/bug-make-2009-05-07'
   VAR=bar VAR2=bar VAR3=bar

VAR is bar and VAR3 is also bar, correct.

The problem is the value of VAR2: in the first case it should be
foo, because the if statement
   ifeq ($(VAR),foo)
   VAR2=foo
   else
   VAR2=bar
   endif

should compare $(VAR) (which is foo in the first case) to foo -
they are the same  so the then-branch should be executed, setting VAR2
to foo. But in the output you can see that VAR2 is not set to foo, and
this is what I reported in my very first mail.


___
Bug-make mailing list
Bug-make@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-make


RE: conditionals not working for conditional variables in sub-make?

2009-05-07 Thread Martin Dorey
(Re-adding list.)
 
 First run
 Second run
 
Make is run three times, once by the human, twice by the makefile.  I'm not 
sure what you mean with this numbering.  I think you mean the first and second 
runs of the echo command in the do-echo rule but please correct me if I'm wrong.
 
 These can clearly be seen in your output.
 
I'll reproduce the two lines of echo output here for clarity:
 
VAR=foo VAR2=bar VAR3=foo
VAR=bar VAR2=bar VAR3=bar
 
 if in the first run VAR3 can pick up the value foo, indicating
 that VAR is also foo
 
In the first line that I quote above, which is produced by a child of the 
second make invocation - the one tasked with building var1 - VAR3 is evaluated 
during the invocation of the do-echo rule as a prerequisite of the var1 rule.  
Per:
 
   There is one more special feature of target-specific variables: when
 you define a target-specific variable that variable value is also in
 effect for all prerequisites of this target
 
This means that var1's target-specific assignment of foo to VAR is in effect.
 
VAR3 is defined using deferred evaluation - = rather than := - so the 
right-hand side of the assignment is deferred to evaluation-time.  At 
evaluation time, as we've seen, the right-hand side - $(VAR) - is foo.
 
 why does the statement ifeq($(VAR),foo) fail?
 
That statement is evaluated during an earlier phase of make's execution.  It's 
not reevaluated for every target.  At the time, and in the scope, when it was 
evaluated, $(VAR) was unset, hence empty.
 
-Original Message-
From: Szekeres István [mailto:szeke...@iii.hu] 
Sent: Thursday, May 07, 2009 14:50
To: Martin Dorey
Subject: Re: conditionals not working for conditional variables in sub-make?
 
2009/5/7 Martin Dorey mdo...@bluearc.com:
 VAR become foo when the var1 rule was executed.
 it reevaluates because of the explicit make commands in the all rule.
 
 Think about the order in which those two things happen.
 
 The second one happens before the first and hence doesn't see the first's 
 effect.
 
 A thought experiment might help you to see the light.  Imagine in the all 
 rule, that instead of running make var1, you ran 
 a-script-which-happens-to-invoke-make-var1.
 
Sorry I am still not convinced.
 
First run: VAR=foo, VAR3 picks up the value of VAR, becoming also foo, correct.
Second run: VAR=bar, VAR3 picks up the value of VAR, becoming also bar, correct.
 
Can we agree that these two statements are OK? These can clearly be
seen in your output.
 
BUT: if in the first run VAR3 can pick up the value foo, indicating
that VAR is also foo, then why does the statement ifeq($(VAR),foo)
fail???
___
Bug-make mailing list
Bug-make@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-make


Re: conditionals not working for conditional variables in sub-make?

2009-05-07 Thread Szekeres István
2009/5/7 Martin Dorey mdo...@bluearc.com:
 But here VAR2 should be foo!

 No, it shouldn't, for exactly the same reason that VAR2 isn't foo here:

 mart...@whitewater:~/tmp/bug-make-2009-05-07$ make var1
 VAR=foo VAR2=bar VAR3=foo
 mart...@whitewater:~/tmp/bug-make-2009-05-07$

 Despite the number of exclamation marks, it's not clear why you think VAR2 
 should be foo.

See Target specific variables in the make info. In my example the
var1 rule sets VAR to foo (correctly), the var2 rule sets it to
bar (correctly).

  Do you think VAR was foo when make was started?

No. VAR become foo when the var1 rule was executed.

 Or do you think that make reevaluates all the code at global scope in the 
 context of every target?

No, it reevaluates because of the explicit make commands in the all rule.

The var1 rule sets VAR to foo, and VAR3 is set to $(VAR) globally,
and this works correctly, you can see this even in your own output:


   mart...@whitewater:~/tmp/bug-make-2009-05-07$ make
   make var1
   make[1]: Entering directory `/home/martind/tmp/bug-make-2009-05-07'
   VAR=foo VAR2=bar VAR3=foo

VAR is foo and VAR3 is also foo, correct.

   make[1]: Leaving directory `/home/martind/tmp/bug-make-2009-05-07'
   make var2
   make[1]: Entering directory `/home/martind/tmp/bug-make-2009-05-07'
   VAR=bar VAR2=bar VAR3=bar

VAR is bar and VAR3 is also bar, correct.

The problem is the value of VAR2: in the first case it should be
foo, because the if statement
   ifeq ($(VAR),foo)
   VAR2=foo
   else
   VAR2=bar
   endif

should compare $(VAR) (which is foo in the first case) to foo -
they are the same  so the then-branch should be executed, setting VAR2
to foo. But in the output you can see that VAR2 is not set to foo, and
this is what I reported in my very first mail.


___
Bug-make mailing list
Bug-make@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-make