[PATCH] cleanup: refactor code to initialize DIST_COMMON

Stefano Lattarini <[email protected]>
Newsgroups gmane.comp.sysutils.automake.patches
Message-ID <912383451a4a394383a8e95240e3e98ee68faf72.1419267358.git.stefano.lattarini@gmail.com>
There is not need to make that an Automake variable early,
only to later get and munge its contents, and use the new
content to redefine the variable.

* bin/automake.in (@dist_common): New global variable.
(push_dist_common, handle_dist): Use it.
(handle_dist): Define am__DIST_COMMON instead of DIST_COMMON
directly.
(initialize_per_input): Reset it to empty.
($configure_dist_common): Turn this scalar variable ...
(@configure_dist_common): ... into this array variable.
(handle_dist): Adjust.
(required_file_check_or_copy): Update and wrap some comments.
* lib/am/distdir.am (DIST_COMMON): Append $(am__DIST_COMMON).
* t/distcom2.sh: Tighten a little.

Signed-off-by: Stefano Lattarini <[email protected]>
---
 bin/automake.in   | 48 ++++++++++++++++++++++++------------------------
 lib/am/distdir.am |  1 +
 t/distcom2.sh     |  2 +-
 3 files changed, 26 insertions(+), 25 deletions(-)

diff --git a/bin/automake.in b/bin/automake.in
index 7851454..d48b286 100644
--- a/bin/automake.in
+++ b/bin/automake.in
@@ -342,7 +342,7 @@ my %extension_map = ();
 
 # List of the DIST_COMMON files we discovered while reading
 # configure.ac.
-my $configure_dist_common = '';
+my @configure_dist_common = ();
 
 # This maps languages names onto objects.
 my %languages = ();
@@ -489,6 +489,9 @@ my %language_scratch;
 # handling on a per-language basis.
 my %lang_specific_files;
 
+# List of distributed files to be put in DIST_COMMON.
+my @dist_common;
+
 # This is set when 'handle_dist' has finished.  Once this happens,
 # we should no longer push on dist_common.
 my $handle_dist_run;
@@ -586,8 +589,11 @@ sub initialize_per_input ()
 
     @dist_targets = ();
 
+    @dist_common = ();
+    $handle_dist_run = 0;
+
     %known_programs = ();
-    %known_libraries= ();
+    %known_libraries = ();
 
     %extension_seen = ();
 
@@ -595,8 +601,6 @@ sub initialize_per_input ()
 
     %lang_specific_files = ();
 
-    $handle_dist_run = 0;
-
     $need_link = 0;
 
     $must_handle_compiled_objects = 0;
@@ -3693,8 +3697,8 @@ sub handle_dist ()
 	}
     }
 
-  # We might copy elements from $configure_dist_common to
-  # %dist_common if we think we need to.  If the file appears in our
+  # We might copy elements from @configure_dist_common to
+  # @dist_common if we think we need to.  If the file appears in our
   # directory, we would have discovered it already, so we don't
   # check that.  But if the file is in a subdir without a Makefile,
   # we want to distribute it here if we are doing '.'.  Ugly!
@@ -3706,26 +3710,25 @@ sub handle_dist ()
   # See also automake bug#9651.
   if ($relative_dir eq '.')
     {
-      foreach my $file (split (' ' , $configure_dist_common))
+      foreach my $file (@configure_dist_common)
 	{
 	  my $dir = dirname ($file);
 	  push_dist_common ($file)
 	    if ($dir eq '.' || ! is_make_dir ($dir));
 	}
+      @configure_dist_common = ();
     }
 
-  # Files to distributed.  Don't use ->value_as_list_recursive as it
-  # recursively expands '$(dist_pkgdata_DATA)' etc.
+  # $(am__DIST_COMMON): files to be distributed automatically.  Will be
+  # appended to $(DIST_COMMON) in the generated Makefile.
   # Use 'sort' so that the expansion of $(DIST_COMMON) in the generated
   # Makefile is deterministic, in face of m4 and/or perl randomizations
   # (see automake bug#17908).
-  my @dist_common = split (' ', rvar ('DIST_COMMON')->variable_value);
-  @dist_common = uniq (sort @dist_common);
-  variable_delete 'DIST_COMMON';
-  define_pretty_variable ('DIST_COMMON', TRUE, INTERNAL, @dist_common);
+  define_pretty_variable ('am__DIST_COMMON', TRUE, INTERNAL,
+                          uniq (sort @dist_common));
 
-  # Now that we've processed DIST_COMMON, disallow further attempts
-  # to set it.
+  # Now that we've processed @dist_common, disallow further attempts
+  # to modify it.
   $handle_dist_run = 1;
 
   $transform{'DISTCHECK-HOOK'} = !! rule 'distcheck-hook';
@@ -5435,8 +5438,7 @@ sub scan_autoconf_files ()
     if -f $config_aux_dir . '/install.sh';
 
   # Preserve dist_common for later.
-  $configure_dist_common = variable_value ('DIST_COMMON') || '';
-
+  @configure_dist_common = @dist_common;
 }
 
 ################################################################
@@ -7402,11 +7404,10 @@ sub required_file_check_or_copy
   return
     if $found_it && (! $add_missing || ! $force_missing);
 
-  # If we've already looked for it, we're done.  You might
-  # wonder why we don't do this before searching for the
-  # file.  If we do that, then something like
-  # AC_OUTPUT(subdir/foo foo) will fail to put foo.in into
-  # DIST_COMMON.
+  # If we've already looked for it, we're done.  You might wonder why we
+  # don't do this before searching for the file.  If we do that, then
+  # something like AC_OUTPUT([subdir/foo foo]) will fail to put 'foo.in'
+  # into $(DIST_COMMON).
   if (! $found_it)
     {
       return if defined $required_file_not_found{$fullfile};
@@ -7693,8 +7694,7 @@ sub push_dist_common
 {
   prog_error "push_dist_common run after handle_dist"
     if $handle_dist_run;
-  Automake::Variable::define ('DIST_COMMON', VAR_AUTOMAKE, '+', TRUE, "@_",
-			      '', INTERNAL, VAR_PRETTY);
+  push @dist_common, @_;
 }
 
 
diff --git a/lib/am/distdir.am b/lib/am/distdir.am
index 0c01960..5a13055 100644
--- a/lib/am/distdir.am
+++ b/lib/am/distdir.am
@@ -14,6 +14,7 @@
 ## You should have received a copy of the GNU General Public License
 ## along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+DIST_COMMON += $(am__DIST_COMMON)
 DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
 
 if %?TOPDIR_P%
diff --git a/t/distcom2.sh b/t/distcom2.sh
index 0cb9307..3eb0376 100644
--- a/t/distcom2.sh
+++ b/t/distcom2.sh
@@ -52,7 +52,7 @@ for opt in '' --no-force; do
 
   for dir in . subdir; do
     sed -n -e "
-      /^\\(am__\\)\\?DIST_COMMON =.*/ {
+      /^am__DIST_COMMON =.*/ {
         b body
         :loop
         n
-- 
2.1.3
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.