A Simple Parser for Makefiles
Version: 0.211Makefile::Parser is a Simple Parser for Makefiles.
License: Perl Artistic License
Operating System: Linux
$parser = Makefile::Parser->new;
# Equivalent to ->parse('Makefile');
# Get last value assigned to the specified variable 'CC':
# Get all the variable names defined in the Makefile:
@vars = $parser->vars;
print join(' ', sort @vars);
@roots = $parser->roots; # Get all the "root targets"
@tars = $parser->targets; # Get all the targets
$tar = join("n", $tars->commands);
# Get the default target, say, the first target defined in Makefile:
$tar = $parser->target;
$tar = $parser->target('install');
# Get the name of the target, say, 'install' here:
# Get the dependencies for the target 'install':
@depends = $tar->depends;
# Access the shell command used to build the current target.
@cmds = $tar->commands;
# Parse another file using the same Parser object:
# Get the target who is specified by variable EXE_FILE
$tar = $parser->target($parser->var('EXE_FILE'));
This is a parser for Makefiles. At this very early stage, the parser only supports a limited set of features, so it may not recognize some advanced features provided by certain make tools like GNU make. Its initial purpose is to provide basic support for another module named Makefile::GraphViz, which is aimed to render the building process specified by a Makefile using the amazing GraphViz library. The Make module is not satisfactory for this purpose, so I decided to build one of my own.