I am still on my way to if/endif in *.am files. I am unifying the
handling of the different kinds of variable so that I can extract
simple variable handling functions which are currently coded here and
there, and in particular in read_am_file.
Once I have extracted these, it should be simple to support if/endif
in *.am files.
Patch is several chunks because it took me several steps to reach the
right one.
Index: ChangeLog
from Akim Demaille <[EMAIL PROTECTED]>
* automake.in (%am_var_defs): Replace with...
(%var_is_am): this.
(&handle_installdirs, &variable_value_as_list_worker, &read_am_file)
(&file_contents, am_primary_&prefixes): Adjust.
(&variable_defined, &define_variable): The actual semantics is
`user defined'.
(&read_main_am_file): Assert the var is user defined when
outputting @var_list.
Index: automake.in
--- automake.in Thu, 08 Mar 2001 21:36:34 +0100 akim (am/f/39_automake.i 1.124 755)
+++ automake.in Thu, 08 Mar 2001 21:36:46 +0100 akim (am/f/39_automake.i 1.124 755)
@@ -448,10 +448,10 @@
# variable was first defined with `+='.
my %var_was_plus_eq;
-# This holds definitions of all variables defined in .am files.
+# 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 %am_var_defs;
+# 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
@@ -632,7 +632,7 @@ sub initialize_per_input ()
%var_was_plus_eq = ();
- %am_var_defs = ();
+ %var_is_am = ();
%conditional = ();
@@ -3827,7 +3827,7 @@ sub handle_installdirs ()
$output_rules .=
&file_contents ('install',
('_am_installdirs'
- => $am_var_defs{'_am_installdirs'} || ''));
+ => $contents{'_am_installdirs'} || ''));
}
@@ -5606,15 +5606,15 @@ sub check_ambiguous_conditional ($$)
# $BOOLEAN
# &variable_defined ($VAR, [$COND])
# ---------------------------------
-# See if a variable exists. $VAR is the variable name, and $COND is
-# the condition which we should check. If no condition is given, we
-# currently return true if the variable is defined under any
-# condition.
+# See if a variable exists, and is a user variable. $VAR is the
+# variable name, and $COND is the condition which we should check. If
+# no condition is given, we currently return true if the variable is
+# defined under any condition.
sub variable_defined ($$)
{
my ($var, $cond) = @_;
- if (defined $contents{$var})
+ if (defined $contents{$var} && !$var_is_am{$var})
{
if ($cond && $conditional{$var})
{
@@ -5990,7 +5990,7 @@ sub variable_value_as_list_worker
my ($var, $cond, $parent) = @_;
my @result = ();
- if (! defined $contents{$var} && ! defined $am_var_defs{$var})
+ if (! defined $contents{$var})
{
if (defined $targets{$var})
{
@@ -6034,13 +6034,6 @@ sub variable_value_as_list_worker
}
}
}
- elsif (defined $am_var_defs{$var})
- {
- $vars_scanned{$var} = 1;
- &variable_conditionally_defined ($var, $parent);
- $content_seen{$var} = 1;
- push (@result, &value_to_list ($var, $am_var_defs{$var}, $cond));
- }
else
{
$vars_scanned{$var} = 1;
@@ -6398,16 +6391,11 @@ sub read_am_file
# If first assignment, set `+=' indicator.
$var_was_plus_eq{$last_var_name} =
($type eq '+'
- && ! defined $am_var_defs{$last_var_name});
+ && ! $var_is_am{$last_var_name});
}
-
+ $var_is_am{$last_var_name} = 0;
if ($type eq '+')
{
- if (! defined $contents{$last_var_name}
- && defined $am_var_defs{$last_var_name})
- {
- $contents{$last_var_name} = $am_var_defs{$last_var_name};
- }
if (substr ($contents{$last_var_name}, -1) eq "\n")
{
# Insert a backslash before a trailing newline.
@@ -6791,17 +6781,17 @@ sub file_contents ($%)
&prog_error ("$file:$.: macro `$var' with trailing backslash")
if /\\$/;;
# Accumulating variables must not be output.
- $am_var_defs{$var} = ''
- unless defined $am_var_defs{$var};
+ $contents{$var} = ''
+ unless defined $contents{$var};
+ $var_is_am{$var} = 1;
if ($type eq '+')
{
- $am_var_defs{$var} .= ($am_var_defs{$var} && ' ') . $val;
+ $contents{$var} .= ($contents{$var} && ' ') . $val;
}
else
{
- $am_var_defs{$var} = $val;
- $result_vars .= "$separator$comment$_\n"
- unless defined $contents{$var};
+ $contents{$var} = $val;
+ $result_vars .= "$separator$comment$_\n";
}
$comment = $separator = '';
}
@@ -6860,6 +6850,11 @@ sub am_primary_prefixes
$valid{'EXTRA'} = 0;
foreach my $varname (keys %contents)
{
+ # Automake is allowed to define variables that look like they
+ # are magic variables, such as INSTALL_DATA.
+ next
+ if $var_is_am{$varname};
+
if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
{
my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
Index: automake.in
--- automake.in Thu, 08 Mar 2001 21:38:32 +0100 akim (am/f/39_automake.i 1.125 755)
+++ automake.in Thu, 08 Mar 2001 21:55:18 +0100 akim (am/f/39_automake.i 1.125 755)
@@ -6783,7 +6781,8 @@ sub file_contents ($%)
# Accumulating variables must not be output.
$contents{$var} = ''
unless defined $contents{$var};
- $var_is_am{$var} = 1;
+ $var_is_am{$var} = 1
+ unless defined $var_is_am{$var};
if ($type eq '+')
{
$contents{$var} .= ($contents{$var} && ' ') . $val;
@@ -6791,7 +6790,12 @@ sub file_contents ($%)
else
{
$contents{$var} = $val;
- $result_vars .= "$separator$comment$_\n";
+ # If the user has set some variables we were in charge
+ # of (which is detected by the first reading of
+ # `header-vars.am'), we must not output them.
+ $result_vars .= "$separator$comment$_\n"
+ if $var_is_am{$var};
+
}
$comment = $separator = '';
}
Index: automake.in
--- automake.in Thu, 08 Mar 2001 21:57:11 +0100 akim (am/f/39_automake.i 1.126 755)
+++ automake.in Thu, 08 Mar 2001 22:41:09 +0100 akim (am/f/39_automake.i 1.126 755)
@@ -6062,7 +6062,7 @@ sub variable_value_as_list
# define_variable ($VAR, $VALUE)
# ------------------------------
-# Define a new variable VAR to VALUE, but only if not already defined.
+# Define a new user variable VAR to VALUE, but only if not already defined.
sub define_variable
{
my ($var, $value) = @_;
@@ -6072,6 +6072,7 @@ sub define_variable
$output_vars .= $var . ' = ' . $value . "\n";
$contents{$var} = $value;
$content_seen{$var} = 1;
+ $var_is_am{$var} = 0;
}
elsif ($var_was_plus_eq{$var})
{