| 1 | #!/usr/bin/env perl | ||
| 2 | |||
| 3 | 3 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 3 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | |||
| 6 | 3 | ▶ | use Getopt::Long; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | 0 | ▶ | use Makefile::GraphViz; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 8 | |||
| 9 | my $layout = 'dot'; | ||
| 10 | GetOptions( | ||
| 11 | 'help|h' => \(my $help), | ||
| 12 | 'file|f=s' => \(my $makefile), | ||
| 13 | 'all|a' => \(my $make_all), | ||
| 14 | 'out|o=s' => \(my $outfile), | ||
| 15 | 'edge-len=f' => \(my $edge_len), | ||
| 16 | 'layout=s' => \($layout), | ||
| 17 | 'debug' => \(my $debug), | ||
| 18 | 'size|s=s' => \(my $size), | ||
| 19 | ) or die help(); | ||
| 20 | |||
| 21 | if ($help) { print help(); exit; } | ||
| 22 | |||
| 23 | sub help { | ||
| 24 | return <<'_EOC_'; | ||
| 25 | Usage: | ||
| 26 | gvmake [options] [target]* | ||
| 27 | |||
| 28 | Options: | ||
| 29 | --all | ||
| 30 | -a Plot all the goals. | ||
| 31 | -f <filename> | ||
| 32 | -file <filename> Use filename as Makefile. | ||
| 33 | --help | ||
| 34 | -h Print this help. | ||
| 35 | --size | ||
| 36 | -s <w>x<h> Specify the size (both for width and height) | ||
| 37 | --out | ||
| 38 | -o <filename> Use filename as output PNG file. | ||
| 39 | --edge-len <len> Specify the "len" attribute for edges. | ||
| 40 | --debug Generate .dot file rather than PNG | ||
| 41 | |||
| 42 | _EOC_ | ||
| 43 | } | ||
| 44 | |||
| 45 | my ($width, $height); | ||
| 46 | ($width, $height) = split 'x', $size if $size; | ||
| 47 | |||
| 48 | my $parser = Makefile::GraphViz->new; | ||
| 49 | |||
| 50 | $makefile ||= 'Makefile'; | ||
| 51 | warn "parsing $makefile...\n"; | ||
| 52 | $parser->parse($makefile) or die $parser->error; | ||
| 53 | |||
| 54 | if ($make_all) { | ||
| 55 | my $gv = $parser->plot_all; | ||
| 56 | $outfile = "$makefile.png"; | ||
| 57 | $gv->as_png($outfile); | ||
| 58 | } else { | ||
| 59 | my $tar = shift @ARGV || $parser->target; | ||
| 60 | warn "plotting target $tar...\n"; | ||
| 61 | my $gv = $parser->plot( | ||
| 62 | $tar, | ||
| 63 | init_args => { | ||
| 64 | width => $width, height => $height, | ||
| 65 | layout => $layout, | ||
| 66 | }, | ||
| 67 | $edge_len ? | ||
| 68 | (edge_style => { | ||
| 69 | len => $edge_len, | ||
| 70 | color => 'red', | ||
| 71 | }) : (), | ||
| 72 | ); | ||
| 73 | if ($debug || $outfile && $outfile =~ /\.dot$/i) { | ||
| 74 | if ($outfile) { | ||
| 75 | open my $out, ">$outfile" or | ||
| 76 | die "Can't open $outfile for writing: $!\n"; | ||
| 77 | print $out $gv->as_debug; | ||
| 78 | close $out; | ||
| 79 | warn "$outfile generated.\n"; | ||
| 80 | } else { | ||
| 81 | print $gv->as_debug; | ||
| 82 | } | ||
| 83 | } else { | ||
| 84 | $outfile ||= "$tar.png"; | ||
| 85 | $gv->as_png($outfile); | ||
| 86 | warn "$outfile generated.\n"; | ||
| 87 | } | ||
| 88 | } | ||
| 89 | |||
| 90 | __END__ | ||