Requires a makefile dependency rule that can handle missing files

We use GNU Make for our system. At the end of our makefiles, we have an include called Makedepends that generates a bunch of .d files using the -MM switch to gcc. Then we include the .d file for each .cc file using the include line (CXXFILES: .cc = .d). But when we delete the file or move the files, the dependency step is interrupted, and we must manually delete the .d files (even make clean does not work because the dependencies fail)

Is there a way to generate these .d dependency files or include these .d file dependencies that will gracefully handle file deletion or movement?

EDIT: For example: I have serial.cc, and the make files generate a serial.d file that has a dependency on buffer.h, but then I change it, so I no longer need buffer.h and I delete the buffer.hour. The next time I run make, it will suffocate because it includes the .d file, which still makes serial.o dependent on buffer.h.

+3
source share
3 answers

http://make.mad-scientist.net/papers/advanced-auto-dependency-generation contains a description of this exact problem and several ways to solve it. The first of them is a little erroneous, but the "advanced" is essentially in place.

+5
source

Two possibilities:

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

.SUFFIXES: .d

%.d::
   makedepend_command_here

, Last Resort info GNU Make:

, makefile, , , . :

 %::
         touch $@

( ) .

.d ?

0

makepp --rm-stale, , . , .makepprc .

But then, of course, makepp handles all this dependency detection, so you don't need to clutter up your makefile. This is even better than your approach, because it can generate the necessary headers on time so that the compiler can pick up where it gcc -MMwill fail.

There are more to makepp. Besides doing just about everything GNU can do, there are many more useful things, and you can even extend your makefiles with some Perl programs.

0
source

Source: https://habr.com/ru/post/1698734/


All Articles