1Makefile::AST::EvaluatoUrs(e3r)Contributed Perl DocumentMaatkieofnile::AST::Evaluator(3)
2
3
4
6 Makefile::AST::Evaluator - Evaluator and runtime for Makefile::AST
7 instances
8
10 use Makefile::AST::Evaluator;
11
12 $Makefile::AST::Evaluator::JustPrint = 0;
13 $Makefile::AST::Evaluator::Quiet = 1;
14 $Makefile::AST::Evaluator::IgnoreErrors = 1;
15 $Makefile::AST::Evaluator::AlwaysMake = 1;
16 $Makefile::AST::Evaluator::Question = 1;
17
18 # $ast is a Makefile::AST instance:
19 my $eval = Makefile::AST::Evaluator->new($ast);
20
21 Makefile::AST::Evaluator->add_trigger(
22 firing_rule => sub {
23 my ($self, $rule, $ast_cmds) = @_;
24 my $target = $rule->target;
25 my $colon = $rule->colon;
26 my @normal_prereqs = @{ $rule->normal_prereqs };
27 # ...
28 }
29 );
30 $eval->set_required_target($user_makefile)
31 $eval->make($goal);
32
34 This module implementes an evaluator or a runtime for makefile ASTs
35 represented by Makefile::AST instances.
36
37 It "executes" the specified GNU make AST by the GNU makefile semantics.
38 Note that, "execution" not necessarily mean building a project tree by
39 firing makefile rule commands. Actually you can defining your own
40 triggers by calling the add_trigger method. (See the "SYNOPSIS" for
41 examples.) In other words, you can do more interesting things like
42 plotting the call path tree of a Makefile using Graphviz, or
43 translating the original makefile to another form (like what the
44 makesimple script does).
45
46 It's worth mentioning that, most of the construction algorithm for
47 topological graph s (including implicit rule application) have already
48 been implemented in Makefile::AST and its child node classes.
49
51 This module provides several package variables (i.e. static class
52 variables) for controlling the behavior of the evaluator.
53
54 Particularly the user needs to set the $AlwaysMake variable to true and
55 $Question to true, if she wants to use the evaluator to do special
56 tasks like plotting dependency graphs and translating GNU makefiles to
57 other format.
58
59 Setting $AlwaysMake to true will force the evaluator to ignore the
60 timestamps of external files appeared in the makefiles while setting
61 $Question to true will prevent the evaluator from executing the shell
62 commands specified in the makefile rules.
63
64 Here's the detailed listing for all the config variables:
65
66 $Question
67 This variable corresponds to the command-line option "-q" or
68 <--question> in GNU make. Its purpose is to make the evaluator
69 enter the "questioning mode", i.e., a mode in which "make" will
70 never try executing rule commands unless it has to, "and" echoing
71 is suppressed at the same time.
72
73 $AlwaysMake
74 This variable corresponds to the command-line option "-B" or
75 "--always-make". It forces re-constructing all the rule's targets
76 related to the goal, ignoring the timestamp or existence of
77 targets' dependencies.
78
79 $Quiet
80 It corresponds to GNU make's command-line option "-s", "--silent",
81 or "--quiet". Its effect is to cancel the echoing of shell commands
82 being executed.
83
84 $JustPrint
85 This variable corresponds to GNU make's command line option "-n",
86 "--just-print", "--dry-run", or "--recon". Its effect is to print
87 out the shell commands requiring execution but without actually
88 executing them.
89
90 $IgnoreErrors
91 This variable corresponds to GNU make's command line option "-i" or
92 "--ignore-errors". It's used to ignore the errors of shell commands
93 being executed during the make process. The default behavior is
94 quitting as soon as a shell command without the "-" modifier fails.
95
97 The "make_by_rule" method of this class defines a trigger named
98 "firing_rule" via the Class::Trait module. Everytime the "make_by_rule"
99 method reaches the trigger point, it will invoke the user's processing
100 handler with the following three arguments: the self object, the
101 Makefile::AST::Rule object, and the corresponding
102 "Makefile::AST::Command" object in the context.
103
104 By registering his own processing handlers for the "firing_rule"
105 trigger, the user's code can reuse the evaluator to do his own cool
106 things without traversing the makefile ASTs himself.
107
108 See the "SYNOPSIS" for code examples.
109
111 For the very latest version of this script, check out the source from
112
113 <http://github.com/agentzh/makefile-parser-pm>.
114
115 There is anonymous access to all.
116
118 Zhang "agentzh" Yichun "<agentzh@gmail.com>"
119
121 Copyright (c) 2007-2008 by Zhang "agentzh" Yichun (agentzh).
122
123 This library is free software; you can redistribute it and/or modify it
124 under the same terms as Perl itself.
125
127 Makefile::AST, Makefile::Parser::GmakeDB, pgmake-db, makesimple,
128 Makefile::DOM.
129
130
131
132perl v5.32.1 2021-01-27 Makefile::AST::Evaluator(3)