Reputation: 1719
C Makefile
This question has a close duplicate, but I still can't fix my problem.
I have the following Makefile:
CFLAGS0 =
CFLAGS1 = -O1
CFLAGS2 = -O2
CFLAGS3 = -O3
CFLAGS4 = -O4
mountain: timer.o mountain.o
gcc -o mountain timer.o mountain.o
timer.o: timer.c timer.h
gcc -c -O2 timer.c
mountain.o: mountain.c timer.h
gcc -c $(CFLAGS1) mountain.c #I'm trying to make changes here
clean:
rm *.o mountain
I'm trying to compile with different optimization levels by changing the flag. But when I try to make, I'm told that 'mountain' is up to date? What am I missing? Thanks.
Upvotes: 0
Views: 410
Reputation: 31
Special targets are case sensitive.
Should add one line
.PHONY : mountain mountain.o timer.o
Upvotes: 0
Reputation: 46249
The makefile looks at the modification time of the sources to each recipe to decide if they should change. If you're changing the makefile itself, it won't notice. But you can tell it to, on a per-recipe basis:
mountain.o: mountain.c timer.h Makefile
gcc -c $(CFLAGS1) mountain.c
Obviously if your makefile is named something different you will have to change that to match.
Also, if you're using GNU Make, you can tell it to always consider a particular recipe to be outdated. But you should avoid this, because it removes the main optimisation of make;
.phony : mountain.o
mountain.o: mountain.c timer.h
gcc -c $(CFLAGS1) mountain.c
This is intended for abstract rules, such as clean
.
Upvotes: 3