automake
[Top][All Lists]
Advanced

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

63-rename-var-vars.patch


From: Akim Demaille
Subject: 63-rename-var-vars.patch
Date: Mon, 19 Mar 2001 10:21:58 +0100

The aim of this patch and the next is to clarify the status of
variables: who owns them, and how their defined type (+=, := or =) can
change.

I end up with a rule which is somewhat unsatisfying:

  # An Automake variable must be consistently defined with the same
  # sign by Automake.  A user variable must be set by either `=' or
  # `:=', and later promoted to `+='.
  if ($var_is_am)
    {
      if (defined $var_type{$var} && $var_type{$var} ne $type)
        {
          am_line_error ($var,
                         ("$var was set with `$var_type{$var}=' "
                          . "and is now set with `$type='"));
        }
    }
  else
    {
      if (!defined $var_type{$var} && $type eq '+')
        {
          am_line_error ($var, "$var must be set with `=' before using `+='");
        }
    }


I fail to understand why the user is not allowed to += a nonexistent
variable.


Index: ChangeLog
from  Akim Demaille  <address@hidden>

        * automake.in (%var_was_plus_eq): Rename as...
        (%var_type): this.
        (%def_type): Remove.
        (&variable_define): %var_type may now hold `', `+', or `:'.
        (%conditional, %am_vars, %content_lines): Rename as...
        (%var_value, %var_comment, %var_line): these.

Index: automake.in
--- automake.in Mon, 12 Mar 2001 22:31:11 +0100 akim (am/f/39_automake.i 1.181 
755)
+++ automake.in Mon, 12 Mar 2001 22:46:19 +0100 akim (am/f/39_automake.i 1.181 
755)
@@ -439,27 +439,19 @@
 # Suffixes found during a run.
 my @suffixes;

-# This maps a variable name onto a flag.  The flag is true iff the
-# variable was first defined with `+='.
-my %var_was_plus_eq;
-
-# Maps a variable name to true iff the variable was defined by Automake.
-# This is used during startup to determine which variables can be
-# assigned with `+='.
-my %var_is_am;
-
-# For a variable or target $ITEM which is defined conditionally,
-# this holds a hash of the conditional values.  The keys of
-# %CONDITIONAL{$ITEM} are the conditions (the variables which
-# configure will substitute), and the values, the associated
-# values (meaningless for targets).
+# Handling the variables.
 #
-# By definition, for an unconditional variable, this is empty.
-my %conditional;
-
-# This holds the line numbers at which various elements of
-# %conditional are defined.
-my %content_lines;
+# For a $VAR:
+# - $var_value{$VAR}{$COND} is its value associated to $COND,
+# - $var_line{$VAR} is where it has been defined,
+# - $var_comment{$VAR} are the comments associated to it.
+# - $var_type{$VAR} is how it has been defined (`', `+', or `:'),
+# - $var_is_am{$VAR} is true if the variable is owned by Automake.
+my %var_value;
+my %var_line;
+my %var_comment;
+my %var_type;
+my %var_is_am;

 # This holds a 1 if a particular variable was examined.
 my %content_seen;
@@ -468,7 +460,7 @@
 # %contents.
 my %targets;

-# Same as %CONDITIONAL, but for targets.
+# Same as %VAR_VALUE, but for targets.
 my %target_conditional;

 # This is the conditional stack.
@@ -588,17 +580,10 @@
 # True if we need `LINK' defined.  This is a hack.
 my $need_link;

-# The keys here are variables we want to dump at the end of this
-# function.  The values are corresponding comments.
-my %am_vars;
-
 # This is the list of such variables to output.
 # FIXME: Might be useless actually.
 my @var_list;

-# Is $am_var{'foo'} defined with `=', or `+='?
-my %def_type;
-

 # &initialize_per_input ()
 # ------------------------
@@ -619,14 +604,12 @@ sub initialize_per_input ()

     @suffixes = ();

-    %var_was_plus_eq = ();
-
+    %var_value = ();
+    %var_line = ();
+    %var_comment = ();
+    %var_type = ();
     %var_is_am = ();

-    %conditional = ();
-
-    %content_lines = ();
-
     %content_seen = ();

     %targets = ();
@@ -735,9 +718,7 @@ sub initialize_per_input ()

     $need_link = 0;

-    %am_vars = ();
     @var_list = ();
-    %def_type = ();
 }


@@ -2443,7 +2424,7 @@ sub handle_ltlibraries
 # EXTRA_ variables don't contain configure substitutions.
 sub check_typos
 {
-    foreach my $varname (keys %conditional)
+    foreach my $varname (keys %var_value)
     {
        foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
                             '_DEPENDENCIES')
@@ -5414,24 +5395,24 @@ sub variable_dump ($)
 {
   my ($var)= @_;

-  if (!exists $conditional{$var})
+  if (!exists $var_value{$var})
     {
       print STDERR "  $var does not exist\n";
     }
   else
     {
       my $var_is_am = $var_is_am{$var} ? "Automake" : "User";
-      my $where = (defined $content_lines{$var}
-                  ? $content_lines{$var} : "undefined");
-      my $pluseq = ((defined $var_was_plus_eq{$var} && $var_was_plus_eq{$var})
+      my $where = (defined $var_line{$var}
+                  ? $var_line{$var} : "undefined");
+      my $pluseq = ((defined $var_type{$var} && $var_type{$var})
                    ? "+=" : "=");
       print STDERR "  $var ($var_is_am, where = $where) $pluseq\n";
       print STDERR "  {\n";
-      print STDERR "$am_vars{$var}"
-       if defined $am_vars{$var};
-      foreach my $vcond (sort by_condition keys %{$conditional{$var}})
+      print STDERR "$var_comment{$var}"
+       if defined $var_comment{$var};
+      foreach my $vcond (sort by_condition keys %{$var_value{$var}})
        {
-         print STDERR "    $vcond => $conditional{$var}{$vcond}\n";
+         print STDERR "    $vcond => $var_value{$var}{$vcond}\n";
        }
       print STDERR "  }\n";
     }
@@ -5444,9 +5425,9 @@ sub variables_dump ()
 {
   my ($var)= @_;

-  print STDERR "%conditional =\n";
+  print STDERR "%var_value =\n";
   print STDERR "{\n";
-  foreach my $var (sort (keys %conditional))
+  foreach my $var (sort (keys %var_value))
     {
       variable_dump ($var);
     }
@@ -5544,7 +5525,7 @@ sub condition_negate ($)
 sub check_ambiguous_conditional ($$)
 {
     my ($var, $cond) = @_;
-    foreach my $vcond (keys %{$conditional{$var}})
+    foreach my $vcond (keys %{$var_value{$var}})
     {
        my $message;
        if ($vcond eq $cond)
@@ -5584,9 +5565,9 @@ sub variable_define ($$$$$$)
   $cond ||= 'TRUE';

   # A variable which was `+=' must not be `='.
-  if (defined $var_was_plus_eq{$var})
+  if (defined $var_type{$var})
     {
-      if ($var_was_plus_eq{$var} && $type ne '+')
+      if ($var_type{$var} && $type ne '+')
        {
          am_line_error ($var,
                         ("$var was set with `+=' "
@@ -5595,24 +5576,24 @@ sub variable_define ($$$$$$)
     }
   else
     {
-      $var_was_plus_eq{$var} = $type eq '+' && ! $var_is_am{$var};
+      $var_type{$var} = $type;
     }

   # Differentiate the first assignment (including with `+=').
-  if ($type eq '+' && defined $conditional{$var}{$cond})
+  if ($type eq '+' && defined $var_value{$var}{$cond})
     {
-      if (substr ($conditional{$var}{$cond}, -1) eq "\n")
+      if (substr ($var_value{$var}{$cond}, -1) eq "\n")
        {
          # Insert a backslash before a trailing newline.
-         $conditional{$var}{$cond} =
-           substr ($conditional{$var}{$cond}, 0, -1) . "\\\n";
+         $var_value{$var}{$cond} =
+           substr ($var_value{$var}{$cond}, 0, -1) . "\\\n";
        }
-      elsif ($conditional{$var}{$cond})
+      elsif ($var_value{$var}{$cond})
        {
          # Insert a separator.
-         $conditional{$var}{$cond} .= ' ';
+         $var_value{$var}{$cond} .= ' ';
        }
-       $conditional{$var}{$cond} .= $value;
+       $var_value{$var}{$cond} .= $value;
     }
   else
     {
@@ -5621,8 +5602,8 @@ sub variable_define ($$$$$$)
       # FIXME: We sometimes redefine some variables, but we want to keep
       # the original location.  More subs are needed to handle
       # properly variables.  Once this done, remove this hack.
-      $content_lines{$var} = $where
-       unless defined $content_lines{$var};
+      $var_line{$var} = $where
+       unless defined $var_line{$var};

       # There must be no previous value unless the user is redefining
       # an Automake variable or an AC_SUBST variable.
@@ -5630,7 +5611,7 @@ sub variable_define ($$$$$$)
        unless ($var_is_am{$var} && !$var_is_am
                || exists $configure_vars{$var});

-      $conditional{$var}{$cond} = $value;
+      $var_value{$var}{$cond} = $value;
     }

   # An Automake variable can be given to the user, but not the converse.
@@ -5638,8 +5619,6 @@ sub variable_define ($$$$$$)
     {
       $var_is_am{$var} = $var_is_am;
     }
-
-  $def_type{$var} = ($type eq ':') ? ':' : '';
 }


@@ -5650,10 +5629,11 @@ sub variable_delete ($)
 {
   my ($var) = @_;

-  delete $content_lines{$var};
-  delete $conditional{$var};
+  delete $var_value{$var};
+  delete $var_line{$var};
   delete $var_is_am{$var};
-  delete $def_type{$var};
+  delete $var_comment{$var};
+  delete $var_type{$var};
 }


@@ -5668,10 +5648,10 @@ sub variable_defined ($$)
 {
     my ($var, $cond) = @_;

-    # Unfortunately we can't just check for $conditional{VAR}{COND}
+    # Unfortunately we can't just check for $var_value{VAR}{COND}
     # as this would make perl create $condition{VAR}, which we
     # don't want.
-    if (!exists $conditional{$var})
+    if (!exists $var_value{$var})
       {
        if (defined $targets{$var})
          {
@@ -5682,13 +5662,13 @@ sub variable_defined ($$)
       }

     if ($var_is_am{$var}
-       || ($cond && !exists $conditional{$var}{$cond}))
+       || ($cond && !exists $var_value{$var}{$cond}))
       {
        # The variable is not defined for the given condition.
        return 0;
       }

-    # Even a conditional examination is good enough for us.  FIXME:
+    # Even a var_value examination is good enough for us.  FIXME:
     # really should maintain examined status on a per-condition basis.
     $content_seen{$var} = 1;
     return 1;
@@ -5772,7 +5752,7 @@ sub variable_conditions_sub
     $vars_scanned{$var} = 1;

     my @this_conds = ();
-    foreach my $vcond (keys %{$conditional{$var}})
+    foreach my $vcond (keys %{$var_value{$var}})
     {
        next
          if ! conditionals_true_when ((@parent_conds), ($vcond));
@@ -5781,7 +5761,7 @@ sub variable_conditions_sub

        push (@parent_conds, $vcond);
        my @subvar_conds = ();
-       foreach (split (' ', $conditional{$var}{$vcond}))
+       foreach (split (' ', $var_value{$var}{$vcond}))
        {
            # If a comment seen, just leave.
            last if /^#/;
@@ -5940,7 +5920,7 @@ sub variable_conditions_permutations
 sub check_variable_defined_unconditionally ($$)
 {
     my ($var, $parent) = @_;
-    foreach my $cond (keys %{$conditional{$var}})
+    foreach my $cond (keys %{$var_value{$var}})
     {
         next
          if $cond =~ /^TRUE|FALSE$/;
@@ -5967,7 +5947,7 @@ sub variable_value
 {
     my ($var) = @_;
     &check_variable_defined_unconditionally ($var);
-    return $conditional{$var}{'TRUE'};
+    return $var_value{$var}{'TRUE'};
 }


@@ -6048,7 +6028,7 @@ sub variable_value_as_list_worker
     my ($var, $cond, $parent) = @_;
     my @result = ();

-    if (! defined $conditional{$var})
+    if (! defined $var_value{$var})
     {
         if (defined $targets{$var})
          {
@@ -6068,9 +6048,9 @@ sub variable_value_as_list_worker
     elsif ($cond eq 'all')
     {
        $vars_scanned{$var} = 1;
-       foreach my $vcond (keys %{$conditional{$var}})
+       foreach my $vcond (keys %{$var_value{$var}})
        {
-           my $val = $conditional{$var}{$vcond};
+           my $val = $var_value{$var}{$vcond};
            push (@result, &value_to_list ($var, $val, $cond));
        }
     }
@@ -6079,9 +6059,9 @@ sub variable_value_as_list_worker
         $cond ||= 'TRUE';
        $vars_scanned{$var} = 1;
        my $onceflag;
-       foreach my $vcond (keys %{$conditional{$var}})
+       foreach my $vcond (keys %{$var_value{$var}})
        {
-           my $val = $conditional{$var}{$vcond};
+           my $val = $var_value{$var}{$vcond};
            if (&conditional_true_when ($vcond, $cond))
            {
                # Warn if we have an ambiguity.  It's hard to know how
@@ -6110,16 +6090,16 @@ sub variable_output ($@)
 {
   my ($var, @conds) = @_;

-  @conds = sort by_condition keys %{$conditional{$var}}
+  @conds = sort by_condition keys %{$var_value{$var}}
     unless @conds;

-  $output_vars .= $am_vars{$var}
-    if defined $am_vars{$var};
+  $output_vars .= $var_comment{$var}
+    if defined $var_comment{$var};

   foreach my $cond (@conds)
     {
-      my $val = $conditional{$var}{$cond};
-      my $output_var = "$var $def_type{$var}= $val";
+      my $val = $var_value{$var}{$cond};
+      my $output_var = "$var $var_type{$var}= $val";
       $output_var =~ s/^/&make_condition ($cond)/meg;
       $output_vars .= $output_var . "\n";
     }
@@ -6134,18 +6114,18 @@ sub variable_pretty_output ($@)
 {
   my ($var, @conds) = @_;

-  @conds = sort by_condition keys %{$conditional{$var}}
+  @conds = sort by_condition keys %{$var_value{$var}}
     unless @conds;

-  $output_vars .= $am_vars{$var}
-    if defined $am_vars{$var};
+  $output_vars .= $var_comment{$var}
+    if defined $var_comment{$var};

   foreach my $cond (@conds)
     {
-      my $val = $conditional{$var}{$cond};
+      my $val = $var_value{$var}{$cond};
       my $make_condition = make_condition ($cond);
       $output_vars .= pretty_print_internal ("$make_condition$var"
-                                            . " $def_type{$var}=",
+                                            . " $var_type{$var}=",
                                             "$make_condition\t",
                                             split (' ' , $val));
     }
@@ -6183,7 +6163,7 @@ sub define_pretty_variable
        variable_pretty_output ($var, $cond || 'TRUE');
        $content_seen{$var} = 1;
     }
-    elsif ($var_was_plus_eq{$var})
+    elsif ($var_type{$var})
     {
        &am_line_error ($var,
                        "internally generated variable `$var' was set with 
`+='");
@@ -6411,10 +6391,10 @@ sub read_am_file

              if (!/\\$/)
                {
-                 $am_vars{$last_var_name} .= "$spacing"
-                   if (!defined $am_vars{$last_var_name}
-                       || substr ($am_vars{$last_var_name}, -1) ne "\n");
-                 $am_vars{$last_var_name} .= "$comment";
+                 $var_comment{$last_var_name} .= "$spacing"
+                   if (!defined $var_comment{$last_var_name}
+                       || substr ($var_comment{$last_var_name}, -1) ne "\n");
+                 $var_comment{$last_var_name} .= "$comment";
                  $comment = $spacing = '';
                  variable_define ($last_var_name, 0,
                                   $last_var_type, $cond,
@@ -6469,7 +6449,7 @@ sub read_am_file

            rule_define ($1, 0, $cond, $.);

-           $content_lines{$1} = $.;
+           $var_line{$1} = $.;
            $output_trailer .= $comment . $spacing;
             $output_trailer .= &make_condition (@conditional_stack);
             $output_trailer .= $_;
@@ -6501,10 +6481,10 @@ sub read_am_file
                # group all comments for a given variable, no matter
                # where defined.
                # Accumulating variables must not be output.
-               $am_vars{$last_var_name} .= "$spacing"
-                 if (!defined $am_vars{$last_var_name}
-                     || substr ($am_vars{$last_var_name}, -1) ne "\n");
-               $am_vars{$last_var_name} .= "$comment";
+               $var_comment{$last_var_name} .= "$spacing"
+                 if (!defined $var_comment{$last_var_name}
+                     || substr ($var_comment{$last_var_name}, -1) ne "\n");
+               $var_comment{$last_var_name} .= "$comment";
                $comment = $spacing = '';

                variable_define ($last_var_name, 0,
@@ -6594,7 +6574,7 @@ sub read_main_am_file
     my ($amfile) = @_;

     # This supports the strange variable tricks we are about to play.
-    if (scalar keys %conditional > 0)
+    if (scalar keys %var_value > 0)
       {
        variables_dump ();
        &prog_error ("variable defined before read_main_am_file");
@@ -6890,10 +6870,10 @@ sub file_contents_internal ($%)
              if /\\$/;;

            # Accumulating variables must not be output.
-           $am_vars{$var} .= "$spacing"
-             if (!defined $am_vars{$var}
-                 || substr ($am_vars{$var}, -1) ne "\n");
-           $am_vars{$var} .= "$comment";
+           $var_comment{$var} .= "$spacing"
+             if (!defined $var_comment{$var}
+                 || substr ($var_comment{$var}, -1) ne "\n");
+           $var_comment{$var} .= "$comment";
            variable_define ($var, 1, $type, $cond, $val, $.);
            push (@var_list, $var);

@@ -6978,7 +6958,7 @@ sub am_primary_prefixes
     my %valid;
     grep ($valid{$_} = 0, @prefixes);
     $valid{'EXTRA'} = 0;
-    foreach my $varname (keys %conditional)
+    foreach my $varname (keys %var_value)
     {
         # Automake is allowed to define variables that look like they
         # are magic variables, such as INSTALL_DATA.
@@ -7630,11 +7610,11 @@ sub am_line_error
            # SYMBOL is a line number, so just add the colon.
            $file .= ':' . $symbol;
        }
-       elsif (defined $content_lines{$symbol})
+       elsif (defined $var_line{$symbol})
        {
            # SYMBOL is a variable defined in Makefile.am, so add the
            # line number we saved from there.
-           $file .= ':' . $content_lines{$symbol};
+           $file .= ':' . $var_line{$symbol};
        }
        elsif (defined $configure_vars{$symbol})
        {



reply via email to

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