title: Is it possible to generate list of dependencies for a C++ file?
body: <p>I want to create a list of dependencies for particular file. For example:</p>
  
  <pre><code>//a.cpp
  #include "b.h"
  #include &lt;cstdio&gt;
  int main(){printf("%d\n",fn());}
  
  //b.h
  int fn();
  
  //b.cpp
  #include "b.h"
  #include "c.h"
  int fn(){return fn2();}
  
  //c.h
  inf fn2();
  
  //c.cpp
  #include "c.h"
  int fn2(){return 5;}
  </code></pre>
  
  <p>For those files, <em>a</em> depends on <em>b</em> which depends on <em>c</em>. So the result of the wanted program should be:</p>
  
  <pre><code>a: a.o b.o c.o
  </code></pre>
  
  <p>Yes, it is for makefiles. For some reasons I do not want the list to include ALL <code>.o</code> files in directory, so <code>%.o</code> won't work. Also, I'm aware of <code>g++ -MMD</code> option, and it <em>almost</em> works as I want - but it lists only direct dependencies, in this case:</p>
  
  <pre><code>a.o: a.cpp b.h
  </code></pre>
  
  <p>(the extensions are not an issue, I can post-process them later)</p>
  
  <p>Is there an easy way for generating such a list?</p>