Open-source project
lindenb/makefile2graph avatar
lindenb/makefile2graph

makefile2graph: turning a GNU Make dependency graph into a picture

Creates a graph of dependencies from GNU-Make; Output is a graphiz-dot file or a Gexf-XML file.

668 stars70 forksCMIT

At a glance

What is it?
makefile2graph is a small C program that reads the database dump of GNU Make and emits a dependency graph as Graphviz dot, Gexf XML, PlantUML, Mermaid, or a list of the deepest independent targets. It reads make output rather than parsing Makefiles, which is both its strength and its limit.
Who is it for?
makefile2graph suits engineers who need to see the dependency shape of a large GNU Make project, who want to export it into Gephi, PlantUML or Mermaid, or who need the deep mode to find targets that can be built in parallel on a cluster. It is the wrong choice for projects using recursive make, since sub-makefiles are not supported, and it is the wrong choice for a toolchain that does not emit the database output it parses.
Can I use it commercially?
Yes. MIT is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
Is it still maintained?
Activity is slowing. The repository last received commits 6 months ago.
What is it written in?
Mainly C, according to GitHub's language statistics.

Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.

Editorial analysis

make2graph reads make's database output instead of parsing Makefiles

makefile2graph is a C program that creates a graph of dependencies from GNU Make. The mechanism is the interesting part, and it is not a Makefile parser. The program consumes the database output that GNU Make itself produces, so the dependency structure comes from the make program rather than from a reimplementation of make's rule semantics. The usage lines in the documentation show the pattern: make is invoked with the flags that print the database, and that output is piped into make2graph, which writes the graph to standard output. That design has a practical upside. Conditional rules, pattern rules, variable expansion and the rest of make's behaviour are resolved by make itself, so the graph reflects what make would actually do. The cost is equally clear. The tool only sees what the make invocation prints, so anything the database dump omits is missing from the graph, and the documentation states plainly that sub-makefiles are not supported, which rules out recursive make setups. The output can be generated in several formats, and the option list in the README enumerates them as a single letter each, with dot as the default, plus xml, gexf, Mermaid, PlantUML, a deep mode and a list mode.

Five output formats cover Graphviz, Gephi, PlantUML and Mermaid

The format options are compact and each one maps to a specific downstream tool. The default is dot output for Graphviz, and the alternatives are xml for Gexf XML, which the documentation links to the Gephi project, Mermaid output, and PlantUML output. The two remaining formats are not graphical at all. One prints the deepest independent targets, and the other lists all targets. The README explains why the deep mode exists in unusually personal terms: it was added because the author needed it while working on a cluster and needed to know the deepest independent targets that should be made. That is a narrow, useful answer to a narrow, useful question. On a machine with many cores, the maximum depth of the dependency tree tells you how much parallelism is available, and the deep mode answers it directly rather than leaving you to read the graph yourself. The plantuml and mermaid additions are dated 2023-08-30 in the history section, and an entry dated 2023-08-14 records that options for setting graph, node, edge and dirty attributes were added, which is what makes the themeable output possible.

The pipeline is make, then make2graph, then your renderer

Because the tool sits in the middle of a pipe, the typical use is a three stage command. Producing a dot file is the shortest form:

bash
make -Bnd | make2graph > output.dot

The same graph can be rendered to an image in one line, since Graphviz does the drawing:

bash
make -Bnd | make2graph | dot -Tpng -o out.png

Switching format is a matter of the format flag, and the flag letter is part of the option list:

bash
make -Bnd | make2graph --format x > output.xml

The attribute options are what let you control the appearance of the rendered output. The graph, node, edge and dirty attributes can each be set, and the documented PlantUML invocation passes a different value to each:

bash
make -Bnd | make2graph --format p -g "skinparam BackgroundColor LightYellow" -n "BackgroundColor Peru" -e "skinparam ArrowColor Blue" -d "BackgroundColor Salmon" > output.puml

The four flags correspond to the four attribute scopes: the graph itself, all nodes, all edges, and dirty nodes only. The dirty node distinction is a convenience of the graph model rather than something about make, since the dot example in the documentation shows targets and sources coloured differently in the same graph.

Building it is a single make target with a -O3 default

There is no package manager step in the documentation, just a compile. The build section is a single command:

bash
make

The Makefile at the root of the repository is short and does the standard Unix install layout. The program is built as bin_PROGRAMS = make2graph with a matching shell wrapper makefile2graph installed as a bin_SCRIPTS, and the compile flags default to -O3 -Wall through a CFLAGS assignment that uses the ?= operator, so a caller can override them without editing the file. The install target creates the binary and script directories, copies the two binaries into the bindir, copies the LICENSE, README.md and screenshot.png into a package documentation directory, and installs the make2graph.1 and makefile2graph.1 man pages into a man1 directory under a /usr/local prefix. An uninstall target removes each of those four categories in turn, so the same make target that installed the files can take them back out. The repository root holds make2graph.c as the source, the man pages in both spellings, the Makefile and a screenshot, and there is a .travis.yml for continuous integration.

The test target exercises every output format the tool claims

The Makefile carries a test target that doubles as the most compact piece of documentation in the project, because it invokes the tool once per documented behaviour. The test target depends on the build and then pipes the make database output through make2graph in each of its modes: the default dot output, then --format x, --format m for Mermaid, --format l for the list of all targets, and --format e for the deep independent targets. It also runs the tool with --root to show the root node, exercises the colour scheme option with a dotted attribute, and applies graph, node and edge attributes together in a single invocation, where -g sets graph attributes, -n sets node attributes and -e sets edge attributes.

The same target also covers the PlantUML format with the four attribute options and the Mermaid format with fill and stroke colours. That last set is the reason to read the test target rather than the README alone, since it demonstrates a colour attribute value using the Mermaid syntax of fill and stroke rather than the Graphviz syntax of bgcolor. The repository also ships a tests/ directory and a resources/ directory alongside the top level source files.

LC_ALL=C is not optional if your shell is not English

There is one locale caveat and it has bitten people before. The documentation states that make2graph only parses English messages from GNU make, and that if you are using another locale you should set LC_ALL=C. The reason follows from the architecture described earlier. Since the tool consumes make's textual database output, it is matching against the English words that make prints, and a localised make emits different strings in its diagnostics and rule listings. The failure mode is therefore a parse that produces an empty or wrong graph rather than a clear error, which is the sort of thing that costs an afternoon if you did not know to look at the locale. The options list contains two more formatting switches that are easy to overlook. The basename option prints only the file basename, and the suffix option prints only the file extension, both of which matter when the graph feeds a tool that keys on file names. There is also a root option to show the root node, and a version option, which the history section records as added on 2014-10-07.

A packaged release from 2021 and a repository pushed in 2026

The maintenance picture is uneven and worth stating plainly. The listed release for this project is version 2021.11.06, published on 2021-11-06, while the last push to the repository was on 2026-04-20. Those two dates point in opposite directions and mean different things. The history section records format additions in 2023 and option additions in 2014, so the source has continued to move for years after the tagged release, which suggests the released tarball is behind the code in the repository. For anyone installing from a distribution package rather than compiling, that gap is the thing to check, since the format list in the README may describe options that the packaged binary does not have. The repository publishes no homepage and the documentation gives no package recipe for any particular distribution, so the documented install path really is the make target described above. The licence is MIT, which is permissive and allows modification and redistribution as long as the copyright notice and licence text are retained, and the repository ships a LICENSE file at the root along with a screenshot and two man pages. The tool has no dependencies beyond a C compiler and Graphviz if you want to render the dot output, and there is no configuration file, which is appropriate for something that reads standard input.

Editorial conclusion

makefile2graph suits engineers who need to see the dependency shape of a large GNU Make project, who want to export it into Gephi, PlantUML or Mermaid, or who need the deep mode to find targets that can be built in parallel on a cluster. It is the wrong choice for projects using recursive make, since sub-makefiles are not supported, and it is the wrong choice for a toolchain that does not emit the database output it parses. Verify first that your make invocation produces the expected dry-run output, set LC_ALL=C if your shell locale is not English, and check the release date of the packaged version you install before assuming the format list you read about is the one you have.

Frequently asked questions

How do I generate a dependency graph from a Makefile?

Pipe the database output of GNU Make into make2graph, for example make -Bnd | make2graph > output.dot. The dot format is the default, and other formats are selected with the --format option.

Which output formats does makefile2graph support?

The option list covers dot for Graphviz, xml for Gexf XML, Mermaid output, PlantUML output, plus a mode that prints the deepest independent targets and a mode that lists all targets.

Does makefile2graph support recursive make?

No. The README states that sub-makefiles are not supported, which rules out projects that split their build across recursive make invocations.

What does the deep output mode in make2graph do?

It prints the deepest independent targets, added because the author needed to know the deepest independent targets that should be made while working on a cluster. It is selected with --format e.

Official sources

  1. Issues
  2. License: MIT
  3. lindenb/makefile2graph on GitHub
  4. README
  5. Releases
Add this badge to your README

If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.

Add this badge to your README

markdown
[![Hysen Labs](https://hysenlabs.com/badge/lindenb-makefile2graph.svg)](https://hysenlabs.com/projects/lindenb-makefile2graph)

Was this useful?