Subject: Re: arithmetic in make
To: Manuel Bouyer <bouyer@antioche.eu.org>
From: David Laight <david@l8s.co.uk>
List: tech-toolchain
Date: 02/25/2007 17:48:17
On Sun, Feb 25, 2007 at 06:35:52PM +0100, Manuel Bouyer wrote:
> > 
> > .for file in ${MYFILES}${n::=n}
> > 	cp ${file} dir/$file${n:[#]}${n::=$n n}
> > .endfor
> 
> Well, I don't claim to understand it but it seems to work.

${<var>::=<str>} assigns <str> to $<var> and expands to nothing.
${<var>:[#]} returns the number of 'words' in $<var>.

So on the '.for' line we set ${n} to "n".
On the 'cp' line we generate the number of words in "n" ie 1,
the set ${n} to "${n} n" or "n n".
Rinse and repeat.

The ${n::=$n n} is probably better written as ${n::+= n}
(which doesn't seem to need the ' ', so is either a make bug or a
documenttaion bug.)

	David

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