1 # Copyright (C) 2002, 2003, 2006, 2008, 2009, 2010 Free Software
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2, or (at your option)
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 package Automake::ChannelDefs;
28 use Automake::Channels;
32 Automake::ChannelDefs - channel definitions for Automake and helper functions
36 use Automake::ChannelDefs;
38 Automake::ChannelDefs::usage ();
39 prog_error ($MESSAGE, [%OPTIONS]);
40 error ($WHERE, $MESSAGE, [%OPTIONS]);
42 fatal ($WHERE, $MESSAGE, [%OPTIONS]);
44 verb ($MESSAGE, [%OPTIONS]);
45 switch_warning ($CATEGORY);
47 parse_warning ($OPTION, $ARGUMENT);
48 Automake::ChannelDefs::set_strictness ($STRICTNESS_NAME);
52 This packages defines channels that can be used in Automake to
53 output diagnostics and other messages (via C<msg()>). It also defines
54 some helper function to enable or disable these channels, and some
55 shorthand function to output on specific channels.
63 use vars qw (@ISA @EXPORT);
66 @EXPORT = qw (&prog_error &error &fatal &verb
67 &switch_warning &parse_WARNINGS &parse_warnings);
71 The following channels can be used as the first argument of
72 C<Automake::Channel::msg>. For some of them we list a shorthand
73 function that makes the code more readable.
79 Fatal errors. Use C<&fatal> to send messages over this channel.
83 Common errors. Use C<&error> to send messages over this channel.
87 Errors related to GNU Standards.
89 =item C<error-gnu/warn>
91 Errors related to GNU Standards that should be warnings in `foreign' mode.
95 Errors related to GNITS Standards (silent by default).
99 Internal errors. Use C<&prog_error> to send messages over this channel.
103 Warnings related to GNU Coding Standards.
107 Warnings about obsolete features (silent by default).
111 Warnings about user redefinitions of Automake rules or
112 variables (silent by default).
116 Warnings about non-portable constructs.
120 Warnings about weird syntax, unused variables, typos...
124 Warnings about unsupported (or mis-supported) features.
128 Messages output in C<--verbose> mode. Use C<&verb> to send such messages.
132 Informative messages.
138 # Initialize our list of error/warning channels.
139 # Do not forget to update &usage and the manual
140 # if you add or change a warning channel.
142 register_channel 'fatal', type => 'fatal', uniq_part => UP_NONE, ordered => 0;
143 register_channel 'error', type => 'error';
144 register_channel 'error-gnu', type => 'error';
145 register_channel 'error-gnu/warn', type => 'error';
146 register_channel 'error-gnits', type => 'error', silent => 1;
147 register_channel 'automake', type => 'fatal', backtrace => 1,
148 header => ("####################\n" .
149 "## Internal Error ##\n" .
150 "####################\n"),
151 footer => "\nPlease contact <$PACKAGE_BUGREPORT>.",
152 uniq_part => UP_NONE, ordered => 0;
154 register_channel 'gnu', type => 'warning';
155 register_channel 'obsolete', type => 'warning', silent => 1;
156 register_channel 'override', type => 'warning', silent => 1;
157 register_channel 'portability', type => 'warning', silent => 1;
158 register_channel 'portability-recursive', type => 'warning', silent => 1;
159 register_channel 'syntax', type => 'warning';
160 register_channel 'unsupported', type => 'warning';
162 register_channel 'verb', type => 'debug', silent => 1, uniq_part => UP_NONE,
164 register_channel 'note', type => 'debug', silent => 0;
172 Display warning categories.
178 print "Warning categories include:
179 `gnu' GNU coding standards (default in gnu and gnits modes)
180 `obsolete' obsolete features or constructions
181 `override' user redefinitions of Automake rules or variables
182 `portability' portability issues (default in gnu and gnits modes)
183 `syntax' dubious syntactic constructs (default)
184 `unsupported' unsupported or incomplete features (default)
185 `all' all the warnings
186 `no-CATEGORY' turn off warnings in CATEGORY
187 `none' turn off all the warnings
188 `error' treat warnings as errors
192 =item C<prog_error ($MESSAGE, [%OPTIONS])>
194 Signal a programming error (on channel C<automake>),
195 display C<$MESSAGE>, and exit 1.
201 my ($msg, %opts) = @_;
202 msg 'automake', '', $msg, %opts;
205 =item C<error ($WHERE, $MESSAGE, [%OPTIONS])>
207 =item C<error ($MESSAGE)>
209 Uncategorized errors.
215 my ($where, $msg, %opts) = @_;
216 msg ('error', $where, $msg, %opts);
219 =item C<fatal ($WHERE, $MESSAGE, [%OPTIONS])>
221 =item C<fatal ($MESSAGE)>
229 my ($where, $msg, %opts) = @_;
230 msg ('fatal', $where, $msg, %opts);
233 =item C<verb ($MESSAGE, [%OPTIONS])>
235 C<--verbose> messages.
241 my ($msg, %opts) = @_;
242 $msg = "thread " . threads->tid . ": " . $msg
244 msg 'verb', '', $msg, %opts;
247 =item C<switch_warning ($CATEGORY)>
249 If C<$CATEGORY> is C<mumble>, turn on channel C<mumble>.
250 If it's C<no-mumble>, turn C<mumble> off.
251 Else handle C<all> and C<none> for completeness.
255 sub switch_warning ($)
260 if ($cat =~ /^no-(.*)$/)
268 setup_channel_type 'warning', silent => $has_no;
270 elsif ($cat eq 'none')
272 setup_channel_type 'warning', silent => ! $has_no;
274 elsif ($cat eq 'error')
276 $warnings_are_errors = ! $has_no;
277 # Set exit code if Perl warns about something
278 # (like uninitialized variables).
280 $has_no ? 'DEFAULT' : sub { print STDERR @_; $exit_code = 1; };
282 elsif (channel_type ($cat) eq 'warning')
284 setup_channel $cat, silent => $has_no;
285 setup_channel 'portability-recursive', silent => $has_no
286 if $cat eq 'portability';
295 =item C<parse_WARNINGS ()>
297 Parse the WARNINGS environment variable.
301 sub parse_WARNINGS ()
303 if (exists $ENV{'WARNINGS'})
305 # Ignore unknown categories. This is required because WARNINGS
306 # should be honored by many tools.
307 switch_warning $_ foreach (split (',', $ENV{'WARNINGS'}));
311 =item C<parse_warning ($OPTION, $ARGUMENT)>
313 Parse the argument of C<--warning=CATEGORY> or C<-WCATEGORY>.
315 C<$OPTIONS> is C<"--warning"> or C<"-W">, C<$ARGUMENT> is C<CATEGORY>.
317 This is meant to be used as an argument to C<Getopt>.
321 sub parse_warnings ($$)
323 my ($opt, $categories) = @_;
325 foreach my $cat (split (',', $categories))
327 msg 'unsupported', "unknown warning category `$cat'"
328 if switch_warning $cat;
332 =item C<set_strictness ($STRICTNESS_NAME)>
334 Configure channels for strictness C<$STRICTNESS_NAME>.
338 sub set_strictness ($)
344 setup_channel 'error-gnu', silent => 0;
345 setup_channel 'error-gnu/warn', silent => 0, type => 'error';
346 setup_channel 'error-gnits', silent => 1;
347 setup_channel 'portability', silent => 0;
348 setup_channel 'gnu', silent => 0;
350 elsif ($name eq 'gnits')
352 setup_channel 'error-gnu', silent => 0;
353 setup_channel 'error-gnu/warn', silent => 0, type => 'error';
354 setup_channel 'error-gnits', silent => 0;
355 setup_channel 'portability', silent => 0;
356 setup_channel 'gnu', silent => 0;
358 elsif ($name eq 'foreign')
360 setup_channel 'error-gnu', silent => 1;
361 setup_channel 'error-gnu/warn', silent => 0, type => 'warning';
362 setup_channel 'error-gnits', silent => 1;
363 setup_channel 'portability', silent => 1;
364 setup_channel 'gnu', silent => 1;
368 prog_error "level `$name' not recognized\n";
376 L<Automake::Channels>
380 Written by Alexandre Duret-Lutz E<lt>F<adl@gnu.org>E<gt>.
384 ### Setup "GNU" style for perl-mode and cperl-mode.
386 ## perl-indent-level: 2
387 ## perl-continued-statement-offset: 2
388 ## perl-continued-brace-offset: 0
389 ## perl-brace-offset: 0
390 ## perl-brace-imaginary-offset: 0
391 ## perl-label-offset: -2
392 ## cperl-indent-level: 2
393 ## cperl-brace-offset: 0
394 ## cperl-continued-brace-offset: 0
395 ## cperl-label-offset: -2
396 ## cperl-extra-newline-before-brace: t
397 ## cperl-merge-trailing-else: nil
398 ## cperl-continued-statement-offset: 2