diff -p -u -r automake/ChangeLog automake_patch1/ChangeLog --- automake/ChangeLog Mon Aug 13 10:36:40 2001 +++ automake_patch1/ChangeLog Thu Aug 16 20:59:00 2001 @@ -1,3 +1,15 @@ +2001-08-16 Richard Boulton + + * automake.in (extract_variable_reference): New function, + containing functionality which was previously repeated several + times. + (define_objects_from_sources): Updated to use + extract_variable_reference(), and some comments added. + (variable_conditions_recursive_sub): Updated to use + extract_variable_reference(). + (value_to_list): Updated to use extract_variable_reference(). + (variable_conditions): Badly formatted comment fixed. + 2001-08-13 Richard Boulton * automake.in (handle_source_transform): Call diff -p -u -r automake/automake.in automake_patch1/automake.in --- automake/automake.in Mon Aug 13 10:36:40 2001 +++ automake_patch1/automake.in Thu Aug 16 20:59:00 2001 @@ -665,6 +665,7 @@ my %substnums = (); sub register_language (%); sub file_contents_internal ($$%); sub define_objects_from_sources ($$$$$$$); +sub variable_conditionally_defined_sub ($$); # &initialize_per_input () @@ -2032,6 +2033,53 @@ sub handle_single_transform_list ($$$$@) return @result; } +# ($ISVAR, $VARNAME, $FROM, $TO) +# extract_variable_reference ($INPUT) +# ----------------------------------- +# Extract a variable reference from the input string. +# Variable references in the forms $(name), ${name}, $(name:from=to) or +# ${name:from=to} are recognised and decomposed into the variable name, the +# "from" part of any substitution, and the "to" part of any substitution. +# +# Arguments: +# $INPUT The input string, which may or may not contain a variable +# reference. +# Returns: +# $ISVAR Whether a variable was found in $INPUT. +# $VARNAME The name of the variable. Undefined if variable name was a +# @...@ substitution. +# $FROM The from part of the substitution. Undefined if no substitution. +# $TO The to part of the substitution. Undefined if no substitution. +# +sub extract_variable_reference ($) +{ + my ($input) = @_; + my ($varname, $from, $to); + if ($input =~ /^\$\{([^}]*)\}$/ || $input =~ /^\$\(([^)]*)\)$/) + { + $varname = $1; + + # If the user uses a losing variable name, just ignore it. + # This isn't ideal, but people have requested it. + if ($varname =~ /address@hidden@/) + { + return ('true', undef, undef, undef); + } + + # See if the variable is actually a substitution reference + if ($varname =~ /$SUBST_REF_PATTERN/o) + { + $varname = $1; + $to = $3; + # Quote non-word characters in from. + ($from = $2) =~ s/(\W)/\\$1/g; + } + + return ('true', $varname, $from, $to); + } + return (''); +} + # $BOOL # define_objects_from_sources ($VAR, $OBJVAR, $NODEFINE, $ONE_FILE, # $OBJ, $PARENT, $TOPPARENT) @@ -2074,27 +2122,19 @@ sub define_objects_from_sources ($$$$$$$ my @result; foreach my $val (&variable_value_as_list ($var, $cond, $parent)) { - if ($val =~ /^\$\{([^}]*)\}$/ || $val =~ /^\$\(([^)]*)\)$/) + my ($isvar, $subvar, $from, $to) = extract_variable_reference($val); + if ($isvar) { # Handle a sub variable - my $subvar = $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@/); + # Check if value is to be ignored + next if ! defined $subvar; - # See if the variable is actually a substitution reference - my ($from, $to); - my @temp_list; - if ($subvar =~ /$SUBST_REF_PATTERN/o) - { - $subvar = $1; - $to = $3; - ($from = $2) =~ s/(\W)/\\$1/g; - } + # Add substitutions to stack push @substfroms, $from; push @substtos, $to; + # Get name for object variable my $subobjvar = &subobjname($subvar); push (@result, '$('. $subobjvar . ')'); @@ -6001,7 +6041,7 @@ sub variable_conditions_recursive ($) # @CONDS # variable_conditions ($VAR) -# --------------------------------------- +# -------------------------- # Get the list of conditions that a variable is defined with, without # recursing through the conditions of any subvariables. # Argument is $VAR: the variable to get the conditions of. @@ -6061,19 +6101,15 @@ sub variable_conditions_recursive_sub last if /^#/; # Handle variable substitutions. - if (/^\$\{(.*)\}$/ || /^\$\((.*)\)$/) + my ($isvar, $subvar) = extract_variable_reference($_); + if ($isvar) { - my $varname = $1; - if ($varname =~ /$SUBST_REF_PATTERN/o) - { - $varname = $1; - } - + next if ! defined $subvar; # Here we compute all the conditions under which the # subvariable is defined. Then we go through and add # $VCOND to each. - my @svc = &variable_conditions_recursive_sub ($varname, $var); + my @svc = &variable_conditions_recursive_sub ($subvar, $var); foreach my $item (@svc) { my $val = conditional_string ($vcond, split (' ', $item)); @@ -6277,25 +6313,15 @@ sub value_to_list last if /^#/; # Handle variable substitutions. - if (/^\$\{([^}]*)\}$/ || /^\$\(([^)]*)\)$/) + my ($isvar, $subvar, $from, $to) = extract_variable_reference($_); + if ($isvar) { - my $varname = $1; - - # If the user uses a losing variable name, just ignore it. - # This isn't ideal, but people have requested it. - next if ($varname =~ /address@hidden@/); - - my ($from, $to); - my @temp_list; - if ($varname =~ /$SUBST_REF_PATTERN/o) - { - $varname = $1; - $to = $3; - ($from = $2) =~ s/(\W)/\\$1/g; - } + # Check if value is to be ignored + next if ! defined $subvar; # Find the value. - @temp_list = &variable_value_as_list_recursive_worker ($1, $cond, $var); + my @temp_list; + @temp_list = &variable_value_as_list_recursive_worker ($subvar, $cond, $var); # Now rewrite the value if appropriate. if (defined $from)