It is correct that ccache currently doesn't support the compiler options -M
and -MM
(and it never has supported them).
Some reasons for why the options in question are unupported:
- The options tell the compiler to let the preprocessor output make rules instead of the preprocessed source code. This is not a good match for how ccache works; it needs to get hold of the "real" preprocessed output for each compiler invocation (see https://ccache.dev/manual/3.7.11.html#_how_ccache_works).
- Nobody has implemented support for the mentioned options, simply put.
It would most likely be possible to implement support by letting ccache run the compiler command twice: one without -M
/-MM
to retrieve the preprocessed source code (with which the result should be associated) and one with -M
/-MM
to retrieve the result (make rules).
However, I (speaking as the ccache maintainer for the last six years) have not heard anybody missing support for -M
/-MM
until now, so my impression is that -M
/-MM
actually aren't used much.
Am I missing something? Is there a more preferred option?
Yes, I would say that the standard way is to use -MD
/-MMD
(which are supported by ccache) instead of -M
/-MM
. -MD
/-MMD
are superior because they produce both the .o
and the .d
file in one go, whereas -M
/-MM
only produce the .d
file, so the compiler must in that case be invoked twice by the Makefile for each source code file. See for instance http://www.microhowto.info/howto/automatically_generate_makefile_dependencies.html for how to use -MD
/-MMD
.