Makefile::GraphViz - Plot the Detailed Structure of Makefiles Using GraphViz


NAME

Makefile::GraphViz - Plot the Detailed Structure of Makefiles Using GraphViz


SYNOPSIS

  use Makefile::GraphViz;
  $parser = Makefile::GraphViz->new;
  $parser->parse('Makefile');
  # plot the tree rooted at the install target in Makefile:
  $gv = $parser->plot('install');  # A GraphViz object returned.
  $gv->as_png('install.png');
  # plot the tree rooted at the default target in Makefile:
  $gv = $parser->plot;
  $gv->as_png('default.png');
  # plot the forest consists of all the targets in Makefile:
  $gv = $parser->plot_all;
  $gv->as_png('default.png');
  # you can also invoke all the methods inherited from the Makefile::Parser class:
  @targets = $parser->targets;


DESCRIPTION

This module uses the Makefile::Parser manpage to render user's Makefiles via the amazing the GraphViz manpage module. Before I decided to write this thing, there had been already a CPAN module named the GraphViz::Makefile manpage which did the same thing. However, the pictures generated by the GraphViz::Makefile manpage is oversimplified in my opinion, So a much complex one is still needed.

IMPORTANT! This stuff is highly experimental and is currently at ALPHA stage, so production use is strongly discouraged. Anyway, I have the plan to improve this stuff unfailingly.


The Makefile::GraphViz Class

This class is a subclass inherited from the Makefile::Parser manpage. So all the methods (and hence all the functionalities) provided by the Makefile::Parser manpage are accessable here. Additionally this class also provides some more methods on its own right.


METHODS

plot($target, ...)
This method is essential to the class. Users invoke this method to plot the specified Makefile target. If the argument is absent, the default target in the Makefile will be used. It will return a the GraphViz manpage object, on which you can later call the ->as_png or ->as_text method to obtain the final graphical output.

The argument can both be the target's name and a Makefile::Target object. If the given target can't be found in Makefile, the target will be plotted separately.

This method also accepts several options.

    $gv = $parser->plot(undef, normal_nodes => ['mytar']);
    $gv = $parser->plot(
        'cmintester',
        exclude  => [qw(
            all hex2bin.exe exe2hex.pl bin2asm.pl
            asm2ast.pl ast2hex.pl cod2ast.pl
        )],
        end_with => [qw(pat_cover.ast pat_cover)],
        normal_nodes => ['pat_cover.ast'],
        vir_nodes => ['pat_cover'],
        trim_mode => 0,
    );
cmd_style
This option controls the style of the shell command box. The default appearance for these nodes are gray ellipses.

edge_style
This option's value will be passed directly to GraphViz's add_edge method. It controls the appearance of the edges in the output graph, which is default to red directed arrows.
    $gv = $parser->plot(
        'install',
        edge_style => {
            style => 'dotted',
            color => 'seagreen',
        },
    );

end_with
This option takes a list ref as its value. The plot method won't continue to interate the subtree rooted at entries in the list. It is worth noting that the entries themselves will be displayed as usual. This is the only difference compared to the exclude option.

Here is an example:

    $gv = $parser->plot(
        'cmintester',
        end_with => [qw(pat_cover.ast pat_cover)],
    );

exclude
This option takes a list ref as its value. All the entries in the list won't be displayed and the subtrees rooted at these entries won't be displayed either.
    $parser->plot(
        'clean',
        exclude=>[qw(foo.exe foo.pl)]
    )->as_png('clean.png');

gv
This option accetps user's GraphViz object to render the graph.
    $gv = GraphViz->new(width => 30, height => 20,
                        pagewidth => 8.5, pageheight => 11);
    $parser->plot('install', gv => $gv);
    print $gv->as_text;

init_args
This option takes a hash ref whose value will be passed to the constructor of the GraphViz class if the option gv is not specified:
    $parser->plot(
        'install',
        init_args => {
            width => 30, height => 20,
            pagewidth => 8.5, pageheight => 11,
        },
    )->as_png('a.png');

normal_nodes
The entries in this option's list are forced to be the normal nodes. Normal nodes are defined to be the Makefile targets corresponding to disk files. In contrast, virtual nodes are those Makefile targets with no real files corresponding to them.

normal_node_style
Override the default style for the normal nodes. By default, normal nodes are yellow rectangles with black border.
    $gv = $parser->plot(
        'install',
        normal_node_style => {
           shape => 'circle',
           style => 'filled',
           fillcolor => 'red',
        },
    );

trim_mode
When this option is set to a true value, no shell command nodes will be plotted.

vir_nodes
The entries in this option's list are forced to be the virtual nodes. Virtual nodes are those Makefile targets with no real files corresponding to them.

vir_node_style
Override the default style for the virtual nodes.
    $gv = $parser->plot(
        'install',
        virtual_node_style => {
           shape => 'box',
           style => 'filled',
           fillcolor => 'blue',
        },
    );

By default, virtual nodes are yellow rectangles with no border.

EXPORT

None by default.


EXAMPLES

Browse http://search.cpan.org/src/AGENT/Makefile-GraphViz-0.03/samples.html for some sample output graphs.

INTERNAL FUNCTIONS

Internal functions should not be used directly.

gen_id
Generate a unique id for command node.

trim_path
Trim the path to a more readable form.

trim_cmd
Trim the shell command to a more friendly size.

find
If the given element is found in the given list, this function will return 1; otherwise, a false value is returned.


CODE COVERAGE

I use the Devel::Cover manpage to test the code coverage of my tests, below is the the Devel::Cover manpage report on this module test suite.

    ---------------------------- ------ ------ ------ ------ ------ ------ ------
    File                           stmt   bran   cond    sub    pod   time  total
    ---------------------------- ------ ------ ------ ------ ------ ------ ------
    .../lib/Makefile/GraphViz.pm  100.0   90.9   69.0  100.0  100.0  100.0   90.9
    Total                         100.0   90.9   69.0  100.0  100.0  100.0   90.9
    ---------------------------- ------ ------ ------ ------ ------ ------ ------


BUGS

Please report bugs or send wish-list to http://rt.cpan.org/NoAuth/Bugs.html.


SEE ALSO

gvmake, the GraphViz manpage, the Makefile::Parser manpage.


AUTHOR

Agent Zhang, <agent2002@126.com>


COPYRIGHT AND LICENSE

Copyright (C) 2005 Agent Zhang.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

 Makefile::GraphViz - Plot the Detailed Structure of Makefiles Using GraphViz