18

Large complex make files can be daunting to read and examine. What tools are good for visualizing or otherwise examining a gnu make file?

Johnny
  • 1,144
  • 2
  • 11
  • 23
  • For what it's worth, I just use the Mk. I eyeball plus editor combo...most people write pretty similar makefiles and you get used to it. That is not true of machine generated makefiles, but for those you should probably start with the input to the generator. – dmckee --- ex-moderator kitten Mar 05 '10 at 03:18
  • 3
    You can use make -d (and optionally -n) to have it print out what's going on, which is often helpful. – i_am_jorf Mar 05 '10 at 03:25

4 Answers4

20

I tried to use CPAN's visualizer and failed. So, I've written my own quick-n-dirty Makefile visualizer.

You may want to try it: http://github.com/vak/makefile2dot

vak
  • 1,694
  • 14
  • 18
9

There is a Perl library for building GraphViz figures from Makefiles:

https://metacpan.org/pod/GraphViz::Makefile

Suic
  • 2,441
  • 1
  • 17
  • 30
Joe Carnahan
  • 2,373
  • 14
  • 15
  • 1
    I found this similarly named one and it's also good for producing png files http://search.cpan.org/~agent/Makefile-GraphViz-0.18/lib/Makefile/GraphViz.pm – Johnny Apr 14 '10 at 04:55
  • 1
    It would be helpful to include some info on getting this to work. For example: 1) install [dependency], 2) install [thisPerlLibrary] via [method], then 3) run [`foo Makefile out.png`] to produce the result. – jvriesem Mar 02 '19 at 17:21
4

I've had good success with the --print-data-base (-p) option.

Combined with --just-print (-n, --dry-run) and redirecting stdout to a file creates a new single makefile containing all the rules and variables in a generic format which you may find easier to understand.

With really bad makefiles I've gone as far as parsing this output in Perl to generate a new build system!

Martin Fido
  • 1,070
  • 11
  • 12
3

I don't know of a tool that can make sense of a set of makefiles. It may indeed be nearly impossible to create one as most large make based build environments are a hodge-podge of random commands, frightening macro substitution, and hugely context dependent control flow.

As an aside, I hear good things about SCons which I'm looking at because I'm involved with a system make environment which has become a maintenance nightmare in its own right.

msw
  • 42,753
  • 9
  • 87
  • 112
  • SCons is my favorite build system, but make has one huge advantage. You can quickly write a make file to execute any program against a set of files. SCons uses various plugins for different build task, it includes plugins for common compilers, but in some cases you might have to write your own. – mikerobi Mar 05 '10 at 03:39