Skip to content

Instantly share code, notes, and snippets.

Last active October 12, 2022 10:18
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save carlislerainey/9a1e49cb195076165a4f07a683ce05a7 to your computer and use it in GitHub Desktop.
Drawing the Makefile DAG

How to Draw a Makefile as a DAG

Makefile for latent-dissent.

Makefile for unnecessary.

Goal: Draw the DAG showing file dependencies implied by the Makefile for a project.

Solution: @lindenb's makefile2graph code.

Here's how I draw these DAGs on my Mac.

Setting Up

First, install Homebrew. In a terminal, run:

/usr/bin/ruby -e "$(curl -fsSL"

Next, install graphviz. Run:

brew install graphviz

Finally, install @lindenb's makefile2graph. Run:

git clone
cd makefile2graph
make install # not sure why I need to run this, but I seem to

To test, run:

make -Bnd | make2graph | dot -Tpng -o makefile-dag.png
open makefile-dag.png

If the file makefile-dag.png appears in the current directory (i.e., makefile2graph/) and opens, then makefile2graph works.

To clean up, run:

cd ..
rm -rf makefile2graph


Try on one of your own Makefiles. Open a terminal in your own project directory (with a Makefile) and run:

make -Bnd | make2graph | dot -Tpng -o makefile-dag.png

This should create the file makefile-dag.png. To open it, run:

open makefile-dag.png

To make it easy to update the png, I add this to the Makefile:

dag: makefile-dag.png

# draw makefile dag
makefile-dag.png: Makefile
	make -Bnd | make2graph | dot -Tpng -Gdpi=300 -o makefile-dag.png


Here's an example using @zmjones's eeesr repo.

git clone # grab @zmjones project from github
cd eeesr  # hop into the main directory
make -Bnd | make2graph | dot -Tpng -Gdpi=300 -o makefile-dag.png  # draw dag
open makefile-dag.png  # open plot


Copy link

how to use on windows

Copy link

windows how to ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment