[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: conditionals not working for conditional variables in sub-make?
From: |
Martin Dorey |
Subject: |
RE: conditionals not working for conditional variables in sub-make? |
Date: |
Thu, 7 May 2009 14:42:57 -0700 |
> 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:address@hidden
Sent: Thursday, May 07, 2009 14:40
To: Martin Dorey
Cc: address@hidden
Subject: Re: conditionals not working for conditional variables in sub-make?
2009/5/7 Martin Dorey <address@hidden>:
>> But here VAR2 should be "foo"!
>
> No, it shouldn't, for exactly the same reason that VAR2 isn't foo here:
>
> address@hidden:~/tmp/bug-make-2009-05-07$ make var1
> VAR=foo VAR2=bar VAR3=foo
> address@hidden:~/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:
address@hidden:~/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.