{
# FIXME: We should disallow conditional definitions of AUTOMAKE_OPTIONS.
if (process_option_list ($var->rdef (TRUE)->location,
- $var->value_as_list_recursive (TRUE)))
+ $var->value_as_list_recursive (cond_filter =>
+ TRUE)))
{
return 1;
}
my $var = var ($varname);
if ($var)
{
- @files = $var->value_as_list_recursive ('all');
+ @files = $var->value_as_list_recursive;
}
elsif ($prefix eq '')
{
if ($var->has_conditional_contents)
{
$distvar = "am__${varname}_DIST";
- my @files =
- uniq ($var->value_as_list_recursive ('all'));
+ my @files = uniq ($var->value_as_list_recursive);
define_pretty_variable ($distvar, TRUE, $where, @files);
}
push @dist_sources, "\$($distvar)"
$rewrite = "^" . quotemeta ($iter) . "\$";
# Only require the file if it is not a built source.
my $bs = var ('BUILT_SOURCES');
- if (! $bs
- || ! grep (/$rewrite/, $bs->value_as_list_recursive ('all')))
+ if (! $bs || ! grep (/$rewrite/, $bs->value_as_list_recursive))
{
require_file_with_macro ($cond, $var, FOREIGN, $iter);
}
# Get the installation directory of each library.
(my $dir = $key) =~ s/^nobase_//;
my $var = rvar ($key . '_LTLIBRARIES');
- for my $pair ($var->loc_and_value_as_list_recursive ('all'))
+ for my $pair ($var->value_as_list_recursive (location => 1))
{
my ($where, $lib) = @$pair;
# We reject libraries which are installed in several places,
my $libname_rx = "^lib.*\.la";
my $ldvar = var ("${xlib}_LDFLAGS") || var ('AM_LDFLAGS');
my $ldvar2 = var ('LDFLAGS');
- if (($ldvar && grep (/-module/, $ldvar->value_as_list_recursive ('all')))
- || ($ldvar2
- && grep (/-module/, $ldvar2->value_as_list_recursive ('all'))))
+ if (($ldvar && grep (/-module/, $ldvar->value_as_list_recursive))
+ || ($ldvar2 && grep (/-module/, $ldvar2->value_as_list_recursive)))
{
# Relax name checking for libtool modules.
$libname_rx = "\.la";
my $d = var 'DISTCLEANFILES';
my $c = var 'CLEANFILES';
my @f = ();
- push @f, $d->value_as_list_recursive (TRUE) if $d;
- push @f, $c->value_as_list_recursive (TRUE) if $c;
+ push @f, $d->value_as_list_recursive (inner_expand => 1) if $d;
+ push @f, $c->value_as_list_recursive (inner_expand => 1) if $c;
@f = map { s|[^A-Za-z_0-9*\[\]\-]|\\$&|g; s|\*|[^/]*|g; $_; } @f;
my $user_cleaned_files = '^(?:' . join ('|', @f) . ')$';
- foreach my $texi ($info_texinfos->value_as_list_recursive ('all'))
+ foreach my $texi ($info_texinfos->value_as_list_recursive (inner_expand
+ => 1))
{
my $infobase = $texi;
$infobase =~ s/\.(txi|texinfo|texi)$//;
my $var = var ($varname);
if ($var)
{
- foreach ($var->value_as_list_recursive ('all'))
+ foreach ($var->value_as_list_recursive)
{
# A page like `foo.1c' goes into man1dir.
if (/\.([0-9a-z])([a-z]*)$/)
# appropriate condition. This is meaningful if the nature of
# the distribution should depend upon the configure options
# used.
- foreach ($extra_dist->value_as_list_recursive ('all'))
+ foreach ($extra_dist->value_as_list_recursive)
{
next if /^\@.*\@$/;
next unless s,/+[^/]+$,,;
# We have to check DIST_COMMON for extra directories in case the
# user put a source used in AC_OUTPUT into a subdir.
my $topsrcdir = backname ($relative_dir);
- foreach (rvar ('DIST_COMMON')->value_as_list_recursive ('all'))
+ foreach (rvar ('DIST_COMMON')->value_as_list_recursive)
{
next if /^\@.*\@$/;
s/\$\(top_srcdir\)/$topsrcdir/;
$dist_subdir_name = 'DIST_SUBDIRS';
define_pretty_variable
('DIST_SUBDIRS', TRUE, INTERNAL,
- uniq ($subdirs->value_as_list_recursive ('all')));
+ uniq ($subdirs->value_as_list_recursive));
}
else
{
return
unless $subdirs;
- my @subdirs = $subdirs->value_as_list_recursive ('all');
+ my @subdirs = $subdirs->value_as_list_recursive;
my @dsubdirs = ();
my $dsubdirs = var ('DIST_SUBDIRS');
- @dsubdirs = $dsubdirs->value_as_list_recursive ('all')
+ @dsubdirs = $dsubdirs->value_as_list_recursive
if $dsubdirs;
# If an `obj/' directory exists, BSD make will enter it before
if (-d 'po')
{
- my @subdirs = $subdirs->value_as_list_recursive ('all');
+ my @subdirs = $subdirs->value_as_list_recursive;
msg_var ('syntax', $subdirs,
"AM_GNU_GETTEXT used but `po' not in SUBDIRS")
# actual suffixes, and not $(SUFFIXES). Some versions of make
# do not like variable substitutions on the .SUFFIXES line.
my @user_suffixes = ($suffixes
- ? $suffixes->value_as_list_recursive ('all')
- : ());
+ ? $suffixes->value_as_list_recursive : ());
my %suffixes = map { $_ => 1 } @suffixes;
delete @suffixes{@user_suffixes};
# Append actual contents of where_PRIMARY variable to
# @result, skipping @substitutions@.
- foreach my $locvals ($one_var->loc_and_value_as_list_recursive ('all'))
+ foreach my $locvals ($one_var->value_as_list_recursive (location => 1))
{
my ($loc, $value) = @$locvals;
# Skip configure substitutions.
return @result;
}
-=item C<@values = $var-E<gt>value_as_list_recursive ($cond)>
+=item C<@values = $var-E<gt>value_as_list_recursive ([%options])>
-Return the list of values of C<$var> and any subvariable in condition
-C<$cond>.
+Return the contents of C<$var> as a list, split on whitespace. This
+will recursively follow C<$(...)> and C<${...}> inclusions. It
+preserves C<@...@> substitutions.
-=cut
+C<%options> is a list of option for C<Variable::traverse_recursively>
+(see this method). The most useful is C<cond_filter>:
-sub value_as_list_recursive ($$)
-{
- return &_value_as_list_recursive_worker (@_, 0);
-}
+ $var->value_as_list_recursive (cond_filter => $cond)
-=item C<@values = $var-E<gt>loc_and_value_as_list_recursive ($cond)>
+will return the contents of C<$var> and any subvariable in all
+conditions implied by C<$cond>.
-Return the values of C<$var> and any subvariable in condition
-C<$cond> as a list of C<[$location, @values]> pairs.
+C<%options> can also carry options specific to C<value_as_list_recursive>.
+Presently, the only such option is C<location =E<gt> 1> which instructs
+C<value_as_list_recursive> to return a list of C<[$location, @values]> pairs.
=cut
-sub loc_and_value_as_list_recursive ($$)
+sub value_as_list_recursive ($;%)
{
- return &_value_as_list_recursive_worker (@_, 1);
-}
-
-# @VALUE
-# &_value_as_list_recursive_worker ($VAR, $COND, $LOC_WANTED)
-# -----------------------------------------------------------
-# Return contents of VAR as a list, split on whitespace. This will
-# recursively follow $(...) and ${...} inclusions. It preserves @...@
-# substitutions. If COND is 'all', then all values under all
-# conditions should be returned; if COND is a particular condition
-# then only the value for that condition should be returned;
-# otherwise, warn if VAR is conditionally defined. If $LOC_WANTED is set,
-# return a list of [$location, $value] instead of a list of values.
-sub _value_as_list_recursive_worker ($$$)
-{
- my ($var, $cond_filter, $loc_wanted) = @_;
+ my ($var, %options) = @_;
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;
+ return [$var->rdef ($cond)->location, $val] if $options{'location'};
return $val;
},
# Collect results.
my ($var, $parent_cond, @allresults) = @_;
return map { my ($cond, @vals) = @$_; return @vals } @allresults;
},
- $cond_filter);
+ %options);
}
return $res;
}
-=item C<$var-E<gt>traverse_recursively (&fun_item, &fun_collect, [$cond_filter])>
+=item C<$var-E<gt>traverse_recursively (&fun_item, &fun_collect, [cond_filter =E<gt> $cond_filter], [inner_expand =E<gt> 1])>
Split the value of the Automake::Variable C<$var> on space, and
-traverse its components recursively. If C<$cond_filter> is an
-C<Automake::Condition>, process any conditions which are true when
-C<$cond_filter> is true. Otherwise, process all conditions.
+traverse its components recursively.
+
+If C<$cond_filter> is an C<Automake::Condition>, process any
+conditions which are true when C<$cond_filter> is true. Otherwise,
+process all conditions.
We distinguish two kinds of items in the content of C<$var>.
Terms that look like C<$(foo)> or C<${foo}> are subvariables
conditions inherited from parent variables
during recursion
+If C<inner_expand> is set, variable references occuring in filename
+(as in C<$(BASE).ext>) are expansed before the filename is passed to
+C<&fun_item>.
+
C<&fun_item> may return a list of items, they will be passed to
C<&fun_store> later on. Define C<&fun_item> as C<undef> when it serve
no purpose, this will speed things up.
# substitutions currently in force.
my @_substfroms;
my @_substtos;
-sub traverse_recursively ($&&;$)
+sub traverse_recursively ($&&;%)
{
++$_traversal;
@_substfroms = ();
@_substtos = ();
- my ($var, $fun_item, $fun_collect, $cond_filter) = @_;
+ my ($var, $fun_item, $fun_collect, %options) = @_;
+ my $cond_filter = $options{'cond_filter'};
+ my $inner_expand = $options{'inner_expand'};
return $var->_do_recursive_traversal ($var,
$fun_item, $fun_collect,
- $cond_filter, TRUE)
+ $cond_filter, TRUE, $inner_expand)
}
# The guts of Automake::Variable::traverse_recursively.
-sub _do_recursive_traversal ($$&&$$)
+sub _do_recursive_traversal ($$&&$$$)
{
- my ($var, $parent, $fun_item, $fun_collect, $cond_filter, $parent_cond) = @_;
+ my ($var, $parent, $fun_item, $fun_collect, $cond_filter, $parent_cond,
+ $inner_expand) = @_;
$var->set_seen;
}
my @result = ();
my $full_cond = $cond->merge ($parent_cond);
- foreach my $val ($var->value_as_list ($cond, $parent, $parent_cond))
+
+ my @to_process = $var->value_as_list ($cond, $parent, $parent_cond);
+ while (@to_process)
{
+ my $val = shift @to_process;
# If $val is a variable (i.e. ${foo} or $(bar), not a filename),
# handle the sub variable recursively.
# (Backslashes before `}' and `)' within brackets are here to
$fun_item,
$fun_collect,
$cond_filter,
- $full_cond);
+ $full_cond,
+ $inner_expand);
push (@result, @res);
pop @_substfroms;
pop @_substtos;
+
+ next;
}
- elsif ($fun_item) # $var is a filename we must process
+ # Try to expand variable references inside filenames such as
+ # `$(NAME).txt'. We do not handle `:.foo=.bar'
+ # substitutions, but it would make little sense to use this
+ # here anyway.
+ elsif ($inner_expand
+ && ($val =~ /\$\{([^\}]*)\}/ || $val =~ /\$\(([^\)]*)\)/))
+ {
+ my $subvarname = $1;
+ my $subvar = var $subvarname;
+ if ($subvar)
+ {
+ # Replace the reference by its value, and reschedule
+ # for expansion.
+ foreach my $c ($subvar->conditions->conds)
+ {
+ if (ref $cond_filter)
+ {
+ # Ignore conditions that don't match $cond_filter.
+ next if ! $c->true_when ($cond_filter);
+ # If we found out several definitions of $var
+ # match $cond_filter then we are in trouble.
+ # Tell the user we don't support this.
+ $subvar->check_defined_unconditionally ($var,
+ $full_cond)
+ if $cond_once;
+ $cond_once = 1;
+ }
+ my $subval = $subvar->rdef ($c)->value;
+ $val =~ s/\$\{$subvarname\}/$subval/g;
+ $val =~ s/\$\($subvarname\)/$subval/g;
+ unshift @to_process, split (' ', $val);
+ }
+ next;
+ }
+ # We do not know any variable with this name. Fall through
+ # to filename processing.
+ }
+
+ if ($fun_item) # $var is a filename we must process
{
my $substnum=$#_substfroms;
while ($substnum >= 0)
return $name;
}
-=item C<$resvar = transform_variable_recursively ($var, $resvar, $base, $nodefine, $where, &fun_item)>
+=item C<$resvar = transform_variable_recursively ($var, $resvar, $base, $nodefine, $where, &fun_item, [%options])>
-=item C<$resvar = $var-E<gt>transform_variable_recursively ($resvar, $base, $nodefine, $where, &fun_item)>
+=item C<$resvar = $var-E<gt>transform_variable_recursively ($resvar, $base, $nodefine, $where, &fun_item, [%options])>
Traverse C<$var> recursively, and create a C<$resvar> variable in
which each filename in C<$var> have been transformed using
This returns the string C<"\$($RESVAR)">.
+C<%options> is a list of options to pass to
+C<Variable::traverse_recursively> (see this method).
+
=cut
-sub transform_variable_recursively ($$$$$&)
+sub transform_variable_recursively ($$$$$&;%)
{
- my ($var, $resvar, $base, $nodefine, $where, $fun_item) = @_;
+ my ($var, $resvar, $base, $nodefine, $where, $fun_item, %options) = @_;
$var = ref $var ? $var : rvar $var;
}
}
return "\$($varname)";
- });
+ },
+ %options);
return $res;
}