GUI: Fix Tomato RAF theme for all builds. Compilation typo.
[tomato.git] / release / src-rt-6.x.4708 / toolchains / hndtools-arm-linux-2.6.36-uclibc-4.5.3 / share / automake-1.11 / Automake / VarDef.pm
blobd7ba15562e2102c25eccbd8a9a2c4ad17513f169
1 # Copyright (C) 2003, 2004, 2006 Free Software Foundation, Inc.
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2, or (at your option)
6 # any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 package Automake::VarDef;
17 use strict;
18 use Carp;
19 use Automake::ChannelDefs;
20 use Automake::ItemDef;
22 require Exporter;
23 use vars '@ISA', '@EXPORT';
24 @ISA = qw/Automake::ItemDef Exporter/;
25 @EXPORT = qw (&VAR_AUTOMAKE &VAR_CONFIGURE &VAR_MAKEFILE
26 &VAR_ASIS &VAR_PRETTY &VAR_SILENT &VAR_SORTED);
28 =head1 NAME
30 Automake::VarDef - a class for variable definitions
32 =head1 SYNOPSIS
34 use Automake::VarDef;
35 use Automake::Location;
37 # Create a VarDef for a definition such as
38 # | # any comment
39 # | foo = bar # more comment
40 # in Makefile.am
41 my $loc = new Automake::Location 'Makefile.am:2';
42 my $def = new Automake::VarDef ('foo', 'bar # more comment',
43 '# any comment',
44 $loc, '', VAR_MAKEFILE, VAR_ASIS);
46 # Appending to a definition.
47 $def->append ('value to append', 'comment to append');
49 # Accessors.
50 my $value = $def->value; # with trailing `#' comments and
51 # continuation ("\\\n") omitted.
52 my $value = $def->raw_value; # the real value, as passed to new().
53 my $comment = $def->comment;
54 my $location = $def->location;
55 my $type = $def->type;
56 my $owner = $def->owner;
57 my $pretty = $def->pretty;
59 # Changing owner.
60 $def->set_owner (VAR_CONFIGURE,
61 new Automake::Location 'configure.ac:15');
63 # Marking examined definitions.
64 $def->set_seen;
65 my $seen_p = $def->seen;
67 # Printing a variable for debugging.
68 print STDERR $def->dump;
70 =head1 DESCRIPTION
72 This class gathers data related to one Makefile-variable definition.
74 =head2 Constants
76 =over 4
78 =item C<VAR_AUTOMAKE>, C<VAR_CONFIGURE>, C<VAR_MAKEFILE>
80 Possible owners for variables. A variable can be defined
81 by Automake, in F<configure.ac> (using C<AC_SUBST>), or in
82 the user's F<Makefile.am>.
84 =cut
86 # Defined so that the owner of a variable can only be increased (e.g
87 # Automake should not override a configure or Makefile variable).
88 use constant VAR_AUTOMAKE => 0; # Variable defined by Automake.
89 use constant VAR_CONFIGURE => 1;# Variable defined in configure.ac.
90 use constant VAR_MAKEFILE => 2; # Variable defined in Makefile.am.
92 =item C<VAR_ASIS>, C<VAR_PRETTY>, C<VAR_SILENT>, C<VAR_SORTED>
94 Possible print styles. C<VAR_ASIS> variables should be output as-is.
95 C<VAR_PRETTY> variables are wrapped on multiple lines if they cannot
96 fit on one. C<VAR_SILENT> variables are not output at all. Finally,
97 C<VAR_SORTED> variables should be sorted and then handled as
98 C<VAR_PRETTY> variables.
100 C<VAR_SILENT> variables can also be overridden silently (unlike the
101 other kinds of variables whose overriding may sometimes produce
102 warnings).
104 =cut
106 # Possible values for pretty.
107 use constant VAR_ASIS => 0; # Output as-is.
108 use constant VAR_PRETTY => 1; # Pretty printed on output.
109 use constant VAR_SILENT => 2; # Not output. (Can also be
110 # overridden silently.)
111 use constant VAR_SORTED => 3; # Sorted and pretty-printed.
113 =back
115 =head2 Methods
117 C<VarDef> defines the following methods in addition to those inherited
118 from L<Automake::ItemDef>.
120 =over 4
122 =item C<my $def = new Automake::VarDef ($varname, $value, $comment, $location, $type, $owner, $pretty)>
124 Create a new Makefile-variable definition. C<$varname> is the name of
125 the variable being defined and C<$value> its value.
127 C<$comment> is any comment preceding the definition. (Because
128 Automake reorders variable definitions in the output, it also tries to
129 carry comments around.)
131 C<$location> is the place where the definition occurred, it should be
132 an instance of L<Automake::Location>.
134 C<$type> should be C<''> for definitions made with C<=>, and C<':'>
135 for those made with C<:=>.
137 C<$owner> specifies who owns the variables, it can be one of
138 C<VAR_AUTOMAKE>, C<VAR_CONFIGURE>, or C<VAR_MAKEFILE> (see these
139 definitions).
141 Finally, C<$pretty> tells how the variable should be output, and can
142 be one of C<VAR_ASIS>, C<VAR_PRETTY>, or C<VAR_SILENT>, or
143 C<VAR_SORTED> (see these definitions).
145 =cut
147 sub new ($$$$$$$$)
149 my ($class, $var, $value, $comment, $location, $type, $owner, $pretty) = @_;
151 # A user variable must be set by either `=' or `:=', and later
152 # promoted to `+='.
153 if ($owner != VAR_AUTOMAKE && $type eq '+')
155 error $location, "$var must be set with `=' before using `+='";
158 my $self = Automake::ItemDef::new ($class, $comment, $location, $owner);
159 $self->{'value'} = $value;
160 $self->{'type'} = $type;
161 $self->{'pretty'} = $pretty;
162 $self->{'seen'} = 0;
163 return $self;
166 =item C<$def-E<gt>append ($value, $comment)>
168 Append C<$value> and <$comment> to the existing value and comment of
169 C<$def>. This is normally called on C<+=> definitions.
171 =cut
173 sub append ($$$)
175 my ($self, $value, $comment) = @_;
176 $self->{'comment'} .= $comment;
178 my $val = $self->{'value'};
180 # Strip comments from augmented variables. This is so that
181 # VAR = foo # com
182 # VAR += bar
183 # does not become
184 # VAR = foo # com bar
185 # Furthermore keeping `#' would not be portable if the variable is
186 # output on multiple lines.
187 $val =~ s/ ?#.*//;
189 if (chomp $val)
191 # Insert a backslash before a trailing newline.
192 $val .= "\\\n";
194 elsif ($val)
196 # Insert a separator.
197 $val .= ' ';
199 $self->{'value'} = $val . $value;
200 # Turn ASIS appended variables into PRETTY variables. This is to
201 # cope with `make' implementation that cannot read very long lines.
202 $self->{'pretty'} = VAR_PRETTY if $self->{'pretty'} == VAR_ASIS;
205 =item C<$def-E<gt>value>
207 =item C<$def-E<gt>type>
209 =item C<$def-E<gt>pretty>
211 Accessors to the various constituents of a C<VarDef>. See the
212 documentation of C<new>'s arguments for a description of these.
214 =cut
216 sub value ($)
218 my ($self) = @_;
219 my $val = $self->raw_value;
220 # Strip anything past `#'. `#' characters cannot be escaped
221 # in Makefiles, so we don't have to be smart.
222 $val =~ s/#.*$//s;
223 # Strip backslashes.
224 $val =~ s/\\$/ /mg;
225 return $val;
228 sub raw_value ($)
230 my ($self) = @_;
231 return $self->{'value'};
234 sub type ($)
236 my ($self) = @_;
237 return $self->{'type'};
240 sub pretty ($)
242 my ($self) = @_;
243 return $self->{'pretty'};
246 =item C<$def-E<gt>set_owner ($owner, $location)>
248 Change the owner of a definition. This usually happens because
249 the user used C<+=> on an Automake variable, so (s)he now owns
250 the content. C<$location> should be an instance of L<Automake::Location>
251 indicating where the change took place.
253 =cut
255 sub set_owner ($$$)
257 my ($self, $owner, $location) = @_;
258 # We always adjust the location when the owner changes (even for
259 # `+=' statements). The risk otherwise is to warn about
260 # a VAR_MAKEFILE variable and locate it in configure.ac...
261 $self->{'owner'} = $owner;
262 $self->{'location'} = $location;
265 =item C<$def-E<gt>set_seen>
267 =item C<$bool = $def-E<gt>seen>
269 These function allows Automake to mark (C<set_seen>) variable that
270 it has examined in some way, and latter check (using C<seen>) for
271 unused variables. Unused variables usually indicate typos.
273 =cut
275 sub set_seen ($)
277 my ($self) = @_;
278 $self->{'seen'} = 1;
281 sub seen ($)
283 my ($self) = @_;
284 return $self->{'seen'};
287 =item C<$str = $def-E<gt>dump>
289 Format the contents of C<$def> as a human-readable string,
290 for debugging.
292 =cut
294 sub dump ($)
296 my ($self) = @_;
297 my $owner = $self->owner;
299 if ($owner == VAR_AUTOMAKE)
301 $owner = 'Automake';
303 elsif ($owner == VAR_CONFIGURE)
305 $owner = 'Configure';
307 elsif ($owner == VAR_MAKEFILE)
309 $owner = 'Makefile';
311 else
313 prog_error ("unexpected owner");
316 my $where = $self->location->dump;
317 my $comment = $self->comment;
318 my $value = $self->raw_value;
319 my $type = $self->type;
321 return "{
322 type: $type=
323 where: $where comment: $comment
324 value: $value
325 owner: $owner
326 }\n";
329 =back
331 =head1 SEE ALSO
333 L<Automake::Variable>, L<Automake::ItemDef>.
335 =cut
339 ### Setup "GNU" style for perl-mode and cperl-mode.
340 ## Local Variables:
341 ## perl-indent-level: 2
342 ## perl-continued-statement-offset: 2
343 ## perl-continued-brace-offset: 0
344 ## perl-brace-offset: 0
345 ## perl-brace-imaginary-offset: 0
346 ## perl-label-offset: -2
347 ## cperl-indent-level: 2
348 ## cperl-brace-offset: 0
349 ## cperl-continued-brace-offset: 0
350 ## cperl-label-offset: -2
351 ## cperl-extra-newline-before-brace: t
352 ## cperl-merge-trailing-else: nil
353 ## cperl-continued-statement-offset: 2
354 ## End: