automake
[Top][All Lists]
Advanced

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

43-load-header-vars-once.patch


From: Akim Demaille
Subject: 43-load-header-vars-once.patch
Date: Sun, 11 Mar 2001 19:09:36 +0100

I had to write this one under the pressure of variable_define which
doesn't want one variable to be defined several times.  Given that it
was due to a hack, fixing it using the regular mechanism seems the
right choice.  In addition the code is much smaller.

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        Avoid reading twice header-vars.am as now variable_define
        complains.

        * automake.in (&define_standard_variables): Don't output the
        variables.
        (&read_main_am_file): Output first user variables, then Automake
        variables.
        Don't call twice &define_standard_variables.
        Save variable comments in $am_vars.
        (&variable_output): New.
        (&file_contents_internal): New.
        Save variable comments in $am_vars.
        (&file_contents): Use it.

Index: Makefile.in
--- Makefile.in Thu, 08 Mar 2001 23:52:12 +0100 akim (am/h/16_Makefile.i 1.42 
644)
+++ Makefile.in Sun, 11 Mar 2001 16:18:08 +0100 akim (am/h/16_Makefile.i 1.42 
644)
@@ -11,6 +11,9 @@
 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 # PARTICULAR PURPOSE.

address@hidden@
+
+
 SHELL = @SHELL@

 srcdir = @srcdir@
@@ -59,8 +62,6 @@

 host_alias = @host_alias@
 host_triplet = @host@
-
address@hidden@
 AMDEP = @AMDEP@
 AMTAR = @AMTAR@
 AWK = @AWK@
@@ -74,7 +75,6 @@
 VERSION = @VERSION@
 _am_include = @_am_include@
 install_sh = @install_sh@
-

 AUTOMAKE_OPTIONS = gnits 1.4
 MAINT_CHARSET = latin1
Index: automake.in
--- automake.in Sun, 11 Mar 2001 14:42:10 +0100 akim (am/f/39_automake.i 1.163 
755)
+++ automake.in Sun, 11 Mar 2001 16:20:58 +0100 akim (am/f/39_automake.i 1.163 
755)
@@ -5490,6 +5490,8 @@ sub variable_dump ($)
                    ? "+=" : "=");
       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 "    $vcond => $conditional{$var}{$vcond}\n";
@@ -6149,6 +6151,28 @@ sub variable_value_as_list_worker
     return @result;
 }

+
+# &variable_output ($VAR)
+# -----------------------
+sub variable_output ($)
+{
+  my ($var) = @_;
+
+  $output_vars .= $am_vars{$var}
+    if defined $am_vars{$var};
+
+  foreach my $cond (sort by_condition keys %{$conditional{$var}})
+    {
+      my $val = $conditional{$var}{$cond};
+      my $output_var = ($var . ' '
+                       . $def_type{$var} . "= "
+                       . $val);
+      $output_var =~ s/^/&make_condition ($cond)/meg;
+      $output_vars .= $output_var . "\n";
+    }
+}
+
+
 # This is just a wrapper for variable_value_as_list_worker that
 # initializes the global hash `vars_scanned'.  This hash is used to
 # avoid infinite recursion.
@@ -6406,6 +6430,8 @@ sub read_am_file

              if (!/\\$/)
                {
+                 $am_vars{$last_var_name} = $comment . $spacing;
+                 $comment = $spacing = '';
                  variable_define ($last_var_name, 0,
                                   $last_var_type, $cond,
                                   $last_var_value, $.);
@@ -6485,14 +6511,14 @@ sub read_am_file
                $last_var_value = $3 . "\n";
            }

-           # FIXME: this doesn't always work correctly; it will group
-           # all comments for a given variable, no matter where
-           # defined.
-           $am_vars{$last_var_name} = $comment . $spacing;
-           $comment = $spacing = '';
-
            if (!/\\$/)
              {
+               # FIXME: this doesn't always work correctly; it will
+               # group all comments for a given variable, no matter
+               # where defined.
+               $am_vars{$last_var_name} = $comment . $spacing;
+               $comment = $spacing = '';
+
                variable_define ($last_var_name, 0,
                                 $last_var_type, $cond,
                                 $last_var_value, $.);
@@ -6554,17 +6580,24 @@ sub read_am_file
 # twice.
 sub define_standard_variables
 {
-    $output_vars .=
-        &file_contents ('header-vars',
-                       ('BUILD'    => $seen_canonical == $AC_CANONICAL_SYSTEM,
-                        'HOST'     => $seen_canonical,
-                        'TARGET'   => $seen_canonical == $AC_CANONICAL_SYSTEM,
-                        'top_builddir' => backname ($relative_dir)));
-
-    foreach my $curs (sort keys %configure_vars)
+    my $saved_output_vars = $output_vars;
+    my ($comments, $variables, $rules) =
+      &file_contents_internal ('header-vars',
+                    ('BUILD'    => $seen_canonical == $AC_CANONICAL_SYSTEM,
+                     'HOST'     => $seen_canonical,
+                     'TARGET'   => $seen_canonical == $AC_CANONICAL_SYSTEM,
+                     'top_builddir' => backname ($relative_dir)));
+
+    # This will output the definitions in $output_vars, which we don't
+    # want...
+    foreach my $var (sort keys %configure_vars)
     {
-       &define_configure_variable ($curs);
+        &define_configure_variable ($var);
+        push (@var_list, $var);
     }
+
+    # ... hence, we restore $output_vars.
+    $output_vars = $saved_output_vars . $comments . $rules;
 }

 # Read main am file.
@@ -6579,79 +6612,38 @@ sub read_main_am_file
        &prog_error ("variable defined before read_main_am_file");
       }

+    # Generate copyright header for generated Makefile.in.
+    # We do discard the output of predefined variables, handled below.
+    $output_vars = ("# $in_file_name generated automatically by automake "
+                  . $VERSION . " from $am_file_name.\n");
+    $output_vars .= $gen_copyright;
+
     # We want to predefine as many variables as possible.  This lets
     # the user set them with `+=' in Makefile.am.  However, we don't
     # want these initial definitions to end up in the output quite
-    # yet.  So we adopt a hack: read the `.am' file twice, throwing
-    # away the output the first time.  We also squirrel away a list of
-    # all the variables defined by the .am file so that we know which
-    # ones to remove from the content list.
-
-    # First pass.
+    # yet.  So we just load them, but output them later.
     &define_standard_variables;
-    # Deep copy. With `%saved_conditional = %conditional' modifying
-    # one modifes the other.
-    my %saved_conditional;
-    foreach my $var (keys %conditional)
-      {
-       foreach my $cond (keys %{$conditional{$var}})
-         {
-           $saved_conditional{$var}{$cond} = $conditional{$var}{$cond};
-         }
-      }

-    # Read user file, but discard text of variable assignments we just
-    # made.
-    $output_vars = '';
+    # Read user file, which might override some of our values.
     &read_am_file ($amfile);

-    # Now dump the variables that were defined.  We do it in the same
-    # order in which they were defined (skipping duplicates).
-    my %done;
-    foreach my $var (@var_list)
+    # Ouput all the Automake variables.  If the user changed one, then
+    # it is now marked as owned by the user.
+    foreach my $var (uniq @var_list)
     {
-       next
-         if $done{$var};
-       $done{$var} = 1;
-
-       # Don't process Automake variables.
-       next
-         if $var_is_am{$var};
-
-       $output_vars .= $am_vars{$var};
-
-       foreach my $vcond (sort by_condition keys %{$conditional{$var}})
-         {
-           my $val = $conditional{$var}{$vcond};
-           my $output_var = ($var . ' '
-                             . $def_type{$var} . "= "
-                             . $val);
-           $output_var =~ s/^/&make_condition ($vcond)/meg;
-           $output_vars .= $output_var . "\n";
-         }
+       # Don't process user variables.
+        variable_output ($var)
+         unless !$var_is_am{$var};
     }

-    # Generate copyright header for generated Makefile.in.
-    my $ov = $output_vars;
-    $output_vars = ("# $in_file_name generated automatically by automake "
-                  . $VERSION . " from $am_file_name.\n");
-    $output_vars .= $gen_copyright;
-
-    # Now go through and delete all the variables that the user did
-    # not change.
-    foreach my $var (keys %saved_conditional)
+    # Now dump the user variables that were defined.  We do it in the same
+    # order in which they were defined (skipping duplicates).
+    foreach my $var (uniq @var_list)
     {
-       if (variable_value ($var) eq $saved_conditional{$var}{'TRUE'})
-       {
-           variable_delete ($var);
-       }
+       # Don't process Automake variables.
+        variable_output ($var)
+         unless $var_is_am{$var};
     }
-
-    # Re-read the standard variables, and this time keep their
-    # contributions to the output.  Then add the user's output to the
-    # end.
-    &define_standard_variables;
-    $output_vars .= $ov;
 }

 ################################################################
@@ -6673,12 +6665,12 @@ sub flatten
 }


-# $CONTENTS
-# &file_contents ($BASENAME, [%TRANSFORM])
-# ----------------------------------------
+# ($COMMENT, $VARIABLES, $RULES)
+# &file_contents_internal ($BASENAME, [%TRANSFORM])
+# -------------------------------------------------
 # Return contents of a file from $am_dir, automatically skipping
 # macros or rules which are already known.
-sub file_contents ($%)
+sub file_contents_internal ($%)
 {
     my ($basename, %transform) = @_;

@@ -6780,7 +6772,6 @@ sub file_contents ($%)
        {
            # Stick comments before the incoming macro or rule.
            $comment = "$_\n";
-
        }

         # Handling the conditionals.
@@ -6876,6 +6867,7 @@ sub file_contents ($%)
              if /\\$/;;

            # Accumulating variables must not be output.
+           $am_vars{$var} .= "$separator$comment";
            variable_define ($var, 1, $type, $cond, $val, $.);
            push (@var_list, $var);

@@ -6896,7 +6888,21 @@ sub file_contents ($%)
        }
     }

-    return $result_vars . $result_rules . $comment;
+    return ($comment, $result_vars, $result_rules);
+}
+
+
+# $CONTENTS
+# &file_contents ($BASENAME, [%TRANSFORM])
+# ----------------------------------------
+# Return contents of a file from $am_dir, automatically skipping
+# macros or rules which are already known.
+sub file_contents ($%)
+{
+    my ($basename, %transform) = @_;
+    my ($comments, $variables, $rules) = file_contents_internal ($basename,
+                                                                %transform);
+    return "$comments$variables$rules";
 }


Index: m4/Makefile.in
--- m4/Makefile.in Thu, 08 Mar 2001 23:52:12 +0100 akim (am/h/15_Makefile.i 
1.33 644)
+++ m4/Makefile.in Sun, 11 Mar 2001 16:18:08 +0100 akim (am/h/15_Makefile.i 
1.33 644)
@@ -11,6 +11,9 @@
 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 # PARTICULAR PURPOSE.

address@hidden@
+
+
 SHELL = @SHELL@

 srcdir = @srcdir@
@@ -59,8 +62,6 @@

 host_alias = @host_alias@
 host_triplet = @host@
-
address@hidden@
 AMDEP = @AMDEP@
 AMTAR = @AMTAR@
 AWK = @AWK@
@@ -74,7 +75,6 @@
 VERSION = @VERSION@
 _am_include = @_am_include@
 install_sh = @install_sh@
-

 AUTOMAKE_OPTIONS = gnits
 MAINT_CHARSET = latin1
Index: tests/Makefile.in
--- tests/Makefile.in Sat, 10 Mar 2001 11:41:12 +0100 akim (am/h/14_Makefile.i 
1.37 644)
+++ tests/Makefile.in Sun, 11 Mar 2001 16:18:08 +0100 akim (am/h/14_Makefile.i 
1.37 644)
@@ -11,6 +11,9 @@
 # even the implied warranty of MERCHANTABILITY or FITNESS FOR A
 # PARTICULAR PURPOSE.

address@hidden@
+
+
 SHELL = @SHELL@

 srcdir = @srcdir@
@@ -59,8 +62,6 @@

 host_alias = @host_alias@
 host_triplet = @host@
-
address@hidden@
 AMDEP = @AMDEP@
 AMTAR = @AMTAR@
 AWK = @AWK@
@@ -74,7 +75,6 @@
 VERSION = @VERSION@
 _am_include = @_am_include@
 install_sh = @install_sh@
-

 AUTOMAKE_OPTIONS = gnits




reply via email to

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