<p>I'm required to write documentation for my current project that lists all .c files and for each one lists every .h file which is directly or indirectly included by that file.</p>

<p>This is a large project, and although we have Makefiles which theoretically have this information, those Makefiles are sometimes incorrect (we inherited this project from another company).  We've often had to do a <code>make clean ; make</code> for our changes to actually be reflected in the recompilation, so I don't want to rely on these Makefiles.</p>

<p>So is there a tool which lets us give it the name of a .c file and an include path and have it tell us all of the .h files which are directly or indirectly included by the .c file?  We don't have anything weird like</p>

<pre><code>#define my_include "some_file.h"
#include my_include
</code></pre>

<p>so the tool doesn't need to be perfect.  Anything that searched .c and .h files in an include path for regular includes would be good enough.</p>

```
gcc -M file.c
```
does what you need.