1 1.1 christos # Copyright (C) 2002-2003, 2006, 2008-2012 Free Software Foundation, 2 1.1 christos # Inc. 3 1.1 christos 4 1.1 christos # This program is free software: you can redistribute it and/or modify 5 1.1 christos # it under the terms of the GNU General Public License as published by 6 1.1 christos # the Free Software Foundation, either version 3 of the License, or 7 1.1 christos # (at your option) any later version. 8 1.1 christos 9 1.1 christos # This program is distributed in the hope that it will be useful, 10 1.1 christos # but WITHOUT ANY WARRANTY; without even the implied warranty of 11 1.1 christos # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 1.1 christos # GNU General Public License for more details. 13 1.1 christos 14 1.1 christos # You should have received a copy of the GNU General Public License 15 1.1 christos # along with this program. If not, see <http://www.gnu.org/licenses/>. 16 1.1 christos 17 1.1 christos package Autom4te::ChannelDefs; 18 1.1 christos 19 1.1 christos use Autom4te::Channels; 20 1.1 christos 21 1.1 christos =head1 NAME 22 1.1 christos 23 1.1 christos Autom4te::ChannelDefs - channel definitions for Automake and helper functions 24 1.1 christos 25 1.1 christos =head1 SYNOPSIS 26 1.1 christos 27 1.1 christos use Autom4te::ChannelDefs; 28 1.1 christos 29 1.1 christos print Autom4te::ChannelDefs::usage (), "\n"; 30 1.1 christos prog_error ($MESSAGE, [%OPTIONS]); 31 1.1 christos error ($WHERE, $MESSAGE, [%OPTIONS]); 32 1.1 christos error ($MESSAGE); 33 1.1 christos fatal ($WHERE, $MESSAGE, [%OPTIONS]); 34 1.1 christos fatal ($MESSAGE); 35 1.1 christos verb ($MESSAGE, [%OPTIONS]); 36 1.1 christos switch_warning ($CATEGORY); 37 1.1 christos parse_WARNINGS (); 38 1.1 christos parse_warnings ($OPTION, @ARGUMENT); 39 1.1 christos Autom4te::ChannelDefs::set_strictness ($STRICTNESS_NAME); 40 1.1 christos 41 1.1 christos =head1 DESCRIPTION 42 1.1 christos 43 1.1 christos This package defines channels that can be used in Automake to 44 1.1 christos output diagnostics and other messages (via C<msg()>). It also defines 45 1.1 christos some helper function to enable or disable these channels, and some 46 1.1 christos shorthand function to output on specific channels. 47 1.1 christos 48 1.1 christos =cut 49 1.1 christos 50 1.1 christos use 5.006; 51 1.1 christos use strict; 52 1.1 christos use Exporter; 53 1.1 christos 54 1.1 christos use vars qw (@ISA @EXPORT); 55 1.1 christos 56 1.1 christos @ISA = qw (Exporter); 57 1.1 christos @EXPORT = qw (&prog_error &error &fatal &verb 58 1.1 christos &switch_warning &parse_WARNINGS &parse_warnings); 59 1.1 christos 60 1.1 christos =head2 CHANNELS 61 1.1 christos 62 1.1 christos The following channels can be used as the first argument of 63 1.1 christos C<Autom4te::Channel::msg>. For some of them we list a shorthand 64 1.1 christos function that makes the code more readable. 65 1.1 christos 66 1.1 christos =over 4 67 1.1 christos 68 1.1 christos =item C<fatal> 69 1.1 christos 70 1.1 christos Fatal errors. Use C<&fatal> to send messages over this channel. 71 1.1 christos 72 1.1 christos =item C<error> 73 1.1 christos 74 1.1 christos Common errors. Use C<&error> to send messages over this channel. 75 1.1 christos 76 1.1 christos =item C<error-gnu> 77 1.1 christos 78 1.1 christos Errors related to GNU Standards. 79 1.1 christos 80 1.1 christos =item C<error-gnu/warn> 81 1.1 christos 82 1.1 christos Errors related to GNU Standards that should be warnings in "foreign" mode. 83 1.1 christos 84 1.1 christos =item C<error-gnits> 85 1.1 christos 86 1.1 christos Errors related to GNITS Standards (silent by default). 87 1.1 christos 88 1.1 christos =item C<automake> 89 1.1 christos 90 1.1 christos Internal errors. Use C<&prog_error> to send messages over this channel. 91 1.1 christos 92 1.1 christos =item C<cross> 93 1.1 christos 94 1.1 christos Constructs compromising the cross-compilation of the package. 95 1.1 christos 96 1.1 christos =item C<gnu> 97 1.1 christos 98 1.1 christos Warnings related to GNU Coding Standards. 99 1.1 christos 100 1.1 christos =item C<obsolete> 101 1.1 christos 102 1.1 christos Warnings about obsolete features (silent by default). 103 1.1 christos 104 1.1 christos =item C<override> 105 1.1 christos 106 1.1 christos Warnings about user redefinitions of Automake rules or 107 1.1 christos variables (silent by default). 108 1.1 christos 109 1.1 christos =item C<portability> 110 1.1 christos 111 1.1 christos Warnings about non-portable constructs. 112 1.1 christos 113 1.1 christos =item C<syntax> 114 1.1 christos 115 1.1 christos Warnings about weird syntax, unused variables, typos ... 116 1.1 christos 117 1.1 christos =item C<unsupported> 118 1.1 christos 119 1.1 christos Warnings about unsupported (or mis-supported) features. 120 1.1 christos 121 1.1 christos =item C<verb> 122 1.1 christos 123 1.1 christos Messages output in C<--verbose> mode. Use C<&verb> to send such messages. 124 1.1 christos 125 1.1 christos =item C<note> 126 1.1 christos 127 1.1 christos Informative messages. 128 1.1 christos 129 1.1 christos =back 130 1.1 christos 131 1.1 christos =cut 132 1.1 christos 133 1.1 christos # Initialize our list of error/warning channels. 134 1.1 christos # Do not forget to update &usage and the manual 135 1.1 christos # if you add or change a warning channel. 136 1.1 christos 137 1.1 christos register_channel 'fatal', type => 'fatal', ordered => 0; 138 1.1 christos register_channel 'error', type => 'error'; 139 1.1 christos register_channel 'error-gnu', type => 'error'; 140 1.1 christos register_channel 'error-gnu/warn', type => 'error'; 141 1.1 christos register_channel 'error-gnits', type => 'error', silent => 1; 142 1.1 christos register_channel 'automake', type => 'fatal', backtrace => 1, 143 1.1 christos header => ("####################\n" . 144 1.1 christos "## Internal Error ##\n" . 145 1.1 christos "####################\n"), 146 1.1 christos footer => "\nPlease contact <bug-automake\@gnu.org>.", 147 1.1 christos ordered => 0; 148 1.1 christos 149 1.1 christos register_channel 'cross', type => 'warning', silent => 1; 150 1.1 christos register_channel 'gnu', type => 'warning'; 151 1.1 christos register_channel 'obsolete', type => 'warning', silent => 1; 152 1.1 christos register_channel 'override', type => 'warning', silent => 1; 153 1.1 christos register_channel 'portability', type => 'warning', silent => 1; 154 1.1 christos register_channel 'syntax', type => 'warning'; 155 1.1 christos register_channel 'unsupported', type => 'warning'; 156 1.1 christos 157 1.1 christos register_channel 'verb', type => 'debug', silent => 1, ordered => 0; 158 1.1 christos register_channel 'note', type => 'debug', silent => 0; 159 1.1 christos 160 1.1 christos =head2 FUNCTIONS 161 1.1 christos 162 1.1 christos =over 4 163 1.1 christos 164 1.1 christos =item C<usage ()> 165 1.1 christos 166 1.1 christos Return the warning category descriptions. 167 1.1 christos 168 1.1 christos =cut 169 1.1 christos 170 1.1 christos sub usage () 171 1.1 christos { 172 1.1 christos return "Warning categories include: 173 1.1 christos `cross' cross compilation issues 174 1.1 christos `gnu' GNU coding standards (default in gnu and gnits modes) 175 1.1 christos `obsolete' obsolete features or constructions 176 1.1 christos `override' user redefinitions of Automake rules or variables 177 1.1 christos `portability' portability issues (default in gnu and gnits modes) 178 1.1 christos `syntax' dubious syntactic constructs (default) 179 1.1 christos `unsupported' unsupported or incomplete features (default) 180 1.1 christos `all' all the warnings 181 1.1 christos `no-CATEGORY' turn off warnings in CATEGORY 182 1.1 christos `none' turn off all the warnings 183 1.1 christos `error' treat warnings as errors"; 184 1.1 christos } 185 1.1 christos 186 1.1 christos =item C<prog_error ($MESSAGE, [%OPTIONS])> 187 1.1 christos 188 1.1 christos Signal a programming error (on channel C<automake>), 189 1.1 christos display C<$MESSAGE>, and exit 1. 190 1.1 christos 191 1.1 christos =cut 192 1.1 christos 193 1.1 christos sub prog_error ($;%) 194 1.1 christos { 195 1.1 christos my ($msg, %opts) = @_; 196 1.1 christos msg 'automake', '', $msg, %opts; 197 1.1 christos } 198 1.1 christos 199 1.1 christos =item C<error ($WHERE, $MESSAGE, [%OPTIONS])> 200 1.1 christos 201 1.1 christos =item C<error ($MESSAGE)> 202 1.1 christos 203 1.1 christos Uncategorized errors. 204 1.1 christos 205 1.1 christos =cut 206 1.1 christos 207 1.1 christos sub error ($;$%) 208 1.1 christos { 209 1.1 christos my ($where, $msg, %opts) = @_; 210 1.1 christos msg ('error', $where, $msg, %opts); 211 1.1 christos } 212 1.1 christos 213 1.1 christos =item C<fatal ($WHERE, $MESSAGE, [%OPTIONS])> 214 1.1 christos 215 1.1 christos =item C<fatal ($MESSAGE)> 216 1.1 christos 217 1.1 christos Fatal errors. 218 1.1 christos 219 1.1 christos =cut 220 1.1 christos 221 1.1 christos sub fatal ($;$%) 222 1.1 christos { 223 1.1 christos my ($where, $msg, %opts) = @_; 224 1.1 christos msg ('fatal', $where, $msg, %opts); 225 1.1 christos } 226 1.1 christos 227 1.1 christos =item C<verb ($MESSAGE, [%OPTIONS])> 228 1.1 christos 229 1.1 christos C<--verbose> messages. 230 1.1 christos 231 1.1 christos =cut 232 1.1 christos 233 1.1 christos sub verb ($;%) 234 1.1 christos { 235 1.1 christos my ($msg, %opts) = @_; 236 1.1 christos msg 'verb', '', $msg, %opts; 237 1.1 christos } 238 1.1 christos 239 1.1 christos =item C<switch_warning ($CATEGORY)> 240 1.1 christos 241 1.1 christos If C<$CATEGORY> is C<mumble>, turn on channel C<mumble>. 242 1.1 christos If it is C<no-mumble>, turn C<mumble> off. 243 1.1 christos Else handle C<all> and C<none> for completeness. 244 1.1 christos 245 1.1 christos =cut 246 1.1 christos 247 1.1 christos sub switch_warning ($) 248 1.1 christos { 249 1.1 christos my ($cat) = @_; 250 1.1 christos my $has_no = 0; 251 1.1 christos 252 1.1 christos if ($cat =~ /^no-(.*)$/) 253 1.1 christos { 254 1.1 christos $cat = $1; 255 1.1 christos $has_no = 1; 256 1.1 christos } 257 1.1 christos 258 1.1 christos if ($cat eq 'all') 259 1.1 christos { 260 1.1 christos setup_channel_type 'warning', silent => $has_no; 261 1.1 christos } 262 1.1 christos elsif ($cat eq 'none') 263 1.1 christos { 264 1.1 christos setup_channel_type 'warning', silent => ! $has_no; 265 1.1 christos } 266 1.1 christos elsif ($cat eq 'error') 267 1.1 christos { 268 1.1 christos $warnings_are_errors = ! $has_no; 269 1.1 christos # Set exit code if Perl warns about something 270 1.1 christos # (like uninitialized variables). 271 1.1 christos $SIG{"__WARN__"} = 272 1.1 christos $has_no ? 'DEFAULT' : sub { print STDERR @_; $exit_code = 1; }; 273 1.1 christos } 274 1.1 christos elsif (channel_type ($cat) eq 'warning') 275 1.1 christos { 276 1.1 christos setup_channel $cat, silent => $has_no; 277 1.1 christos } 278 1.1 christos else 279 1.1 christos { 280 1.1 christos return 1; 281 1.1 christos } 282 1.1 christos return 0; 283 1.1 christos } 284 1.1 christos 285 1.1 christos =item C<parse_WARNINGS ()> 286 1.1 christos 287 1.1 christos Parse the WARNINGS environment variable. 288 1.1 christos 289 1.1 christos =cut 290 1.1 christos 291 1.1 christos sub parse_WARNINGS () 292 1.1 christos { 293 1.1 christos if (exists $ENV{'WARNINGS'}) 294 1.1 christos { 295 1.1 christos # Ignore unknown categories. This is required because WARNINGS 296 1.1 christos # should be honored by many tools. 297 1.1 christos switch_warning $_ foreach (split (',', $ENV{'WARNINGS'})); 298 1.1 christos } 299 1.1 christos } 300 1.1 christos 301 1.1 christos =item C<parse_warnings ($OPTION, @ARGUMENT)> 302 1.1 christos 303 1.1 christos Parse the argument of C<--warning=CATEGORY> or C<-WCATEGORY>. 304 1.1 christos 305 1.1 christos C<$OPTIONS> is C<"--warning"> or C<"-W">, C<@ARGUMENT> is a list of 306 1.1 christos C<CATEGORY>. 307 1.1 christos 308 1.1 christos This can be used as an argument to C<Getopt>. 309 1.1 christos 310 1.1 christos =cut 311 1.1 christos 312 1.1 christos sub parse_warnings ($@) 313 1.1 christos { 314 1.1 christos my ($opt, @categories) = @_; 315 1.1 christos 316 1.1 christos foreach my $cat (map { split ',' } @categories) 317 1.1 christos { 318 1.1 christos msg 'unsupported', "unknown warning category `$cat'" 319 1.1 christos if switch_warning $cat; 320 1.1 christos } 321 1.1 christos } 322 1.1 christos 323 1.1 christos =item C<set_strictness ($STRICTNESS_NAME)> 324 1.1 christos 325 1.1 christos Configure channels for strictness C<$STRICTNESS_NAME>. 326 1.1 christos 327 1.1 christos =cut 328 1.1 christos 329 1.1 christos sub set_strictness ($) 330 1.1 christos { 331 1.1 christos my ($name) = @_; 332 1.1 christos 333 1.1 christos if ($name eq 'gnu') 334 1.1 christos { 335 1.1 christos setup_channel 'error-gnu', silent => 0; 336 1.1 christos setup_channel 'error-gnu/warn', silent => 0, type => 'error'; 337 1.1 christos setup_channel 'error-gnits', silent => 1; 338 1.1 christos setup_channel 'portability', silent => 0; 339 1.1 christos setup_channel 'gnu', silent => 0; 340 1.1 christos } 341 1.1 christos elsif ($name eq 'gnits') 342 1.1 christos { 343 1.1 christos setup_channel 'error-gnu', silent => 0; 344 1.1 christos setup_channel 'error-gnu/warn', silent => 0, type => 'error'; 345 1.1 christos setup_channel 'error-gnits', silent => 0; 346 1.1 christos setup_channel 'portability', silent => 0; 347 1.1 christos setup_channel 'gnu', silent => 0; 348 1.1 christos } 349 1.1 christos elsif ($name eq 'foreign') 350 1.1 christos { 351 1.1 christos setup_channel 'error-gnu', silent => 1; 352 1.1 christos setup_channel 'error-gnu/warn', silent => 0, type => 'warning'; 353 1.1 christos setup_channel 'error-gnits', silent => 1; 354 1.1 christos setup_channel 'portability', silent => 1; 355 1.1 christos setup_channel 'gnu', silent => 1; 356 1.1 christos } 357 1.1 christos else 358 1.1 christos { 359 1.1 christos prog_error "level `$name' not recognized\n"; 360 1.1 christos } 361 1.1 christos } 362 1.1 christos 363 1.1 christos =back 364 1.1 christos 365 1.1 christos =head1 SEE ALSO 366 1.1 christos 367 1.1 christos L<Autom4te::Channels> 368 1.1 christos 369 1.1 christos =head1 HISTORY 370 1.1 christos 371 1.1 christos Written by Alexandre Duret-Lutz E<lt>F<adl (at] gnu.org>E<gt>. 372 1.1 christos 373 1.1 christos =cut 374 1.1 christos 375 1.1 christos ### Setup "GNU" style for perl-mode and cperl-mode. 376 1.1 christos ## Local Variables: 377 1.1 christos ## perl-indent-level: 2 378 1.1 christos ## perl-continued-statement-offset: 2 379 1.1 christos ## perl-continued-brace-offset: 0 380 1.1 christos ## perl-brace-offset: 0 381 1.1 christos ## perl-brace-imaginary-offset: 0 382 1.1 christos ## perl-label-offset: -2 383 1.1 christos ## cperl-indent-level: 2 384 1.1 christos ## cperl-brace-offset: 0 385 1.1 christos ## cperl-continued-brace-offset: 0 386 1.1 christos ## cperl-label-offset: -2 387 1.1 christos ## cperl-extra-newline-before-brace: t 388 1.1 christos ## cperl-merge-trailing-else: nil 389 1.1 christos ## cperl-continued-statement-offset: 2 390 1.1 christos ## End: 391