From b26695267b2a60b20a8500371c02c986411e1541 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 31 Jan 2001 14:16:17 +0000 Subject: [PATCH] * automake.in (file_contents): Rewrite: instead of trying to parse it line by line, first swallow it completely into $CONTENTS, *then*, parse it *paragraph* by paragraph. --- ChangeLog | 6 ++ Makefile.in | 9 +-- automake.in | 167 +++++++++++++++++++++++++++++------------------------- m4/Makefile.in | 2 +- tests/Makefile.in | 2 +- 5 files changed, 102 insertions(+), 84 deletions(-) diff --git a/ChangeLog b/ChangeLog index 32ffa01..72c05ec 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2001-01-31 Akim Demaille + + * automake.in (file_contents): Rewrite: instead of trying to parse + it line by line, first swallow it completely into $CONTENTS, + *then*, parse it *paragraph* by paragraph. + 2001-01-30 Akim Demaille * automake.in (file_contents): Remove. diff --git a/Makefile.in b/Makefile.in index c197541..f14e504 100644 --- a/Makefile.in +++ b/Makefile.in @@ -360,7 +360,6 @@ uninstall-dist_scriptDATA: # (1) if the variable is set in `config.status', edit `config.status' # (which will cause the Makefiles to be regenerated when you run `make'); # (2) otherwise, pass the desired values on the `make' command line. - all-recursive install-data-recursive install-exec-recursive \ installdirs-recursive install-recursive uninstall-recursive \ check-recursive installcheck-recursive info-recursive dvi-recursive: @@ -602,7 +601,7 @@ maintainer-clean-am: maintainer-clean-vti maintainer-clean-aminfo \ maintainer-clean: maintainer-clean-recursive -rm -f config.status -.PHONY: all all-am all-recursive all-redirect check check-am \ +.PHONY: all all-am all-recursive all-redirect check check-am \ check-recursive clean clean-aminfo clean-generic clean-recursive \ clean-tags clean-vti distclean distclean-aminfo distclean-generic \ distclean-recursive distclean-tags distclean-vti distdir dvi dvi-am \ @@ -617,10 +616,8 @@ maintainer-clean-generic maintainer-clean-recursive \ maintainer-clean-tags maintainer-clean-vti mostlyclean \ mostlyclean-aminfo mostlyclean-generic mostlyclean-recursive \ mostlyclean-tags mostlyclean-vti tags tags-recursive uninstall \ -uninstall-am uninstall-binSCRIPTS uninstall-data-recursive \ -uninstall-dist_pkgdataDATA uninstall-dist_scriptDATA \ -uninstall-exec-recursive uninstall-info uninstall-recursive \ -uninstalldirs-recursive +uninstall-am uninstall-binSCRIPTS uninstall-dist_pkgdataDATA \ +uninstall-dist_scriptDATA uninstall-info uninstall-recursive install-data-hook: diff --git a/automake.in b/automake.in index c803db8..96ee510 100755 --- a/automake.in +++ b/automake.in @@ -40,7 +40,8 @@ $am_dir = "@datadir@/@PACKAGE@"; $IGNORE_PATTERN = "^##([^#].*)?\$"; $WHITE_PATTERN = "^[ \t]*\$"; $COMMENT_PATTERN = "^#"; -$RULE_PATTERN = "^([\$a-zA-Z_.][-.a-zA-Z0-9_(){}/\$]*) *:([^=].*|)\$"; +$TARGET_PATTERN="[\$a-zA-Z_.][-.a-zA-Z0-9_(){}/\$]*"; +$RULE_PATTERN = "^($TARGET_PATTERN) *:([^=].*|)\$"; $SUFFIX_RULE_PATTERN = "^\\.([a-zA-Z0-9]+)\\.([a-zA-Z0-9]+)\$"; # Only recognize leading spaces, not leading tabs. If we recognize # leading tabs here then we need to make the reader smarter, because @@ -6988,13 +6989,9 @@ sub file_contents # Looks stupid? # print "automake: reading $file\n" if $verbose; - local ($was_rule) = 0; - local ($result_vars) = ''; - local ($result_rules) = ''; - local ($comment) = ''; - local ($spacing) = "\n"; - local ($skipping) = 0; - local ($had_chars); + # Swallow into $CONTENTS the whole content of the file, after + # having performed the $COMMAND, and removed Automake comments. + local ($contents) = ''; while () { @@ -7002,7 +6999,7 @@ sub file_contents unless $seen_maint_mode; $had_chars = length ($_) && $_ ne "\n"; - eval $command; + eval $command; # If the transform caused all the characters to go away, then # ignore the line. Why do this? Because in Perl 4, a "next" # inside of an eval doesn't affect a loop outside the eval. @@ -7011,76 +7008,83 @@ sub file_contents # newline. next if $had_chars && ($_ eq '' || $_ eq "\n"); - if (/$IGNORE_PATTERN/o) - { - # Merely delete comments beginning with two hashes. - } - elsif (/$WHITE_PATTERN/o) - { - # Stick a single white line before the incoming macro or rule. - $spacing = "\n"; - &am_line_error ($., "blank line following trailing backslash") - if $saw_bk; - } - elsif (/$COMMENT_PATTERN/o) - { - # Stick comments before the incoming macro or rule. - $comment .= $spacing . $_; - $spacing = ''; - &am_line_error ($., "comment following trailing backslash") - if $saw_bk; - } - elsif ($saw_bk) - { - if ($was_rule) - { - $result_rules .= $_ if ! $skipping; - } - else - { - $result_vars .= $_ if ! $skipping; - } - $saw_bk = /\\$/; - } - elsif (/^.PHONY: (.*)$/) - { - # Having a special case for PHONY upstream seems much easier than - # trying to have it fit in RULE_PATTERN and extract it later. - push (@phony, split (/\s+/, $1)); - } - elsif (/$RULE_PATTERN/o) - { - # Found a rule. - $was_rule = 1; - $skipping = defined $contents{$1}; - $result_rules .= $comment . $spacing . $_ if ! $skipping; - $comment = $spacing = ''; - $saw_bk = /\\$/; - } - elsif (/$MACRO_PATTERN/o) - { - # Found a variable reference. - $was_rule = 0; - $skipping = defined $contents{$1}; - $result_vars .= $comment . $spacing . $_ if ! $skipping; - $comment = $spacing = ''; - $saw_bk = /\\$/; - &prog_error (".am macro \`$1' with trailing backslash at $file:$.") - if $saw_bk; - $am_var_defs{$1} = $3; - } - else - { - # This isn't an error; it is probably a continued rule. - # In fact, this is what we assume. - $was_rule = 1; - $result_rules .= $comment . $spacing . $_ if ! $skipping; - $comment = $spacing = ''; - $saw_bk = /\\$/; - } + # Merely delete comments beginning with two hashes. + next if /$IGNORE_PATTERN/o; + + $contents .= $_; } close (FC_FILE); + + # We don't need more than two consecutive new-lines. + $contents =~ s/\n{3,}/\n\n/g; + + # Process each Make `paragraph'. + # + # A Make `paragraph' is delimited by a new line which is not + # escaped, and not followed by a tab or a comment. + # + # Frankly, unless you like fighting with Perl (you're a freak!), + # if I were you I would not try some other implementation, it's + # very easy falling either into extremely low RE matching + # (backtracking...), or worse yet: infloop... For instance, (my) + # perl goes loopy if you try to + # + # $result_rules =~ /^($TARGET_PATTERN *)+: ($TARGET_PATTERN *)+\n\n/sm + local ($result_vars) = ''; + local ($result_rules) = ''; + local ($comment) = ''; + foreach (split (/(?