Skip to content

Instantly share code, notes, and snippets.

@sjackman
Last active December 8, 2018 15:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sjackman/f8607390d6aebb2021b64edc6e58305d to your computer and use it in GitHub Desktop.
Save sjackman/f8607390d6aebb2021b64edc6e58305d to your computer and use it in GitHub Desktop.
Build a dependency graph of selected formulae
# Build a dependency graph of selected formulae
.DELETE_ON_ERROR:
.SECONDARY:
.PHONY: all
all: cxx.deps.unisolated.gv.tsort.txt cxx.deps.unisolated.pdf
# Generate the dependencies of a list of formula
%.deps.tsv: %.txt
for i in `<$<`; do \
for j in `brew deps $$i`; do \
printf "%s\t%s\n" $$i $$j; \
done; \
done >$@
# Convert a TSV file of dependencies to GraphViz
%.gv: %.tsv
( \
echo 'digraph {' ; \
cut -f1 $< | sort -u | sed 's/.*/"&" [cxx=1]/'; \
awk '{ print "\"" $$2 "\" -> \"" $$1 "\"" }' <$<; \
echo '}' \
) | gvpr -i 'N[cxx]' | tred >$@
# Remove isolated vertices.
%.unisolated.gv: %.gv
gvpr 'E[1]' $< >$@
# Extract vertex names from a GraphViz file.
%.gv.txt: %.gv
gvpr 'N{ print(name) }' $< | sort >$@
# Convert a GraphViz file to a TSV file.
%.gv.tsv: %.gv
gvpr 'E{ print(tail, "\t", head) }' $< >$@
# Topological sort a TSV file.
%.tsort.txt: %.tsv
tsort $< >$@
# Render a GraphViz file to PDF.
%.pdf: %.gv
dot -Tpdf -o $@ $<
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment