amorimluc
amorimluc

Reputation: 1719

Why does Makefile think it's up-to-date despite changes being made?

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

Answers (2)

Xiangyu Meng
Xiangyu Meng

Reputation: 31

Special targets are case sensitive.

Should add one line

 .PHONY : mountain mountain.o timer.o

related question

make special targets

Upvotes: 0

Dave
Dave

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

Related Questions