Skip to content

Instantly share code, notes, and snippets.

@carlislerainey
Last active October 12, 2022 10:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save carlislerainey/9a1e49cb195076165a4f07a683ce05a7 to your computer and use it in GitHub Desktop.
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 https://raw.githubusercontent.com/Homebrew/install/master/install)"

Next, install graphviz. Run:

brew install graphviz

Finally, install @lindenb's makefile2graph. Run:

git clone https://github.com/lindenb/makefile2graph.git
cd makefile2graph
make
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
ls
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

Using

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

Example

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

git clone https://github.com/zmjones/eeesr.git # 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

image

@cultivatecq
Copy link

how to use on windows

@cultivatecq
Copy link

windows how to ?

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