+2004-08-08 Alexandre Duret-Lutz <adl@gnu.org>
+
+ * lib/Automake/Variable.pm (%_primary_dict): New hash.
+ (_new, variable_delete): Update %_primary_dict.
+ (variables): Accept an optional $suffix argument.
+ * automake.in (check_typos, am_primary_prefixes): Use that
+ optional argument to restrict the loops over the variables we are
+ interested in.
+
2004-08-06 Alexandre Duret-Lutz <adl@gnu.org>
* lib/Automake/Item.pm (def): Rewrite more concisely, it's faster
# It is ok if the user sets this particular variable.
set_seen 'AM_LDFLAGS';
- foreach my $var (variables)
+ foreach my $primary ('SOURCES', 'LIBADD', 'LDADD', 'LDFLAGS', 'DEPENDENCIES')
{
- my $varname = $var->name;
- # A configure variable is always legitimate.
- next if exists $configure_vars{$varname};
-
- my $check = 0;
- foreach my $primary ('_SOURCES', '_LIBADD', '_LDADD', '_LDFLAGS',
- '_DEPENDENCIES')
+ foreach my $var (variables $primary)
{
- if ($varname =~ /^(.*)$primary$/)
+ my $varname = $var->name;
+ # A configure variable is always legitimate.
+ next if exists $configure_vars{$varname};
+
+ for my $cond ($var->conditions->conds)
{
- $check = $1;
- last;
+ $varname =~ /^(?:nobase_)?(?:dist_|nodist_)?(.*)_[[:alnum:]]+$/;
+ msg_var ('syntax', $var, "variable `$varname' is defined but no"
+ . " program or\nlibrary has `$1' as canonic name"
+ . " (possible typo)")
+ unless $var->rdef ($cond)->seen;
}
}
- next unless $check;
-
- for my $cond ($var->conditions->conds)
- {
- msg_var ('syntax', $var, "variable `$varname' is defined but no"
- . " program or\nlibrary has `$check' as canonic name"
- . " (possible typo)")
- unless $var->rdef ($cond)->seen;
- }
}
}
local $_;
my %valid = map { $_ => 0 } @prefixes;
$valid{'EXTRA'} = 0;
- foreach my $var (variables)
+ foreach my $var (variables $primary)
{
# Automake is allowed to define variables that look like primaries
# but which aren't. E.g. INSTALL_sh_DATA.
my $varname = $var->name;
- if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_$primary$/)
+ if ($varname =~ /^(nobase_)?(dist_|nodist_)?(.*)_[[:alnum:]]+$/)
{
my ($base, $dist, $X) = ($1 || '', $2 || '', $3 || '');
if ($dist ne '' && ! $can_dist)
$valid{"$base$dist$X"} = 1;
}
}
+ else
+ {
+ prog_error "unexpected variable name: $varname";
+ }
}
# Return only those which are actually defined.
$_hooks{$var} = $fun;
}
-=item C<variables>
+=item C<variables ([$suffix])>
Returns the list of all L<Automake::Variable> instances. (I.e., all
-variables defined so far.)
+variables defined so far.) If C<$suffix> is supplied, return only
+the L<Automake::Variable> instances that ends with C<_$suffix>.
=cut
-use vars '%_variable_dict';
-sub variables ()
+use vars '%_variable_dict', '%_primary_dict';
+sub variables (;$)
{
- return values %_variable_dict;
+ my ($suffix) = @_;
+ if ($suffix)
+ {
+ if (exists $_primary_dict{$suffix})
+ {
+ return values %{$_primary_dict{$suffix}};
+ }
+ else
+ {
+ return ();
+ }
+ }
+ else
+ {
+ return values %_variable_dict;
+ }
}
=item C<Automake::Variable::reset>
sub reset ()
{
%_variable_dict = ();
+ %_primary_dict = ();
%_appendvar = ();
@_var_order = ();
%_gen_varname = ();
my $self = Automake::Item::new ($class, $name);
$self->{'scanned'} = 0;
$_variable_dict{$name} = $self;
+ if ($name =~ /_([[:alnum:]]+)$/)
+ {
+ $_primary_dict{$1}{$name} = $self;
+ }
return $self;
}
delete $_variable_dict{$var}{'defs'}{$cond};
}
}
+ if ($var =~ /_([[:alnum:]]+)$/)
+ {
+ delete $_primary_dict{$1}{$var};
+ }
}
=item C<$str = variables_dump>