]> git.ipfire.org Git - thirdparty/automake.git/commitdiff
[ng] automake: new function 'slurp_makefile_fragment'
authorStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 30 Jul 2012 15:54:40 +0000 (17:54 +0200)
committerStefano Lattarini <stefano.lattarini@gmail.com>
Mon, 30 Jul 2012 15:54:40 +0000 (17:54 +0200)
This is a pure refactoring, with no semantic change intended.
It will be required by future changes.

* automake.in (slurp_makefile_fragment): New.
(preprocess_file): Use it.

Signed-off-by: Stefano Lattarini <stefano.lattarini@gmail.com>
automake.in

index e3e96a702bb6bdca5c355cde4243859946e4a696..5ed904b45bfbd166df83c06fef6eccf11582622c 100644 (file)
@@ -5723,6 +5723,35 @@ sub transform ($$)
     }
 }
 
+# $TEXT
+# slurp_makefile_fragment ($MAKEFILE)
+# -----------------------------------
+# Load a $MAKEFILE, strip '##'-style comments, and return the result.
+# No extra parsing, %TRANSFORM application, or post-processing is
+# done (e.g., recognition of rules declaration or of make variables
+# definitions).
+sub slurp_makefile_fragment ($)
+{
+  my $file = shift;
+  local $_;
+  if (not defined ($_ = $am_file_cache{$file}))
+    {
+      verb "reading $file";
+      # Swallow the whole file.
+      my $fc_file = new Automake::XFile "< $file";
+      my $saved_dollar_slash = $/;
+      undef $/;
+      $_ = $fc_file->getline;
+      $/ = $saved_dollar_slash;
+      $fc_file->close;
+      # Remove ##-comments.
+      s/$IGNORE_PATTERN//gom;
+      # Remember the contents of the just-read file.
+      $am_file_cache{$file} = $_;
+    }
+  return $_;
+}
+
 # $TEXT
 # preprocess_file ($MAKEFILE, [%TRANSFORM])
 # -----------------------------------------
@@ -5764,23 +5793,10 @@ sub preprocess_file ($%)
                 'SILENT'       => silent_flag (),
                %transform);
 
-  if (! defined ($_ = $am_file_cache{$file}))
-    {
-      verb "reading $file";
-      # Swallow the whole file.
-      my $fc_file = new Automake::XFile "< $file";
-      my $saved_dollar_slash = $/;
-      undef $/;
-      $_ = $fc_file->getline;
-      $/ = $saved_dollar_slash;
-      $fc_file->close;
-      # Remove ##-comments.
-      # Besides we don't need more than two consecutive new-lines.
-      s/(?:$IGNORE_PATTERN|(?<=\n\n)\n+)//gom;
-      # Remember the contents of the just-read file.
-      $am_file_cache{$file} = $_;
-    }
+  local $_ = slurp_makefile_fragment ($file);
 
+  # We don't need more than two consecutive new-lines.
+  s/(?<=\n\n)\n+//gm;
   # Substitute Automake template tokens.
   s/(?: % \?? [\w\-]+ %
       | \? !? [\w\-]+ \?