views:

56

answers:

2

I'm trying to understand the build process of a codebase. The project uses both autoconf (configure scripts that generate makefiles) and Maven.

I would like to be able identify all of the file dependencies in the project, so that for any output file that ends up being generated by a build, I can identify how it was actually produced. Ultimately, I'd like to generate a diagram using something like graphviz to visualize the dependencies, but for now I just want to extract them.

Is there any automated way to do this? In other words, given some makefiles and Maven or ant XML files, and the name of the top-level target, is there a way to identify all of the files that will be generated, the programs used to generate them, and the input files associated with those programs?

A: 

I don't know about the maven side, but once you've ./configured the project, you could grep through the output of make -pd (make --print-data-base --dry-run) to find the dependencies. This will probably be more annoying if it's based on recursive make, but still manageable.

Note that if you're using automake, it computes detailed dependencies as a side-effect of compilation, so you won't get all the dependencies on #included headers until you do a full build.

Jack Kelly
+1  A: 

Electric Accelerator and ClearCase are two systems that do this, by running the build and watching what it does (presumably by intercepting operating system calls). This has the advantage of working for any tool, and being unaffected by buggy makefiles (hint: they're all buggy).

That's probably the only reliable way for non-trivial makefiles, since they all do things like generating new make rules on the fly, or have behaviour that depends on the existence of files on disk that are not explicitly listed in rules.

slowdog
@slowdog: Your assertion that "all makefiles are buggy" is about as valid as asserting that "all X is buggy", for any other use of language/tool X.
Jack Kelly
@Jack: can't tell if you're agreeing or disagreeing with slowdog.
Eric Melski
@slowdog: ElectricAccelerator intercepts at the filesystem layer, using a custom filesystem driver that is mounted in place of the source tree.
Eric Melski
@Eric: disagreeing. It's not hard to put in the effort to make correct makefiles. Alternatively, just use automake, which is actually a really nice tool, despite its infamy.
Jack Kelly
@Jack: I agree with you :-)
slowdog
What I meant was: Faced with an unknown codebase (as the OP is), it is not safe to assume that its build system explicitly describes all dependencies of the build process. Even a build system that is bug-free in the sense that it reliably produces a correct build every time can have missing dependencies.
slowdog