Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Makefile always thinks project is up to date - but files don't even exist

Tags:

c++

makefile

I have the following makefile:

CCC = g++
CCFLAGS = -ansi

driver: driver.o graph.o
        $(CCC) -o driver driver.o graph.o

graph.o: graph.h
driver.o: graph.h

adjl:
        rm -f graph.h graph.cc
        ln -s adjl/graph.cc .
        ln -s adjl/graph.h .
        touch graph.cc graph.h
adjm:
        rm -f graph.h graph.cc
        ln -s adjm/graph.cc .
        ln -s adjm/graph.h .
        touch graph.cc graph.h

clean:
        rm -f *.o
real_clean: clean
        rm -f graph.cc graph.h
        rm -f driver

The idea is that I am trying to link two different .cc/.h files depending on which implementation I want to use. If I make real_clean, none of the .cc/.h files exist, I merely have a driver.cc file and the makefile in the folder. If I call make, it says they are up to date. This happens even if I edit the files in adjl/adjm to make them "newer" versions.

 [95]% ls
adjl/  adjm/  driver.cc  makefile
 [96]% make adjl
make: `adjl' is up to date.
 [97]% make adjm
make: `adjm' is up to date.

I took the template makefile from another project I had done, and they are written the same way but I can repeatedly make the same commands with no "up to date" issues.

I have googled but have not found a problem similar to mine (they generally seem to involve users who aren't cleaning before making).

Thanks to anyone for reading.

like image 963
Dwayne Avatar asked Dec 14 '10 02:12

Dwayne


2 Answers

The problem is that you have directory named the same as your targets in Makefile.

When you issue make adjl make checks for file adjl which it finds and does nothing. Rename targets to something else and try again.

like image 52
stefanB Avatar answered Sep 23 '22 15:09

stefanB


The adjl and adjm targets are real targets. Since they have no dependencies, and the files are present (the 2 directories in your listing), make doesn't do anything (because they are around).

However, what you want is to specify adjl and adjm as phony targets (so that the commands are executed when you specify them). To do so,

.PHONY: adjl adjm

Read http://www.gnu.org/software/automake/manual/make/Phony-Targets.html for more information.

EDIT

In fact, the real_clean and clean rules should probably also be made phony.

like image 41
lijie Avatar answered Sep 20 '22 15:09

lijie