| 1 |
#!/bin/env perl -w |
| 2 |
# |
| 3 |
# $Id: depgraph 11860 2010-12-09 03:47:03Z skayser $ |
| 4 |
# |
| 5 |
# Copyright 2006 Cory Omand <comand@blastwave.org> |
| 6 |
# All rights reserved. Use is subject to license terms. |
| 7 |
# |
| 8 |
# Redistribution and/or use, with or without modification, is |
| 9 |
# permitted. This software is without warranty of any kind. The |
| 10 |
# author(s) shall not be liable in the event that use of the |
| 11 |
# software causes damage. |
| 12 |
# |
| 13 |
# depgraph - draw a 'dot' graph showing GAR package interdependencies |
| 14 |
# |
| 15 |
|
| 16 |
use strict; |
| 17 |
|
| 18 |
my ($graph_all, $output_dot) = (0, 0); |
| 19 |
foreach my $arg (@ARGV) { |
| 20 |
$graph_all = 1 if $arg eq '-all'; |
| 21 |
$output_dot = 1 if $arg eq '-dot'; |
| 22 |
} |
| 23 |
|
| 24 |
my $dot = "dot"; |
| 25 |
$dot .= " -Earrowhead=dot -Edot_radius=0.5 -Earrowtail=none"; |
| 26 |
$dot .= " -Nshape=diamond -Nfontsize=12"; |
| 27 |
$dot .= " -Tpng"; |
| 28 |
|
| 29 |
sub makeDigraph { |
| 30 |
my ($name, @makefiles) = @_; |
| 31 |
|
| 32 |
printf STDERR " %12s ... ", $name; |
| 33 |
|
| 34 |
if (@makefiles) { |
| 35 |
my $device; |
| 36 |
if ($output_dot) { |
| 37 |
$device = \*STDOUT; |
| 38 |
} else { |
| 39 |
open DOT, "| $dot -o $name.png" or die "Failed to open PNG stream: $!"; |
| 40 |
$device = \*DOT; |
| 41 |
} |
| 42 |
|
| 43 |
print $device "digraph sunx {\n"; |
| 44 |
|
| 45 |
foreach my $makefile (@makefiles) { |
| 46 |
open FH, $makefile or die "Failed to open $makefile: $!\n"; |
| 47 |
my @lines = <FH>; |
| 48 |
close FH; |
| 49 |
|
| 50 |
my ($garname, @deps); |
| 51 |
foreach (@lines) { |
| 52 |
if (/^NAME\s*=\s*(\S*)\s*$/) { |
| 53 |
$garname = $1; |
| 54 |
next; |
| 55 |
} |
| 56 |
if (/^(?:DEPENDS|LIBDEPS)\s*\+?=\s*(.+)$/) { |
| 57 |
push @deps, split /\s+/, $1; |
| 58 |
next; |
| 59 |
} |
| 60 |
} |
| 61 |
|
| 62 |
foreach (@deps) { |
| 63 |
my ($dummy, $depname) = split '/', $_; |
| 64 |
print $device qq{"$garname" -> "$depname"\n}; |
| 65 |
} |
| 66 |
} |
| 67 |
print $device "}\n"; |
| 68 |
close $device; |
| 69 |
|
| 70 |
print STDERR "ok\n"; |
| 71 |
|
| 72 |
} else { |
| 73 |
print STDERR "nothing to do\n"; |
| 74 |
} |
| 75 |
} |
| 76 |
|
| 77 |
print STDERR "\nCreating digraphs:\n\n"; |
| 78 |
|
| 79 |
if ($graph_all) { |
| 80 |
foreach my $subdir (`gfind -type d -mindepth 1 -maxdepth 1 -not -name meta`) { |
| 81 |
chomp $subdir; $subdir =~ s/^\.\///; |
| 82 |
makeDigraph "sunx_$subdir", `gfind $subdir -type f -mindepth 2 -maxdepth 2 -name Makefile`; |
| 83 |
} |
| 84 |
} |
| 85 |
|
| 86 |
makeDigraph "sunx_all", `gfind . -type f -mindepth 3 -maxdepth 3 -name Makefile | grep -v ./meta`; |
| 87 |
|
| 88 |
print STDERR "\nComplete.\n\n"; |