1 # Copyright (C) 2002-2013 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)
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
::ChannelDefs
;
27 use Automake
::Channels
;
31 Automake::ChannelDefs - channel definitions for Automake and helper functions
35 use Automake::ChannelDefs;
37 Automake::ChannelDefs::usage ();
38 prog_error ($MESSAGE, [%OPTIONS]);
39 error ($WHERE, $MESSAGE, [%OPTIONS]);
41 fatal ($WHERE, $MESSAGE, [%OPTIONS]);
43 verb ($MESSAGE, [%OPTIONS]);
44 switch_warning ($CATEGORY);
46 parse_warnings ($OPTION, $ARGUMENT);
47 Automake::ChannelDefs::set_strictness ($STRICTNESS_NAME);
51 This packages defines channels that can be used in Automake to
52 output diagnostics and other messages (via C<msg()>). It also defines
53 some helper function to enable or disable these channels, and some
54 shorthand function to output on specific channels.
62 use vars qw
(@ISA @EXPORT);
65 @EXPORT = qw
(&prog_error
&error
&fatal
&verb
66 &switch_warning
&parse_WARNINGS
&parse_warnings
);
70 The following channels can be used as the first argument of
71 C<Automake::Channel::msg>. For some of them we list a shorthand
72 function that makes the code more readable.
78 Fatal errors. Use C<&fatal> to send messages over this channel.
82 Common errors. Use C<&error> to send messages over this channel.
86 Errors related to GNU Standards.
88 =item C<error-gnu/warn>
90 Errors related to GNU Standards that should be warnings in 'foreign' mode.
94 Errors related to GNITS Standards (silent by default).
98 Internal errors. Use C<&prog_error> to send messages over this channel.
102 Warnings related to GNU Coding Standards.
106 Warnings about obsolete features (silent by default).
110 Warnings about user redefinitions of Automake rules or
111 variables (silent by default).
115 Warnings about non-portable constructs.
117 =item C<extra-portability>
119 Extra warnings about non-portable constructs covering obscure tools.
123 Warnings about weird syntax, unused variables, typos...
127 Warnings about unsupported (or mis-supported) features.
131 Messages output in C<--verbose> mode. Use C<&verb> to send such messages.
135 Informative messages.
141 # Initialize our list of error/warning channels.
142 # Do not forget to update &usage and the manual
143 # if you add or change a warning channel.
145 register_channel
'fatal', type
=> 'fatal', uniq_part
=> UP_NONE
, ordered
=> 0;
146 register_channel
'error', type
=> 'error';
147 register_channel
'error-gnu', type
=> 'error';
148 register_channel
'error-gnu/warn', type
=> 'error';
149 register_channel
'error-gnits', type
=> 'error', silent
=> 1;
150 register_channel
'automake', type
=> 'fatal', backtrace
=> 1,
151 header
=> ("####################\n" .
152 "## Internal Error ##\n" .
153 "####################\n"),
154 footer
=> "\nPlease contact <$PACKAGE_BUGREPORT>.",
155 uniq_part
=> UP_NONE
, ordered
=> 0;
157 register_channel
'extra-portability', type
=> 'warning', silent
=> 1;
158 register_channel
'gnu', type
=> 'warning';
159 register_channel
'obsolete', type
=> 'warning';
160 register_channel
'override', type
=> 'warning', silent
=> 1;
161 register_channel
'portability', type
=> 'warning', silent
=> 1;
162 register_channel
'portability-recursive', type
=> 'warning', silent
=> 1;
163 register_channel
'syntax', type
=> 'warning';
164 register_channel
'unsupported', type
=> 'warning';
166 register_channel
'verb', type
=> 'debug', silent
=> 1, uniq_part
=> UP_NONE
,
168 register_channel
'note', type
=> 'debug', silent
=> 0;
170 setup_channel_type
'warning', header
=> 'warning: ';
171 setup_channel_type
'error', header
=> 'error: ';
172 setup_channel_type
'fatal', header
=> 'error: ';
180 Display warning categories.
187 Warning categories include:
188 gnu GNU coding standards (default in gnu and gnits modes)
189 obsolete obsolete features or constructions
190 override user redefinitions of Automake rules or variables
191 portability portability issues (default in gnu and gnits modes)
192 extra-portability extra portability issues related to obscure tools
193 syntax dubious syntactic constructs (default)
194 unsupported unsupported or incomplete features (default)
196 no-CATEGORY turn off warnings in CATEGORY
197 none turn off all the warnings
198 error treat warnings as errors
202 =item C<prog_error ($MESSAGE, [%OPTIONS])>
204 Signal a programming error (on channel C<automake>),
205 display C<$MESSAGE>, and exit 1.
211 my ($msg, %opts) = @_;
212 msg
'automake', '', $msg, %opts;
215 =item C<error ($WHERE, $MESSAGE, [%OPTIONS])>
217 =item C<error ($MESSAGE)>
219 Uncategorized errors.
225 my ($where, $msg, %opts) = @_;
226 msg
('error', $where, $msg, %opts);
229 =item C<fatal ($WHERE, $MESSAGE, [%OPTIONS])>
231 =item C<fatal ($MESSAGE)>
239 my ($where, $msg, %opts) = @_;
240 msg
('fatal', $where, $msg, %opts);
243 =item C<verb ($MESSAGE, [%OPTIONS])>
245 C<--verbose> messages.
251 my ($msg, %opts) = @_;
252 $msg = "thread " . threads
->tid . ": " . $msg
254 msg
'verb', '', $msg, %opts;
257 =item C<switch_warning ($CATEGORY)>
259 If C<$CATEGORY> is C<mumble>, turn on channel C<mumble>.
260 If it's C<no-mumble>, turn C<mumble> off.
261 Else handle C<all> and C<none> for completeness.
265 sub switch_warning
($)
270 if ($cat =~ /^no-(.*)$/)
278 setup_channel_type
'warning', silent
=> $has_no;
280 elsif ($cat eq 'none')
282 setup_channel_type
'warning', silent
=> ! $has_no;
284 elsif ($cat eq 'error')
286 $warnings_are_errors = ! $has_no;
287 # Set exit code if Perl warns about something
288 # (like uninitialized variables).
290 $has_no ?
'DEFAULT' : sub { print STDERR
@_; $exit_code = 1; };
292 elsif (channel_type
($cat) eq 'warning')
294 setup_channel
$cat, silent
=> $has_no;
296 # Handling of portability warnings is trickier. For relevant tests,
297 # see 'dollarvar2', 'extra-portability' and 'extra-portability3'.
299 # -Wportability-recursive and -Wno-portability-recursive should not
300 # have any effect on other 'portability' or 'extra-portability'
301 # warnings, so there's no need to handle them separately or ad-hoc.
303 if ($cat eq 'extra-portability' && ! $has_no) # -Wextra-portability
305 # -Wextra-portability must enable 'portability' and
306 # 'portability-recursive' warnings.
307 setup_channel
'portability', silent
=> 0;
308 setup_channel
'portability-recursive', silent
=> 0;
310 if ($cat eq 'portability') # -Wportability or -Wno-portability
312 if ($has_no) # -Wno-portability
314 # -Wno-portability must disable 'extra-portability' and
315 # 'portability-recursive' warnings.
316 setup_channel
'portability-recursive', silent
=> 1;
317 setup_channel
'extra-portability', silent
=> 1;
321 # -Wportability must enable 'portability-recursive'
322 # warnings. But it should have no influence over the
323 # 'extra-portability' warnings.
324 setup_channel
'portability-recursive', silent
=> 0;
335 =item C<parse_WARNINGS ()>
337 Parse the WARNINGS environment variable.
341 sub parse_WARNINGS
()
343 if (exists $ENV{'WARNINGS'})
345 # Ignore unknown categories. This is required because WARNINGS
346 # should be honored by many tools.
347 switch_warning
$_ foreach (split (',', $ENV{'WARNINGS'}));
351 =item C<parse_warnings ($OPTION, $ARGUMENT)>
353 Parse the argument of C<--warning=CATEGORY> or C<-WCATEGORY>.
355 C<$OPTIONS> is C<"--warning"> or C<"-W">, C<$ARGUMENT> is C<CATEGORY>.
357 This is meant to be used as an argument to C<Getopt>.
361 sub parse_warnings
($$)
363 my ($opt, $categories) = @_;
365 foreach my $cat (split (',', $categories))
367 msg
'unsupported', "unknown warning category '$cat'"
368 if switch_warning
$cat;
372 =item C<set_strictness ($STRICTNESS_NAME)>
374 Configure channels for strictness C<$STRICTNESS_NAME>.
378 sub set_strictness
($)
384 setup_channel
'error-gnu', silent
=> 0;
385 setup_channel
'error-gnu/warn', silent
=> 0, type
=> 'error';
386 setup_channel
'error-gnits', silent
=> 1;
387 setup_channel
'portability', silent
=> 0;
388 setup_channel
'extra-portability', silent
=> 1;
389 setup_channel
'gnu', silent
=> 0;
391 elsif ($name eq 'gnits')
393 setup_channel
'error-gnu', silent
=> 0;
394 setup_channel
'error-gnu/warn', silent
=> 0, type
=> 'error';
395 setup_channel
'error-gnits', silent
=> 0;
396 setup_channel
'portability', silent
=> 0;
397 setup_channel
'extra-portability', silent
=> 1;
398 setup_channel
'gnu', silent
=> 0;
400 elsif ($name eq 'foreign')
402 setup_channel
'error-gnu', silent
=> 1;
403 setup_channel
'error-gnu/warn', silent
=> 0, type
=> 'warning';
404 setup_channel
'error-gnits', silent
=> 1;
405 setup_channel
'portability', silent
=> 1;
406 setup_channel
'extra-portability', silent
=> 1;
407 setup_channel
'gnu', silent
=> 1;
411 prog_error
"level '$name' not recognized";
419 L<Automake::Channels>
423 Written by Alexandre Duret-Lutz E<lt>F<adl@gnu.org>E<gt>.
429 ### Setup "GNU" style for perl-mode and cperl-mode.
431 ## perl-indent-level: 2
432 ## perl-continued-statement-offset: 2
433 ## perl-continued-brace-offset: 0
434 ## perl-brace-offset: 0
435 ## perl-brace-imaginary-offset: 0
436 ## perl-label-offset: -2
437 ## cperl-indent-level: 2
438 ## cperl-brace-offset: 0
439 ## cperl-continued-brace-offset: 0
440 ## cperl-label-offset: -2
441 ## cperl-extra-newline-before-brace: t
442 ## cperl-merge-trailing-else: nil
443 ## cperl-continued-statement-offset: 2