From 9c3d8bd4a06677c99a01ad7174a13c9646c16112 Mon Sep 17 00:00:00 2001 From: Alexandre Duret-Lutz Date: Sun, 8 Aug 2004 17:11:24 +0000 Subject: [PATCH] * 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. --- ChangeLog | 9 +++++++++ automake.in | 40 ++++++++++++++++++---------------------- lib/Automake/Variable.pm | 35 ++++++++++++++++++++++++++++++----- 3 files changed, 57 insertions(+), 27 deletions(-) diff --git a/ChangeLog b/ChangeLog index bbe0b91f3..4177e7e99 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2004-08-08 Alexandre Duret-Lutz + + * 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 * lib/Automake/Item.pm (def): Rewrite more concisely, it's faster diff --git a/automake.in b/automake.in index 0d8a52f37..39e275a00 100755 --- a/automake.in +++ b/automake.in @@ -2684,31 +2684,23 @@ sub check_typos () # 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; - } } } @@ -6497,7 +6489,7 @@ sub am_primary_prefixes ($$@) 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. @@ -6511,7 +6503,7 @@ sub am_primary_prefixes ($$@) 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) @@ -6539,6 +6531,10 @@ sub am_primary_prefixes ($$@) $valid{"$base$dist$X"} = 1; } } + else + { + prog_error "unexpected variable name: $varname"; + } } # Return only those which are actually defined. diff --git a/lib/Automake/Variable.pm b/lib/Automake/Variable.pm index 30ffd26dc..c9455ce7c 100644 --- a/lib/Automake/Variable.pm +++ b/lib/Automake/Variable.pm @@ -295,17 +295,33 @@ sub hook ($$) $_hooks{$var} = $fun; } -=item C +=item C Returns the list of all L instances. (I.e., all -variables defined so far.) +variables defined so far.) If C<$suffix> is supplied, return only +the L 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 @@ -318,6 +334,7 @@ other internal data. sub reset () { %_variable_dict = (); + %_primary_dict = (); %_appendvar = (); @_var_order = (); %_gen_varname = (); @@ -420,6 +437,10 @@ sub _new ($$) my $self = Automake::Item::new ($class, $name); $self->{'scanned'} = 0; $_variable_dict{$name} = $self; + if ($name =~ /_([[:alnum:]]+)$/) + { + $_primary_dict{$1}{$name} = $self; + } return $self; } @@ -1012,6 +1033,10 @@ sub variable_delete ($@) delete $_variable_dict{$var}{'defs'}{$cond}; } } + if ($var =~ /_([[:alnum:]]+)$/) + { + delete $_primary_dict{$1}{$var}; + } } =item C<$str = variables_dump> -- 2.47.2