GC: Makefile loop math

This weeks the Geek Challenge is brought to you by the letter 'M', mmmm makefiles are fun.

Somehow I have taken on the joy of answering makefile questions which more time than not really turn in to scripting questions and just how to do it in a makefile. Here is one that I recently worked on:

How can I set and use a variable inside a loop in a makefile so that var1=var2\*var3, where var2 is update in the loop?

ARY1=1 2 3 4 5
VAR3=2
loop:
    @for i in $(ARY1); do \\
        (VAR1=$(VAR3)\*$$i ; \\
        echo $(NP) ; \\
    done;
So there it is. The problem has been solved but I thought I would throw it out to the Geek Challenge as well and see what you all come up with. I will post what we used in a couple of days.

For what it's worth.

Comments:

Well since no one has posted what they thinks might be a solution, I will post what we used as a solution.


ARY1=1 2 3 4 5
VAR3=2
loop:
    @for i in $(ARY1); do \\
        (VAR1=$(VAR3)\*$$i ; \\
        echo $$NP ; \\
    done;

Note the double $ on the NP inside the loop when you want to use the assigned variable.

dl

Posted by Dan Lacher on December 16, 2005 at 04:22 AM EST #

Post a Comment:
Comments are closed for this entry.
About

dlacher

Search

Archives
« April 2014
SunMonTueWedThuFriSat
  
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
   
       
Today