* lib/Automake/Channels.pm (dup_channel_setup,
authorAlexandre Duret-Lutz <adl@gnu.org>
Tue, 16 Jul 2002 21:46:59 +0000 (21:46 +0000)
committerAlexandre Duret-Lutz <adl@gnu.org>
Tue, 16 Jul 2002 21:46:59 +0000 (21:46 +0000)
drop_channel_setup): New functions.
(@EXPORT): Add them.
* automake.in (generate_makefile): Call dup_channel_setup and
drop_channel_setup.
(process_option_list): Recognize --warnings and -W options.
* automake.texi (Options): Document them.
* tests/pluseq5.test: Check that -Wno-obsolete will disable the
warning.
* tests/warnopts.test: New file.
* tests/Makefile.am (TESTS): Add warnopts.test.

ChangeLog
automake.in
automake.texi
lib/Automake/Channels.pm
stamp-vti
tests/Makefile.am
tests/Makefile.in
tests/pluseq5.test
tests/warnopts.test [new file with mode: 0755]
version.texi

index e5d304f..440623d 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2002-07-16  Alexandre Duret-Lutz  <duret_g@epita.fr>
+
+       * lib/Automake/Channels.pm (dup_channel_setup,
+       drop_channel_setup): New functions.
+       (@EXPORT): Add them.
+       * automake.in (generate_makefile): Call dup_channel_setup and
+       drop_channel_setup.
+       (process_option_list): Recognize --warnings and -W options.
+       * automake.texi (Options): Document them.
+       * tests/pluseq5.test: Check that -Wno-obsolete will disable the
+       warning.
+       * tests/warnopts.test: New file.
+       * tests/Makefile.am (TESTS): Add warnopts.test.
+
 2002-07-12  Alexandre Duret-Lutz  <duret_g@epita.fr>
 
        * automake.in: Register warning channel `gnu'.
index 068ed51..4e5869b 100755 (executable)
@@ -1527,6 +1527,9 @@ sub generate_makefile
     # Reset all the Makefile.am related variables.
     &initialize_per_input;
 
+    # Any warning setting now local to this Makefile.am.
+    &dup_channel_setup;
+
     # Name of input file ("Makefile.am") and output file
     # ("Makefile.in").  These have no directory components.
     $am_file_name = basename ($makefile) . '.am';
@@ -1689,6 +1692,9 @@ sub generate_makefile
     print $gm_file $output_header;
     print $gm_file $output_rules;
     print $gm_file $output_trailer;
+
+    # Back out any warning setting.
+    &drop_channel_setup;
 }
 
 ################################################################
@@ -1836,6 +1842,14 @@ sub process_option_list
                return 1;
            }
        }
+      elsif (/^(?:--warnings=|-W)(.*)$/)
+       {
+         foreach my $cat (split (',', $1))
+           {
+             msg 'unsupported', $where, "unknown warning category `$cat'"
+               if switch_warning $cat;
+           }
+       }
       else
        {
          err ($where, "option `$_' not recognized",
index c97bff5..97271ee 100644 (file)
@@ -4289,12 +4289,21 @@ the source file.  For instance if the source file is
 A version number (e.g. @samp{0.30}) can be specified.  If Automake is not
 newer than the version specified, creation of the @file{Makefile.in}
 will be suppressed.
+
+@item @code{-W@var{category}} or @code{--warnings=@var{category}}
+@cindex Option, warnings
+These options behave exactly like their command-line counterpart
+(@pxref{Invoking Automake}).  This allows you to enable or disable some
+warning categories on a per-file basis.  You can also setup some warnings
+for your entire project; for instance try @code{AM_INIT_AUTOMAKE([-Wall])}
+in your @file{configure.in}.
+
 @end table
 
 Unrecognized options are diagnosed by @code{automake}.
 
 If you want an option to apply to all the files in the tree, you can use
-the @code{AM_AUTOMAKE_OPTIONS} macro in @file{configure.in}.
+the @code{AM_INIT_AUTOMAKE} macro in @file{configure.in}.
 @xref{Macros}.
 
 
index 9019b1d..b543c17 100644 (file)
@@ -67,6 +67,7 @@ our @EXPORT = qw ($exit_code $warnings_are_errors
                  &reset_local_duplicates &reset_global_duplicates
                  &register_channel &msg &exists_channel &channel_type
                  &setup_channel &setup_channel_type
+                  &dup_channel_setup &drop_channel_setup
                  US_GLOBAL US_LOCAL
                  UP_NONE UP_TEXT UP_LOC_TEXT);
 
@@ -491,6 +492,39 @@ sub setup_channel_type ($%)
     }
 }
 
+=item C<dup_channel_setup ()>, C<drop_channel_setup ()>
+
+Sometimes it is necessary to make temporary modifications to channels.
+For instance one may want to disable a warning while processing a
+particular file, and then restore the initial setup.  These two
+functions make it easy: C<dup_channel_setup ()> saves a copy of the
+current configuration for later restoration by
+C<drop_channel_setup ()>.
+
+You can think of this as a stack of configurations whose first entry
+is the active one.  C<dup_channel_setup ()> duplicates the first
+entry, while C<drop_channel_setup ()> just deletes it.
+
+=cut
+
+our @_saved_channels = ();
+
+sub dup_channel_setup ()
+{
+  my %channels_copy;
+  foreach my $k1 (keys %channels)
+    {
+      $channels_copy{$k1} = {%{$channels{$k1}}};
+    }
+  push @_saved_channels, \%channels_copy;
+}
+
+sub drop_channel_setup ()
+{
+  my $saved = pop @_saved_channels;
+  %channels = %$saved;
+}
+
 =back
 
 =head1 HISTORY
index 92aa9a8..e5cda01 100644 (file)
--- a/stamp-vti
+++ b/stamp-vti
@@ -1,4 +1,4 @@
-@set UPDATED 12 July 2002
+@set UPDATED 16 July 2002
 @set UPDATED-MONTH July 2002
 @set EDITION 1.6a
 @set VERSION 1.6a
index 912883b..cea03eb 100644 (file)
@@ -394,6 +394,7 @@ version6.test \
 vpath.test \
 vtexi.test \
 vtexi2.test \
+warnopts.test \
 werror.test \
 whoami.test \
 xsource.test \
index b686fac..3bfe8fe 100644 (file)
@@ -481,6 +481,7 @@ version6.test \
 vpath.test \
 vtexi.test \
 vtexi2.test \
+warnopts.test \
 werror.test \
 whoami.test \
 xsource.test \
index 1c444c9..ab73a68 100755 (executable)
@@ -34,3 +34,12 @@ test `grep ':  ' stderr | wc -l` = 1 || exit 1
 # By the way, Automake should suggest using AM_CPPFLAGS,
 # because INCLUDES is an obsolete name.
 grep AM_CPPFLAGS stderr || exit 1
+
+# A way to suppress the obsolete warning is to use
+# -Wno-obsolete:
+echo 'AUTOMAKE_OPTIONS = -Wno-obsolete' >> Makefile.am
+$AUTOMAKE 2>stderr && exit 1
+cat stderr
+grep AM_CPPFLAGS stderr && exit 1
+# CHECK_FALSE should still be mentioned.
+grep ':.*CHECK_FALSE$' stderr || exit 1
diff --git a/tests/warnopts.test b/tests/warnopts.test
new file mode 100755 (executable)
index 0000000..3857f8b
--- /dev/null
@@ -0,0 +1,54 @@
+#! /bin/sh
+
+# Make sure that we can enable or disable warnings on a per-file basis.
+
+. $srcdir/defs || exit 1
+
+set -e
+
+
+cat >>configure.in <<END
+AC_CONFIG_FILES([sub/Makefile])
+AC_OUTPUT
+END
+
+mkdir sub
+
+# These two Makefile contain the same errors, but have different
+# warnings disabled.
+
+cat >Makefile.am <<END
+AUTOMAKE_OPTIONS = -Wno-obsolete
+INCLUDES = -Ifoo
+foo_SOURCES = unused
+SUBDIRS = sub
+END
+
+cat >sub/Makefile.am <<END
+AUTOMAKE_OPTIONS = -Wno-unused
+INCLUDES = -Ifoo
+foo_SOURCES = unused
+END
+
+$ACLOCAL
+$AUTOMAKE 2>stderr && exit 1
+cat stderr
+# The expected diagnostic is
+#   Makefile.am:3: unused variable: `foo_SOURCES'
+#   sub/Makefile.am:2: `INCLUDES' is the old name for `AM_CPPFLAGS'
+grep '^Makefile.am:.*foo_SOURCES' stderr
+grep '^sub/Makefile.am:.*INCLUDES' stderr
+grep '^sub/Makefile.am:.*foo_SOURCES' stderr && exit 1
+grep '^Makefile.am:.*INCLUDES' stderr && exit 1
+# Only two lines of warnings.
+test `wc -l < stderr` = 2
+
+# If we add a global -Wnone, all warnings should disappear.
+cat >configure.in <<END
+AC_INIT([warnopts], [1.0])
+AM_INIT_AUTOMAKE([-Wnone])
+AC_CONFIG_FILES([Makefile sub/Makefile])
+AC_OUTPUT
+END
+$ACLOCAL
+$AUTOMAKE
index 92aa9a8..e5cda01 100644 (file)
@@ -1,4 +1,4 @@
-@set UPDATED 12 July 2002
+@set UPDATED 16 July 2002
 @set UPDATED-MONTH July 2002
 @set EDITION 1.6a
 @set VERSION 1.6a