I'm starting a new project and thinking of using gcc 6.3.1 -MM to generate the dependencies into a file called Make.Dep, that I'll include from Makefile.
The -M option outputs all headers, including system headers. The -MM option doesn't output system headers, but I'm still buried in literally thousands of vendor and package headers such as Sybase and Boost, which I don't think will change (and if they do I'm happy to have to do a full rebuild manually).
Obviously I could wrap gcc -MM in a perl script or what have you that knows what directories I consider packages, but is there some more widely-accepted solution?
Note that one of my vendors' headers look for specific gcc-defined pre-processor symbols to configure their portability. I'd rather not curate a set of such symbols manually to allow dependency generation with some non-gcc method (e.g., makedepend).
Instead of
-I, use-isystemto state directories that you don't wish to be output with-MM.This is not mentioned currently at https://gcc.gnu.org/onlinedocs/gcc/Preprocessor-Options.html despite it seeming to be very closely tied to
-Mand-MMoptions.Example: this creates correct dependencies of foo.cpp and bar.cpp, including Sybase headers:
Example: this does the same, but not including Sybase headers:
Here is a sample
Makefileimplementation forgmake. Thepatsubstfunction is a pattern substitution using % as a part that matches on the "before" that is then captured and used in the "after."isystemappears to need a space after it, but this is easy to generate withpatsubstas the percent sign keeps the space from being truncated. The minus option on-includetellsgmakenot to complain if the file named doesn't exist. This allows you to usegmaketo makedependand produceMake.Depeven before there is aMake.Dep.Finally, this assumes$(PkgIncDirs)hold package include directories none of which should be changing, while$(ProjIncDirs)would be include directories inside the project that you'd want dependencies to be generated for.