views:

1069

answers:

2

We use GNU Make for our system. At the end of our makefiles, we have an include called Makedepends which generates a bunch of .d files using -MM switch on gcc. We then include the .d file for each .cc file using an include $(CXXFILES:.cc=.d) line. But when we delete file or move files, the dependancies step breaks and we have to manually delete the .d files (even a make clean doesn't work because the dependencies fail)

Is there a way to generate these dependency .d files or include these dependency .d files which will gracefully handle a file deletion or relocation?

EDIT: For example: I have serial.cc and the makefiles generate a serial.d file which has a dependency on buffer.h but then I change it so I don't need buffer.h any more and I delete buffer.h. Next time I run make, it will choke because it includes the .d file which still makes serial.o depend on buffer.h.

A: 

Two possibilities:

First, can you add a rule to your Makefile to run the dependency step:

.SUFFIXES: .d

%.d::
   makedepend_command_here

If not, then from the Last Resort section of the info page for GNU Make:

For example, when testing a makefile, you might not care if the source files contain real data, only that they exist. Then you might do this:

 %::
         touch $@

to cause all the source files needed (as prerequisites) to be created automatically.

Will this work to create empty .d files for you?

Adam Liss
it's not so much that the .d files are missing but that if the .cc file is removed, the corresponding .d file is still hanging around from the previous make and it will cause make to fail because it is depending on the .c file.
MattSmith
Then I recommend wnoise's link: as he says, scroll past the first section to the "useful" part. And do try "info make" or find a good book on make for details and examples. You're never "finished" learning make ... there's always another gem! Good luck!
Adam Liss
+1  A: 

http://make.paulandlesley.org/autodep.html has a description of this exact problem, and a couple of ways around it. The first is a bit misguided, but the "advanced" is essentially spot on.

wnoise