Skip to content

Instantly share code, notes, and snippets.

@xdbr
Created August 19, 2015 19:03
Show Gist options
  • Save xdbr/de41448e6ce1f5d77528 to your computer and use it in GitHub Desktop.
Save xdbr/de41448e6ce1f5d77528 to your computer and use it in GitHub Desktop.
Build GNU make dependency graph using dot
#!/usr/bin/env perl
use strict;
use warnings;
use feature 'say';
@ARGV or die "Usage:\n\tperl $0 Makefile\nthen:\n\t | dot -Tpng -oout.png\n";
my $dotopts = q{
# rankdir=LR
# node [shape=record,width=.1,height=.1]
};
my %target;
open my $file, "make -prn -f $ARGV[0]|";
while (<$file>) {
m/^([\w-]+):(.*)/i and do {
$target{$1} = [
grep { $_ if defined $_ }
map { s/^\s*|\s*$//g; $_}
split /\s+/, $2
]
}
}
say "digraph G {";
say "$dotopts";
while ( my ($target,$prereqs) = each %target) {
for my $prereq (@$prereqs) {
say qq{ "$target" -> "$prereq"};
}
}
say "}";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment