Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loops in Makefile

I have a lot of assignments where I have to continually update a Makefile as I add more subsequently numbered C programs. Is there a way to do this with a loop which iterates over the values 1.1, 1.2, 1.3, etc.?

all: 1.1 1.2 1.3 1.4 1.5 1.6 1.7. 1.8 1.9

1.1: 1.1.o
    gcc -o 1.1 $(FLAGS) 1.1.o
1.1.o: 1.1.c
    gcc -c $(FLAGS) 1.1.c

1.2: 1.2.o
    gcc -o 1.2 $(FLAGS) 1.2.o
1.2.o: 1.2.c
    gcc -c $(FLAGS) 1.2.c

1.3: 1.3.o
    gcc -o 1.3 $(FLAGS) 1.3.o
1.3.o: 1.3.c
    gcc -c $(FLAGS) 1.3.c

1.4: 1.4.o
    gcc -o 1.4 $(FLAGS) 1.4.o
1.4.o: 1.4.c
    gcc -c $(FLAGS) 1.4.c

1.5: 1.5.o
    gcc -o 1.5 $(FLAGS) 1.5.o
1.5.o: 1.5.c
    gcc -c $(FLAGS) 1.5.c

1.6: 1.6.o
    gcc -o 1.6 $(FLAGS) 1.6.o
1.6.o: 1.6.c
    gcc -c $(FLAGS) 1.6.c

1.7: 1.7.o
    gcc -o 1.7 $(FLAGS) 1.7.o
1.7.o: 1.7.c
    gcc -c $(FLAGS) 1.7.c

1.8: 1.8.o
    gcc -o 1.8 $(FLAGS) 1.8.o
1.8.o: 1.8.c
    gcc -c $(FLAGS) 1.8.c

1.9: 1.9.o
    gcc -o 1.9 $(FLAGS) 1.9.o
1.9.o: 1.9.c
    gcc -c $(FLAGS) 1.9.c

clean:
    rm -f *.o
    rm -f 1.1 1.2 1.3 1.4 1.5 1.6 1.7. 1.8 1.9
like image 401
titaniumdecoy Avatar asked Dec 31 '22 08:12

titaniumdecoy


1 Answers

You want a suffix rule, not a loop.

like image 187
S.Lott Avatar answered Jan 04 '23 18:01

S.Lott