10

Closely related to How to display dependencies given in a makefile as a tree? But the answers given there is not satisfactory (i.e. do not work).

Is there a tool to visualize the Directed Acylic Graphs (DAGs) coded up in standard Makefiles? eg, a shell-script for post-processing through Unix pipes can be an acceptable solution as well (maybe there is a pandoc filter to convert MakeFiles to graphviz or LaTeX).

I don't strictly need a tool that directly typesets this graphical visualisation? Just a common file-format translation of the makefile to a graph-viz file or something similar would suffice.

  • 1
    You can use `dot` etc. from the `graphviz` package to render DAGs. Transforming a (simple) makefile (explicit direct dependencies) into `dot` format is an exercise in shell programming, or perl etc. (split lines with colon in part before colon and part after colon). – dirkt Oct 25 '17 at 17:11
  • @dirkt, is there a rudimentary shell script available somewhere? I am really new to *nix programming – Dr Krishnakumar Gopalakrishnan Oct 25 '17 at 17:26
  • Is your `makefile` recursive: does it include `$(MAKE)` or `make`. If so it will be slow, and generating this graph will be very very hard. (Recursion is usually good, but recursive make is bad.) – ctrl-alt-delor Jul 02 '19 at 08:02
  • Related: https://stackoverflow.com/q/2947821/537980 https://gist.github.com/carlislerainey/9a1e49cb195076165a4f07a683ce05a7 – ctrl-alt-delor Jul 02 '19 at 08:09

1 Answers1

9

I believe makefile2graph does exactly what the original post author wanted.

For the full installation and usage example:

  • Installation (make sure graphviz is installed, e.g. with sudo apt install graphviz on Debian systems)
cd /my/install/dir
git clone https://github.com/lindenb/makefile2graph
cd makefile2graph
make
  • Generate PNG (no need to use dedicated variable GDIR if you add makefile2graph's path to your PATH variable)
cd /path/to/my/makefile
GDIR=/my/install/dir/makefile2graph
make -Bnd |  ${GDIR}/make2graph | dot -Tpng -o my_graph.png
michael
  • 206
  • 2
  • 3