@@ -1027,12 +1027,41 @@ sub get_outdir {
10271027}
10281028
10291029
1030+ sub aggressively_replace {
1031+ my ($self , $icwd , $val ) = @_ ;
1032+ my $count = 0;
1033+ my $wd = $icwd ;
1034+ my $ival = ($self -> {' case_tolerant' } ? lc ($val ) : $val );
1035+
1036+ # # Search back up the directories until we either find a match or we
1037+ # # run out of directories.
1038+ while ($wd =~ s / [^\/ ]+[\/ ]?$// ) {
1039+ # # We have gone up one directory
1040+ $count ++;
1041+
1042+ # # Make a regular expression and see if we have found a match
1043+ # # with our provided directory value.
1044+ my $re = $self -> escape_regex_special($wd );
1045+ if ($ival =~ / ^($re )/ ) {
1046+ # # We have found how it is relative. Now make the relative path
1047+ # # and return it.
1048+ my $prefix = $1 ;
1049+ my $suffix = substr ($val , length ($prefix ));
1050+ return (' ../' x $count ) . $suffix ;
1051+ }
1052+ }
1053+
1054+ # # We never found a match
1055+ return undef ;
1056+ }
1057+
10301058sub expand_variables {
10311059 my ($self , $value , $rel , $expand_template , $scopes , $expand , $warn ) = @_ ;
10321060 my $cwd = $self -> getcwd();
10331061 my $start = 0;
10341062 my $forward_slashes = $self -> {' convert_slashes' } ||
10351063 $self -> {' requires_forward_slashes' };
1064+ my $aggrep = $self -> aggressive_relative_replacement();
10361065
10371066 # # Fix up the value for Windows switch the \\'s to /
10381067 $cwd =~ s /\\ / \/ / g if ($forward_slashes );
@@ -1100,13 +1129,31 @@ sub expand_variables {
11001129 # # instead of leaving it we will expand it. But, we will only
11011130 # # get into this section if this is the secondary attempt to
11021131 # # replace the variable (indicated by the $warn boolean).
1103- $val =~ s /\/ / \\ / g if ($self -> {' convert_slashes' });
1104- substr ($value , $start ) =~ s /\$\( [^)]+\) / $val / ;
1105- $whole = $val ;
1132+ my $aggressive_rel ;
1133+ if ($aggrep &&
1134+ ($aggressive_rel = $self -> aggressively_replace($icwd , $val ))) {
1135+ $aggressive_rel =~ s /\/ / \\ / g if ($self -> {' convert_slashes' });
1136+ substr ($value , $start ) =~ s /\$\( [^)]+\) / $aggressive_rel / ;
1137+ $whole = $aggressive_rel ;
1138+ }
1139+ else {
1140+ $val =~ s /\/ / \\ / g if ($self -> {' convert_slashes' });
1141+ substr ($value , $start ) =~ s /\$\( [^)]+\) / $val / ;
1142+ $whole = $val ;
1143+ }
11061144 }
11071145 else {
1108- my $loc = index (substr ($value , $start ), $whole );
1109- $start += $loc if ($loc > 0);
1146+ my $aggressive_rel ;
1147+ if ($aggrep &&
1148+ ($aggressive_rel = $self -> aggressively_replace($icwd , $val ))) {
1149+ $aggressive_rel =~ s /\/ / \\ / g if ($self -> {' convert_slashes' });
1150+ substr ($value , $start ) =~ s /\$\( [^)]+\) / $aggressive_rel / ;
1151+ $whole = $aggressive_rel ;
1152+ }
1153+ else {
1154+ my $loc = index (substr ($value , $start ), $whole );
1155+ $start += $loc if ($loc > 0);
1156+ }
11101157 }
11111158 }
11121159 }
@@ -1285,6 +1332,12 @@ sub get_secondary_relative_values {
12851332}
12861333
12871334
1335+ sub aggressive_relative_replacement {
1336+ # my $self = shift;
1337+ return 0;
1338+ }
1339+
1340+
12881341sub convert_all_variables {
12891342 # my $self = shift;
12901343 return 0;
0 commit comments