Makefil...aluator(3)
π Makefile::AST::Evaluator π
okay bestie, gather round, because we're looking at a page from the User Contributed Perl Documentation (that's the perl manual, section 3 β the library-functions corner of the docs), and it's literally called Makefile::AST::Evaluator. it's giving build-system-brain and i'm obsessed π«Ά
β¨ NAME β¨
Makefile::AST::Evaluator β the evaluator and the runtime for Makefile::AST instances. like, you bring the AST, it brings the vibes and also the execution. π
πΈ SYNOPSIS πΈ
use Makefile::AST::Evaluator;
$Makefile::AST::Evaluator::JustPrint = 0;
$Makefile::AST::Evaluator::Quiet = 1;
$Makefile::AST::Evaluator::IgnoreErrors = 1;
$Makefile::AST::Evaluator::AlwaysMake = 1;
$Makefile::AST::Evaluator::Question = 1;
# $ast is a Makefile::AST instance:
my $eval = Makefile::AST::Evaluator->new($ast);
Makefile::AST::Evaluator->add_trigger(
firing_rule => sub {
my ($self, $rule, $ast_cmds) = @_;
my $target = $rule->target;
my $colon = $rule->colon;
my @normal_prereqs = @{ $rule->normal_prereqs };
# ...
}
);
$eval->set_required_target($user_makefile)
$eval->make($goal);
lowkey that last chunk is copied character-for-character from the original, so yes, i'm keeping it exactly how it is. no notes. π
π¦ DESCRIPTION π¦
so this module implementes an evaluator β a runtime, bestie β for makefile ASTs, and those ASTs are represented by Makefile::AST instances. it's the whole "you built the tree, now let's go" moment. π
it "executes" the GNU make AST you hand it, following GNU makefile semantics. but here's the tea: "execution" does not necessarily mean building a project tree by firing off makefile rule commands. nope! you can literally define your own triggers by calling the add_trigger method (peep the "SYNOPSIS" for examples, i got u). in other words, you can do way more interesting stuff β like plotting the call path tree of a Makefile with Graphviz, or translating the original makefile into another form (which is exactly what the makesimple script does, iykyk). π₯
and it's worth mentioning β worth mentioning, okay β that most of the construction algorithm for topological graph s (including implicit rule application, yes ma'am) has already been implemented in Makefile::AST and its child node classes. so you're not starting from zero, you're starting from slay. β¨
π CONFIGURE VARIABLES π
this module ships several package variables (aka static class variables, same thing bestie) that control how the evaluator behaves. think of them as the little dials on the main character's console. π
particularly, the user needs to set the $AlwaysMake variable to true and $Question to true, if she wants to use the evaluator for special tasks β like plotting dependency graphs, or translating GNU makefiles into another format. π
setting $AlwaysMake to true will force the evaluator to ignore the timestamps of external files that appear in the makefiles, and setting $Question to true will stop the evaluator from executing the shell commands specified in the makefile rules. two dials, one dream. π«Ά
here's the detailed listing for all the config variables:
$Questionβ corresponds to the command-line option-qor<--question>in GNU make. its whole purpose is to make the evaluator enter the "questioning mode" β a mode wheremakewill never try executing rule commands unless it has to, and echoing is suppressed at the same time. double whammy. π€«$AlwaysMakeβ corresponds to the command-line option-Bor--always-make. it forces re-constructing all of the rule's targets related to the goal, ignoring the timestamp or existence of the targets' dependencies. no thoughts, just rebuild. π¨$Quietβ corresponds to GNU make's command-line option-s,--silent, or--quiet. its effect is to cancel the echoing of shell commands being executed. shhh. π€$JustPrintβ corresponds to GNU make's command line option-n,--just-print,--dry-run, or--recon. its effect is to print out the shell commands requiring execution, but without actually executing them. all talk, no action, iconic behaviour. π$IgnoreErrorsβ corresponds to GNU make's command line option-ior--ignore-errors. it's used to ignore the errors of shell commands being executed during the make process. the default behavior is quitting as soon as a shell command without the-modifier fails. so like, no$IgnoreErrors, no mercy. π
π CLASS TRIGGERS π
the make_by_rule method of this class defines a trigger named firing_rule via the Class::Trait module. every single time the make_by_rule method reaches that trigger point, it will invoke your processing handler with these three arguments, in this order, no substitutions:
- the self object
- the
Makefile::AST::Ruleobject - the corresponding
Makefile::AST::Commandobject in the context
by registering your own processing handlers for the firing_rule trigger, your code gets to reuse the evaluator and do your own cool things β without traversing the makefile ASTs yourself. the evaluator does the walking, you do the plotting. main character energy fr fr. π
see the "SYNOPSIS" for code examples. π§
β CODE REPOSITORY β
for the very latest version of this script, check out the source from
<http://github.com/agentzh/makefile-parser-pm>.
there is anonymous access to all. yes, all. go look. π¦
πΈ AUTHOR πΈ
Zhang "agentzh" Yichun <agentzh@gmail.com>
π COPYRIGHT AND LICENSE π
Copyright (c) 2007-2008 by Zhang "agentzh" Yichun (agentzh).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
π SEE ALSO π
Makefile::ASTMakefile::Parser::GmakeDBpgmake-dbmakesimpleMakefile::DOM
π ok that's the whole page bestie, every option, every variable, every trigger, nothing skipped, nothing invented. periodt. π
perl v5.42.0 Β· 2025-07-25 β that's the version and date from the footer, mwah, signing off, stay evaluating πβ¨π¦
π¦ where this page comes from
- fedora 43: perl-Makefile-Parser 0.216-31.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms