From: Stefano Lattarini Date: Mon, 30 Jul 2012 15:54:40 +0000 (+0200) Subject: [ng] automake: new function 'slurp_makefile_fragment' X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=09dcf0c5ff160b837cd7cade1df5252760695168;p=thirdparty%2Fautomake.git [ng] automake: new function 'slurp_makefile_fragment' 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 --- diff --git a/automake.in b/automake.in index e3e96a702..5ed904b45 100644 --- a/automake.in +++ b/automake.in @@ -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\-]+ \?