Index: ChangeLog from Raja R Harinath * lib/Automake/Variable.pm (@EXPORT): Remove traverse_variable_recursively and require_variables_for_variable. (require_variables_for_variable, traverse_variable_recursively) (_traverse_variable_recursively_worker): Convert to Automake::Variable methods, remove support for being invoked with variable names, and rename to ... (requires_variables, traverse_recursively) (_do_recursive_traversal): ... these. (_value_as_list_recursive_worker, transform_variable_recursively): Update to reflect changes. * automake.in (handle_LIBOBJS, handle_ALLOCA) (handle_libraries, handle_ltlibraries, am_primary_prefixes): Likewise. (define_objects_from_sources): Fix typo in comment. Index: automake.in =================================================================== RCS file: /cvs/automake/automake/automake.in,v retrieving revision 1.1491 diff -u -p -u -r1.1491 automake.in --- automake.in 2 Aug 2003 14:14:58 -0000 1.1491 +++ automake.in 3 Aug 2003 03:38:23 -0000 @@ -2011,7 +2011,7 @@ sub define_objects_from_sources ($$$$$$$ transform_variable_recursively ($var, $objvar, 'am__objects', $nodefine, $where, - # The transfom code to run on each filename. + # The transform code to run on each filename. sub { my ($subvar, $val, $cond, $full_cond) = @_; my @trans = &handle_single_transform_list ($subvar, $topparent, @@ -2211,12 +2211,8 @@ sub handle_LIBOBJS ($$$) $lt ||= ''; my $myobjext = ($1 ? 'l' : '') . 'o'; - if (! keys %libsources) - { - require_variables_for_variable ($var, - "address@hidden@ used", - $lt . 'LIBOBJS'); - } + $var->requires_variables ("address@hidden@ used", $lt . 'LIBOBJS') + if ! keys %libsources; foreach my $iter (keys %libsources) { @@ -2252,8 +2248,7 @@ sub handle_ALLOCA ($$$) my ($var, $cond, $lt) = @_; my $myobjext = ($lt ? 'l' : '') . 'o'; $lt ||= ''; - require_variables_for_variable ($var, "address@hidden@ used", - $lt . 'ALLOCA'); + $var->requires_variables ("address@hidden@ used", $lt . 'ALLOCA'); $dep_files{'$(DEPDIR)/alloca.P' . $myobjext} = 1; require_file_with_macro ($cond, $var, FOREIGN, 'alloca.c'); &saw_extension ('c'); @@ -2502,9 +2497,11 @@ sub handle_libraries my @prefix = am_primary_prefixes ('LIBRARIES', 0, 'lib', 'pkglib', 'noinst', 'check'); - require_variables_for_variable ($prefix[0] . '_LIBRARIES', - 'library used', 'RANLIB') - if (@prefix); + if (@prefix) + { + my $var = var ($prefix[0] . '_LIBRARIES'); + $var->requires_variables ('library used', 'RANLIB'); + } foreach my $pair (@liblist) { @@ -2588,9 +2585,11 @@ sub handle_ltlibraries my @prefix = am_primary_prefixes ('LTLIBRARIES', 0, 'lib', 'pkglib', 'noinst', 'check'); - require_variables_for_variable ($prefix[0] . '_LTLIBRARIES', - 'Libtool library used', 'LIBTOOL') - if (@prefix); + if (@prefix) + { + my $var = var ($prefix[0] . '_LTLIBRARIES'); + $var->requires_variables ('Libtool library used', 'LIBTOOL'); + } my %liblocations = (); # Location (in Makefile.am) of each library. @@ -6574,12 +6573,10 @@ sub am_primary_prefixes ($$@) } # A not explicitely valid directory is allowed if Xdir is defined. elsif (! defined $valid{$X} && - require_variables_for_variable ($varname, - "`$varname' is used", - "${X}dir")) + $var->requires_variables ("`$varname' is used", "${X}dir")) { # Nothing to do. Any error message has been output - # by require_variables_for_variable. + # by $var->requires_variables. } else { Index: lib/Automake/Variable.pm =================================================================== RCS file: /cvs/automake/automake/lib/Automake/Variable.pm,v retrieving revision 1.13 diff -u -p -u -r1.13 Variable.pm --- lib/Automake/Variable.pm 2 Aug 2003 04:27:02 -0000 1.13 +++ lib/Automake/Variable.pm 3 Aug 2003 03:38:23 -0000 @@ -38,10 +38,9 @@ use vars '@ISA', '@EXPORT', '@EXPORT_OK' variable_delete variables_dump set_seen - require_variables require_variables_for_variable + require_variables variable_value output_variables - traverse_variable_recursively transform_variable_recursively); =head1 NAME @@ -191,8 +190,8 @@ my %_silent_variable_override = # the named of the helper variable used to append to VAR in CONDITIONS. my %_appendvar = (); -# Each call to C gets an unique label. -# This is used to detect recursively defined variables. +# Each call to C gets an +# unique label. This is used to detect recursively defined variables. my $_traversal = 0; @@ -756,9 +755,8 @@ sub _value_as_list_recursive_worker ($$$ { my ($var, $cond_filter, $loc_wanted) = @_; - return traverse_variable_recursively - ($var, - # Construct [$location, $value] pairs if requested. + return $var->traverse_recursively + (# Construct [$location, $value] pairs if requested. sub { my ($var, $val, $cond, $full_cond) = @_; return [$var->rdef ($cond)->location, $val] if $loc_wanted; @@ -791,7 +789,7 @@ sub has_conditional_contents ($) # because we found a condition, or for some other error. eval { - $self->traverse_variable_recursively + $self->traverse_recursively (sub { my ($subvar, $val, $cond, $full_cond) = @_; @@ -1320,23 +1318,24 @@ sub require_variables ($$$@) return $res; } -=item C<$count = require_variables_for_variable ($var, $reason, @variables)> +=item C<$count = $var->requires_variables ($reason, @variables)> -Same as C, but take a variable name as first argument. +Same as C, but a method of Automake::Variable. C<@variables> should be defined in the same conditions as C<$var> is -defined. C<$var> can be a variable name or an C. +defined. =cut -sub require_variables_for_variable ($$@) +sub requires_variables ($$@) { my ($var, $reason, @args) = @_; - $var = rvar ($var) unless ref $var; + my $res = 0; for my $cond ($var->conditions->conds) { - return require_variables ($var->rdef ($cond)->location, $reason, - $cond, @args); + $res += require_variables ($var->rdef ($cond)->location, $reason, + $cond, @args); } + return $res; } @@ -1396,18 +1395,14 @@ sub output_variables () return $res; } -=item C +=item C<$var-Etraverse_recursively (&fun_item, &fun_collect, [$cond_filter])> -=item C<$var-Etraverse_variable_recursively (&fun_item, &fun_collect, [$cond_filter])> +Split the value of the Automake::Variable C<$var> on space, and +traverse its components recursively. If C<$cond_filter> is an +C, process any conditions which are true when +C<$cond_filter> is true. Otherwise, process all conditions. -Split the value of the variable C<$var> on space, and traverse its -componants recursively. (C<$var> may be a variable name in the first -syntax. It must be an C otherwise.) If -C<$cond_filter> is an C, process any conditions -which are true when C<$cond_filter> is true. Otherwise, process all -conditions. - -We distinguish to kinds of items in the content of C<$var>. +We distinguish two kinds of items in the content of C<$var>. Terms that look like C<$(foo)> or C<${foo}> are subvariables and cause recursion. Other terms are assumed to be filenames. @@ -1442,8 +1437,8 @@ arguments: Typically you should do C<$cond->merge ($parent_cond)> to recompute the C<$full_cond> associated to C<@result>. C<&fun_collect> may return a list of items, that will be used as the result of -C<&traverse_variable_recursively> (the top-level, or it's recursive -calls). +C (the top-level, or it's +recursive calls). =cut @@ -1451,27 +1446,23 @@ calls). # substitutions currently in force. my @_substfroms; my @_substtos; -sub traverse_variable_recursively ($&&;$) +sub traverse_recursively ($&&;$) { ++$_traversal; @_substfroms = (); @_substtos = (); my ($var, $fun_item, $fun_collect, $cond_filter) = @_; - return _traverse_variable_recursively_worker ($var, $var, - $fun_item, $fun_collect, - $cond_filter, TRUE) + return $var->_do_recursive_traversal ($var, + $fun_item, $fun_collect, + $cond_filter, TRUE) } -# The guts of &traverse_variable_recursively. -sub _traverse_variable_recursively_worker ($$&&$$) +# The guts of Automake::Variable::traverse_recursively. +sub _do_recursive_traversal ($$&&$$) { my ($var, $parent, $fun_item, $fun_collect, $cond_filter, $parent_cond) = @_; - # Don't recurse into undefined variables and mark - # existing variable as examined. - $var = set_seen $var; - return () - unless $var; + $var->set_seen; if ($var->{'scanned'} == $_traversal) { @@ -1505,38 +1496,39 @@ sub _traverse_variable_recursively_worke # only of Emacs's indentation.) if ($val =~ /^\$\{([^\}]*)\}$/ || $val =~ /^\$\(([^\)]*)\)$/) { - my $subvar = $1; + my $subvarname = $1; # If the user uses a losing variable name, just ignore it. # This isn't ideal, but people have requested it. - next if ($subvar =~ /address@hidden@/); - + next if ($subvarname =~ /address@hidden@/); # See if the variable is actually a substitution reference my ($from, $to); - my @temp_list; # This handles substitution references like ${foo:.a=.b}. - if ($subvar =~ /^([^:]*):([^=]*)=(.*)$/o) + if ($subvarname =~ /^([^:]*):([^=]*)=(.*)$/o) { - $subvar = $1; + $subvarname = $1; $to = $3; $from = quotemeta $2; } push @_substfroms, $from; push @_substtos, $to; - my @res = - &_traverse_variable_recursively_worker ($subvar, $parent, - $fun_item, - $fun_collect, - $cond_filter, - $full_cond); + my $subvar = var ($subvarname); + # Don't recurse into undefined variables. + next unless $subvar; + + my @res = $subvar->_do_recursive_traversal ($parent, + $fun_item, + $fun_collect, + $cond_filter, + $full_cond); push (@result, @res); pop @_substfroms; pop @_substtos; } - elsif ($fun_item) # $var is a filename we must process + elsif ($fun_item) # $var is a filename we must process { my $substnum=$#_substfroms; while ($substnum >= 0) @@ -1546,7 +1538,8 @@ sub _traverse_variable_recursively_worke $substnum -= 1; } - # Make sure you update the doc of &traverse_variable_recursively + # Make sure you update the doc of + # Automake::Variable::traverse_recursively # if you change the prototype of &fun_item. my @transformed = &$fun_item ($var, $val, $cond, $full_cond); push (@result, @transformed); @@ -1559,7 +1552,7 @@ sub _traverse_variable_recursively_worke # is free to use the same variable several times in the same definition. $var->{'scanned'} = -1; - # Make sure you update the doc of &traverse_variable_recursively + # Make sure you update the doc of Automake::Variable::traverse_recursively # if you change the prototype of &fun_collect. return &$fun_collect ($var, $parent_cond, @allresults); } @@ -1637,7 +1630,7 @@ Arguments are: (this assumes &fun_item has some useful side-effect) $where context into which variable definitions are done &fun_item a transformation function -- see the documentation - of &fun_item in traverse_variable_recursively. + of &fun_item in Automake::Variable::traverse_recursively. This returns the string C<"\$($RESVAR)">. @@ -1647,13 +1640,10 @@ sub transform_variable_recursively ($$$$ { my ($var, $resvar, $base, $nodefine, $where, $fun_item) = @_; - # Convert $var here, even though &traverse_variable_recursively - # would do it, because we need to compare $var and $subvar below. $var = ref $var ? $var : rvar $var; - my $res = &traverse_variable_recursively - ($var, - $fun_item, + my $res = $var->traverse_recursively + ($fun_item, # The code that define the variable holding the result # of the recursive transformation of a subvariable. sub {