From 2f6afb92e0ef4b1cd6559de258621c2ec7b4841e Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Thu, 4 Nov 2004 22:19:40 +0000 Subject: [PATCH] * aclocal.in: Use Automake::ChannelDefs, and adjust all output to be done via `fatal', `msg', `verb', or `prog_error'. (version): New function. (parse_arguments): Rewrite using Getopt::Long, call &version, and honor -W and --warning. ($verbose): Remove. (trace_used_macros): Do not trace the first arguments of macros for which we do not need it. This caused failures because of unexpected newlines in the output. * doc/automake.texi (aclocal options): Document -W and --warning. * tests/defs.in (ACLOCAL): Always use -Werror, to catch Perl warnings about uninitialized variables. --- ChangeLog | 15 ++++ NEWS | 2 + aclocal.in | 206 ++++++++++++++++++++++++---------------------- doc/automake.texi | 26 ++++++ doc/stamp-vti | 4 +- doc/version.texi | 4 +- tests/defs.in | 10 ++- 7 files changed, 162 insertions(+), 105 deletions(-) diff --git a/ChangeLog b/ChangeLog index 71bac9ed..5ca21e03 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-11-04 Alexandre Duret-Lutz + + * aclocal.in: Use Automake::ChannelDefs, and adjust all output + to be done via `fatal', `msg', `verb', or `prog_error'. + (version): New function. + (parse_arguments): Rewrite using Getopt::Long, call &version, and + honor -W and --warning. + ($verbose): Remove. + (trace_used_macros): Do not trace the first arguments of macros + for which we do not need it. This caused failures because of + unexpected newlines in the output. + * doc/automake.texi (aclocal options): Document -W and --warning. + * tests/defs.in (ACLOCAL): Always use -Werror, to catch Perl + warnings about uninitialized variables. + 2004-11-03 Alexandre Duret-Lutz * tests/defs.in: Do not distinguish VERBOSE=x from diff --git a/NEWS b/NEWS index c80ecb5f..22b2ba8e 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,8 @@ New in 1.9a: - Preprocessed assembler (*.S) compilation now honnors CPPFLAGS, AM_CPPFLAGS and per-target _CPPFLAGS, and supports dependency tracking, unlike non-preprocessed assembler (*.s). + + - aclocal now also supports -Wmumble and -Wno-mumble options. New in 1.9: diff --git a/aclocal.in b/aclocal.in index b6ffce61..a14849a7 100644 --- a/aclocal.in +++ b/aclocal.in @@ -40,6 +40,7 @@ use Automake::Config; use Automake::General; use Automake::Configure_ac; use Automake::Channels; +use Automake::ChannelDefs; use Automake::XFile; use Automake::FileUtils; use File::Basename; @@ -94,9 +95,6 @@ my %file_contents = (); # Map file names to included files (transitively closed). my %file_includes = (); -# How much to say. -my $verbose = 0; - # Matches a macro definition. # AC_DEFUN([macroname], ...) # or @@ -122,9 +120,9 @@ sub check_acinclude () foreach my $key (keys %map) { # FIXME: should print line number of acinclude.m4. - warn ("aclocal: warning: macro `$key' defined in " - . "acinclude.m4 but never used\n") - if $map{$key} eq 'acinclude.m4' && ! $macro_seen{$key}; + msg ('syntax', "warning: macro `$key' defined in " + . "acinclude.m4 but never used") + if $map{$key} eq 'acinclude.m4' && ! exists $macro_seen{$key}; } } @@ -150,8 +148,7 @@ sub scan_m4_files (@) { if (! opendir (DIR, $m4dir)) { - print STDERR "aclocal: couldn't open directory `$m4dir': $!\n"; - exit 1; + fatal "couldn't open directory `$m4dir': $!"; } # We reverse the directory contents so that foo2.m4 gets @@ -181,7 +178,7 @@ sub scan_m4_files (@) } $search .= "return \$found;\n};\n"; eval $search; - die "internal error: $@\n search is $search" if $@; + prog_error "$@\n search is $search" if $@; } ################################################################ @@ -197,7 +194,7 @@ sub add_macro ($) # complain when we trace for macro usage later. return unless defined $map{$macro}; - print STDERR "aclocal: saw macro $macro\n" if $verbose; + verb "saw macro $macro"; $macro_seen{$macro} = 1; &add_file ($map{$macro}); } @@ -251,8 +248,8 @@ sub scan_configure_dep ($) # Macro not found, but AM_ prefix found. # Make this just a warning, because we do not know whether # the macro is actually used (it could be called conditionally). - warn ("aclocal:$file:$line: warning: " - . "macro `$2' not found in library\n"); + msg ('unsupported', "$file:$line", + "warning: macro `$2' not found in library"); } } @@ -294,11 +291,7 @@ sub scan_file ($$) unshift @file_order, $file; - if (! -e $file) - { - print STDERR "$where: file `$file' does not exist\n"; - exit 1; - } + fatal "$where: file `$file' does not exist" if ! -e $file; my $fh = new Automake::XFile $file; my $contents = ''; @@ -310,23 +303,23 @@ sub scan_file ($$) next if /^##/; $contents .= $_; + my $line = $_; - while (/$ac_defun_rx/go) + while ($line =~ /$ac_defun_rx/go) { if (! defined $1) { - print STDERR "$file:$.: warning: underquoted definition of $2\n"; - print STDERR " run info '(automake)Extending aclocal'\n" - . " or see http://sources.redhat.com/automake/" - . "automake.html#Extending-aclocal\n" + msg ('syntax', "$file:$.", "warning: underquoted definition of $2" + . "\n run info '(automake)Extending aclocal'\n" + . " or see http://sources.redhat.com/automake/" + . "automake.html#Extending-aclocal") unless $underquoted_manual_once; $underquoted_manual_once = 1; } my $macro = $1 || $2; if (! defined $map{$macro}) { - print STDERR "aclocal: found macro $macro in $file: $.\n" - if $verbose; + verb "found macro $macro in $file: $."; $map{$macro} = $file; } else @@ -336,12 +329,11 @@ sub scan_file ($$) # extremely unpopular. It causes actual problems which # are hard to work around, especially when you must # mix-and-match tool versions. - print STDERR "aclocal: ignoring macro $macro in $file: $.\n" - if $verbose; + verb "ignoring macro $macro in $file: $."; } } - while (/$m4_include_rx/go) + while ($line =~ /$m4_include_rx/go) { my $ifile = $1 || $2; # m4_include is relative to the directory of the file which @@ -389,8 +381,7 @@ sub strip_redundant_includes (%) { next unless exists $files{$ifile}; delete $files{$ifile}; - print STDERR "$ifile is already included by $file\n" - if $verbose; + verb "$ifile is already included by $file"; } } return %files; @@ -409,12 +400,16 @@ sub trace_used_macros () # All candidate files. $traces .= join (' ', grep { exists $files{$_} } @file_order) . " "; # All candidate macros. - $traces .= join (' ', map { "--trace='$_:\$f:\$n:\$1'" } ('AC_DEFUN', - 'AC_DEFUN_ONCE', - 'AU_DEFUN', - keys %macro_seen)); + $traces .= join (' ', + (map { "--trace='$_:\$f::\$n::\$1'" } ('AC_DEFUN', + 'AC_DEFUN_ONCE', + 'AU_DEFUN')), + # Do not trace $1 for all other macros as we do + # not need it and it might contains harmful + # characters (like newlines). + (map { "--trace='$_:\$f::\$n'" } (keys %macro_seen))); - print STDERR "aclocal: running $traces $configure_ac\n" if $verbose; + verb "running $traces $configure_ac"; my $tracefh = new Automake::XFile ("$traces $configure_ac |"); @@ -423,9 +418,9 @@ sub trace_used_macros () while ($_ = $tracefh->getline) { chomp; - my ($file, $macro, $arg1) = split (/:/); + my ($file, $macro, $arg1) = split (/::/); - $traced{$macro} = 1 if $macro_seen{$macro}; + $traced{$macro} = 1 if exists $macro_seen{$macro}; $map_traced_defs{$arg1} = $file if ($macro eq 'AC_DEFUN' @@ -536,11 +531,11 @@ $output"; && $greatest_mtime < mtime ($output_file) && $output eq contents ($output_file)) { - print STDERR "aclocal: $output_file unchanged\n" if $verbose; + verb "$output_file unchanged"; return; } - print STDERR "aclocal: writing $output_file\n" if $verbose; + verb "writing $output_file"; my $out = new Automake::XFile "> $output_file"; print $out $output; @@ -554,79 +549,93 @@ sub usage ($) { my ($status) = @_; - print "Usage: aclocal [OPTIONS] ...\n\n"; - print "\ + print "Usage: aclocal [OPTIONS] ... + Generate `aclocal.m4' by scanning `configure.ac' or `configure.in' - --acdir=DIR directory holding config files - --help print this help, then exit - -I DIR add directory to search list for .m4 files - --force always update output file - --output=FILE put output in FILE (default aclocal.m4) - --print-ac-dir print name of directory holding m4 files - --verbose don't be silent - --version print version number, then exit +Options: + --acdir=DIR directory holding config files (for debugging) + --force always update output file + --help print this help, then exit + -I DIR add directory to search list for .m4 files + --output=FILE put output in FILE (default aclocal.m4) + --print-ac-dir print name of directory holding m4 files, then exit + --verbose don't be silent + --version print version number, then exit + -W, --warnings=CATEGORY report the warnings falling in CATEGORY + +Warning categories include: + `syntax' dubious syntactic constructs (default) + `unsupported' unknown macros (default) + `all' all the warnings (default) + `no-CATEGORY' turn off warnings in CATEGORY + `none' turn off all the warnings + `error' treat warnings as errors Report bugs to .\n"; exit $status; } +# Print version and exit. +sub version() +{ + print "\ +aclocal (GNU $PACKAGE) $VERSION +Written by Tom Tromey + and Alexandre Duret-Lutz +Copyright (C) 2004 Free Software Foundation, Inc. +This is free software; see the source for copying conditions. There is NO +warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE."; + exit 0; +} + # Parse command line. -sub parse_arguments (@) +sub parse_arguments () { - my @arglist = @_; my @dirlist; my $print_and_exit = 0; - while (@arglist) + my %cli_options = + ( + 'acdir=s' => \$acdir, + 'force' => \$force_output, + 'I=s' => \@dirlist, + 'output=s' => \$output_file, + 'print_ac_dir' => \$print_and_exit, + 'verbose' => sub { setup_channel 'verb', silent => 0; }, + 'W|warnings:s' => \&parse_warnings, + ); + use Getopt::Long; + Getopt::Long::config ("bundling", "pass_through"); + + # See if --version or --help is used. We want to process these before + # anything else because the GNU Coding Standards require us to + # `exit 0' after processing these options, and we can't guarantee this + # if we treat other options first. (Handling other options first + # could produce error diagnostics, and in this condition it is + # confusing if Automake does `exit 0'.) + my %cli_options_1st_pass = + ( + 'version' => \&version, + 'help' => sub { usage(0); }, + # Recognize all other options (and their arguments) but do nothing. + map { $_ => sub {} } (keys %cli_options) + ); + my @ARGV_backup = @ARGV; + Getopt::Long::GetOptions %cli_options_1st_pass + or exit 1; + @ARGV = @ARGV_backup; + + # Now *really* process the options. This time we know + # that --help and --version are not present. + Getopt::Long::GetOptions %cli_options + or exit 1; + + if (@ARGV) { - if ($arglist[0] =~ /^--acdir=(.+)$/) - { - $acdir = $1; - } - elsif ($arglist[0] =~/^--output=(.+)$/) - { - $output_file = $1; - } - elsif ($arglist[0] eq '-I') - { - shift (@arglist); - push (@dirlist, $arglist[0]); - } - elsif ($arglist[0] eq '--print-ac-dir') - { - $print_and_exit = 1; - } - elsif ($arglist[0] eq '--force') - { - $force_output = 1; - } - elsif ($arglist[0] eq '--verbose') - { - ++$verbose; - } - elsif ($arglist[0] eq '--version') - { - print "aclocal (GNU $PACKAGE) $VERSION\n"; - print "Written by Tom Tromey \n"; - print " and Alexandre Duret-Lutz \n\n"; - print "Copyright (C) 2004 Free Software Foundation, Inc.\n"; - print "This is free software; see the source for copying conditions. There is NO\n"; - print "warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n"; - exit 0; - } - elsif ($arglist[0] eq '--help') - { - &usage (0); - } - else - { - print STDERR "aclocal: unrecognized option -- `$arglist[0]'\nTry `aclocal --help' for more information.\n"; - exit 1; - } - - shift (@arglist); + fatal ("unrecognized option `$ARGV[0]'\n" + . "Try `$0 --help' for more information."); } if ($print_and_exit) @@ -670,7 +679,8 @@ sub parse_arguments (@) ################################################################ -my @dirlist = parse_arguments (@ARGV); +parse_WARNINGS; # Parse the WARNINGS environment variable. +my @dirlist = parse_arguments; $configure_ac = require_configure_ac; scan_m4_files (@dirlist); scan_configure; diff --git a/doc/automake.texi b/doc/automake.texi index b08207a9..5833edc4 100644 --- a/doc/automake.texi +++ b/doc/automake.texi @@ -1602,6 +1602,32 @@ Print the names of the files it examines. @item --version @opindex --version Print the version number of Automake and exit. + +@item -W CATEGORY +@item --warnings=@var{category} +@opindex -W +@opindex --warnings +Output warnings falling in @var{category}. @var{category} can be +one of: +@table @samp +@item syntax +dubious syntactic constructs, underquoted macros, unused macros, etc. +@item unsupported +unknown macros +@item all +all the warnings, this is the default +@item none +turn off all the warnings +@item error +treat warnings as errors +@end table + +All warnings are output by default. + +@vindex WARNINGS +The environment variable @samp{WARNINGS} is honored in the same +way as it is for @command{automake} (@pxref{Invoking Automake}). + @end table @node Macro search path diff --git a/doc/stamp-vti b/doc/stamp-vti index 54cd093c..c9071b8e 100644 --- a/doc/stamp-vti +++ b/doc/stamp-vti @@ -1,4 +1,4 @@ -@set UPDATED 22 October 2004 -@set UPDATED-MONTH October 2004 +@set UPDATED 4 November 2004 +@set UPDATED-MONTH November 2004 @set EDITION 1.9a @set VERSION 1.9a diff --git a/doc/version.texi b/doc/version.texi index 54cd093c..c9071b8e 100644 --- a/doc/version.texi +++ b/doc/version.texi @@ -1,4 +1,4 @@ -@set UPDATED 22 October 2004 -@set UPDATED-MONTH October 2004 +@set UPDATED 4 November 2004 +@set UPDATED-MONTH November 2004 @set EDITION 1.9a @set VERSION 1.9a diff --git a/tests/defs.in b/tests/defs.in index 0267f3b1..87d9857c 100644 --- a/tests/defs.in +++ b/tests/defs.in @@ -74,7 +74,9 @@ test -z "$AUTOCONF" && AUTOCONF="@am_AUTOCONF@" test -z "$AUTOHEADER" && AUTOHEADER="@AUTOHEADER@" test -z "$AUTOUPDATE" && AUTOUPDATE=autoupdate test -z "$MISSING" && MISSING=`pwd`/../lib/missing -test -z "$ACLOCAL" && ACLOCAL="aclocal-@APIVERSION@" +# Use -Werror because this also turns some Perl warnings into error. +# (Tests for which this is inappropriate should use -Wno-error.) +test -z "$ACLOCAL" && ACLOCAL="aclocal-@APIVERSION@ -Werror" # See how Automake should be run. We put --foreign as the default # strictness to avoid having to create lots and lots of files. A test # can override this by specifying a different strictness. Use -Wall @@ -264,6 +266,8 @@ echo "=== Running test $0" # Use `-I $srcdir/../m4' in addition to `--acdir=$srcdir/../m4', because the # other `-I' directories added for libtool and gettext might contain # files from an old version of Automake that we don't want to use. +# Use `-Wno-syntax' because we do not want our test suite to fail because +# some third-party .m4 file is underquoted. aclocaldir='@prefix@/share/aclocal' extra_includes="" if [ -f $aclocaldir/dirlist ] ; then @@ -282,7 +286,7 @@ case $required in fi done test "x$libtool_found" = "xyes" || exit 77 - ACLOCAL="$ACLOCAL -I $srcdir/../m4 $extra_includes -I $aclocaldir" + ACLOCAL="$ACLOCAL -Wno-syntax -I $srcdir/../m4 $extra_includes -I $aclocaldir" ;; *gettext* ) gettext_found=no @@ -292,7 +296,7 @@ case $required in fi done test "x$gettext_found" = "xyes" || exit 77 - ACLOCAL="$ACLOCAL -I $srcdir/../m4 $extra_includes -I $aclocaldir" + ACLOCAL="$ACLOCAL -Wno-syntax -I $srcdir/../m4 $extra_includes -I $aclocaldir" ;; esac -- 2.43.5