#!/usr/bin/env perl use strict; use warnings; use Getopt::Std; use Makefile::GraphViz; my %opts; getopts('hf:o:s:a', \%opts) or die "Use -h to see the usage\n"; if ($opts{h}) { print <<'_EOC_'; Usage: gvmake [options] [target]* Options: -a Plot all the goals. -f Use filename as Makefile. -h Print this help. -s x Specify the size (both for width and height) -o Use filename as output PNG file. _EOC_ exit(0); } my $size = $opts{s}; my ($width, $height); ($width, $height) = split 'x', $opts{s} if $opts{s}; my $parser = Makefile::GraphViz->new; my $makefile = $opts{f} || 'Makefile'; warn "parsing $makefile...\n"; $parser->parse($makefile) or die $parser->error; my $outfile; if ($opts{a}) { my $gv = $parser->plot_all; $outfile = "$makefile.png"; $gv->as_png($outfile); } else { my $tar = shift @ARGV || $parser->target; warn "plotting target $tar...\n"; my $gv = $parser->plot( $tar, init_args => { width => $width, height => $height, }, ); $outfile = $opts{o} || "$tar.png"; $gv->as_png($outfile); } warn "$outfile generated.\n"; __END__ =head1 NAME gvmake - A make tool that generates pretty graphs from Makefiles =head1 SYNOPSIS # print usage info to stdout: gvmake -h # if the default target is 'all', the following # command will generate all.png gvmake # this command will generate 'test.png' where # 'test' is a target defined in the Makefile: gvmake test # override the default output file name: gvmake -o make.png test # specify the Makefile name explicitly: gvmake -f t/Makefile.old install # generate Makefile.png which contains all the goals gvmake -a # specify the size of the output image: gvmake -s 5x8 # width is 5 inch, and height is 8 inch =head1 DESCRIPTION This is a make tool that generates pretty graphs for the building process according to user's Makefile instead of actually building something. It is a simple command-line frontend for the L module. For GNU makefile, it's I recommended to use L's L script to convert your GNU makefile to the simplest form I running this script. Because this L uses the toy L engine which can only handle a very limited set of GNU makefile features while the L engine used by the L script reuses the GNU make executable to do the (first-pass) parsing. Thus you normally should do something like this: cd dir_where_your_project_lives makesimple -f your_makefile > simplest.mk gvmake -f simplest.mk some_target Currently only PNG format and the default settings for the graph style are used. This inflexible design will be changed soon. =head1 TODO =over =item * Add more command-line options to control the graph appearance =item * To support more output file format =item * Add support for multiple goals passed in via command-line. =back =head1 BUGS Please report bugs or send wish-list to L. =head1 SEE ALSO L, L, L. =head1 AUTHOR Agent Zhang, Eagentzh@gmail.comE =head1 COPYRIGHT AND LICENSE Copyright (C) 2005, 2006, 2007 by Agent Zhang. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut