Question

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.

Was it helpful?

Solution

http://make.mad-scientist.net/papers/advanced-auto-dependency-generation 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.

OTHER TIPS

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?

If you use makepp with the option --rm-stale, it will notice files which are no longer buildable and remove them. If this is a normal usecase for you, you can put that option into .makepprc at the root of your build tree, and it will always be used.

But then of course makepp handles all this dependency detection itself, so you don't need to clutter your makefile. It is even better than your approach, because it can generate needed headers in time for the compiler to pick up, where gcc -MM would fail.

There is much more to makepp. Besides doing almost all that GNU make can, there are lots more useful things, and you can even extend your makefiles with some Perl programming.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top