Subject: Re: arithmetic in make
To: None <tech-toolchain@NetBSD.org>
From: der Mouse <mouse@Rodents.Montreal.QC.CA>
List: tech-toolchain
Date: 02/25/2007 11:12:29
> .for file in ${MYFILES}
> cp ${file} dir/file{$n}
> .endfor
n := 1
.for file in $(MYFILES)
cp $(file) dir/file$(n)
n != echo $(($(n)+1)) # or != expr $(n) + 1
.endfor
I don't know of any way to do the arithmetic itself within make. For
general arithmetic, it's probably possible, but I suspect only with the
help of an include file which implements recursion through re-including
itself. However, incrementing is a special case:
n := 1
.for file in $(MYFILES)
cp $(file) dir/file$(n)
n1 := $(n:C/\(.*\)\(.\)\(9*\)/\1/)
n2 := $(n:C/\(.*\)\(.\)\(9*\)/\2/)
n3 := $(n:C/\(.*\)\(.\)\(9*\)/\3/)
n := $(n1)$(n2:S/9/10/:S/8/9/:S/7/8/:S/6/7/:S/5/6/:S/4/5/:S/3/4/:S/2/3:S/1/2/:S/0/1/)$(n3:S/9/0/g)
.endfor
The three regex lines can probably be done with only one regex line,
producing a string containing delimiters, picking apart the result
separately.
/~\ The ASCII der Mouse
\ / Ribbon Campaign
X Against HTML mouse@rodents.montreal.qc.ca
/ \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B