1 # Copyright (C) 2002, 2003, 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 3, or (at your option)
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, write to the Free Software
15 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 package Autom4te
::ChannelDefs
;
20 use Autom4te
::Channels
;
24 Autom4te::ChannelDefs - channel definitions for Automake and helper functions
28 use Autom4te::ChannelDefs;
30 print Autom4te::ChannelDefs::usage (), "\n";
31 prog_error ($MESSAGE, [%OPTIONS]);
32 error ($WHERE, $MESSAGE, [%OPTIONS]);
34 fatal ($WHERE, $MESSAGE, [%OPTIONS]);
36 verb ($MESSAGE, [%OPTIONS]);
37 switch_warning ($CATEGORY);
39 parse_warnings ($OPTION, $ARGUMENT);
40 Autom4te::ChannelDefs::set_strictness ($STRICTNESS_NAME);
44 This packages defines channels that can be used in Automake to
45 output diagnostics and other messages (via C<msg()>). It also defines
46 some helper function to enable or disable these channels, and some
47 shorthand function to output on specific channels.
55 use vars qw
(@ISA @EXPORT);
58 @EXPORT = qw
(&prog_error
&error
&fatal
&verb
59 &switch_warning
&parse_WARNINGS
&parse_warnings
);
63 The following channels can be used as the first argument of
64 C<Autom4te::Channel::msg>. For some of them we list a shorthand
65 function that makes the code more readable.
71 Fatal errors. Use C<&fatal> to send messages over this channel.
75 Common errors. Use C<&error> to send messages over this channel.
79 Errors related to GNU Standards.
81 =item C<error-gnu/warn>
83 Errors related to GNU Standards that should be warnings in "foreign" mode.
87 Errors related to GNITS Standards (silent by default).
91 Internal errors. Use C<&prog_error> to send messages over this channel.
95 Constructs compromising the cross-compilation of the package.
99 Warnings related to GNU Coding Standards.
103 Warnings about obsolete features (silent by default).
107 Warnings about user redefinitions of Automake rules or
108 variables (silent by default).
112 Warnings about non-portable constructs.
116 Warnings about weird syntax, unused variables, typos...
120 Warnings about unsupported (or mis-supported) features.
124 Messages output in C<--verbose> mode. Use C<&verb> to send such messages.
128 Informative messages.
134 # Initialize our list of error/warning channels.
135 # Do not forget to update &usage and the manual
136 # if you add or change a warning channel.
138 register_channel
'fatal', type
=> 'fatal';
139 register_channel
'error', type
=> 'error';
140 register_channel
'error-gnu', type
=> 'error';
141 register_channel
'error-gnu/warn', type
=> 'error';
142 register_channel
'error-gnits', type
=> 'error', silent
=> 1;
143 register_channel
'automake', type
=> 'fatal', backtrace
=> 1,
144 header
=> ("####################\n" .
145 "## Internal Error ##\n" .
146 "####################\n"),
147 footer
=> "\nPlease contact <bug-automake\@gnu.org>.";
149 register_channel
'cross', type
=> 'warning', silent
=> 1;
150 register_channel
'gnu', type
=> 'warning';
151 register_channel
'obsolete', type
=> 'warning', silent
=> 1;
152 register_channel
'override', type
=> 'warning', silent
=> 1;
153 register_channel
'portability', type
=> 'warning', silent
=> 1;
154 register_channel
'syntax', type
=> 'warning';
155 register_channel
'unsupported', type
=> 'warning';
157 register_channel
'verb', type
=> 'debug', silent
=> 1;
158 register_channel
'note', type
=> 'debug', silent
=> 0;
166 Return the warning category descriptions.
172 return "Warning categories include:
173 `cross' cross compilation issues
174 `gnu' GNU coding standards (default in gnu and gnits modes)
175 `obsolete' obsolete features or constructions
176 `override' user redefinitions of Automake rules or variables
177 `portability' portability issues (default in gnu and gnits modes)
178 `syntax' dubious syntactic constructs (default)
179 `unsupported' unsupported or incomplete features (default)
180 `all' all the warnings
181 `no-CATEGORY' turn off warnings in CATEGORY
182 `none' turn off all the warnings
183 `error' treat warnings as errors";
186 =item C<prog_error ($MESSAGE, [%OPTIONS])>
188 Signal a programming error (on channel C<automake>),
189 display C<$MESSAGE>, and exit 1.
195 my ($msg, %opts) = @_;
196 msg
'automake', '', $msg, %opts;
199 =item C<error ($WHERE, $MESSAGE, [%OPTIONS])>
201 =item C<error ($MESSAGE)>
203 Uncategorized errors.
209 my ($where, $msg, %opts) = @_;
210 msg
('error', $where, $msg, %opts);
213 =item C<fatal ($WHERE, $MESSAGE, [%OPTIONS])>
215 =item C<fatal ($MESSAGE)>
223 my ($where, $msg, %opts) = @_;
224 msg
('fatal', $where, $msg, %opts);
227 =item C<verb ($MESSAGE, [%OPTIONS])>
229 C<--verbose> messages.
235 my ($msg, %opts) = @_;
236 msg
'verb', '', $msg, %opts;
239 =item C<switch_warning ($CATEGORY)>
241 If C<$CATEGORY> is C<mumble>, turn on channel C<mumble>.
242 If it is C<no-mumble>, turn C<mumble> off.
243 Else handle C<all> and C<none> for completeness.
247 sub switch_warning
($)
252 if ($cat =~ /^no-(.*)$/)
260 setup_channel_type
'warning', silent
=> $has_no;
262 elsif ($cat eq 'none')
264 setup_channel_type
'warning', silent
=> ! $has_no;
266 elsif ($cat eq 'error')
268 $warnings_are_errors = ! $has_no;
269 # Set exit code if Perl warns about something
270 # (like uninitialized variables).
272 $has_no ?
'DEFAULT' : sub { print STDERR
@_; $exit_code = 1; };
274 elsif (channel_type
($cat) eq 'warning')
276 setup_channel
$cat, silent
=> $has_no;
285 =item C<parse_WARNINGS ()>
287 Parse the WARNINGS environment variable.
291 sub parse_WARNINGS
()
293 if (exists $ENV{'WARNINGS'})
295 # Ignore unknown categories. This is required because WARNINGS
296 # should be honored by many tools.
297 switch_warning
$_ foreach (split (',', $ENV{'WARNINGS'}));
301 =item C<parse_warnings ($OPTION, @ARGUMENT)>
303 Parse the argument of C<--warning=CATEGORY> or C<-WCATEGORY>.
305 C<$OPTIONS> is C<"--warning"> or C<"-W">, C<@ARGUMENT> is a list of
308 This can be used as a argument to C<Getopt>.
312 sub parse_warnings
($@
)
314 my ($opt, @categories) = @_;
316 foreach my $cat (map { split ',' } @categories)
318 msg
'unsupported', "unknown warning category `$cat'"
319 if switch_warning
$cat;
323 =item C<set_strictness ($STRICTNESS_NAME)>
325 Configure channels for strictness C<$STRICTNESS_NAME>.
329 sub set_strictness
($)
335 setup_channel
'error-gnu', silent
=> 0;
336 setup_channel
'error-gnu/warn', silent
=> 0, type
=> 'error';
337 setup_channel
'error-gnits', silent
=> 1;
338 setup_channel
'portability', silent
=> 0;
339 setup_channel
'gnu', silent
=> 0;
341 elsif ($name eq 'gnits')
343 setup_channel
'error-gnu', silent
=> 0;
344 setup_channel
'error-gnu/warn', silent
=> 0, type
=> 'error';
345 setup_channel
'error-gnits', silent
=> 0;
346 setup_channel
'portability', silent
=> 0;
347 setup_channel
'gnu', silent
=> 0;
349 elsif ($name eq 'foreign')
351 setup_channel
'error-gnu', silent
=> 1;
352 setup_channel
'error-gnu/warn', silent
=> 0, type
=> 'warning';
353 setup_channel
'error-gnits', silent
=> 1;
354 setup_channel
'portability', silent
=> 1;
355 setup_channel
'gnu', silent
=> 1;
359 prog_error
"level `$name' not recognized\n";
367 L<Autom4te::Channels>
371 Written by Alexandre Duret-Lutz E<lt>F<adl@gnu.org>E<gt>.
375 ### Setup "GNU" style for perl-mode and cperl-mode.
377 ## perl-indent-level: 2
378 ## perl-continued-statement-offset: 2
379 ## perl-continued-brace-offset: 0
380 ## perl-brace-offset: 0
381 ## perl-brace-imaginary-offset: 0
382 ## perl-label-offset: -2
383 ## cperl-indent-level: 2
384 ## cperl-brace-offset: 0
385 ## cperl-continued-brace-offset: 0
386 ## cperl-label-offset: -2
387 ## cperl-extra-newline-before-brace: t
388 ## cperl-merge-trailing-else: nil
389 ## cperl-continued-statement-offset: 2