Makefile always thinks the project is updated, but the files do not even exist

I have the following make file:

  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'm trying to link two different .cc / .h files depending on which implementation I want to use. If I do real_clean, none of the .cc / .h files exist, I just have a driver.cc file and a makefile in the folder. If I call, he says they are relevant. This happens even if I edit the files in adjl / adjm to make them newer.

  [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 makefile template from another project that I did, and they are written the same way, but I can repeatedly do the same commands without the "actual" problems.

I have googled, but I did not find a problem similar to mine (usually they seem to attract users who do not clean up before they are created).

Thanks for reading.

+7
source share
3 answers

The problem is that you have a directory with a name similar to your goals in the Makefile.

When releasing make adjl check the adjl file, which it finds and does nothing. Rename the goals to something else and try again.

+18
source

The goals of adjl and adjm are real goals. Since they have no dependencies and the files are present (2 directories in your listing), make does nothing (because they are around).

However, you want to specify adjl and adjm as fake targets (so that the commands execute when you specify them). For this

 .PHONY: adjl adjm 

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

EDIT

In fact, the real_clean and clean rules must also be made fake.

+8
source

You have directories with the same name as your goals.

Since your goals are not dependent on anything, they will always be considered relevant.

When specifying a target that is not associated with a file on disk, you need to use a special .PHONY target:

 .PHONY: adjl adjm 

You must also do the same for your clean and real_clean goals, otherwise they will break if someone creates a file called "clean".

+3
source

All Articles