summaryrefslogtreecommitdiffstats
path: root/util/perl
diff options
context:
space:
mode:
authorRichard Levitte <levitte@openssl.org>2021-02-22 07:29:03 +0100
committerRichard Levitte <levitte@openssl.org>2021-02-23 09:35:04 +0100
commit9e1094ad3df16a7d9a1224925ed8a9c3f76b9bba (patch)
treed0d43cfd5f5e2e46e1acda5d0f803bb73a7c12a9 /util/perl
parent444b25b1e96fa444ffe3a67671796cfc1b599735 (diff)
util/perl/OpenSSL/config.pm: Fix determine_compiler_settings()
There may be times when a compiler can't be detected, in which case determine_compiler_settings() bailed out too early, before platform specific fallbacks have a chance to set the record straight. That bail out has been moved to be done after the platform specific fallbacks. Furthermore, the attempt to check for gcc or clang and get their version number was done even if no compiler had been automatically detected or pre-specified via $CC. It now only does this when there is a compiler specified or detected. The platform specific fallbacks check the versions separately. Reviewed-by: Paul Dale <pauli@openssl.org> (Merged from https://github.com/openssl/openssl/pull/14270)
Diffstat (limited to 'util/perl')
-rwxr-xr-xutil/perl/OpenSSL/config.pm97
1 files changed, 52 insertions, 45 deletions
diff --git a/util/perl/OpenSSL/config.pm b/util/perl/OpenSSL/config.pm
index 776e448df4..841ef4b6aa 100755
--- a/util/perl/OpenSSL/config.pm
+++ b/util/perl/OpenSSL/config.pm
@@ -193,6 +193,8 @@ sub maybe_abort {
# Look for ISC/SCO with its unique uname program
sub is_sco_uname {
+ return undef unless IPC::Cmd::can_run('uname');
+
open UNAME, "uname -X 2>/dev/null|" or return '';
my $line = "";
while ( <UNAME> ) {
@@ -200,9 +202,11 @@ sub is_sco_uname {
$line = $_ if m@^Release@;
}
close UNAME;
- return "" if $line eq '';
+
+ return undef if $line eq '';
+
my @fields = split(/\s+/, $line);
- return $fields[2] // '';
+ return $fields[2];
}
sub get_sco_type {
@@ -237,7 +241,7 @@ sub guess_system {
# Special-cases for ISC, SCO, Unixware
my $REL = is_sco_uname();
- if ( $REL ne "" ) {
+ if ( defined $REL ) {
my $result = get_sco_type($REL);
return eval "\"$result\"" if $result ne '';
}
@@ -276,8 +280,8 @@ sub _pairs (@) {
# Figure out CC, GCCVAR, etc.
sub determine_compiler_settings {
- # Make a copy and don't touch it. That helps determine if we're
- # finding the compiler here
+ # Make a copy and don't touch it. That helps determine if we're finding
+ # the compiler here (false), or if it was set by the user (true.
my $cc = $CC;
# Set certain default
@@ -293,50 +297,45 @@ sub determine_compiler_settings {
}
}
- # Find the compiler vendor and version number for certain compilers
- foreach my $pair (_pairs @cc_version) {
- # Try to get the version number.
- # Failure gets us undef or an empty string
- my ( $k, $v ) = @$pair;
- $v = $v->();
-
- # If we got a version number, process it
- if ($v) {
- $CCVENDOR = $k;
-
- # The returned version is expected to be one of
- #
- # MAJOR
- # MAJOR.MINOR
- # MAJOR.MINOR.{whatever}
- #
- # We don't care what comes after MAJOR.MINOR. All we need is to
- # have them calculated into a single number, using this formula:
- #
- # MAJOR * 100 + MINOR
- # Here are a few examples of what we should get:
- #
- # 2.95.1 => 295
- # 3.1 => 301
- # 9 => 900
- my @numbers = split /\./, $v;
- my @factors = (100, 1);
- while (@numbers && @factors) {
- $CCVER += shift(@numbers) * shift(@factors)
+ if ( $CC ) {
+ # Find the compiler vendor and version number for certain compilers
+ foreach my $pair (_pairs @cc_version) {
+ # Try to get the version number.
+ # Failure gets us undef or an empty string
+ my ( $k, $v ) = @$pair;
+ $v = $v->();
+
+ # If we got a version number, process it
+ if ($v) {
+ $CCVENDOR = $k;
+
+ # The returned version is expected to be one of
+ #
+ # MAJOR
+ # MAJOR.MINOR
+ # MAJOR.MINOR.{whatever}
+ #
+ # We don't care what comes after MAJOR.MINOR. All we need is
+ # to have them calculated into a single number, using this
+ # formula:
+ #
+ # MAJOR * 100 + MINOR
+ # Here are a few examples of what we should get:
+ #
+ # 2.95.1 => 295
+ # 3.1 => 301
+ # 9 => 900
+ my @numbers = split /\./, $v;
+ my @factors = (100, 1);
+ while (@numbers && @factors) {
+ $CCVER += shift(@numbers) * shift(@factors)
+ }
+ last;
}
- last;
}
}
- # If no C compiler has been determined at this point, we die. Hard.
- die <<_____
-ERROR!
-No C compiler found, please specify one with the environment variable CC,
-or configure with an explicit configuration target.
-_____
- unless $CC;
-
- # Vendor specific overrides, only if we determined the compiler here
+ # Vendor specific overrides, only if we didn't determine the compiler here
if ( ! $cc ) {
if ( ${SYSTEM} eq 'AIX' ) {
# favor vendor cc over gcc
@@ -375,6 +374,14 @@ EOF
}
}
+ # If no C compiler has been determined at this point, we die. Hard.
+ die <<_____
+ERROR!
+No C compiler found, please specify one with the environment variable CC,
+or configure with an explicit configuration target.
+_____
+ unless $CC;
+
# On some systems, we assume a cc vendor if it's not already determined
if ( ! $CCVENDOR ) {