Reword the copyright notices to match what's suggested in GPLv3.
[automake/plouj.git] / lib / Automake / ChannelDefs.pm
blob898b1ea4e6482d2497f5cc9f56de16a7ab301369
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)
6 # any later version.
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;
18 use Automake::Channels;
20 =head1 NAME
22 Automake::ChannelDefs - channel definitions for Automake and helper functions
24 =head1 SYNOPSIS
26 use Automake::ChannelDefs;
28 Automake::ChannelDefs::usage ();
29 prog_error ($MESSAGE, [%OPTIONS]);
30 error ($WHERE, $MESSAGE, [%OPTIONS]);
31 error ($MESSAGE);
32 fatal ($WHERE, $MESSAGE, [%OPTIONS]);
33 fatal ($MESSAGE);
34 verb ($MESSAGE, [%OPTIONS]);
35 switch_warning ($CATEGORY);
36 parse_WARNINGS ();
37 parse_warning ($OPTION, $ARGUMENT);
38 Automake::ChannelDefs::set_strictness ($STRICTNESS_NAME);
40 =head1 DESCRIPTION
42 This packages defines channels that can be used in Automake to
43 output diagnostics and other messages (via C<msg()>). It also defines
44 some helper function to enable or disable these channels, and some
45 shorthand function to output on specific channels.
47 =cut
49 use 5.005;
50 use strict;
51 use Exporter;
53 use vars qw (@ISA @EXPORT);
55 @ISA = qw (Exporter);
56 @EXPORT = qw (&prog_error &error &fatal &verb
57 &switch_warning &parse_WARNINGS &parse_warnings);
59 =head2 CHANNELS
61 The following channels can be used as the first argument of
62 C<Automake::Channel::msg>. For some of them we list a shorthand
63 function that makes the code more readable.
65 =over 4
67 =item C<fatal>
69 Fatal errors. Use C<&fatal> to send messages over this channel.
71 =item C<error>
73 Common errors. Use C<&error> to send messages over this channel.
75 =item C<error-gnu>
77 Errors related to GNU Standards.
79 =item C<error-gnu/warn>
81 Errors related to GNU Standards that should be warnings in `foreign' mode.
83 =item C<error-gnits>
85 Errors related to GNITS Standards (silent by default).
87 =item C<automake>
89 Internal errors. Use C<&prog_error> to send messages over this channel.
91 =item C<gnu>
93 Warnings related to GNU Coding Standards.
95 =item C<obsolete>
97 Warnings about obsolete features (silent by default).
99 =item C<override>
101 Warnings about user redefinitions of Automake rules or
102 variables (silent by default).
104 =item C<portability>
106 Warnings about non-portable constructs.
108 =item C<syntax>
110 Warnings about weird syntax, unused variables, typos...
112 =item C<unsupported>
114 Warnings about unsupported (or mis-supported) features.
116 =item C<verb>
118 Messages output in C<--verbose> mode. Use C<&verb> to send such messages.
120 =item C<note>
122 Informative messages.
124 =back
126 =cut
128 # Initialize our list of error/warning channels.
129 # Do not forget to update &usage and the manual
130 # if you add or change a warning channel.
132 register_channel 'fatal', type => 'fatal';
133 register_channel 'error', type => 'error';
134 register_channel 'error-gnu', type => 'error';
135 register_channel 'error-gnu/warn', type => 'error';
136 register_channel 'error-gnits', type => 'error', silent => 1;
137 register_channel 'automake', type => 'fatal', backtrace => 1,
138 header => ("####################\n" .
139 "## Internal Error ##\n" .
140 "####################\n"),
141 footer => "\nPlease contact <bug-automake\@gnu.org>.";
143 register_channel 'gnu', type => 'warning';
144 register_channel 'obsolete', type => 'warning', silent => 1;
145 register_channel 'override', type => 'warning', silent => 1;
146 register_channel 'portability', type => 'warning', silent => 1;
147 register_channel 'syntax', type => 'warning';
148 register_channel 'unsupported', type => 'warning';
150 register_channel 'verb', type => 'debug', silent => 1;
151 register_channel 'note', type => 'debug', silent => 0;
153 =head2 FUNCTIONS
155 =over 4
157 =item C<usage ()>
159 Display warning categories.
161 =cut
163 sub usage ()
165 print "Warning categories include:
166 `gnu' GNU coding standards (default in gnu and gnits modes)
167 `obsolete' obsolete features or constructions
168 `override' user redefinitions of Automake rules or variables
169 `portability' portability issues (default in gnu and gnits modes)
170 `syntax' dubious syntactic constructs (default)
171 `unsupported' unsupported or incomplete features (default)
172 `all' all the warnings
173 `no-CATEGORY' turn off warnings in CATEGORY
174 `none' turn off all the warnings
175 `error' treat warnings as errors
179 =item C<prog_error ($MESSAGE, [%OPTIONS])>
181 Signal a programming error (on channel C<automake>),
182 display C<$MESSAGE>, and exit 1.
184 =cut
186 sub prog_error ($;%)
188 my ($msg, %opts) = @_;
189 msg 'automake', '', $msg, %opts;
192 =item C<error ($WHERE, $MESSAGE, [%OPTIONS])>
194 =item C<error ($MESSAGE)>
196 Uncategorized errors.
198 =cut
200 sub error ($;$%)
202 my ($where, $msg, %opts) = @_;
203 msg ('error', $where, $msg, %opts);
206 =item C<fatal ($WHERE, $MESSAGE, [%OPTIONS])>
208 =item C<fatal ($MESSAGE)>
210 Fatal errors.
212 =cut
214 sub fatal ($;$%)
216 my ($where, $msg, %opts) = @_;
217 msg ('fatal', $where, $msg, %opts);
220 =item C<verb ($MESSAGE, [%OPTIONS])>
222 C<--verbose> messages.
224 =cut
226 sub verb ($;%)
228 my ($msg, %opts) = @_;
229 msg 'verb', '', $msg, %opts;
232 =item C<switch_warning ($CATEGORY)>
234 If C<$CATEGORY> is C<mumble>, turn on channel C<mumble>.
235 If it's C<no-mumble>, turn C<mumble> off.
236 Else handle C<all> and C<none> for completeness.
238 =cut
240 sub switch_warning ($)
242 my ($cat) = @_;
243 my $has_no = 0;
245 if ($cat =~ /^no-(.*)$/)
247 $cat = $1;
248 $has_no = 1;
251 if ($cat eq 'all')
253 setup_channel_type 'warning', silent => $has_no;
255 elsif ($cat eq 'none')
257 setup_channel_type 'warning', silent => ! $has_no;
259 elsif ($cat eq 'error')
261 $warnings_are_errors = ! $has_no;
262 # Set exit code if Perl warns about something
263 # (like uninitialized variables).
264 $SIG{"__WARN__"} =
265 $has_no ? 'DEFAULT' : sub { print STDERR @_; $exit_code = 1; };
267 elsif (channel_type ($cat) eq 'warning')
269 setup_channel $cat, silent => $has_no;
271 else
273 return 1;
275 return 0;
278 =item C<parse_WARNINGS ()>
280 Parse the WARNINGS environment variable.
282 =cut
284 sub parse_WARNINGS ()
286 if (exists $ENV{'WARNINGS'})
288 # Ignore unknown categories. This is required because WARNINGS
289 # should be honored by many tools.
290 switch_warning $_ foreach (split (',', $ENV{'WARNINGS'}));
294 =item C<parse_warning ($OPTION, $ARGUMENT)>
296 Parse the argument of C<--warning=CATEGORY> or C<-WCATEGORY>.
298 C<$OPTIONS> is C<"--warning"> or C<"-W">, C<$ARGUMENT> is C<CATEGORY>.
300 This is meant to be used as a argument to C<Getopt>.
302 =cut
304 sub parse_warnings ($$)
306 my ($opt, $categories) = @_;
308 foreach my $cat (split (',', $categories))
310 msg 'unsupported', "unknown warning category `$cat'"
311 if switch_warning $cat;
315 =item C<set_strictness ($STRICTNESS_NAME)>
317 Configure channels for strictness C<$STRICTNESS_NAME>.
319 =cut
321 sub set_strictness ($)
323 my ($name) = @_;
325 if ($name eq 'gnu')
327 setup_channel 'error-gnu', silent => 0;
328 setup_channel 'error-gnu/warn', silent => 0, type => 'error';
329 setup_channel 'error-gnits', silent => 1;
330 setup_channel 'portability', silent => 0;
331 setup_channel 'gnu', silent => 0;
333 elsif ($name eq 'gnits')
335 setup_channel 'error-gnu', silent => 0;
336 setup_channel 'error-gnu/warn', silent => 0, type => 'error';
337 setup_channel 'error-gnits', silent => 0;
338 setup_channel 'portability', silent => 0;
339 setup_channel 'gnu', silent => 0;
341 elsif ($name eq 'foreign')
343 setup_channel 'error-gnu', silent => 1;
344 setup_channel 'error-gnu/warn', silent => 0, type => 'warning';
345 setup_channel 'error-gnits', silent => 1;
346 setup_channel 'portability', silent => 1;
347 setup_channel 'gnu', silent => 1;
349 else
351 prog_error "level `$name' not recognized\n";
355 =back
357 =head1 SEE ALSO
359 L<Automake::Channels>
361 =head1 HISTORY
363 Written by Alexandre Duret-Lutz E<lt>F<adl@gnu.org>E<gt>.
365 =cut
367 ### Setup "GNU" style for perl-mode and cperl-mode.
368 ## Local Variables:
369 ## perl-indent-level: 2
370 ## perl-continued-statement-offset: 2
371 ## perl-continued-brace-offset: 0
372 ## perl-brace-offset: 0
373 ## perl-brace-imaginary-offset: 0
374 ## perl-label-offset: -2
375 ## cperl-indent-level: 2
376 ## cperl-brace-offset: 0
377 ## cperl-continued-brace-offset: 0
378 ## cperl-label-offset: -2
379 ## cperl-extra-newline-before-brace: t
380 ## cperl-merge-trailing-else: nil
381 ## cperl-continued-statement-offset: 2
382 ## End: