Conversation
Does anyone know of a tool to turn Makefiles into a graphviz-style graph, *with support for recursive Makefiles*? I've found several such tools, but they all only work on one level of Makefile.

Doesn't matter if it uses graphviz or something else; I'm just looking for a DAG visualization. I'd also be happy with something that turns it into a data structure I can introspect, so I can ask questions like "what's the deepest branch".
2
0
0
@josh BuildRoot can do graphs. It is based on kbuild so pretty close at least.
2
0
1
@josh If I wanted something like I'd look how BuildRoot thing is implemented, and derive something more generic from that. The reason being that it is already pretty well field tested.
0
0
0
If I'm understanding correctly, that would only work for software already using BuildRoot for building, rather than for arbitrary makefiles, right?
1
0
0

@josh You want to do this for a specific invocation of a makefile, or statically?

The latter seems quite hard to do reliably, even if you assume limited logic triggering the recursion.

If the former, the infrastructure for tools like https://github.com/rizsotto/Bear or scan-build could be helpful?

Depending on what dependencies you're looking for, it could also be worth to look at compiler/linker generated dynamic dependencies.

3
0
0

@josh Similar to the longstanding support in compilers (via -M -MP) linkers recently-ish got support for emitting those dependencies via --dependency-file=.

Of course using just the generated dependencies will often miss a lot of dependencies just in the makefile...

0
0
0

@josh On second thought, depending on the build definition, just using make -s -p might do the trick, with a bit of parsing of the output? Dealing with targets that print output even with -s could be a bit annoying.

0
0
0
I could live with "for one invocation"; that would be enough to do some interesting analysis. Though it'd be nice to not have to actually *run* the build.
0
0
0
@josh that is correct. on plus side it is still built on top of fairly primitive blocks so thought that it might be good to mention anyhow.

If I really had to do this. I would simply create a fake cross compile toolchain let's say CROSS_COMPILE=" dot-linux-". For all tools I would implement either take no other action but returns success but those relevant to the graph I'd update the dot file.

That is at least universal across toolchains (GCC, LLVM) and requires zero changes to the makefiles, and you'd only had to implement it once.
1
0
0
@josh Or probably would have some intermediate presentation for the graph that I would later on render as dot file.
1
0
0
@josh actually that sort of mock cross compilation toolchain would be pretty useful as a tool
0
0
0