automake
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

20-file-contents-cond-string.patch


From: Akim Demaille
Subject: 20-file-contents-cond-string.patch
Date: Fri, 09 Mar 2001 00:48:14 +0100

Full scale use is not ready, please don't try to use if/endif by
yourselves.

There are several traps, the easiest being that for the time being it
does not work for variables (fortunately there are only a few).  It's
very easy to fix this, the problem being that there are several
possible choices, and I can't make my mind for the time being.

The nastier problem is related to the fact that the paragraph
splitting routine in file_contents is too naive and needs to be
strengthen: if currently does not properly separate as a distinct
paragraph the if lines (under some conditions).  This is examplified
by the following changes in distdir.am:

distdir: $(DISTFILES)
##
## For Gnits users, this is pretty handy.  Look at 15 lines
## in case some explanatory text is desirable.
##
if %?TOPDIR%
if  %?CK-NEWS%
        @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" >/dev/null;
        then :; else \
          echo "NEWS not updated; not releasing" 1>&2; \
          exit 1; \
        fi
endif  %?CK-NEWS%
endif %?TOPDIR%


Yielding to

 distdir: $(DISTFILES)
+if  TRUE
+       @if sed 15q $(srcdir)/NEWS | fgrep -e "$(VERSION)" >/dev/null;
+       then :; else \
+         echo "NEWS not updated; not releasing" 1>&2; \
+         exit 1; \
+       fi
+endif FALSE

automake did not notice the two paragraphs holding the if TRUE, and
the endif FALSE (but properly found the two others.


It's been a while I decided to write a better parser for Makefiles.  I
know some constructs that even read_am_file breaks (e.g., define/endef
paragraph from GNU Make).  So my next steps will be writing that
better Makefile paragraph splitter, and then to use if/endif in more
*.am files.

Personally, I'm happy: I can see many things converging together.
More factorization to come!




Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * automake.in (&file_contents): Maintain $cond_string sync with
        @cond_stack.
        Output rules only if not under `FALSE'.
        Define variables under $cond_string.
        * scripts.am: For the time being if/endif does not work properly
        with macros.

Index: automake.in
--- automake.in Fri, 09 Mar 2001 00:09:32 +0100 akim (am/f/39_automake.i 1.134 
755)
+++ automake.in Fri, 09 Mar 2001 00:24:13 +0100 akim (am/f/39_automake.i 1.134 
755)
@@ -6740,6 +6740,7 @@ sub file_contents ($%)
     my $comment = '';
     my $separator = '';
     my @cond_stack = ();
+    my $cond_string = '';
     foreach (split (/(?<!\\)\n(?![\t#])/, $contents))
     {
         # Strip leading new lines.  This can happen for comments:
@@ -6775,6 +6776,7 @@ sub file_contents ($%)
                if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
            push (@cond_stack,
                  ($cond =~ /^TRUE|FALSE$/) ? "$cond" : "${cond}_TRUE");
+           $cond_string = conditional_string (@cond_stack);
        }
        elsif (/$ELSE_PATTERN/o)
        {
@@ -6789,6 +6791,7 @@ sub file_contents ($%)
            else
            {
                $cond_stack[$#cond_stack] =~ s/TRUE$/FALSE/;
+               $cond_string = conditional_string (@cond_stack);
            }
        }
        elsif (/$ENDIF_PATTERN/o)
@@ -6800,6 +6803,7 @@ sub file_contents ($%)
            else
            {
                pop @cond_stack;
+               $cond_string = conditional_string (@cond_stack);
            }
        }

@@ -6827,7 +6831,10 @@ sub file_contents ($%)
            {
              # FIXME: We are not robust to people defining several targets
              # at once, only some of them being in %dependencies.
-             if (defined $dependencies{$_})
+
+             # Output only if not in FALSE.
+             if (defined $dependencies{$_}
+                 && $cond_string ne "#")
                {
                  &depend ($_, @deps);
                  $actions{$_} .= $actions;
@@ -6836,11 +6843,11 @@ sub file_contents ($%)
                {
                  # Free lance dependency.  Output the rule for all the
                  # targets instead of one by one.
-                 if (!defined $targets{$targets})
+                 if (!defined $targets{$targets}
+                     && $cond_string ne "#")
                    {
                      $result_rules .= "$separator$comment$paragraph\n";
-                     rule_define ($targets, 1,
-                                  conditional_string (@cond_stack), $.);
+                     rule_define ($targets, 1, $cond_string, $.);
                    }
                  $comment = $separator = '';
                  last;
@@ -6854,7 +6861,7 @@ sub file_contents ($%)
              if /\\$/;;

            # Accumulating variables must not be output.
-           variable_define ($var, 1, $type, '', $val, $.);
+           variable_define ($var, 1, $type, $cond_string, $val, $.);

            # If the user has set some variables we were in charge
            # of (which is detected by the first reading of
Index: scripts.am
--- scripts.am Fri, 09 Mar 2001 00:02:44 +0100 akim (am/g/15_scripts.am 1.8 644)
+++ scripts.am Fri, 09 Mar 2001 00:25:15 +0100 akim (am/g/15_scripts.am 1.8 644)
@@ -22,7 +22,8 @@
 ## ------------ ##

 if %?INSTALL%
-_am_installdirs += $(DESTDIR)$(%NDIR%dir)
+## if doesn't work properly for Automake variables yet.
+?INSTALL?_am_installdirs += $(DESTDIR)$(%NDIR%dir)
 ?EXEC?.PHONY install-exec-am: install-%DIR%SCRIPTS
 ?!EXEC?.PHONY install-data-am: install-%DIR%SCRIPTS
 install-%DIR%SCRIPTS: $(%DIR%_SCRIPTS)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]