diff options
author | Richard Levitte <levitte@openssl.org> | 2020-02-26 14:35:17 +0100 |
---|---|---|
committer | Richard Levitte <levitte@openssl.org> | 2020-03-02 03:34:30 +0100 |
commit | e42921790267d54054cde1596711219b72a184ad (patch) | |
tree | 4fde9afd10c5130bed9de1b579b1a5e1eae35b02 /Configure | |
parent | build.info: Make it possible to have more than one item in KEYWORD[] (diff) | |
download | openssl-e42921790267d54054cde1596711219b72a184ad.tar.xz openssl-e42921790267d54054cde1596711219b72a184ad.zip |
build.info: Implement simply substitutions in variable values
Use case: having a variable with multiple source files in its value,
and wanting to refer to the corresponding object file.
$SRCS=foo.c bar.c
SOURCE[program]=$SRCS
DEPEND[${SRCS/.c/.o}]=prog.h
GENERATE[prog.h]=...
Reviewed-by: Tomas Mraz <tmraz@fedoraproject.org>
(Merged from https://github.com/openssl/openssl/pull/11185)
Diffstat (limited to 'Configure')
-rwxr-xr-x | Configure | 49 |
1 files changed, 44 insertions, 5 deletions
@@ -1807,23 +1807,62 @@ if ($builder eq "unified") { # contains a dollar sign, it had better be escaped, or it will be # taken for a variable name prefix. my %variables = (); - my $variable_re = qr/\$(?P<VARIABLE>[[:alpha:]][[:alnum:]_]*)/; + # Variable name syntax + my $variable_name_re = qr/(?P<VARIABLE>[[:alpha:]][[:alnum:]_]*)/; + # Value modifier syntaxes + my $variable_subst_re = qr/\/(?P<RE>(?:\\\/|.)*?)\/(?P<SUBST>.*?)/; + # Put it all together + my $variable_re = qr/\$ + (?| + # Simple case, just the name + ${variable_name_re} + | + # Expressive case, with braces and possible + # modifier expressions + \{ + ${variable_name_re} + (?: + # Pile on modifier expressions, + # separated by | + ${variable_subst_re} + ) + \} + )/x; my $expand_variables = sub { my $value = ''; my $value_rest = shift; if ($ENV{CONFIGURE_DEBUG_VARIABLE_EXPAND}) { print STDERR - "DEBUG[\$expand_variables] Parsed '$value_rest' into:\n" + "DEBUG[\$expand_variables] Parsed '$value_rest' ...\n" } while ($value_rest =~ /(?<!\\)${variable_re}/) { - $value .= $`; - $value .= $variables{$+{VARIABLE}}; $value_rest = $'; + $value .= $`; + + my $variable_value = $variables{$+{VARIABLE}}; + + # Process modifier expressions, if present + if (defined $+{RE}) { + # We must save important %+ values, because the s/// + # below clears them + my $re = $+{RE}; + my $subst = $+{SUBST}; + + $variable_value =~ s/\Q$re\E/$subst/g; + + if ($ENV{CONFIGURE_DEBUG_VARIABLE_EXPAND}) { + print STDERR + "DEBUG[\$expand_variables] ... and substituted ", + "'$re' with '$subst'\n"; + } + } + + $value .= $variable_value; } if ($ENV{CONFIGURE_DEBUG_VARIABLE_EXPAND}) { print STDERR - "DEBUG[\$expand_variables] ... '$value$value_rest'\n"; + "DEBUG[\$expand_variables] ... into: '$value$value_rest'\n"; } return $value . $value_rest; }; |