diff options
author | Alexandre Duret-Lutz <adl@gnu.org> | 2006-04-09 13:56:33 +0000 |
---|---|---|
committer | Alexandre Duret-Lutz <adl@gnu.org> | 2006-04-09 13:56:33 +0000 |
commit | 9d0eaef6e6a5aa18194602dd0be1b0af8f8e0d1b (patch) | |
tree | f2f7618c5d0a232ce219a8e13a6c59280fad5bc0 /lib/Automake/Variable.pm | |
parent | d2e347928cea947cfcf19eefea2bc975ecb6e092 (diff) | |
download | automake-9d0eaef6e6a5aa18194602dd0be1b0af8f8e0d1b.tar.gz |
* lib/Automake/Variable.pm (_hash_varname, _hash_values): New functions.
(_gen_varname): Use _hash_values, and return a flag indicating whether
the variable name was generated or reused.
(transform_variable_recursively): Do not redefine variables that
are reused, and try to reuse the variable being transformed.
* tests/check2.test: Make sure TESTS hasn't been redefined.
* tests/check5.test, tests/exeext4.test: Make sure variables have
been reused.
* tests/subst2.test: Make sure bin_PROGRAMS gets rewritten.
Diffstat (limited to 'lib/Automake/Variable.pm')
-rw-r--r-- | lib/Automake/Variable.pm | 84 |
1 files changed, 67 insertions, 17 deletions
diff --git a/lib/Automake/Variable.pm b/lib/Automake/Variable.pm index 49cd2a143..1f89c5fe1 100644 --- a/lib/Automake/Variable.pm +++ b/lib/Automake/Variable.pm @@ -1,4 +1,4 @@ -# Copyright (C) 2003, 2004, 2005 Free Software Foundation, Inc. +# Copyright (C) 2003, 2004, 2005, 2006 Free Software Foundation, Inc. # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -142,6 +142,11 @@ my @_var_order; # Keys have the form "(COND1)VAL1(COND2)VAL2..." where VAL1 and VAL2 # are the values of the variable for condition COND1 and COND2. my %_gen_varname = (); +# $_gen_varname_n{$base} is the number of variables generated by +# _gen_varname() for $base. This is not the same as keys +# %{$_gen_varname{$base}} because %_gen_varname may also contain +# variables not generated by _gen_varname. +my %_gen_varname_n = (); # Declare the macros that define known variables, so we can # hint the user if she try to use one of these variables. @@ -338,6 +343,7 @@ sub reset () $_appendvar = 0; @_var_order = (); %_gen_varname = (); + %_gen_varname_n = (); $_traversal = 0; } @@ -1463,14 +1469,48 @@ sub _do_recursive_traversal ($$&&$$$$) return &$fun_collect ($var, $parent_cond, @allresults); } -# $VARNAME +# _hash_varname ($VAR) +# -------------------- +# Compute the key associated $VAR in %_gen_varname. +# See _gen_varname() below. +sub _hash_varname ($) +{ + my ($var) = @_; + my $key = ''; + foreach my $cond ($var->conditions->conds) + { + my @values = $var->value_as_list ($cond); + $key .= "($cond)@values"; + } + return $key; +} + +# _hash_values (@VALUES) +# ---------------------- +# Hash @VALUES for %_gen_varname. @VALUES shoud be a list +# of pairs: ([$cond, @values], [$cond, @values], ...). +# See _gen_varname() below. +sub _hash_values (@) +{ + my $key = ''; + foreach my $pair (@_) + { + my ($cond, @values) = @$pair; + $key .= "($cond)@values"; + } + return $key; +} +# ($VARNAME, $GENERATED) # _gen_varname ($BASE, @DEFINITIONS) # --------------------------------- # Return a variable name starting with $BASE, that will be # used to store definitions @DEFINITIONS. # @DEFINITIONS is a list of pair [$COND, @OBJECTS]. # -# If we already have a $BASE-variable containing @DEFINITIONS, reuse it. +# If we already have a $BASE-variable containing @DEFINITIONS, reuse +# it and set $GENERATED to 0. Otherwise construct a new name and set +# $GENERATED to 1. +# # This way, we avoid combinatorial explosion of the generated # variables. Especially, in a Makefile such as: # @@ -1501,19 +1541,17 @@ sub _do_recursive_traversal ($$&&$$$$) sub _gen_varname ($@) { my $base = shift; - my $key = ''; - foreach my $pair (@_) - { - my ($cond, @values) = @$pair; - $key .= "($cond)@values"; - } + my $key = _hash_values @_; - return $_gen_varname{$base}{$key} if exists $_gen_varname{$base}{$key}; + return ($_gen_varname{$base}{$key}, 0) + if exists $_gen_varname{$base}{$key}; - my $num = 1 + keys (%{$_gen_varname{$base}}); + my $num = 1 + ($_gen_varname_n{$base} || 0); + $_gen_varname_n{$base} = $num; my $name = "${base}_${num}"; $_gen_varname{$base}{$key} = $name; - return $name; + + return ($name, 1); } =item C<$resvar = transform_variable_recursively ($var, $resvar, $base, $nodefine, $where, &fun_item, [%options])> @@ -1557,12 +1595,24 @@ sub transform_variable_recursively ($$$$$&;%) # of the recursive transformation of a subvariable. sub { my ($subvar, $parent_cond, @allresults) = @_; + # If no definition is required, return anything: the result is + # not expected to be used, only the side effect of $fun_item + # should matter. + return 'report-me' if $nodefine; + # Cache $subvar, so that we reuse it if @allresults is the same. + my $key = _hash_varname $subvar; + $_gen_varname{$base}{$key} = $subvar->name; + # Find a name for the variable, unless this is the top-variable # for which we want to use $resvar. - my $varname = - ($var != $subvar) ? _gen_varname ($base, @allresults) : $resvar; - # Define the variable if required. - unless ($nodefine) + my ($varname, $generated) = + ($var != $subvar) ? _gen_varname ($base, @allresults) : ($resvar, 1); + + # Define the variable if we are not reusing a previously + # defined variable. At the top-level, we can also avoid redefining + # the variable if it already contains the same values. + if ($generated + && !($varname eq $var->name && $key eq _hash_values @allresults)) { # If the new variable is the source variable, we assume # we are trying to override a user variable. Delete @@ -1587,8 +1637,8 @@ sub transform_variable_recursively ($$$$$&;%) '', $where, VAR_PRETTY); } } - set_seen $varname; } + set_seen $varname; return "\$($varname)"; }, %options); |