How does the gcc decide what files are to be listed as dependencies to an object file being produced, when it writes a .d file?
I'm seeing different .d files when sysroot path is absolute, and relative.
g++ --MMD --sysroot=absolute_path_to_sysroot -c -o file.o -MF file.d file.cpp
g++ --MMD --sysroot=relative_path_to_sysroot -c -o file.o -MF file.d file.cpp
I'm seeing a weird case, where, If the compiler path and --sysroot are absolute, then 2 additional header files are being listed as dependencies in the .d file.
If the --sysroot is relative, then 2 additional header files are not being listed as dependencies in the .d file anymore.
This made me wonder, what is the criterion, other than a header being #included, based on which, the .d files are actually written by the compiler, and how would sysroot affect this?
As far as I can tell, it is based on the actual directory where the file is found
The actual "make this a dependancy" happens here, where sysp
is set a few lines above based on the directory that it is found in.
http://gcc.gnu.org/viewcvs/gcc/trunk/libcpp/files.c?revision=206293&view=markup#l884
sysp gets set here:
http://gcc.gnu.org/viewcvs/gcc/trunk/gcc/incpath.c?revision=206289&view=markup#l446
Now, it gets complicated if the same directory is both in -I
and -isystem
directories. In that case, it gets determined by whether the file is included with #include <name>
or #include "name"
- those using <>
are selected only if you use -MD
or -M
, etc, where the -MMD
will ignore anything using <>
(or in a directory marked with sysp
).