summaryrefslogtreecommitdiff
path: root/lib/Autom4te/ChannelDefs.pm
diff options
context:
space:
mode:
Diffstat (limited to 'lib/Autom4te/ChannelDefs.pm')
-rw-r--r--lib/Autom4te/ChannelDefs.pm172
1 files changed, 133 insertions, 39 deletions
diff --git a/lib/Autom4te/ChannelDefs.pm b/lib/Autom4te/ChannelDefs.pm
index 84e634e8..21f444b9 100644
--- a/lib/Autom4te/ChannelDefs.pm
+++ b/lib/Autom4te/ChannelDefs.pm
@@ -1,10 +1,9 @@
-# Copyright (C) 2002-2003, 2006, 2008-2017, 2020 Free Software
-# Foundation, Inc.
+# Copyright (C) 2002-2020 Free Software Foundation, Inc.
-# This program is free software: you can redistribute it and/or modify
+# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation, either version 3 of the License, or
-# (at your option) any later version.
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
@@ -16,8 +15,6 @@
package Autom4te::ChannelDefs;
-use Autom4te::Channels;
-
=head1 NAME
Autom4te::ChannelDefs - channel definitions for Automake and helper functions
@@ -53,6 +50,17 @@ use warnings FATAL => 'all';
use Exporter;
+use Autom4te::Channels;
+use Autom4te::Config;
+BEGIN
+{
+ if ($perl_threads)
+ {
+ require threads;
+ import threads;
+ }
+}
+
our @ISA = qw (Exporter);
our @EXPORT = qw (&prog_error &error &fatal &verb
&switch_warning &parse_WARNINGS &parse_warnings);
@@ -79,7 +87,7 @@ Errors related to GNU Standards.
=item C<error-gnu/warn>
-Errors related to GNU Standards that should be warnings in "foreign" mode.
+Errors related to GNU Standards that should be warnings in 'foreign' mode.
=item C<error-gnits>
@@ -99,7 +107,7 @@ Warnings related to GNU Coding Standards.
=item C<obsolete>
-Warnings about obsolete features (silent by default).
+Warnings about obsolete features.
=item C<override>
@@ -110,9 +118,21 @@ variables (silent by default).
Warnings about non-portable constructs.
+=item C<portability-recursive>
+
+Warnings about recursive variable expansions (C<$(foo$(x))>).
+These are not universally supported, but are more portable than
+the other non-portable constructs diagnosed by C<-Wportability>.
+These warnings are turned on by C<-Wportability> but can then be
+turned off separately by C<-Wno-portability-recursive>.
+
+=item C<extra-portability>
+
+Extra warnings about non-portable constructs covering obscure tools.
+
=item C<syntax>
-Warnings about weird syntax, unused variables, typos ...
+Warnings about weird syntax, unused variables, typos...
=item C<unsupported>
@@ -134,7 +154,7 @@ Informative messages.
# Do not forget to update &usage and the manual
# if you add or change a warning channel.
-register_channel 'fatal', type => 'fatal', ordered => 0;
+register_channel 'fatal', type => 'fatal', uniq_part => UP_NONE, ordered => 0;
register_channel 'error', type => 'error';
register_channel 'error-gnu', type => 'error';
register_channel 'error-gnu/warn', type => 'error';
@@ -143,20 +163,27 @@ register_channel 'automake', type => 'fatal', backtrace => 1,
header => ("####################\n" .
"## Internal Error ##\n" .
"####################\n"),
- footer => "\nPlease contact <bug-automake\@gnu.org>.",
- ordered => 0;
+ footer => "\nPlease contact <$PACKAGE_BUGREPORT>.",
+ uniq_part => UP_NONE, ordered => 0;
register_channel 'cross', type => 'warning', silent => 1;
register_channel 'gnu', type => 'warning';
-register_channel 'obsolete', type => 'warning', silent => 1;
+register_channel 'obsolete', type => 'warning';
register_channel 'override', type => 'warning', silent => 1;
register_channel 'portability', type => 'warning', silent => 1;
+register_channel 'extra-portability', type => 'warning', silent => 1;
+register_channel 'portability-recursive', type => 'warning', silent => 1;
register_channel 'syntax', type => 'warning';
register_channel 'unsupported', type => 'warning';
-register_channel 'verb', type => 'debug', silent => 1, ordered => 0;
+register_channel 'verb', type => 'debug', silent => 1, uniq_part => UP_NONE,
+ ordered => 0;
register_channel 'note', type => 'debug', silent => 0;
+setup_channel_type 'warning', header => 'warning: ';
+setup_channel_type 'error', header => 'error: ';
+setup_channel_type 'fatal', header => 'error: ';
+
=head2 FUNCTIONS
=over 4
@@ -170,17 +197,19 @@ Return the warning category descriptions.
sub usage ()
{
return "Warning categories include:
- `cross' cross compilation issues
- `gnu' GNU coding standards (default in gnu and gnits modes)
- `obsolete' obsolete features or constructions
- `override' user redefinitions of Automake rules or variables
- `portability' portability issues (default in gnu and gnits modes)
- `syntax' dubious syntactic constructs (default)
- `unsupported' unsupported or incomplete features (default)
- `all' all the warnings
- `no-CATEGORY' turn off warnings in CATEGORY
- `none' turn off all the warnings
- `error' treat warnings as errors";
+ cross cross compilation issues
+ gnu GNU coding standards (default in gnu and gnits modes)
+ obsolete obsolete features or constructions (default)
+ override user redefinitions of Automake rules or variables
+ portability portability issues (default in gnu and gnits modes)
+ portability-recursive nested Make variables (default with -Wportability)
+ extra-portability extra portability issues related to obscure tools
+ syntax dubious syntactic constructs (default)
+ unsupported unsupported or incomplete features (default)
+ all all the warnings
+ no-CATEGORY turn off warnings in CATEGORY
+ none turn off all the warnings
+ error treat warnings as errors";
}
=item C<prog_error ($MESSAGE, [%OPTIONS])>
@@ -233,6 +262,8 @@ C<--verbose> messages.
sub verb ($;%)
{
my ($msg, %opts) = @_;
+ $msg = "thread " . threads->tid . ": " . $msg
+ if $perl_threads;
msg 'verb', '', $msg, %opts;
}
@@ -274,6 +305,38 @@ sub switch_warning ($)
elsif (channel_type ($cat) eq 'warning')
{
setup_channel $cat, silent => $has_no;
+ #
+ # Handling of portability warnings is trickier. For relevant tests,
+ # see 'dollarvar2', 'extra-portability' and 'extra-portability3'.
+ #
+ # -Wportability-recursive and -Wno-portability-recursive should not
+ # have any effect on other 'portability' or 'extra-portability'
+ # warnings, so there's no need to handle them separately or ad-hoc.
+ #
+ if ($cat eq 'extra-portability' && ! $has_no) # -Wextra-portability
+ {
+ # -Wextra-portability must enable 'portability' and
+ # 'portability-recursive' warnings.
+ setup_channel 'portability', silent => 0;
+ setup_channel 'portability-recursive', silent => 0;
+ }
+ if ($cat eq 'portability') # -Wportability or -Wno-portability
+ {
+ if ($has_no) # -Wno-portability
+ {
+ # -Wno-portability must disable 'extra-portability' and
+ # 'portability-recursive' warnings.
+ setup_channel 'portability-recursive', silent => 1;
+ setup_channel 'extra-portability', silent => 1;
+ }
+ else # -Wportability
+ {
+ # -Wportability must enable 'portability-recursive'
+ # warnings. But it should have no influence over the
+ # 'extra-portability' warnings.
+ setup_channel 'portability-recursive', silent => 0;
+ }
+ }
}
else
{
@@ -288,36 +351,62 @@ Parse the WARNINGS environment variable.
=cut
+# Used to communicate from parse_WARNINGS to parse_warnings.
+our $_werror = 0;
+
sub parse_WARNINGS ()
{
if (exists $ENV{'WARNINGS'})
{
# Ignore unknown categories. This is required because WARNINGS
# should be honored by many tools.
- switch_warning $_ foreach (split (',', $ENV{'WARNINGS'}));
+ # For the same reason, do not turn on -Werror at this point, just
+ # record that we saw it; parse_warnings will turn on -Werror after
+ # the command line has been processed.
+ foreach (split (',', $ENV{'WARNINGS'}))
+ {
+ if (/^(no-)?error$/)
+ {
+ $_werror = !defined $1;
+ }
+ else
+ {
+ switch_warning $_;
+ }
+ }
}
}
-=item C<parse_warnings ($OPTION, @ARGUMENT)>
+=item C<parse_warnings (@CATEGORIES)>
Parse the argument of C<--warning=CATEGORY> or C<-WCATEGORY>.
+C<@CATEGORIES> is the accumulated set of warnings categories.
+Use like this:
-C<$OPTIONS> is C<"--warning"> or C<"-W">, C<@ARGUMENT> is a list of
-C<CATEGORY>.
-
-This can be used as an argument to C<Getopt>.
+ Autom4te::GetOpt::parse_options (
+ # ...
+ 'W|warnings=s' => \@warnings,
+ )
+ # possibly call set_strictness here
+ parse_warnings @warnings;
=cut
-sub parse_warnings ($@)
+sub parse_warnings (@)
{
- my ($opt, @categories) = @_;
-
- foreach my $cat (map { split ',' } @categories)
+ foreach my $cat (map { split ',' } @_)
{
- msg 'unsupported', "unknown warning category `$cat'"
- if switch_warning $cat;
+ if ($cat =~ /^(no-)?error$/)
+ {
+ $_werror = !defined $1;
+ }
+ elsif (switch_warning $cat)
+ {
+ msg 'unsupported', "unknown warning category '$cat'";
+ }
}
+
+ switch_warning ($_werror ? 'error' : 'no-error');
}
=item C<set_strictness ($STRICTNESS_NAME)>
@@ -336,6 +425,7 @@ sub set_strictness ($)
setup_channel 'error-gnu/warn', silent => 0, type => 'error';
setup_channel 'error-gnits', silent => 1;
setup_channel 'portability', silent => 0;
+ setup_channel 'extra-portability', silent => 1;
setup_channel 'gnu', silent => 0;
}
elsif ($name eq 'gnits')
@@ -344,6 +434,7 @@ sub set_strictness ($)
setup_channel 'error-gnu/warn', silent => 0, type => 'error';
setup_channel 'error-gnits', silent => 0;
setup_channel 'portability', silent => 0;
+ setup_channel 'extra-portability', silent => 1;
setup_channel 'gnu', silent => 0;
}
elsif ($name eq 'foreign')
@@ -352,11 +443,12 @@ sub set_strictness ($)
setup_channel 'error-gnu/warn', silent => 0, type => 'warning';
setup_channel 'error-gnits', silent => 1;
setup_channel 'portability', silent => 1;
+ setup_channel 'extra-portability', silent => 1;
setup_channel 'gnu', silent => 1;
}
else
{
- prog_error "level `$name' not recognized\n";
+ prog_error "level '$name' not recognized";
}
}
@@ -372,6 +464,8 @@ Written by Alexandre Duret-Lutz E<lt>F<adl@gnu.org>E<gt>.
=cut
+1;
+
### Setup "GNU" style for perl-mode and cperl-mode.
## Local Variables:
## perl-indent-level: 2