# 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;
# %contents.
my %targets;
-# Same as %CONDITIONAL, but for targets.
+# Same as %VAR_VALUE, but for targets.
my %target_conditional;
# This is the conditional stack.
# 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 ()
# ------------------------
@suffixes = ();
- %var_was_plus_eq = ();
-
+ %var_value = ();
+ %var_line = ();
+ %var_comment = ();
+ %var_type = ();
%var_is_am = ();
- %conditional = ();
-
- %content_lines = ();
-
%content_seen = ();
%targets = ();
$need_link = 0;
- %am_vars = ();
@var_list = ();
- %def_type = ();
}
# 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')
{
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";
}
{
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);
}
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)
$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 `+=' "
}
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
{
# 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.
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.
{
$var_is_am{$var} = $var_is_am;
}
-
- $def_type{$var} = ($type eq ':') ? ':' : '';
}
{
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};
}
{
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})
{
}
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;
$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));
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 /^#/;
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$/;
{
my ($var) = @_;
&check_variable_defined_unconditionally ($var);
- return $conditional{$var}{'TRUE'};
+ return $var_value{$var}{'TRUE'};
}
my ($var, $cond, $parent) = @_;
my @result = ();
- if (! defined $conditional{$var})
+ if (! defined $var_value{$var})
{
if (defined $targets{$var})
{
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));
}
}
$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
{
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";
}
{
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));
}
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 `+='");
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 = '';
macro_define ($last_var_name, 0,
$last_var_type, $cond,
rule_define ($1, 0, $cond, $.);
- $content_lines{$1} = $.;
+ $var_line{$1} = $.;
$output_trailer .= $comment . $spacing;
$output_trailer .= &make_condition (@conditional_stack);
$output_trailer .= $_;
# 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 = '';
macro_define ($last_var_name, 0,
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");
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";
macro_define ($var, 1, $type, $cond, $val, $.);
push (@var_list, $var);
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.
# 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})
{