3 # graph-includes - create a graphviz graph of source-files
4 # dependencies, with an emphasis on getting usable graphs even for
7 # (c) 2005 Yann Dirson <ydirson@altern.org>
8 # Distributed under version 2 of the GNU GPL.
20 our ($minshow, $maxshow) = (1, 1);
27 Usage: $0 [options] src/*.[ch]
29 --class {default|uniqueincludes|<your-own-class>}
30 Select "class" of source code
31 --prefixstrip <prefix> Strip <prefix> (eg. "src/") from filenames in the graph
32 --group <min>-<max> Draw file groups of levels <min> through <max> (default: 1 1)
33 --color <n>:<label>=<color>[,<label>=<color>...]
34 Use specified colors to show members of level-<n> group labelled <label>
35 --alldeps Do not apply transitive reduction to the graph
37 --showdropped Show in special color edges dropped during transitive reduction
38 --focus <node-label> Like -showdropped but only for edges starting from given node
40 --output <outfile>.<fmt>
41 Format to output file, using <fmt> as target format
43 --verbose Show progress
44 --verbose Show details of ignored include directives
45 --debug Loads of debuging output
52 GetOptions
('alldeps' => \
$showalldeps,
53 'showdropped' => \
$showdropped,
59 my (undef, $range) = @_;
60 ($minshow, $maxshow) = split /-/, $range;
63 my (undef, $colspec) = @_;
64 my @temp = split /:/, $colspec;
65 push @colspecs, [$temp[1], $temp[2]];
67 'output=s' => \
$outfile,
69 'prefixstrip=s' => \
$prefixstrip,
71 'verbose+' => \
$verbose,
73 'help' => sub { print $usage; exit 0; },
75 ) or die "Could not parse command-line: $!";
77 # create a project with specified files
78 our $classmodule = "graphincludes::project::" . $class;
79 eval "require $classmodule" or die "cannot locate $classmodule";
80 our $project = ($classmodule)->new($prefixstrip, @ARGV);
83 @colors = $project->defaultcolors();
84 foreach my $colspec (@colspecs) {
85 foreach my $coldef (split /,/, $colspec->[2]) {
86 my @coldef = split /=/, $coldef;
87 $colors[$colspec->[1]]->{$coldef[0]} = $coldef[1];
91 # maybe get rid of shortcut deps (transitive reduction)
92 $project->reduce() unless ($showalldeps);
97 if (defined $outfile) {
98 $outfile =~ m/.*\.([^.]+)$/ or die "cannot guess output format";
99 open STDOUT
, "| dot -T$1 -o $outfile";
102 print "strict digraph dependencies {\nrankdir=LR;\n";
105 my ($file, $min, $max) = @_;
106 my $node = $project->filelabel($file,$max);
107 if (!defined $node and $max > $min) {
108 return sprintnode
($file, $min, $max-1);
109 } elsif ($min == $max) {
111 $fill=",style=filled,fillcolor=" . $colors[2]->{$project->filelabel($file,2)}
112 if defined $colors[2] and defined $project->filelabel($file,2) and
113 defined $colors[2]->{$project->filelabel($file,2)};
114 return $project->{NODEIDS
}->{$node} . " [label=\"$node\"" . $fill . "];";
116 return "subgraph \"cluster $node\" {" . sprintnode
($file, $min, $max-1) . '}';
120 foreach my $file (@
{$project->{FILES
}}) {
121 print sprintnode
($file, $minshow, $maxshow), "\n";
124 foreach my $file (keys %{$project->{DEPS
}}) {
125 foreach my $dest (@
{$project->{DEPS
}->{$file}}) {
126 print "$file -> $dest";
127 my $special = $project->special_edge($file, $dest);
128 print " [$special]" if defined $special;