From f1895f943d9f58e05fbb3f6ba1d3c5e53733a6a9 Mon Sep 17 00:00:00 2001 From: Stefano Lattarini Date: Mon, 16 Apr 2012 14:59:53 +0200 Subject: [PATCH] automake: refactor pre-processing of makefile fragments This change will provide the automake script with a new function that reads in a Makefile fragment *without* performing Automake ad-hoc parsing, but only the pre-processing step, i.e., removal of '##' comments and substitution of tokens like '%SUBDIRS%', '%?LIBTOOL%' or '?GENENRIC?'. This will very likely be useful for the work on Automake-NG. This is a pure refactoring, with no intended functional or semantic changes. * automake.in (preprocess_file): New function, extracted ... (make_paragraphs): ... from here. Signed-off-by: Stefano Lattarini --- automake.in | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/automake.in b/automake.in index 38e09dc..43a7ba6 100644 --- a/automake.in +++ b/automake.in @@ -6938,13 +6938,13 @@ sub transform ($$) } } - -# @PARAGRAPHS -# &make_paragraphs ($MAKEFILE, [%TRANSFORM]) -# ------------------------------------------ -# Load a $MAKEFILE, apply the %TRANSFORM, and return it as a list of -# paragraphs. -sub make_paragraphs ($%) +# $TEXT +# preprocess_file ($MAKEFILE, [%TRANSFORM]) +# ----------------------------------------- +# Load a $MAKEFILE, apply the %TRANSFORM, and return the result. +# No extra parsing of post-processing is done (i.e., recognition of +# rules declaration or of make variables definitions). +sub preprocess_file ($%) { my ($file, %transform) = @_; @@ -6977,13 +6977,9 @@ sub make_paragraphs ($%) 'LIBTOOL' => !! var ('LIBTOOL'), 'NONLIBTOOL' => 1, - 'FIRST' => ! $transformed_files{$file}, %transform); - $transformed_files{$file} = 1; - $_ = $am_file_cache{$file}; - - if (! defined $_) + if (! defined ($_ = $am_file_cache{$file})) { verb "reading $file"; # Swallow the whole file. @@ -6993,11 +6989,10 @@ sub make_paragraphs ($%) $_ = $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} = $_; } @@ -7011,8 +7006,22 @@ sub make_paragraphs ($%) # ####### and do not remove the latter.) s/^[ \t]*(?:##%)+.*\n//gm; - # Split at unescaped new lines. - my @lines = split (/(?