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_warnings ($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;
166 setup_channel_type 'warning', header => 'warning: ';
167 setup_channel_type 'error', header => 'error: ';
168 setup_channel_type 'fatal', header => 'error: ';
176 Display warning categories.
182 print "Warning categories include:
183 `gnu' GNU coding standards (default in gnu and gnits modes)
184 `obsolete' obsolete features or constructions
185 `override' user redefinitions of Automake rules or variables
186 `portability' portability issues (default in gnu and gnits modes)
187 `syntax' dubious syntactic constructs (default)
188 `unsupported' unsupported or incomplete features (default)
189 `all' all the warnings
190 `no-CATEGORY' turn off warnings in CATEGORY
191 `none' turn off all the warnings
192 `error' treat warnings as errors
196 =item C<prog_error ($MESSAGE, [%OPTIONS])>
198 Signal a programming error (on channel C<automake>),
199 display C<$MESSAGE>, and exit 1.
205 my ($msg, %opts) = @_;
206 msg 'automake', '', $msg, %opts;
209 =item C<error ($WHERE, $MESSAGE, [%OPTIONS])>
211 =item C<error ($MESSAGE)>
213 Uncategorized errors.
219 my ($where, $msg, %opts) = @_;
220 msg ('error', $where, $msg, %opts);
223 =item C<fatal ($WHERE, $MESSAGE, [%OPTIONS])>
225 =item C<fatal ($MESSAGE)>
233 my ($where, $msg, %opts) = @_;
234 msg ('fatal', $where, $msg, %opts);
237 =item C<verb ($MESSAGE, [%OPTIONS])>
239 C<--verbose> messages.
245 my ($msg, %opts) = @_;
246 $msg = "thread " . threads->tid . ": " . $msg
248 msg 'verb', '', $msg, %opts;
251 =item C<switch_warning ($CATEGORY)>
253 If C<$CATEGORY> is C<mumble>, turn on channel C<mumble>.
254 If it's C<no-mumble>, turn C<mumble> off.
255 Else handle C<all> and C<none> for completeness.
259 sub switch_warning ($)
264 if ($cat =~ /^no-(.*)$/)
272 setup_channel_type 'warning', silent => $has_no;
274 elsif ($cat eq 'none')
276 setup_channel_type 'warning', silent => ! $has_no;
278 elsif ($cat eq 'error')
280 $warnings_are_errors = ! $has_no;
281 # Set exit code if Perl warns about something
282 # (like uninitialized variables).
284 $has_no ? 'DEFAULT' : sub { print STDERR @_; $exit_code = 1; };
286 elsif (channel_type ($cat) eq 'warning')
288 setup_channel $cat, silent => $has_no;
289 setup_channel 'portability-recursive', silent => $has_no
290 if $cat eq 'portability';
299 =item C<parse_WARNINGS ()>
301 Parse the WARNINGS environment variable.
305 sub parse_WARNINGS ()
307 if (exists $ENV{'WARNINGS'})
309 # Ignore unknown categories. This is required because WARNINGS
310 # should be honored by many tools.
311 switch_warning $_ foreach (split (',', $ENV{'WARNINGS'}));
315 =item C<parse_warnings ($OPTION, $ARGUMENT)>
317 Parse the argument of C<--warning=CATEGORY> or C<-WCATEGORY>.
319 C<$OPTIONS> is C<"--warning"> or C<"-W">, C<$ARGUMENT> is C<CATEGORY>.
321 This is meant to be used as an argument to C<Getopt>.
325 sub parse_warnings ($$)
327 my ($opt, $categories) = @_;
329 foreach my $cat (split (',', $categories))
331 msg 'unsupported', "unknown warning category `$cat'"
332 if switch_warning $cat;
336 =item C<set_strictness ($STRICTNESS_NAME)>
338 Configure channels for strictness C<$STRICTNESS_NAME>.
342 sub set_strictness ($)
348 setup_channel 'error-gnu', silent => 0;
349 setup_channel 'error-gnu/warn', silent => 0, type => 'error';
350 setup_channel 'error-gnits', silent => 1;
351 setup_channel 'portability', silent => 0;
352 setup_channel 'gnu', silent => 0;
354 elsif ($name eq 'gnits')
356 setup_channel 'error-gnu', silent => 0;
357 setup_channel 'error-gnu/warn', silent => 0, type => 'error';
358 setup_channel 'error-gnits', silent => 0;
359 setup_channel 'portability', silent => 0;
360 setup_channel 'gnu', silent => 0;
362 elsif ($name eq 'foreign')
364 setup_channel 'error-gnu', silent => 1;
365 setup_channel 'error-gnu/warn', silent => 0, type => 'warning';
366 setup_channel 'error-gnits', silent => 1;
367 setup_channel 'portability', silent => 1;
368 setup_channel 'gnu', silent => 1;
372 prog_error "level `$name' not recognized";
380 L<Automake::Channels>
384 Written by Alexandre Duret-Lutz E<lt>F<adl@gnu.org>E<gt>.
390 ### Setup "GNU" style for perl-mode and cperl-mode.
392 ## perl-indent-level: 2
393 ## perl-continued-statement-offset: 2
394 ## perl-continued-brace-offset: 0
395 ## perl-brace-offset: 0
396 ## perl-brace-imaginary-offset: 0
397 ## perl-label-offset: -2
398 ## cperl-indent-level: 2
399 ## cperl-brace-offset: 0
400 ## cperl-continued-brace-offset: 0
401 ## cperl-label-offset: -2
402 ## cperl-extra-newline-before-brace: t
403 ## cperl-merge-trailing-else: nil
404 ## cperl-continued-statement-offset: 2