Refactor config - rewrite handling of "reconf"

The way the "reconf"/"reconfigure" argument is handled is overly
complicated.  Just grep for it first, and if it is there in the
current arguments, get the old command line arguments from Makefile.

While we're at it, make the Makefile variable CONFIGURE_ARGS hold the
value as a perl list of strings.  This makes things much safer in case
one of the arguments would contain a space.  Since CONFIGURE_ARGS is
used for nothing else, there's no harm in this.

Reviewed-by: Viktor Dukhovni <viktor@openssl.org>
This commit is contained in:
Richard Levitte 2015-05-18 03:33:55 +02:00
parent feb2f53edc
commit fe05264e32

119
Configure
View file

@ -619,45 +619,57 @@ my $no_sse2=0;
&usage if ($#ARGV < 0);
my $flags;
my $depflags;
my $openssl_experimental_defines;
my $openssl_algorithm_defines;
my $openssl_thread_defines;
my $flags="";
my $depflags="";
my $openssl_experimental_defines="";
my $openssl_algorithm_defines="";
my $openssl_thread_defines="";
my $openssl_sys_defines="";
my $openssl_other_defines;
my $libs;
my $target;
my $options;
my $openssl_other_defines="";
my $libs="";
my $target="";
my $options="";
my $api;
my $make_depend=0;
my %withargs=();
my $build_prefix = "release_";
my @argvcopy=@ARGV;
my $argvstring="";
my $argv_unprocessed=1;
while($argv_unprocessed)
{
$flags="";
$depflags="";
$openssl_experimental_defines="";
$openssl_algorithm_defines="";
$openssl_thread_defines="";
$openssl_sys_defines="";
$openssl_other_defines="";
$libs="";
$target="";
$options="";
if (grep /^reconf(igure)?$/, @argvcopy) {
if (open IN, "<$Makefile") {
while (<IN>) {
chomp;
if (/^CONFIGURE_ARGS=\s*(.*)\s*/) {
my $line = $1;
if ($line =~ /^\s*\(/) {
# New form perl expression saved in Makefile, eval it
@argvcopy = eval $line;
} else {
# Older form, we split the string and hope for the best
@argvcopy = split /\s+/, $line;
}
die "Incorrect data to reconfigure, please do a normal configuration\n"
if (grep(/^reconf/,@argvcopy));
} elsif (/^CROSS_COMPILE=\s*(.*)/) {
$ENV{CROSS_COMPILE}=$1;
} elsif (/^CC=\s*(?:\$\(CROSS_COMPILE\))?(.*?)$/) {
$ENV{CC}=$1;
}
}
print "Reconfiguring with: ", join(" ",@argvcopy), "\n";
print " CROSS_COMPILE = ",$ENV{CROSS_COMPILE},"\n"
if $ENV{CROSS_COMPILE};
print " CC = ",$ENV{CC},"\n" if $ENV{CC};
close IN;
} else {
die "Insufficient data to reconfigure, please do a normal configuration\n";
}
}
$argv_unprocessed=0;
$argvstring=join(' ',@argvcopy);
PROCESS_ARGS:
{
my %unsupported_options = ();
foreach (@argvcopy)
my %unsupported_options = ();
foreach (@argvcopy)
{
s /^-no-/no-/; # some people just can't read the instructions
@ -741,38 +753,6 @@ PROCESS_ARGS:
{
$build_prefix = "release_";
}
elsif (/^reconfigure/ || /^reconf/)
{
if (open(IN,"<$Makefile"))
{
my $config_args_found=0;
while (<IN>)
{
chomp;
if (/^CONFIGURE_ARGS=(.*)/)
{
$argvstring=$1;
@argvcopy=split(' ',$argvstring);
die "Incorrect data to reconfigure, please do a normal configuration\n"
if (grep(/^reconf/,@argvcopy));
print "Reconfiguring with: $argvstring\n";
$argv_unprocessed=1;
$config_args_found=1;
}
elsif (/^CROSS_COMPILE=\s*(.*)/)
{
$ENV{CROSS_COMPILE}=$1;
}
elsif (/^CC=\s*(?:\$\(CROSS_COMPILE\))?(.*?)$/)
{
$ENV{CC}=$1;
}
}
close(IN);
last PROCESS_ARGS if ($config_args_found);
}
die "Insufficient data to reconfigure, please do a normal configuration\n";
}
elsif (/^386$/)
{ $processor=386; }
elsif (/^fips$/)
@ -856,7 +836,6 @@ PROCESS_ARGS:
die "target already defined - $target (offending arg: $_)\n" if ($target ne "");
$target=$_;
}
unless ($_ eq $target || /^no-/ || /^disable-/)
{
# "no-..." follows later after implied disactivations
@ -869,7 +848,6 @@ PROCESS_ARGS:
else
{ $options .= " ".$_; }
}
}
if (defined($api) && !exists $apitable->{$api}) {
die "***** Unsupported api compatibility level: $api\n",
@ -881,7 +859,6 @@ PROCESS_ARGS:
join(", ", keys %unsupported_options), "\n";
}
}
}
if ($processor eq "386")
@ -1617,6 +1594,7 @@ while (<IN>)
s/^INSTALL_PREFIX=.*$/INSTALL_PREFIX=$install_prefix/;
s/^PLATFORM=.*$/PLATFORM=$target/;
s/^OPTIONS=.*$/OPTIONS=$options/;
my $argvstring = "(".join(", ", map { quotify("perl", $_) } @argvcopy).")";
s/^CONFIGURE_ARGS=.*$/CONFIGURE_ARGS=$argvstring/;
if ($cross_compile_prefix)
{
@ -2384,3 +2362,16 @@ EOF
print " },\n";
}
}
sub quotify {
my %processors = (
perl => sub { my $x = shift;
$x =~ s/([\\\$\@"])/\\$1/g;
return '"'.$x.'"'; },
);
my $for = shift;
my $processor =
defined($processors{$for}) ? $processors{$for} : sub { shift; };
map { $processor->($_); } @_;
}