1 # Copyright (C) 2002, 2003, 2006, 2008, 2009 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_warning ($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.
119 Warnings about weird syntax, unused variables, typos...
123 Warnings about unsupported (or mis-supported) features.
127 Messages output in C<--verbose> mode. Use C<&verb> to send such messages.
131 Informative messages.
137 # Initialize our list of error/warning channels.
138 # Do not forget to update &usage and the manual
139 # if you add or change a warning channel.
141 register_channel
'fatal', type
=> 'fatal', uniq_part
=> UP_NONE
, ordered
=> 0;
142 register_channel
'error', type
=> 'error';
143 register_channel
'error-gnu', type
=> 'error';
144 register_channel
'error-gnu/warn', type
=> 'error';
145 register_channel
'error-gnits', type
=> 'error', silent
=> 1;
146 register_channel
'automake', type
=> 'fatal', backtrace
=> 1,
147 header
=> ("####################\n" .
148 "## Internal Error ##\n" .
149 "####################\n"),
150 footer
=> "\nPlease contact <bug-automake\@gnu.org>.",
151 uniq_part
=> UP_NONE
, ordered
=> 0;
153 register_channel
'gnu', type
=> 'warning';
154 register_channel
'obsolete', type
=> 'warning', silent
=> 1;
155 register_channel
'override', type
=> 'warning', silent
=> 1;
156 register_channel
'portability', type
=> 'warning', silent
=> 1;
157 register_channel
'portability-recursive', type
=> 'warning', silent
=> 1;
158 register_channel
'syntax', type
=> 'warning';
159 register_channel
'unsupported', type
=> 'warning';
161 register_channel
'verb', type
=> 'debug', silent
=> 1, uniq_part
=> UP_NONE
,
163 register_channel
'note', type
=> 'debug', silent
=> 0;
171 Display warning categories.
177 print "Warning categories include:
178 `gnu' GNU coding standards (default in gnu and gnits modes)
179 `obsolete' obsolete features or constructions
180 `override' user redefinitions of Automake rules or variables
181 `portability' portability issues (default in gnu and gnits modes)
182 `syntax' dubious syntactic constructs (default)
183 `unsupported' unsupported or incomplete features (default)
184 `all' all the warnings
185 `no-CATEGORY' turn off warnings in CATEGORY
186 `none' turn off all the warnings
187 `error' treat warnings as errors
191 =item C<prog_error ($MESSAGE, [%OPTIONS])>
193 Signal a programming error (on channel C<automake>),
194 display C<$MESSAGE>, and exit 1.
200 my ($msg, %opts) = @_;
201 msg
'automake', '', $msg, %opts;
204 =item C<error ($WHERE, $MESSAGE, [%OPTIONS])>
206 =item C<error ($MESSAGE)>
208 Uncategorized errors.
214 my ($where, $msg, %opts) = @_;
215 msg
('error', $where, $msg, %opts);
218 =item C<fatal ($WHERE, $MESSAGE, [%OPTIONS])>
220 =item C<fatal ($MESSAGE)>
228 my ($where, $msg, %opts) = @_;
229 msg
('fatal', $where, $msg, %opts);
232 =item C<verb ($MESSAGE, [%OPTIONS])>
234 C<--verbose> messages.
240 my ($msg, %opts) = @_;
241 $msg = "thread " . threads
->tid . ": " . $msg
243 msg
'verb', '', $msg, %opts;
246 =item C<switch_warning ($CATEGORY)>
248 If C<$CATEGORY> is C<mumble>, turn on channel C<mumble>.
249 If it's C<no-mumble>, turn C<mumble> off.
250 Else handle C<all> and C<none> for completeness.
254 sub switch_warning
($)
259 if ($cat =~ /^no-(.*)$/)
267 setup_channel_type
'warning', silent
=> $has_no;
269 elsif ($cat eq 'none')
271 setup_channel_type
'warning', silent
=> ! $has_no;
273 elsif ($cat eq 'error')
275 $warnings_are_errors = ! $has_no;
276 # Set exit code if Perl warns about something
277 # (like uninitialized variables).
279 $has_no ?
'DEFAULT' : sub { print STDERR
@_; $exit_code = 1; };
281 elsif (channel_type
($cat) eq 'warning')
283 setup_channel
$cat, silent
=> $has_no;
284 setup_channel
'portability-recursive', silent
=> $has_no
285 if $cat eq 'portability';
294 =item C<parse_WARNINGS ()>
296 Parse the WARNINGS environment variable.
300 sub parse_WARNINGS
()
302 if (exists $ENV{'WARNINGS'})
304 # Ignore unknown categories. This is required because WARNINGS
305 # should be honored by many tools.
306 switch_warning
$_ foreach (split (',', $ENV{'WARNINGS'}));
310 =item C<parse_warning ($OPTION, $ARGUMENT)>
312 Parse the argument of C<--warning=CATEGORY> or C<-WCATEGORY>.
314 C<$OPTIONS> is C<"--warning"> or C<"-W">, C<$ARGUMENT> is C<CATEGORY>.
316 This is meant to be used as an argument to C<Getopt>.
320 sub parse_warnings
($$)
322 my ($opt, $categories) = @_;
324 foreach my $cat (split (',', $categories))
326 msg
'unsupported', "unknown warning category `$cat'"
327 if switch_warning
$cat;
331 =item C<set_strictness ($STRICTNESS_NAME)>
333 Configure channels for strictness C<$STRICTNESS_NAME>.
337 sub set_strictness
($)
343 setup_channel
'error-gnu', silent
=> 0;
344 setup_channel
'error-gnu/warn', silent
=> 0, type
=> 'error';
345 setup_channel
'error-gnits', silent
=> 1;
346 setup_channel
'portability', silent
=> 0;
347 setup_channel
'gnu', silent
=> 0;
349 elsif ($name eq 'gnits')
351 setup_channel
'error-gnu', silent
=> 0;
352 setup_channel
'error-gnu/warn', silent
=> 0, type
=> 'error';
353 setup_channel
'error-gnits', silent
=> 0;
354 setup_channel
'portability', silent
=> 0;
355 setup_channel
'gnu', silent
=> 0;
357 elsif ($name eq 'foreign')
359 setup_channel
'error-gnu', silent
=> 1;
360 setup_channel
'error-gnu/warn', silent
=> 0, type
=> 'warning';
361 setup_channel
'error-gnits', silent
=> 1;
362 setup_channel
'portability', silent
=> 1;
363 setup_channel
'gnu', silent
=> 1;
367 prog_error
"level `$name' not recognized\n";
375 L<Automake::Channels>
379 Written by Alexandre Duret-Lutz E<lt>F<adl@gnu.org>E<gt>.
383 ### Setup "GNU" style for perl-mode and cperl-mode.
385 ## perl-indent-level: 2
386 ## perl-continued-statement-offset: 2
387 ## perl-continued-brace-offset: 0
388 ## perl-brace-offset: 0
389 ## perl-brace-imaginary-offset: 0
390 ## perl-label-offset: -2
391 ## cperl-indent-level: 2
392 ## cperl-brace-offset: 0
393 ## cperl-continued-brace-offset: 0
394 ## cperl-label-offset: -2
395 ## cperl-extra-newline-before-brace: t
396 ## cperl-merge-trailing-else: nil
397 ## cperl-continued-statement-offset: 2