Last active
December 8, 2018 15:27
-
-
Save sjackman/f8607390d6aebb2021b64edc6e58305d to your computer and use it in GitHub Desktop.
Build a dependency graph of selected formulae
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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