Re: CVS commit: src/usr.bin/make

2010-06-09 Thread Joerg Sonnenberger
On Wed, Jun 09, 2010 at 12:58:23PM -0400, Christos Zoulas wrote:
 Log Message:
 Explain variable expansion better. Requested by Aleksey Cheusov

This is wrong. Loop variables are not exapnded on each loop iteration.
Each loop iteration effectively creates a new variable. The rest of his
confusion comes from two simple facts:
(1) += is lazy in bmake. This is different from FreeBSD, where it forces
expansion.
(2) The evaluation of j is lazy as well. That's why he sees the last
loop iteration.

Therefore I don't agree with the content and it is actually making
things a lot more complicated than necessary.

Joerg


Re: CVS commit: src/usr.bin/make

2010-06-09 Thread Christos Zoulas
In article 20100609171621.ga23...@britannica.bec.de,
Joerg Sonnenberger  jo...@britannica.bec.de wrote:
On Wed, Jun 09, 2010 at 12:58:23PM -0400, Christos Zoulas wrote:
 Log Message:
 Explain variable expansion better. Requested by Aleksey Cheusov

This is wrong. Loop variables are not exapnded on each loop iteration.
Each loop iteration effectively creates a new variable. The rest of his
confusion comes from two simple facts:
(1) += is lazy in bmake. This is different from FreeBSD, where it forces
expansion.
(2) The evaluation of j is lazy as well. That's why he sees the last
loop iteration.

Well, it was true when I wrote the for code (more than 16 years
ago!). I guess dsl re-wrote it, but the net effect is the same.

When did FreeBSD changed += not to be lazy? That would break a lot
of existing Makefiles I presume.

Therefore I don't agree with the content and it is actually making
things a lot more complicated than necessary.

How is the net effect different than what I am describing? Feel free
to improve the explanation, to match the actual implementation.

christos



Re: CVS commit: src/usr.bin/make

2010-06-09 Thread M. Warner Losh
In message: huonge$v4...@dough.gmane.org
chris...@astron.com (Christos Zoulas) writes:
: In article 20100609171621.ga23...@britannica.bec.de,
: Joerg Sonnenberger  jo...@britannica.bec.de wrote:
: On Wed, Jun 09, 2010 at 12:58:23PM -0400, Christos Zoulas wrote:
:  Log Message:
:  Explain variable expansion better. Requested by Aleksey Cheusov
: 
: This is wrong. Loop variables are not exapnded on each loop iteration.
: Each loop iteration effectively creates a new variable. The rest of his
: confusion comes from two simple facts:
: (1) += is lazy in bmake. This is different from FreeBSD, where it forces
: expansion.
: (2) The evaluation of j is lazy as well. That's why he sees the last
: loop iteration.
: 
: Well, it was true when I wrote the for code (more than 16 years
: ago!). I guess dsl re-wrote it, but the net effect is the same.
: 
: When did FreeBSD changed += not to be lazy? That would break a lot
: of existing Makefiles I presume.

It looks like it is lazy to me for all non-loop variables in FreeBSD:

% uname
FreeBSD
% cat M
FOO=1
BAR=2
.for j in a b c
FOO+= ${BAR} ${j}
.endfor
BAR=3

all:
@echo ${FOO}
@echo ${BAR}
%  make -f M
1 3 a 3 b 3 c
3
%

Not sure if this is correct or expected but it strikes me as
useful and changes to this behavior would break things...

Warner


Re: CVS commit: src/usr.bin/make

2010-06-09 Thread David Laight
On Wed, Jun 09, 2010 at 06:45:35PM +, Christos Zoulas wrote:
 
 This is wrong. Loop variables are not exapnded on each loop iteration.
 Each loop iteration effectively creates a new variable. The rest of his
 confusion comes from two simple facts:
 (1) += is lazy in bmake. This is different from FreeBSD, where it forces
 expansion.
 (2) The evaluation of j is lazy as well. That's why he sees the last
 loop iteration.
 
 Well, it was true when I wrote the for code (more than 16 years
 ago!). I guess dsl re-wrote it, but the net effect is the same.

I don't have a source tree handy, and the change hasn't made it to cvsweb,
but the .for loop should:
1) evaluate the list of values when the .for list is parsed
2) process the loop body such that the value substituted for the loop
   variable differs for each iteration.

xtos's version substituted the loop variable into the text prior to
the line being parsed - that gave some rather unexpected problems.

My rewrite left the expansion as a variable substitution by subtituting
${:Uvalue} for the loop vsriable. This allows other modifiers that
use variables that are only defined later (or in commands) to work.
However it did cause some different quoting issues.

I didn't think of generating a unique name for the variable on each
iteration - and just substituting that value.
In fact this would only be needed for command lines - which have delayed
expansion. For control lines (processed during file parsing) the
value can just be put into the symbol table.
It would solve all the quoting issues.

David

-- 
David Laight: da...@l8s.co.uk


Re: CVS commit: src/usr.bin/make

2010-06-09 Thread David Laight
On Wed, Jun 09, 2010 at 01:19:29PM -0600, M. Warner Losh wrote:
 
 It looks like it is lazy to me for all non-loop variables in FreeBSD:
...
 % cat M
 FOO=1
 BAR=2
 .for j in a b c
 FOO+= ${BAR} ${j}
 .endfor
 BAR=3
 
 all:
 @echo ${FOO}
 @echo ${BAR}
 %  make -f M
 1 3 a 3 b 3 c
 3
 %
 
 Not sure if this is correct or expected but it strikes me as
 useful and changes to this behavior would break things...

That is the expected/correct behaviour.

David

-- 
David Laight: da...@l8s.co.uk