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.
118 =item C<extra-portability>
120 Extra warnings about non-portable constructs covering obscure tools.
124 Warnings about weird syntax, unused variables, typos...
128 Warnings about unsupported (or mis-supported) features.
132 Messages output in C<--verbose> mode. Use C<&verb> to send such messages.
136 Informative messages.
142 # Initialize our list of error/warning channels.
143 # Do not forget to update &usage and the manual
144 # if you add or change a warning channel.
146 register_channel 'fatal', type => 'fatal', uniq_part => UP_NONE, ordered => 0;
147 register_channel 'error', type => 'error';
148 register_channel 'error-gnu', type => 'error';
149 register_channel 'error-gnu/warn', type => 'error';
150 register_channel 'error-gnits', type => 'error', silent => 1;
151 register_channel 'automake', type => 'fatal', backtrace => 1,
152 header => ("####################\n" .
153 "## Internal Error ##\n" .
154 "####################\n"),
155 footer => "\nPlease contact <$PACKAGE_BUGREPORT>.",
156 uniq_part => UP_NONE, ordered => 0;
158 register_channel 'extra-portability', type => 'warning', silent => 1;
159 register_channel 'gnu', type => 'warning';
160 register_channel 'obsolete', type => 'warning', silent => 1;
161 register_channel 'override', type => 'warning', silent => 1;
162 register_channel 'portability', type => 'warning', silent => 1;
163 register_channel 'portability-recursive', type => 'warning', silent => 1;
164 register_channel 'syntax', type => 'warning';
165 register_channel 'unsupported', type => 'warning';
167 register_channel 'verb', type => 'debug', silent => 1, uniq_part => UP_NONE,
169 register_channel 'note', type => 'debug', silent => 0;
177 Display warning categories.
183 print "Warning categories include:
184 `gnu' GNU coding standards (default in gnu and gnits modes)
185 `obsolete' obsolete features or constructions
186 `override' user redefinitions of Automake rules or variables
187 `portability' portability issues (default in gnu and gnits modes)
188 `extra-portability' extra portability issues related to obscure tools
189 `syntax' dubious syntactic constructs (default)
190 `unsupported' unsupported or incomplete features (default)
191 `all' all the warnings
192 `no-CATEGORY' turn off warnings in CATEGORY
193 `none' turn off all the warnings
194 `error' treat warnings as errors
198 =item C<prog_error ($MESSAGE, [%OPTIONS])>
200 Signal a programming error (on channel C<automake>),
201 display C<$MESSAGE>, and exit 1.
207 my ($msg, %opts) = @_;
208 msg 'automake', '', $msg, %opts;
211 =item C<error ($WHERE, $MESSAGE, [%OPTIONS])>
213 =item C<error ($MESSAGE)>
215 Uncategorized errors.
221 my ($where, $msg, %opts) = @_;
222 msg ('error', $where, $msg, %opts);
225 =item C<fatal ($WHERE, $MESSAGE, [%OPTIONS])>
227 =item C<fatal ($MESSAGE)>
235 my ($where, $msg, %opts) = @_;
236 msg ('fatal', $where, $msg, %opts);
239 =item C<verb ($MESSAGE, [%OPTIONS])>
241 C<--verbose> messages.
247 my ($msg, %opts) = @_;
248 $msg = "thread " . threads->tid . ": " . $msg
250 msg 'verb', '', $msg, %opts;
253 =item C<switch_warning ($CATEGORY)>
255 If C<$CATEGORY> is C<mumble>, turn on channel C<mumble>.
256 If it's C<no-mumble>, turn C<mumble> off.
257 Else handle C<all> and C<none> for completeness.
261 # HACK to have `-Wextra-portability' *not* implied by `-Wall'.
262 # This will go away in automake 1.12.
263 my $have_extra_portability = 0;
265 sub switch_warning ($)
270 if ($cat =~ /^no-(.*)$/)
278 setup_channel_type 'warning', silent => $has_no;
279 setup_channel 'extra-portability', silent => 1
280 unless $have_extra_portability;
282 elsif ($cat eq 'none')
284 setup_channel_type 'warning', silent => ! $has_no;
286 elsif ($cat eq 'error')
288 $warnings_are_errors = ! $has_no;
289 # Set exit code if Perl warns about something
290 # (like uninitialized variables).
292 $has_no ? 'DEFAULT' : sub { print STDERR @_; $exit_code = 1; };
294 elsif (channel_type ($cat) eq 'warning')
296 setup_channel $cat, silent => $has_no;
297 setup_channel 'portability-recursive', silent => $has_no
298 if $cat eq 'portability';
299 if ($cat eq 'portability' && $has_no)
301 setup_channel 'extra-portability', silent => 1;
302 $have_extra_portability = 0;
304 if ($cat eq 'extra-portability' && ! $has_no)
306 setup_channel 'portability', silent => 0;
307 setup_channel 'portability-recursive', silent => 0;
308 $have_extra_portability = 1;
318 =item C<parse_WARNINGS ()>
320 Parse the WARNINGS environment variable.
324 sub parse_WARNINGS ()
326 if (exists $ENV{'WARNINGS'})
328 # Ignore unknown categories. This is required because WARNINGS
329 # should be honored by many tools.
330 switch_warning $_ foreach (split (',', $ENV{'WARNINGS'}));
334 =item C<parse_warning ($OPTION, $ARGUMENT)>
336 Parse the argument of C<--warning=CATEGORY> or C<-WCATEGORY>.
338 C<$OPTIONS> is C<"--warning"> or C<"-W">, C<$ARGUMENT> is C<CATEGORY>.
340 This is meant to be used as an argument to C<Getopt>.
344 sub parse_warnings ($$)
346 my ($opt, $categories) = @_;
348 foreach my $cat (split (',', $categories))
350 msg 'unsupported', "unknown warning category `$cat'"
351 if switch_warning $cat;
355 =item C<set_strictness ($STRICTNESS_NAME)>
357 Configure channels for strictness C<$STRICTNESS_NAME>.
361 sub set_strictness ($)
367 setup_channel 'error-gnu', silent => 0;
368 setup_channel 'error-gnu/warn', silent => 0, type => 'error';
369 setup_channel 'error-gnits', silent => 1;
370 setup_channel 'portability', silent => 0;
371 setup_channel 'extra-portability', silent => 1;
372 setup_channel 'gnu', silent => 0;
374 elsif ($name eq 'gnits')
376 setup_channel 'error-gnu', silent => 0;
377 setup_channel 'error-gnu/warn', silent => 0, type => 'error';
378 setup_channel 'error-gnits', silent => 0;
379 setup_channel 'portability', silent => 0;
380 setup_channel 'extra-portability', silent => 1;
381 setup_channel 'gnu', silent => 0;
383 elsif ($name eq 'foreign')
385 setup_channel 'error-gnu', silent => 1;
386 setup_channel 'error-gnu/warn', silent => 0, type => 'warning';
387 setup_channel 'error-gnits', silent => 1;
388 setup_channel 'portability', silent => 1;
389 setup_channel 'extra-portability', silent => 1;
390 setup_channel 'gnu', silent => 1;
394 prog_error "level `$name' not recognized\n";
404 L<Automake::Channels>
408 Written by Alexandre Duret-Lutz E<lt>F<adl@gnu.org>E<gt>.
412 ### Setup "GNU" style for perl-mode and cperl-mode.
414 ## perl-indent-level: 2
415 ## perl-continued-statement-offset: 2
416 ## perl-continued-brace-offset: 0
417 ## perl-brace-offset: 0
418 ## perl-brace-imaginary-offset: 0
419 ## perl-label-offset: -2
420 ## cperl-indent-level: 2
421 ## cperl-brace-offset: 0
422 ## cperl-continued-brace-offset: 0
423 ## cperl-label-offset: -2
424 ## cperl-extra-newline-before-brace: t
425 ## cperl-merge-trailing-else: nil
426 ## cperl-continued-statement-offset: 2