views:

634

answers:

4

What I'm looking for is a tool that, given a root source file, outputs a graph of file dependencies (with some customization thrown in, of course, like --maxdepth, etc.)

+1  A: 

Been asked many times before. always the same answer - doxygen.

anon
+4  A: 

doxygen has a graph of file dependencies as one of its several outputs. It might not be exactly what you want, but it is a start.

CesarB
Yeah, it mentions it in the documentation, but it only seems to work for "documented" files, according to the manual. In other words, if you just run it on a source tree, it won't generate a graph. Any doxygen experts would like to chime in at this point?
Lajos Nagy
You need to create a configuration file (or better get doxygen to do it for you). You then need to edit the file to turn on quite a few features. I don't produce full trees normally, so I don't have an example to hand.
anon
You may be calling it to ignore undocumented members. Doxygen can definitely parse everything, given the right options.Check the following options:EXTRACT_ALLHIDE_UNDOC_MEMBERSHIDE_UNDOC_CLASSESYou may also need dot (via Graphviz) to generate class diagrams and other useful stuff.
Soo Wei Tan
I'd also mention that setting RECURSIVE to YES (it's NO by default) is a good idea as it will tell doxy to process subdirectories (makes sense for a source tree, n'est-ce pas?)
Lajos Nagy
A: 

I know it's not open source (nor linux, which you don't mention in your question but is in your tags), but I've found the best solution to this problem is ProFactor IncludeManager -- it was the best answer to a question I asked that is pretty much an exact dupe of your question, minus the open-source bit (hence why I didn't mark your question as a dupe of mine).

rmeador
+6  A: 

For the impatient, who, like me, just want a list of commands and not RTFM :) So without further ado (assuming you have Debian, or its ilk) ...

First, install Doxygen and Graphviz (which provides `dot' for drawing directed graphs):

apt-get install doxygen graphviz

Next, tell Doxygen to generate an initial config file that we can then modify by hand:

doxygen -g

This will result in a new config file, called Doxyfile, generated in the current directory. You can then modify it with your favorite text editor. Make sure to set the following flags to the specified values:

HAVE_DOT = YES
RECURSIVE = YES
EXTRACT_ALL = YES
GENERATE_LATEX = NO  # Unless you want LaTeX output besides the HTML ...

You might also want to set the following two flags to tell Doxygen where to generate the documentation (which is basically just a bunch of files organized into a directory structure):

PROJECT_NAME = Foobar
OUTPUT_DIRECTORY = /tmp/foobar/doc

All that remains is to tell doxygen to do its thing:

cd foobar/src
doxygen ~/Doxyfile  # Assuming you saved Doxyfile in your home directory.

Now, if you are lucky, you can point your browser at the file /tmp/foobar/doc/html/index.html, select the "Files" tab, and then click on a header file to look at two nice graphs: one shows which header files are included by your header file (directly or indirectly), while the other shows what other files include directly or indirectly the given header file.

Lajos Nagy
+1: Ah, beautiful answer. I was just trying to use Doxygen to generate an include file graph and wondered why it didn't work - turned out that `EXTRACT_ALL` wasn't set to `YES`.
Frerich Raabe