#!/usr/bin/perl -w # # Tom Moertel # $Id: makefile-to-digraph,v 1.7 2003/02/10 19:50:31 thor Exp $ # # Documentation is at the end in POD format. # Licensing terms are specified in the documentation. use strict; my $page = "8.5,11"; if (@ARGV && $ARGV[0] =~ /--?p(age)?/) { $page = (shift, shift); } # read input in one big slurp undef $/; my $input = <>; # join continued lines $input =~ s/\\(\r\n?|\n)\s*/ /g; # build dependency graph my %depgraph; my %names; foreach (split /\r\n?|\n/, $input) { s/\#.*//; # trim comments next unless /^\S/; # skip command lines next if /^\s*include\s/; # skip include directives next unless /^[^:=]+:[^=]/; # skip lines that don't define dependencies s/\;.*//; # trim same-line build rule, if any my ($targets, $prerequisites) = split /\s*:\s*/, $_, 2; next unless $prerequisites; foreach my $target (split /\s+/, $targets) { $names{$target} = 1; foreach my $prerequisite (split /\s+/, $prerequisites) { $names{$prerequisite} = 1; push @{$depgraph{$target}}, $prerequisite; } } } # generate output print < \"$prerequisite\" "; print "[style=dotted]" if $dependent =~ /%/; print ";\n"; } } foreach my $name (sort keys %names) { print "\"$name\" [shape=box];\n" if $name =~ /%/; } print "\n}\n"; =head1 NAME B - converts Makefile rules into a dot(1) directed graph =head1 SYNOPSIS B [opts] I | Bps E I.ps =head1 DESCRIPTION This tool reads Makefile rules and converts their dependency information into a directed-graph description. The description is suitable for rendering with dot(1) from the Graphviz toolkit. =head1 OPTIONS The tool accepts one optional flag of the form B<--page> I, which can be used to specify the page size for dot(1) to use. The format of I is I,I in inches. For example, 8.5,11 for a U.S. Letter page size. =head1 LICENSE This software is licensed under the GNU General Public License, as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. The text of the GNU GPL may be found online: http://www.gnu.org/copyleft/gpl.html This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. Except as provided for under the terms of the GNU GPL, all rights are reserved worldwide. =head1 SEE ALSO dot(1) =head1 AUTHOR Tom Moertel Etom-perl@moertel.comE $Id: makefile-to-digraph,v 1.7 2003/02/10 19:50:31 thor Exp $ =cut