automake
[Top][All Lists]
Advanced

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

111-if-bang.patch


From: Akim Demaille
Subject: 111-if-bang.patch
Date: Sun, 01 Apr 2001 21:57:30 +0200

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        
        Support `if !COND', `else COND', `end COND'.
        
        * automake.texi (Conditionals): Document it.
        * automake.in ($WHITE_PATTERN, $MACRO_PATTERN, $BOGUS_MACRO_PATTERN)
        ($GNITS_VERSION_PATTERN, $INCLUDE_PATTERN): Use `\d' and `\s'.
        ($IF_PATTERN, $ELSE_PATTERN, $ENDIF_PATTERN): Likewise, and accept
        a leading `!' before the condition.
        (&handle_options): Use `\d'.
        (&cond_stack_if, &cond_stack_else, &&cond_stack_endif): New.
        (&read_am_file, &file_contents_internal): Use them.
        (&transform): No longer substitute `%!COND%', forcing the use of
        `! %?COND%'.
        * ansi2knr.am, lex.am, tags.am, texinfos.am, yacc.am: Adjust.
        
Index: NEWS
--- NEWS Sat, 17 Feb 2001 17:56:59 +0100 akim (am/g/8_NEWS 1.3 644)
+++ NEWS Sun, 01 Apr 2001 19:12:21 +0200 akim (am/g/8_NEWS 1.3 644)
@@ -1,5 +1,6 @@
 New in 1.4e:
 * Support for `configure.ac'.
+* Support for `else COND', `endif COND' and negated conditions `!COND'.
 
 New in 1.4b:
 * Faster AM_INIT_AUTOMAKE (requires update of `missing' script)
Index: automake.in
--- automake.in Sat, 31 Mar 2001 16:22:59 +0200 akim (am/f/39_automake.i 1.246 
755)
+++ automake.in Sun, 01 Apr 2001 18:59:14 +0200 akim (am/f/39_automake.i 1.246 
755)
@@ -79,7 +79,7 @@ sub finish ($)
 
 # String constants.
 my $IGNORE_PATTERN = '^##([^#].*)?$';
-my $WHITE_PATTERN = '^[ \t]*$';
+my $WHITE_PATTERN = '^\s*$';
 my $COMMENT_PATTERN = '^#';
 my $TARGET_PATTERN='[$a-zA-Z_.][-.a-zA-Z0-9_(){}/$]*';
 my $RULE_PATTERN = "^($TARGET_PATTERN) *:([^=].*|)\$";
@@ -87,18 +87,18 @@ sub finish ($)
 # Only recognize leading spaces, not leading tabs.  If we recognize
 # leading tabs here then we need to make the reader smarter, because
 # otherwise it will think rules like `foo=bar; \' are errors.
-my $MACRO_PATTERN = '^ *(address@hidden)[ \t]*([:+]?)=[ \t]*(.*)$';
-my $BOGUS_MACRO_PATTERN = '^ *([^ \t]*)[ \t]*([:+]?)=[ \t]*(.*)$';
-my $GNITS_VERSION_PATTERN = '[0-9]+\.[0-9]+([a-z]|\.[0-9]+)?';
-my $IF_PATTERN = '^if[ \t]+([A-Za-z][A-Za-z0-9_]*)[ \t]*(#.*)?$';
-my $ELSE_PATTERN =   '^else(?:[ \t]+([A-Za-z][A-Za-z0-9_]*))?[ \t]*(#.*)?$';
-my $ENDIF_PATTERN = '^endif(?:[ \t]+([A-Za-z][A-Za-z0-9_]*))?[ \t]*(#.*)?$';
+my $MACRO_PATTERN = '^ *(address@hidden)\s*([:+]?)=\s*(.*)$';
+my $BOGUS_MACRO_PATTERN = '^ *([^ \t]*)\s*([:+]?)=\s*(.*)$';
+my $GNITS_VERSION_PATTERN = '\d+\.\d+([a-z]|\.\d+)?';
+my $IF_PATTERN =          '^if\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*)\s*(?:#.*)?$';
+my $ELSE_PATTERN =   '^else(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
+my $ENDIF_PATTERN = '^endif(?:\s+(!?)\s*([A-Za-z][A-Za-z0-9_]*))?\s*(?:#.*)?$';
 my $PATH_PATTERN='(\w|[/.-])+';
 # This will pass through anything not of the prescribed form.
-my $INCLUDE_PATTERN = ('^include[ \t]+'
+my $INCLUDE_PATTERN = ('^include\s+'
                       . '((\$\(top_srcdir\)/' . $PATH_PATTERN . ')'
                       . '|(\$\(srcdir\)/' . $PATH_PATTERN . ')'
-                      . '|([^/\$]' . $PATH_PATTERN. '))[ \t]*(#.*)?$');
+                      . '|([^/\$]' . $PATH_PATTERN. '))\s*(#.*)?$');
 
 # Some regular expressions.  One reason to put them here is that it
 # makes indentation work better in Emacs.
@@ -1232,14 +1232,14 @@ sub handle_options
            {
                $use_dependencies = 0;
            }
-           elsif (/([0-9]+)\.([0-9]+)([a-z]?)/)
+           elsif (/(\d+)\.(\d+)([a-z]?)/)
            {
                # Got a version number.
 
                my ($rmajor, $rminor, $ralpha) = ($1, $2, $3);
 
                &prog_error ("version is incorrect: $VERSION")
-                   if $VERSION !~ /([0-9]+)\.([0-9]+)([a-z]?)/;
+                   if $VERSION !~ /(\d+)\.(\d+)([a-z]?)/;
 
                my ($tmajor, $tminor, $talpha) = ($1, $2, $3);
 
@@ -5350,6 +5350,103 @@ sub check_ambiguous_conditional ($$)
 
 
 
+## ------------------------------ ##
+## Handling the condition stack.  ##
+## ------------------------------ ##
+
+
+# $COND_STRING
+# cond_stack_if ($NEGATE, $COND, $WHERE)
+# --------------------------------------
+sub cond_stack_if ($$$)
+{
+  my ($negate, $cond, $where) = @_;
+
+  &am_file_error ($where, "$cond does not appear in AM_CONDITIONAL")
+    if ! $configure_cond{$cond} && $cond !~ /^TRUE|FALSE$/;
+
+  $cond = "${cond}_TRUE"
+    unless $cond =~ /^TRUE|FALSE$/;
+  $cond = condition_negate ($cond)
+    if $negate;
+
+  push (@cond_stack, $cond);
+
+  return conditional_string (@cond_stack);
+}
+
+
+# $COND_STRING
+# cond_stack_else ($NEGATE, $COND, $WHERE)
+# ----------------------------------------
+sub cond_stack_else ($$$)
+{
+  my ($negate, $cond, $where) = @_;
+
+  if (! @cond_stack)
+    {
+      &am_file_error ($where, "else without if");
+      return;
+    }
+
+  $cond_stack[$#cond_stack] = condition_negate ($cond_stack[$#cond_stack]);
+
+  # If $COND is given, check against it.
+  if (defined $cond)
+    {
+      $cond = "${cond}_TRUE"
+       unless $cond =~ /^TRUE|FALSE$/;
+      $cond = condition_negate ($cond)
+       if $negate;
+
+      &am_file_error ($where,
+                     "else reminder ($negate$cond) incompatible with "
+                     . "current conditional: $cond_stack[$#cond_stack]")
+       if $cond_stack[$#cond_stack] ne $cond;
+    }
+
+  return conditional_string (@cond_stack);
+}
+
+
+# $COND_STRING
+# cond_stack_endif ($NEGATE, $COND, $WHERE)
+# -----------------------------------------
+sub cond_stack_endif ($$$)
+{
+  my ($negate, $cond, $where) = @_;
+  my $old_cond;
+
+  if (! @cond_stack)
+    {
+      &am_file_error ($where, "endif without if");
+      return;
+    }
+
+
+  # If $COND is given, check against it.
+  if (defined $cond)
+    {
+      $cond = "${cond}_TRUE"
+       unless $cond =~ /^TRUE|FALSE$/;
+      $cond = condition_negate ($cond)
+       if $negate;
+
+      &am_file_error ($where,
+                     "endif reminder ($negate$cond) incompatible with "
+                     . "current conditional: $cond_stack[$#cond_stack]")
+       if $cond_stack[$#cond_stack] ne $cond;
+    }
+
+  pop @cond_stack;
+
+  return conditional_string (@cond_stack);
+}
+
+
+
+
+
 ## ------------------------ ##
 ## Handling the variables.  ##
 ## ------------------------ ##
@@ -6212,45 +6309,20 @@ sub read_am_file
                }
            }
        }
+
        elsif (/$IF_PATTERN/o)
-       {
-           my $new_cond = $1;
-           &am_line_error ($., "$new_cond does not appear in AM_CONDITIONAL")
-               if ! $configure_cond{$new_cond} && $new_cond !~ /^TRUE|FALSE$/;
-           push (@cond_stack,
-                 (($new_cond =~ /^TRUE|FALSE$/)
-                  ? "$new_cond" : "${new_cond}_TRUE"));
-           $cond = conditional_string (@cond_stack);
-       }
+         {
+           $cond = cond_stack_if ($1, $2, "$amfile:$.");
+         }
        elsif (/$ELSE_PATTERN/o)
-       {
-           if (! @cond_stack)
-           {
-               &am_line_error ($., "else without if");
-           }
-           elsif ($cond_stack[$#cond_stack] =~ /_FALSE$/)
-           {
-               &am_line_error ($., "else after else");
-           }
-           else
-           {
-               $cond_stack[$#cond_stack]
-                 = condition_negate ($cond_stack[$#cond_stack]);
-               $cond = conditional_string (@cond_stack);
-           }
-       }
+         {
+           $cond = cond_stack_else ($1, $2, "$amfile:$.");
+         }
        elsif (/$ENDIF_PATTERN/o)
-       {
-           if (! @cond_stack)
-           {
-               &am_line_error ($., "endif without if");
-           }
-           else
-           {
-               pop @cond_stack;
-               $cond = conditional_string (@cond_stack);
-           }
-       }
+         {
+           $cond = cond_stack_endif ($1, $2, "$amfile:$.");
+         }
+
        elsif (/$RULE_PATTERN/o)
        {
            # Found a rule.
@@ -6608,43 +6680,17 @@ sub file_contents_internal ($%)
 
         # Handling the conditionals.
         elsif (/$IF_PATTERN/o)
-       {
-           my $new_cond = $1;
-           &am_line_error ($., "$new_cond does not appear in AM_CONDITIONAL")
-               if ! $configure_cond{$new_cond} && $new_cond !~ /^TRUE|FALSE$/;
-           push (@cond_stack,
-                 ($new_cond =~ /^TRUE|FALSE$/) ? "$new_cond" : 
"${new_cond}_TRUE");
-           $cond = conditional_string (@cond_stack);
-       }
+         {
+           $cond = cond_stack_if ($1, $2, $basename);
+         }
        elsif (/$ELSE_PATTERN/o)
-       {
-           if (! @cond_stack)
-           {
-               &am_error ("else without if");
-           }
-           elsif ($cond_stack[$#cond_stack] =~ /_FALSE$/)
-           {
-               &am_error ("else after else");
-           }
-           else
-           {
-             $cond_stack[$#cond_stack] =
-               condition_negate ($cond_stack[$#cond_stack]);
-             $cond = conditional_string (@cond_stack);
-           }
-       }
+         {
+           $cond = cond_stack_else ($1, $2, $basename);
+         }
        elsif (/$ENDIF_PATTERN/o)
-       {
-           if (! @cond_stack)
-           {
-               &am_error ("endif without if");
-           }
-           else
-           {
-               pop @cond_stack;
-               $cond = conditional_string (@cond_stack);
-           }
-       }
+         {
+           $cond = cond_stack_endif ($1, $2, $basename);
+         }
 
         # Handling rules.
        elsif (/$RULE_PATTERN/mso)
@@ -6780,12 +6826,12 @@ sub transform (%)
        if ($val)
        {
            $result .= "s/\Q?$token?\E//gm;s/^.*\Q?!$token?\E.*\\n//gm;";
-           $result .= "s/\Q%?$token%\E/TRUE/gm;s/\Q%!$token%\E/FALSE/gm;";
+           $result .= "s/\Q%?$token%\E/TRUE/gm;";
        }
        else
        {
            $result .= "s/\Q?!$token?\E//gm;s/^.*\Q?$token?\E.*\\n//gm;";
-           $result .= "s/\Q%?$token%\E/FALSE/gm;s/\Q%!$token%\E/TRUE/gm;";
+           $result .= "s/\Q%?$token%\E/FALSE/gm;";
        }
     }
 
Index: automake.texi
--- automake.texi Mon, 26 Feb 2001 23:44:40 +0100 akim (am/f/34_automake.t 1.8 
644)
+++ automake.texi Sun, 01 Apr 2001 19:13:54 +0200 akim (am/f/34_automake.t 1.8 
644)
@@ -3400,9 +3400,23 @@ @node Conditionals, Gnits, Include, Top
 This trivial example could also be handled using EXTRA_PROGRAMS
 (@pxref{A Program}).
 
-You may only test a single variable in an @code{if} statement.  The
address@hidden statement may be omitted.  Conditionals may be nested to any
-depth.
+You may only test a single variable in an @code{if} statement, possibly
+negated using @samp{!}.  The @code{else} statement may be omitted.
+Conditionals may be nested to any depth.  You may specify an argument to
address@hidden in which case it must be the negation of the condition used
+for the current @code{if}.  Similarly you may specify the condition
+which is closed by an @code{end}:
+
address@hidden
+if DEBUG
+DBG = debug
+else !DEBUG
+DBG =
+endif !DEBUG
address@hidden example
+
address@hidden
+Unbalanced conditions are errors.
 
 Note that conditionals in Automake are not the same as conditionals in
 GNU Make.  Automake conditionals are checked at configure time by the
Index: ansi2knr.am
--- ansi2knr.am Wed, 28 Mar 2001 22:05:50 +0200 akim (am/h/37_ansi2knr.a 1.2 
644)
+++ ansi2knr.am Sat, 31 Mar 2001 19:03:07 +0200 akim (am/h/37_ansi2knr.a 1.2 
644)
@@ -30,7 +30,7 @@
 %ANSI2KNR-DIR%/ansi2knr:
        cd %ANSI2KNR-DIR% && $(MAKE) $(AM_MAKEFLAGS) ansi2knr
 
-else %?ANSI2KNR-DIR%
+else !%?ANSI2KNR-DIR%
 
 ## Substitution from AM_C_PROTOTYPES.  This makes it be built only when
 ## necessary.
@@ -39,7 +39,7 @@
        $(LINK) ansi2knr.$(OBJEXT) $(LIBS)
 ansi2knr.$(OBJEXT): $(CONFIG_HEADER)
 
-endif %?ANSI2KNR-DIR%
+endif !%?ANSI2KNR-DIR%
 
 
 ## ------------------- ##
@@ -47,7 +47,7 @@
 ## ------------------- ##
 
 
-if %!ANSI2KNR-DIR%
+if !%?ANSI2KNR-DIR%
 .PHONY: clean-krextra
 
 clean-am: clean-krextra
@@ -59,7 +59,7 @@
 ## should remove it (and if the maintainer built it, then
 ## maintainer-clean should remove it).
        -rm -f ansi2knr
-endif %!ANSI2KNR-DIR%
+endif !%?ANSI2KNR-DIR%
 
 
 
Index: lex.am
--- lex.am Sun, 11 Mar 2001 20:30:44 +0100 akim (am/h/36_lex.am 1.1 644)
+++ lex.am Sat, 31 Mar 2001 19:02:15 +0200 akim (am/h/36_lex.am 1.1 644)
@@ -23,6 +23,6 @@
 %LEX_SUFFIX%%C_SUFFIX%:
 if %?YLWRAP%
        $(SHELL) $(YLWRAP) $(LEX) $< $(LEX_OUTPUT_ROOT).c $@ -- $(AM_LFLAGS) 
$(LFLAGS)
-else
+else !%?YLWRAP%
        $(LEX) $(AM_LFLAGS) $(LFLAGS) $< && mv $(LEX_OUTPUT_ROOT).c $@
-endif %?YLWRAP%
+endif !%?YLWRAP%
Index: stamp-vti
--- stamp-vti Mon, 26 Feb 2001 23:44:40 +0100 akim (am/f/36_stamp-vti 1.7 644)
+++ stamp-vti Sun, 01 Apr 2001 19:10:01 +0200 akim (am/f/36_stamp-vti 1.7 644)
@@ -1,4 +1,4 @@
address@hidden UPDATED 26 February 2001
address@hidden UPDATED-MONTH February 2001
address@hidden UPDATED 1 April 2001
address@hidden UPDATED-MONTH April 2001
 @set EDITION 1.4e
 @set VERSION 1.4e
Index: tags.am
--- tags.am Sun, 18 Mar 2001 20:59:31 +0100 akim (am/g/12_tags.am 1.10 644)
+++ tags.am Sat, 31 Mar 2001 19:01:37 +0200 akim (am/g/12_tags.am 1.10 644)
@@ -85,9 +85,9 @@
 ## Make sure we have something to run etags on.
        test -z "$(ETAGS_ARGS)%CONFIG%$$unique$(LISP)$$tags" \
          || etags $(ETAGS_ARGS) $$tags %CONFIG% $$unique $(LISP)
-else %?TAGS%
+else !%?TAGS%
 TAGS:
-endif %?TAGS%
+endif !%?TAGS%
 
 
 
Index: texinfos.am
--- texinfos.am Wed, 14 Mar 2001 22:49:34 +0100 akim (am/g/10_texinfos.a 1.20 
644)
+++ texinfos.am Sat, 31 Mar 2001 19:01:18 +0200 akim (am/g/10_texinfos.a 1.20 
644)
@@ -27,10 +27,10 @@
 RECURSIVE_TARGETS += info-recursive dvi-recursive
 .PHONY info: info-recursive
 .PHONY dvi: dvi-recursive
-else %?SUBDIRS%
+else !%?SUBDIRS%
 info: info-am
 dvi: dvi-am
-endif %?SUBDIRS%
+endif !%?SUBDIRS%
 
 info-am: $(INFO_DEPS)
 dvi-am: $(DVIS)
@@ -55,9 +55,9 @@
 if %?SUBDIRS%
 RECURSIVE_TARGETS += install-info-recursive
 .PHONY install-info: install-info-recursive
-else %?SUBDIRS%
+else !%?SUBDIRS%
 .PHONY install-info: install-info-am
-endif %?SUBDIRS%
+endif !%?SUBDIRS%
 endif %?INSTALL-INFO%
 install-info-am: $(INFO_DEPS)
        @$(NORMAL_INSTALL)
Index: version.texi
--- version.texi Mon, 26 Feb 2001 23:44:40 +0100 akim (am/f/35_version.te 1.7 
644)
+++ version.texi Sun, 01 Apr 2001 19:10:01 +0200 akim (am/f/35_version.te 1.7 
644)
@@ -1,4 +1,4 @@
address@hidden UPDATED 26 February 2001
address@hidden UPDATED-MONTH February 2001
address@hidden UPDATED 1 April 2001
address@hidden UPDATED-MONTH April 2001
 @set EDITION 1.4e
 @set VERSION 1.4e
Index: yacc.am
--- yacc.am Tue, 13 Mar 2001 00:07:50 +0100 akim (am/h/35_yacc.am 1.2 644)
+++ yacc.am Sat, 31 Mar 2001 19:02:35 +0200 akim (am/h/35_yacc.am 1.2 644)
@@ -20,7 +20,7 @@
 %YACC_SUFFIX%%C_SUFFIX%:
 if %?YLWRAP%
        $(SHELL) $(YLWRAP) $(YACC) $< y.tab.c $*%C_SUFFIX% y.tab.h $*.h -- 
$(AM_YFLAGS) $(YFLAGS)
-else
+else !%?YLWRAP%
        $(YACC) $(AM_YFLAGS) $(YFLAGS) $< && mv y.tab.c $*%C_SUFFIX%
        if test -f y.tab.h; then \
          if cmp -s y.tab.h $*.h; then \
@@ -29,4 +29,4 @@
            mv y.tab.h $*.h; \
          fi \
        fi
-endif %?YLWRAP%
+endif !%?YLWRAP%



reply via email to

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