Subject: bug#7819: automake does not really automatically distribute all the files it's advertised to.

From: Stefano Lattarini <[email-masked]>
Date: Sat, 15 Jan 2011 21:09:35 +0100

Reference:
 <http://debbugs.gnu.org/cgi/bugreport.cgi?bug=7819>

On Monday 10 January 2011, Ralf Wildenhues wrote:
> Hi Stefano,
> 
> * Stefano Lattarini wrote on Mon, Jan 10, 2011 at 08:50:13PM CET:
> >   Files which are automatically distributed, if found:
> >     ABOUT-GNU           README              config.rpath        ltcf-gcj.sh
> >     ABOUT-NLS           THANKS              config.sub          ltconfig
> >     AUTHORS             TODO                configure           ltmain.sh
> >     BACKLOG             acconfig.h          configure.ac        mdate-sh
> [...]
> >   ...
> > 
> > But the above is not always correct, as some of these files are distributed
> > *only* if other conditions are met.  For example, acconfig.h and aclocal.m4
> > are distributed only if they really exists at automake runtime (having them
> > as targets in Makefile.am won't work), config.h.bot and config.h.top are
> > distributed only if the AC_CONFIG_HEADERS macro is used, and stamp-vti is
> > distributed only if info_TEXINFOS and version.texi are used.
> > 
> > So, either the automake script or the automake help screen should be
> > adjusted.
> > 
> > IMHO the current behaviour of automake is good enough, so I think we
> > should adjust the automake help screen to read something like:
> 
> Agreed.  With many of the names, I have been wondering though whether we
> should distribute them at all in arbitrary directories.  For example,
> most scripts don't make that much sense outside of the toplevel or the
> build-aux directories.
> 
> Then again, changing the current behavior here is quite likely to break
> some existing package setups, and even silently and only upon 'make
> dist' (so it might never show up for the developer), so that I'm not
> inclined to change this lightly.
> 
> Documenting the existing behavior better sounds like a good idea to me.
> 
> Thanks for the report,
> Ralf
>

The attached two-patch series should fix the bug, by making it clear
in the documentation and in the help screen that certain files are
automatically distributed only under certain conditions or in certain
situations (without fully specifying which conditions or situations,
as that would be too detailed IMHO and make suboptimal behaviour
more difficult to be changed in future).

OK for maint?

Regards,
   Stefano

-*-*-

refactor: split 'usage' subroutine in automake

This change is related to automake bug#7819.

* automake.in (print_autodist_files): New subroutine,
extracted from ...
(usage): ... this, which now uses it.
* tests/autodist-no-duplicate.test: New test.
* tests/Makefile.am (TESTS): Update.
---
 ChangeLog                        |   10 ++++
 automake.in                      |   89 +++++++++++++++++++-------------------
 tests/Makefile.am                |    1 +
 tests/Makefile.in                |    1 +
 tests/autodist-no-duplicate.test |   40 +++++++++++++++++
 5 files changed, 97 insertions(+), 44 deletions(-)
 create mode 100755 tests/autodist-no-duplicate.test

-*-*-

help: improve text about automatically-distributed files

This change fixes automake bug#7819.

* automake.in (usage): Distinguish between files that are always
automatically distributed when found, and those which are only
"under certain conditions".
* doc/automake.texi (Basics of Distribution): Update accordingly.
* tests/autodist-subdir.test: Update.
* tests/autodist-no-duplicate.test: Likewise.
* tests/autodist.test: Likewise.
(configure.in): Remove useless call to AM_MAINTAINER_MODE.
---
 ChangeLog                        |   11 +++++++++++
 automake.in                      |    8 ++++++--
 doc/automake.texi                |    4 +++-
 tests/autodist-no-duplicate.test |   32 +++++++++++++++++++++-----------
 tests/autodist-subdir.test       |   27 +--------------------------
 tests/autodist.test              |   29 +----------------------------
 6 files changed, 43 insertions(+), 68 deletions(-)

From 486824c88082cc9d9a66dfce3eb5a8e793669f5f Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <[email-masked]>
Date: Wed, 12 Jan 2011 01:06:33 +0100
Subject: [PATCH 1/2] refactor: split 'usage' subroutine in automake

This change is related to automake bug#7819.

* automake.in (print_autodist_files): New subroutine,
extracted from ...
(usage): ... this, which now uses it.
* tests/autodist-no-duplicate.test: New test.
* tests/Makefile.am (TESTS): Update.
---
 ChangeLog                        |   10 ++++
 automake.in                      |   89 +++++++++++++++++++-------------------
 tests/Makefile.am                |    1 +
 tests/Makefile.in                |    1 +
 tests/autodist-no-duplicate.test |   40 +++++++++++++++++
 5 files changed, 97 insertions(+), 44 deletions(-)
 create mode 100755 tests/autodist-no-duplicate.test

diff --git a/ChangeLog b/ChangeLog
index be35937..4e1e093 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2011-01-15   Stefano Lattarini  <[email-masked]>
+
+	refactor: split 'usage' subroutine in automake
+	This change is related to automake bug#7819.
+	* automake.in (print_autodist_files): New subroutine,
+	extracted from ...
+	(usage): ... this, which now uses it.
+	* tests/autodist-no-duplicate.test: New test.
+	* tests/Makefile.am (TESTS): Update.
+
 2011-01-15  Ralf Wildenhues  <[email-masked]>
 
 	docs: ensure example are separated with empty lines in the input
diff --git a/automake.in b/automake.in
index d56fbf7..3a214e0 100755
--- a/automake.in
+++ b/automake.in
@@ -8308,6 +8308,50 @@ sub generate_makefile ($$)
 
 ################################################################
 
+# Helper function for usage().
+sub print_autodist_files (@)
+{
+  my @lcomm = sort (&uniq (@_));
+
+  my @four;
+  format USAGE_FORMAT =
+  @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
+  $four[0],           $four[1],           $four[2],           $four[3]
+.
+  local $~ = "USAGE_FORMAT";
+
+  my $cols = 4;
+  my $rows = int(@lcomm / $cols);
+  my $rest = @lcomm % $cols;
+
+  if ($rest)
+    {
+      $rows++;
+    }
+  else
+    {
+      $rest = $cols;
+    }
+
+  for (my $y = 0; $y < $rows; $y++)
+    {
+      @four = ("", "", "", "");
+      for (my $x = 0; $x < $cols; $x++)
+        {
+          last if $y + 1 == $rows && $x == $rest;
+
+          my $idx = (($x > $rest)
+      	       ?  ($rows * $rest + ($rows - 1) * ($x - $rest))
+      	       : ($rows * $x));
+
+          $idx += $y;
+          $four[$x] = $lcomm[$idx];
+        }
+      write;
+    }
+}
+
+
 # Print usage information.
 sub usage ()
 {
@@ -8341,51 +8385,8 @@ Library files:
 ";
     Automake::ChannelDefs::usage;
 
-    my ($last, @lcomm);
-    $last = '';
-    foreach my $iter (sort ((@common_files, @common_sometimes)))
-    {
-	push (@lcomm, $iter) unless $iter eq $last;
-	$last = $iter;
-    }
-
-    my @four;
     print "\nFiles which are automatically distributed, if found:\n";
-    format USAGE_FORMAT =
-  @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<   @<<<<<<<<<<<<<<<<
-  $four[0],           $four[1],           $four[2],           $four[3]
-.
-    $~ = "USAGE_FORMAT";
-
-    my $cols = 4;
-    my $rows = int(@lcomm / $cols);
-    my $rest = @lcomm % $cols;
-
-    if ($rest)
-    {
-	$rows++;
-    }
-    else
-    {
-	$rest = $cols;
-    }
-
-    for (my $y = 0; $y < $rows; $y++)
-    {
-	@four = ("", "", "", "");
-	for (my $x = 0; $x < $cols; $x++)
-	{
-	    last if $y + 1 == $rows && $x == $rest;
-
-	    my $idx = (($x > $rest)
-		       ?  ($rows * $rest + ($rows - 1) * ($x - $rest))
-		       : ($rows * $x));
-
-	    $idx += $y;
-	    $four[$x] = $lcomm[$idx];
-	}
-	write;
-    }
+    print_autodist_files (@common_files, @common_sometimes);
 
     print '
 Report bugs to <@PACKAGE_BUGREPORT@>.
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 890e69b..63ad4d9 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -101,6 +101,7 @@ autodist-acconfig-no-subdir.test \
 autodist-aclocal-m4.test \
 autodist-config-headers.test \
 autodist-configure-no-subdir.test \
+autodist-no-duplicate.test \
 autodist-stamp-vti.test \
 autohdr.test \
 autohdr2.test \
diff --git a/tests/Makefile.in b/tests/Makefile.in
index 7600c14..0f88916 100644
--- a/tests/Makefile.in
+++ b/tests/Makefile.in
@@ -368,6 +368,7 @@ autodist-acconfig-no-subdir.test \
 autodist-aclocal-m4.test \
 autodist-config-headers.test \
 autodist-configure-no-subdir.test \
+autodist-no-duplicate.test \
 autodist-stamp-vti.test \
 autohdr.test \
 autohdr2.test \
diff --git a/tests/autodist-no-duplicate.test b/tests/autodist-no-duplicate.test
new file mode 100755
index 0000000..e2b7da0
--- /dev/null
+++ b/tests/autodist-no-duplicate.test
@@ -0,0 +1,40 @@
+#! /bin/sh
+# Copyright (C) 2011 Free Software Foundation, Inc.
+#
+# 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 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
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
+
+# Check that there are no duplicates in the list of files automatically
+# distributed by automake.
+
+. ./defs || Exit 1
+
+set -e
+
+# The automake manual states that the list of automatically-distributed
+# files should be given by `automake --help'.
+list=`$AUTOMAKE --help \
+        | sed -n '/^Files .*automatically distributed.*if found/,/^ *$/p' \
+        | sed 1d`
+
+list=`echo $list`
+test -n "$list" # sanity check
+
+for f in $list; do echo $f; done | sort > files.lst
+uniq files.lst > files.uniq
+
+cat files.lst
+cat files.uniq
+diff files.lst files.uniq
+
+:
-- 
1.7.2.3

From 60370a87d28b0c3e7ddddc24c7da904a69b71d5b Mon Sep 17 00:00:00 2001
From: Stefano Lattarini <[email-masked]>
Date: Wed, 12 Jan 2011 01:27:07 +0100
Subject: [PATCH 2/2] help: improve text about automatically-distributed files

This change fixes automake bug#7819.

* automake.in (usage): Distinguish between files that are always
automatically distributed when found, and those which are only
"under certain conditions".
* doc/automake.texi (Basics of Distribution): Update accordingly.
* tests/autodist-subdir.test: Update.
* tests/autodist-no-duplicate.test: Likewise.
* tests/autodist.test: Likewise.
(configure.in): Remove useless call to AM_MAINTAINER_MODE.
---
 ChangeLog                        |   11 +++++++++++
 automake.in                      |    8 ++++++--
 doc/automake.texi                |    4 +++-
 tests/autodist-no-duplicate.test |   32 +++++++++++++++++++++-----------
 tests/autodist-subdir.test       |   27 +--------------------------
 tests/autodist.test              |   29 +----------------------------
 6 files changed, 43 insertions(+), 68 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 4e1e093..b532fcf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2011-01-15   Stefano Lattarini  <[email-masked]>
 
+	help: improve text about automatically-distributed files
+	This change fixes automake bug#7819.
+	* automake.in (usage): Distinguish between files that are always
+	automatically distributed when found, and those which are only
+	"under certain conditions".
+	* doc/automake.texi (Basics of Distribution): Update accordingly.
+	* tests/autodist-subdir.test: Update.
+	* tests/autodist-no-duplicate.test: Likewise.
+	* tests/autodist.test: Likewise.
+	(configure.in): Remove useless call to AM_MAINTAINER_MODE.
+
 	refactor: split 'usage' subroutine in automake
 	This change is related to automake bug#7819.
 	* automake.in (print_autodist_files): New subroutine,
diff --git a/automake.in b/automake.in
index 3a214e0..2603e44 100755
--- a/automake.in
+++ b/automake.in
@@ -8385,8 +8385,12 @@ Library files:
 ";
     Automake::ChannelDefs::usage;
 
-    print "\nFiles which are automatically distributed, if found:\n";
-    print_autodist_files (@common_files, @common_sometimes);
+    print "\nFiles automatically distributed if found " .
+          "(always):\n";
+    print_autodist_files @common_files;
+    print "\nFiles automatically distributed if found " .
+          "(under certain conditions):\n";
+    print_autodist_files @common_sometimes;
 
     print '
 Report bugs to <@PACKAGE_BUGREPORT@>.
diff --git a/doc/automake.texi b/doc/automake.texi
index 73c0e51..cb1445f 100644
--- a/doc/automake.texi
+++ b/doc/automake.texi
@@ -8289,7 +8289,9 @@ as are all @file{Makefile.am}s and @file{Makefile.in}s.  Automake also
 has a built-in list of commonly used files that are automatically
 included if they are found in the current directory (either physically,
 or as the target of a @file{Makefile.am} rule).  This list is printed by
-@samp{automake --help}.  Also, files that are read by @command{configure}
+@samp{automake --help}@footnote{Note that some of these files are actually
+distributed only when other certain conditions hold}.  Also, files that
+are read by @command{configure}
 (i.e.@: the source files corresponding to the files specified in various
 Autoconf macros such as @code{AC_CONFIG_FILES} and siblings) are
 automatically distributed.  Files included in @file{Makefile.am}s (using
diff --git a/tests/autodist-no-duplicate.test b/tests/autodist-no-duplicate.test
index e2b7da0..65fe034 100755
--- a/tests/autodist-no-duplicate.test
+++ b/tests/autodist-no-duplicate.test
@@ -21,20 +21,30 @@
 
 set -e
 
+re='Files .*automatically distributed.*if found'
+
 # The automake manual states that the list of automatically-distributed
 # files should be given by `automake --help'.
-list=`$AUTOMAKE --help \
-        | sed -n '/^Files .*automatically distributed.*if found/,/^ *$/p' \
+list1=`$AUTOMAKE --help \
+        | sed -n "/^$re.*always/,/^ *$/p" \
         | sed 1d`
+list1=`echo $list1`
 
-list=`echo $list`
-test -n "$list" # sanity check
-
-for f in $list; do echo $f; done | sort > files.lst
-uniq files.lst > files.uniq
-
-cat files.lst
-cat files.uniq
-diff files.lst files.uniq
+list2=`$AUTOMAKE --help \
+        | sed -n "/^$re.*under certain conditions/,/^ *$/p" \
+        | sed 1d`
+list2=`echo $list2`
+
+# Sanity checks.
+test -n "$list1"
+test -n "$list2"
+
+for i in 1 2; do
+  eval "for f in \${list$i}; do echo \$f; done | sort > files$i.lst"
+  uniq files$i.lst > files$i.uniq
+  cat files$i.lst
+  cat files$i.uniq
+  diff files$i.lst files$i.uniq
+done
 
 :
diff --git a/tests/autodist-subdir.test b/tests/autodist-subdir.test
index db694f8..83b293e 100755
--- a/tests/autodist-subdir.test
+++ b/tests/autodist-subdir.test
@@ -39,33 +39,8 @@ $AUTOCONF
 # The automake manual states that the list of automatically-distributed
 # files should be given by `automake --help'.
 list=`$AUTOMAKE --help \
-        | sed -n '/^Files .*automatically distributed.*if found/,/^ *$/p' \
+        | sed -n '/^Files.*automatically distributed.*if found.*always/,/^ *$/p' \
         | sed 1d`
-list=`for f in $list; do
-        case $f in
-          configure|configure.in|configure.ac)
-            # See test 'autodist-configure-no-subdir.test'.
-            ;;
-          aclocal.m4)
-            # This file should be distributed only when it is a real
-            # dependency for configure.  Anyway, not a check to be
-            # performed in this test.
-            ;;
-          acconfig.h)
-            # Works only when it really exists, not when it is a
-            # target in Makefile.am.
-            ;;
-          stamp-vti)
-            # Works only when using info_TEXINFOS and version.texi.
-            ;;
-          config.h.bot|config.h.top)
-            # Works only when the AC_CONFIG_HADERS macro is used.
-            ;;
-          *)
-            echo $f
-            ;;
-        esac
-      done`
 # Normalize whitespace, just in case.
 list=`echo $list`
 
diff --git a/tests/autodist.test b/tests/autodist.test
index 34b9526..7992608 100755
--- a/tests/autodist.test
+++ b/tests/autodist.test
@@ -32,8 +32,6 @@ cat > configure.in <<END
 AC_INIT([$me], [1.0])
 AC_CONFIG_AUX_DIR([.])
 AM_INIT_AUTOMAKE
-## Will avoid useless regeneration of aclocal.m4, configure, etc.
-AM_MAINTAINER_MODE
 AC_CONFIG_FILES([Makefile])
 AC_OUTPUT
 END
@@ -44,33 +42,8 @@ $AUTOCONF
 # The automake manual states that the list of automatically-distributed
 # files should be given by `automake --help'.
 list=`$AUTOMAKE --help \
-        | sed -n '/^Files .*automatically distributed.*if found/,/^ *$/p' \
+        | sed -n '/^Files.*automatically distributed.*if found.*always/,/^ *$/p' \
         | sed 1d`
-list=`for f in $list; do
-        case $f in
-          configure|configure.in|configure.ac)
-            # See test 'autodist-configure-no-subdir.test'.
-            ;;
-          aclocal.m4)
-            # This file should be distributed only when it is a real
-            # dependency for configure.  Anyway, not a check to be
-            # performed in this test.
-            ;;
-          acconfig.h)
-            # Works only when it really exists, not when it is a
-            # target in Makefile.am.
-            ;;
-          stamp-vti)
-            # Works only when using info_TEXINFOS and version.texi.
-            ;;
-          config.h.bot|config.h.top)
-            # Works only when the AC_CONFIG_HADERS macro is used.
-            ;;
-          *)
-            echo $f
-            ;;
-        esac
-      done`
 # Normalize whitespace, just in case.
 list=`echo $list`
 
-- 
1.7.2.3