util/perl/OpenSSL/config.pm: refactor map_guess()

map_guess() is now table driven, just like get_system().
Additionally, it now takes a config hash table and returns one of its
own.  This way, 'Configure' can pass whatever it has already found to
OpenSSL::config::get_platform(), and easily merge the returned hash
table into its %config.

This also gets rid of variables that we no longer need.  That includes
$PERL and all the $__CNF_ environment variables.

Reviewed-by: Tim Hudson <tjh@openssl.org>
(Merged from https://github.com/openssl/openssl/pull/11230)
This commit is contained in:
Richard Levitte 2020-03-03 00:01:35 +01:00
parent 081436bf73
commit e39795af0a
2 changed files with 423 additions and 389 deletions

View File

@ -20,6 +20,7 @@ use File::Path qw/mkpath/;
use OpenSSL::fallback "$FindBin::Bin/external/perl/MODULES.txt"; use OpenSSL::fallback "$FindBin::Bin/external/perl/MODULES.txt";
use OpenSSL::Glob; use OpenSSL::Glob;
use OpenSSL::Template; use OpenSSL::Template;
use OpenSSL::config;
# see INSTALL.md for instructions. # see INSTALL.md for instructions.
@ -608,8 +609,6 @@ while ((my $first, my $second) = (shift @list, shift @list)) {
# To remove something from %disabled, use "enable-foo". # To remove something from %disabled, use "enable-foo".
# For symmetry, "disable-foo" is a synonym for "no-foo". # For symmetry, "disable-foo" is a synonym for "no-foo".
&usage if ($#ARGV < 0);
# For the "make variables" CPPINCLUDES and CPPDEFINES, we support lists with # For the "make variables" CPPINCLUDES and CPPDEFINES, we support lists with
# platform specific list separators. Users from those platforms should # platform specific list separators. Users from those platforms should
# recognise those separators from how you set up the PATH to find executables. # recognise those separators from how you set up the PATH to find executables.
@ -1068,6 +1067,23 @@ if (grep { /-rpath\b/ } ($user{LDFLAGS} ? @{$user{LDFLAGS}} : ())
"***** any of asan, msan or ubsan\n"; "***** any of asan, msan or ubsan\n";
} }
# If no target was given, try guessing.
unless ($target) {
my %system_config = OpenSSL::config::get_platform(%config, %user);
# The $system_config{disable} is used to populate %disabled with
# entries that aren't already there.
foreach ( @{$system_config{disable} // []} ) {
$disabled{$_} = 'system' unless defined $disabled{$_};
}
delete $system_config{disable};
# Override config entries with stuff from the guesser.
# It's assumed that this really is nothing new.
%config = ( %config, %system_config );
$target = $system_config{target};
}
sub disable { sub disable {
my $disable_type = shift; my $disable_type = shift;

View File

@ -36,11 +36,9 @@ my $GCC_BITS;
my $GCC_ARCH; my $GCC_ARCH;
# Some environment variables; they will affect Configure # Some environment variables; they will affect Configure
my $PERL = $ENV{PERL} // $^X // 'perl';
my $CONFIG_OPTIONS = $ENV{CONFIG_OPTIONS} // ''; my $CONFIG_OPTIONS = $ENV{CONFIG_OPTIONS} // '';
my $CC = $ENV{CC} // ''; my $CC;
my $CROSS_COMPILE = $ENV{CROSS_COMPILE} // ""; my $CROSS_COMPILE;
my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
# For determine_compiler_settings, the list of known compilers # For determine_compiler_settings, the list of known compilers
my @c_compilers = qw(clang gcc cc); my @c_compilers = qw(clang gcc cc);
@ -67,15 +65,6 @@ my @cc_version =
# This is what we will set as the target for calling Configure. # This is what we will set as the target for calling Configure.
my $options = ''; my $options = '';
# Environment that will be passed to Configure
my $__CNF_CPPDEFINES = '';
my $__CNF_CPPINCLUDES = '';
my $__CNF_CPPFLAGS = '';
my $__CNF_CFLAGS = '';
my $__CNF_CXXFLAGS = '';
my $__CNF_LDFLAGS = '';
my $__CNF_LDLIBS = '';
# Pattern matches against "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}" # Pattern matches against "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}"
my $simple_guess_patterns = [ my $simple_guess_patterns = [
[ 'A\/UX:', 'm68k-apple-aux3' ], [ 'A\/UX:', 'm68k-apple-aux3' ],
@ -450,392 +439,451 @@ EOF
} }
} }
# Map GUESSOS into OpenSSL terminology. Also sets some of variables my $map_patterns =
# like $options, $__CNX_xxx. And uses some, like the KERNEL flags [ [ 'uClinux.*64.*', { target => 'uClinux-dist64' } ],
# and MACHINE. [ 'uClinux.*', { target => 'uClinux-dist' } ],
# It would be nice to fix this so that this weren't necessary. :( XXX [ 'mips3-sgi-irix', { target => 'irix-mips3' } ],
sub map_guess { [ 'mips4-sgi-irix64',
my $GUESSOS = shift; sub {
my $OUT; print <<EOF;
return 'uClinux-dist64' if $GUESSOS =~ 'uClinux.*64.*';
return 'uClinux-dist' if $GUESSOS =~ 'uClinux.*';
return "irix-mips3-$CC" if $GUESSOS =~ 'mips3-sgi-irix';
if ( $GUESSOS =~ 'mips4-sgi-irix64' ) {
print <<EOF;
WARNING! To build 64-bit package, do this: WARNING! To build 64-bit package, do this:
$WHERE/Configure irix64-mips4-$CC $WHERE/Configure irix64-mips4-$CC
EOF EOF
maybe_abort(); maybe_abort();
return "irix-mips3-$CC"; return { target => "irix-mips3" };
} }
return "rhapsody-ppc-cc" if $GUESSOS =~ 'ppc-apple-rhapsody'; ],
if ( $GUESSOS =~ 'ppc-apple-darwin' ) { [ 'ppc-apple-rhapsody', { target => "rhapsody-ppc" } ],
my $ISA64 = `sysctl -n hw.optional.64bitops 2>/dev/null`; [ 'ppc-apple-darwin.*',
if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) { sub {
print <<EOF; my $KERNEL_BITS = $ENV{KERNEL_BITS};
my $ISA64 = `sysctl -n hw.optional.64bitops 2>/dev/null`;
if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
print <<EOF;
WARNING! To build 64-bit package, do this: WARNING! To build 64-bit package, do this:
$WHERE/Configure darwin64-ppc-cc $WHERE/Configure darwin64-ppc-cc
EOF EOF
maybe_abort(); maybe_abort();
}
return "darwin64-ppc-cc" if $ISA64 == 1 && $KERNEL_BITS eq '64';
return "darwin-ppc-cc";
}
if ( $GUESSOS =~ 'i.86-apple-darwin' ) {
my $ISA64 = `sysctl -n hw.optional.x86_64 2>/dev/null`;
if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
print <<EOF;
WARNING! To build 64-bit package, do this:
KERNEL_BITS=64 $WHERE/config $options
EOF
maybe_abort();
}
return "darwin64-x86_64-cc" if $ISA64 == 1 && $KERNEL_BITS eq '64';
return "darwin-i386-cc";
}
if ( $GUESSOS =~ 'x86_64-apple-darwin' ) {
return "darwin-i386-cc" if $KERNEL_BITS eq '32';
print <<EOF;
WARNING! To build 32-bit package, do this:
KERNEL_BITS=32 $WHERE/config $options
EOF
maybe_abort();
return "darwin64-x86_64-cc"
}
if ( $GUESSOS =~ 'armv6+7-.*-iphoneos' ) {
$__CNF_CFLAGS .= " -arch armv6 -arch armv7";
$__CNF_CXXFLAGS .= " -arch armv6 -arch armv7";
return "iphoneos-cross";
}
if ( $GUESSOS =~ '.*-.*-iphoneos' ) {
$__CNF_CFLAGS .= " -arch ${MACHINE}";
$__CNF_CXXFLAGS .= " -arch ${MACHINE}";
return "iphoneos-cross";
}
return "ios64-cross" if $GUESSOS =~ 'arm64-.*-iphoneos|.*-.*-ios64';
if ( $GUESSOS =~ 'alpha-.*-linux2' ) {
my $ISA = `awk '/cpu model/{print \$4;exit(0);}' /proc/cpuinfo`;
$ISA //= 'generic';
if ( $CCVENDOR eq "gnu" ) {
if ( $ISA =~ 'EV5|EV45' ) {
$__CNF_CFLAGS .= " -mcpu=ev5";
$__CNF_CFLAGS .= " -mcpu=ev5";
} elsif ( $ISA =~ 'EV56|PCA56' ) {
$__CNF_CFLAGS .= " -mcpu=ev56";
$__CNF_CXXFLAGS .= " -mcpu=ev56";
} else {
$__CNF_CFLAGS .= "-mcpu=ev6";
$__CNF_CXXFLAGS .= "-mcpu=ev6";
} }
return { target => "darwin64-ppc" }
if $ISA64 == 1 && $KERNEL_BITS eq '64';
return { target => "darwin-ppc" };
} }
return "linux-alpha-$CC"; ],
} [ 'i.86-apple-darwin.*',
if ( $GUESSOS =~ 'ppc64-.*-linux2' ) { sub {
if ( $KERNEL_BITS eq '' ) { my $KERNEL_BITS = $ENV{KERNEL_BITS};
my $ISA64 = `sysctl -n hw.optional.x86_64 2>/dev/null`;
if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
print <<EOF;
WARNING! To build 64-bit package, do this:
KERNEL_BITS=64 $WHERE/Configure \[\[ options \]\]
EOF
maybe_abort();
}
return { target => "darwin64-x86_64" }
if $ISA64 == 1 && $KERNEL_BITS eq '64';
return { target => "darwin-i386" };
}
],
[ 'x86_64-apple-darwin.*',
sub {
my $KERNEL_BITS = $ENV{KERNEL_BITS};
return { target => "darwin-i386" } if $KERNEL_BITS eq '32';
print <<EOF; print <<EOF;
WARNING! To build 32-bit package, do this:
KERNEL_BITS=32 $WHERE/Configure \[\[ options \]\]
EOF
maybe_abort();
return { target => "darwin64-x86_64" };
}
],
[ 'armv6\+7-.*-iphoneos',
{ target => "iphoneos-cross",
cflags => [ qw(-arch armv6 -arch armv7) ],
cxxflags => [ qw(-arch armv6 -arch armv7) ] }
],
[ 'arm64-.*-iphoneos|.*-.*-ios64',
{ target => "ios64-cross" }
],
[ '.*-.*-iphoneos',
sub { return { target => "iphoneos-cross",
cflags => [ "-arch ${MACHINE}" ],
cxxflags => [ "-arch ${MACHINE}" ] }; }
],
[ 'alpha-.*-linux2.*',
sub {
my $ISA = `awk '/cpu model/{print \$4;exit(0);}' /proc/cpuinfo`;
$ISA //= 'generic';
my %config = ();
if ( $CCVENDOR eq "gnu" ) {
if ( $ISA =~ 'EV5|EV45' ) {
%config = ( cflags => [ '-mcpu=ev5' ],
cxxflags => [ '-mcpu=ev5' ] );
} elsif ( $ISA =~ 'EV56|PCA56' ) {
%config = ( cflags => [ '-mcpu=ev56' ],
cxxflags => [ '-mcpu=ev56' ] );
} else {
%config = ( cflags => [ '-mcpu=ev6' ],
cxxflags => [ '-mcpu=ev6' ] );
}
}
return { target => "linux-alpha",
%config };
}
],
[ 'ppc64-.*-linux2',
sub {
my $KERNEL_BITS = $ENV{KERNEL_BITS};
if ( $KERNEL_BITS eq '' ) {
print <<EOF;
WARNING! To build 64-bit package, do this: WARNING! To build 64-bit package, do this:
$WHERE/Configure linux-ppc64 $WHERE/Configure linux-ppc64
EOF EOF
maybe_abort(); maybe_abort();
}
return { target => "linux-ppc64" } if $KERNEL_BITS eq '64';
my %config = ();
if (!okrun('echo __LP64__',
'gcc -E -x c - 2>/dev/null',
'grep "^__LP64__" 2>&1 >/dev/null') ) {
%config = ( cflags => [ '-m32' ],
cxxflags => [ '-m32' ] );
}
return { target => "linux-ppc",
%config };
} }
return "linux-ppc64" if $KERNEL_BITS eq '64'; ],
if (!okrun('echo __LP64__', [ 'ppc64le-.*-linux2', { target => "linux-ppc64le" } ],
'gcc -E -x c - 2>/dev/null', [ 'ppc-.*-linux2', { target => "linux-ppc" } ],
'grep "^__LP64__" 2>&1 >/dev/null') ) { [ 'mips64.*-*-linux2',
$__CNF_CFLAGS .= " -m32"; sub {
$__CNF_CXXFLAGS .= " -m32"; print <<EOF;
}
return "linux-ppc";
}
return "linux-ppc64le" if $GUESSOS =~ 'ppc64le-.*-linux2';
return "linux-ppc" if $GUESSOS =~ 'ppc-.*-linux2';
if ( $GUESSOS =~ 'mips64.*-*-linux2' ) {
print <<EOF;
WARNING! To build 64-bit package, do this: WARNING! To build 64-bit package, do this:
$WHERE/Configure linux64-mips64 $WHERE/Configure linux64-mips64
EOF EOF
maybe_abort(); maybe_abort();
return "linux-mips64"; return { target => "linux-mips64" };
} }
return "linux-mips32" if $GUESSOS =~ 'mips.*-.*-linux2'; ],
return "vxworks-ppc60x" if $GUESSOS =~ 'ppc60x-.*-vxworks*'; [ 'mips.*-.*-linux2', { target => "linux-mips32" } ],
return "vxworks-ppcgen" if $GUESSOS =~ 'ppcgen-.*-vxworks*'; [ 'ppc60x-.*-vxworks.*', { target => "vxworks-ppc60x" } ],
return "vxworks-pentium" if $GUESSOS =~ 'pentium-.*-vxworks*'; [ 'ppcgen-.*-vxworks.*', { target => "vxworks-ppcgen" } ],
return "vxworks-simlinux" if $GUESSOS =~ 'simlinux-.*-vxworks*'; [ 'pentium-.*-vxworks.*', { target => "vxworks-pentium" } ],
return "vxworks-mips" if $GUESSOS =~ 'mips-.*-vxworks*'; [ 'simlinux-.*-vxworks.*', { target => "vxworks-simlinux" } ],
return "linux-generic64 -DL_ENDIAN" if $GUESSOS =~ 'e2k-.*-linux*'; [ 'mips-.*-vxworks.*', { target => "vxworks-mips" } ],
return "linux-ia64" if $GUESSOS =~ 'ia64-.*-linux.'; [ 'e2k-.*-linux.*', { target => "linux-generic64",
if ( $GUESSOS =~ 'sparc64-.*-linux2' ) { defines => [ 'L_ENDIAN' ] } ],
print <<EOF; [ 'ia64-.*-linux.', { target => "linux-ia64" } ],
[ 'sparc64-.*-linux2',
sub {
print <<EOF;
WARNING! If you *know* that your GNU C supports 64-bit/V9 ABI and you WARNING! If you *know* that your GNU C supports 64-bit/V9 ABI and you
want to build 64-bit library, do this: want to build 64-bit library, do this:
$WHERE/Configure linux64-sparcv9 $WHERE/Configure linux64-sparcv9
EOF EOF
maybe_abort(); maybe_abort();
return "linux-sparcv9"; return { target => "linux-sparcv9" };
} }
if ( $GUESSOS =~ 'sparc-.*-linux2' ) { ],
my $KARCH = `awk '/^type/{print \$3;exit(0);}' /proc/cpuinfo`; [ 'sparc-.*-linux2',
$KARCH //= "sun4"; sub {
return "linux-sparcv9" if $KARCH =~ 'sun4u*'; my $KARCH = `awk '/^type/{print \$3;exit(0);}' /proc/cpuinfo`;
return "linux-sparcv8" if $KARCH =~ 'sun4[md]'; $KARCH //= "sun4";
$__CNF_CPPFLAGS .= " -DB_ENDIAN"; return { target => "linux-sparcv9" } if $KARCH =~ 'sun4u.*';
return "linux-generic32"; return { target => "linux-sparcv8" } if $KARCH =~ 'sun4[md]';
} return { target => "linux-generic32",
if ( $GUESSOS =~ 'parisc.*-.*-linux2' ) { defines => [ 'L_ENDIAN' ] };
# 64-bit builds under parisc64 linux are not supported and }
# compiler is expected to generate 32-bit objects... ],
my $CPUARCH = [ 'parisc.*-.*-linux2',
`awk '/cpu family/{print substr(\$5,1,3); exit(0);}' /proc/cpuinfo`; sub {
my $CPUSCHEDULE = # 64-bit builds under parisc64 linux are not supported and
`awk '/^cpu.[ ]*: PA/{print substr(\$3,3); exit(0);}' /proc/cpuinfo`; # compiler is expected to generate 32-bit objects...
# TODO XXX Model transformations my $CPUARCH =
# 0. CPU Architecture for the 1.1 processor has letter suffixes. We `awk '/cpu family/{print substr(\$5,1,3); exit(0);}' /proc/cpuinfo`;
# strip that off assuming no further arch. identification will ever my $CPUSCHEDULE =
# be used by GCC. `awk '/^cpu.[ ]*: PA/{print substr(\$3,3); exit(0);}' /proc/cpuinfo`;
# 1. I'm most concerned about whether is a 7300LC is closer to a 7100 # TODO XXX Model transformations
# versus a 7100LC. # 0. CPU Architecture for the 1.1 processor has letter suffixes.
# 2. The variant 64-bit processors cause concern should GCC support # We strip that off assuming no further arch. identification
# explicit schedulers for these chips in the future. # will ever be used by GCC.
# PA7300LC -> 7100LC (1.1) # 1. I'm most concerned about whether is a 7300LC is closer to a
# PA8200 -> 8000 (2.0) # 7100 versus a 7100LC.
# PA8500 -> 8000 (2.0) # 2. The variant 64-bit processors cause concern should GCC support
# PA8600 -> 8000 (2.0) # explicit schedulers for these chips in the future.
$CPUSCHEDULE =~ s/7300LC/7100LC/; # PA7300LC -> 7100LC (1.1)
$CPUSCHEDULE =~ s/8.00/8000/; # PA8200 -> 8000 (2.0)
# Finish Model transformations # PA8500 -> 8000 (2.0)
$__CNF_CPPFLAGS .= " -DB_ENDIAN"; # PA8600 -> 8000 (2.0)
$__CNF_CFLAGS .= " -mschedule=$CPUSCHEDULE -march=$CPUARCH"; $CPUSCHEDULE =~ s/7300LC/7100LC/;
$__CNF_CXXFLAGS .= " -mschedule=$CPUSCHEDULE -march=$CPUARCH"; $CPUSCHEDULE =~ s/8.00/8000/;
return "linux-generic32"; return
} { target => "linux-generic32",
return "linux-generic32" if $GUESSOS =~ 'armv[1-3].*-.*-linux2'; defines => [ 'B_ENDIAN' ],
if ( $GUESSOS =~ 'armv[7-9].*-.*-linux2' ) { cflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ],
$__CNF_CFLAGS .= " -march=armv7-a"; cxxflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ]
$__CNF_CXXFLAGS .= " -march=armv7-a"; };
return "linux-armv4"; }
} ],
return "linux-armv4" if $GUESSOS =~ 'arm.*-.*-linux2'; [ 'armv[1-3].*-.*-linux2', { target => "linux-generic32" } ],
return "linux-aarch64" if $GUESSOS =~ 'aarch64-.*-linux2'; [ 'armv[7-9].*-.*-linux2', { target => "linux-armv4",
if ( $GUESSOS =~ 'sh.*b-.*-linux2' ) { defines => [ 'B_ENDIAN' ],
$__CNF_CPPFLAGS .= " -DB_ENDIAN"; cflags => [ '-march=armv7-a' ],
return "linux-generic32"; cxxflags => [ '-march=armv7-a' ] } ],
} [ 'arm.*-.*-linux2', { target => "linux-armv4" } ],
if ( $GUESSOS =~ 'sh.*-.*-linux2' ) { [ 'aarch64-.*-linux2', { target => "linux-aarch64" } ],
$__CNF_CPPFLAGS .= " -DL_ENDIAN"; [ 'sh.*b-.*-linux2', { target => "linux-generic32",
return "linux-generic32"; defines => [ 'B_ENDIAN' ] } ],
} [ 'sh.*-.*-linux2', { target => "linux-generic32",
if ( $GUESSOS =~ 'm68k.*-.*-linux2' || $GUESSOS =~ 's390-.*-linux2' ) { defines => [ 'L_ENDIAN' ] } ],
$__CNF_CPPFLAGS .= " -DB_ENDIAN"; [ 'm68k.*-.*-linux2', { target => "linux-generic32",
return "linux-generic32"; defines => [ 'B_ENDIAN' ] } ],
} [ 's390-.*-linux2', { target => "linux-generic32",
if ( $GUESSOS =~ 's390x-.*-linux2' ) { defines => [ 'B_ENDIAN' ] } ],
# Disabled until a glibc bug is fixed; see Configure. [ 's390x-.*-linux2',
if (0 || okrun( sub {
'egrep -e \'^features.* highgprs\' /proc/cpuinfo >/dev/null') ) # Disabled until a glibc bug is fixed; see Configure.
{ if (0
print <<EOF; || okrun('egrep -e \'^features.* highgprs\' /proc/cpuinfo >/dev/null') )
{
print <<EOF;
WARNING! To build "highgprs" 32-bit package, do this: WARNING! To build "highgprs" 32-bit package, do this:
$WHERE/Configure linux32-s390x $WHERE/Configure linux32-s390x
EOF EOF
maybe_abort(); maybe_abort();
}
return { target => "linux64-s390x" };
} }
return "linux64-s390x"; ],
} [ 'x86_64-.*-linux.',
if ( $GUESSOS =~ 'x86_64-.*-linux.' ) { sub {
return "linux-x32" return { target => "linux-x32" }
if okrun("$CC -dM -E -x c /dev/null 2>&1", if okrun("$CC -dM -E -x c /dev/null 2>&1",
'grep -q ILP32 >/dev/null'); 'grep -q ILP32 >/dev/null');
return "linux-x86_64"; return { target => "linux-x86_64" };
} }
if ( $GUESSOS =~ '.*86-.*-linux2' ) { ],
# On machines where the compiler understands -m32, prefer a [ '.*86-.*-linux2',
# config target that uses it sub {
return "linux-x86" # On machines where the compiler understands -m32, prefer a
if okrun("$CC -m32 -E -x c /dev/null >/dev/null 2>&1"); # config target that uses it
return "linux-elf" return { target => "linux-x86" }
} if okrun("$CC -m32 -E -x c /dev/null >/dev/null 2>&1");
return "linux-aout" if $GUESSOS =~ '.*86-.*-linux1'; return { target => "linux-elf" };
return "linux-generic32" if $GUESSOS =~ '.*-.*-linux.'; }
if ( $GUESSOS =~ 'sun4[uv].*-.*-solaris2' ) { ],
my $ISA64 = `isainfo 2>/dev/null | grep sparcv9`; [ '.*86-.*-linux1', { target => "linux-aout" } ],
if ( $ISA64 ne "" && $KERNEL_BITS eq '' ) { [ '.*-.*-linux.', { target => "linux-generic32" } ],
if ( $CCVENDOR eq "sun" && $CCVER >= 500 ) { [ 'sun4[uv].*-.*-solaris2',
print <<EOF; sub {
my $KERNEL_BITS = $ENV{KERNEL_BITS};
my $ISA64 = `isainfo 2>/dev/null | grep sparcv9`;
if ( $ISA64 ne "" && $KERNEL_BITS eq '' ) {
if ( $CCVENDOR eq "sun" && $CCVER >= 500 ) {
print <<EOF;
WARNING! To build 64-bit package, do this: WARNING! To build 64-bit package, do this:
$WHERE/Configure solaris64-sparcv9-cc $WHERE/Configure solaris64-sparcv9-cc
EOF EOF
maybe_abort(); maybe_abort();
} elsif ( $CCVENDOR eq "gnu" && $GCC_ARCH eq "-m64" ) { } elsif ( $CCVENDOR eq "gnu" && $GCC_ARCH eq "-m64" ) {
# $GCC_ARCH denotes default ABI chosen by compiler driver # $GCC_ARCH denotes default ABI chosen by compiler driver
# (first one found on the $PATH). I assume that user # (first one found on the $PATH). I assume that user
# expects certain consistency with the rest of his builds # expects certain consistency with the rest of his builds
# and therefore switch over to 64-bit. <appro> # and therefore switch over to 64-bit. <appro>
print <<EOF; print <<EOF;
WARNING! To build 32-bit package, do this: WARNING! To build 32-bit package, do this:
$WHERE/Configure solaris-sparcv9-gcc $WHERE/Configure solaris-sparcv9-gcc
EOF EOF
maybe_abort(); maybe_abort();
return "solaris64-sparcv9-gcc"; return { target => "solaris64-sparcv9" };
} elsif ( $GCC_ARCH eq "-m32" ) { } elsif ( $GCC_ARCH eq "-m32" ) {
print <<EOF; print <<EOF;
NOTICE! If you *know* that your GNU C supports 64-bit/V9 ABI and you wish NOTICE! If you *know* that your GNU C supports 64-bit/V9 ABI and you wish
to build 64-bit library, do this: to build 64-bit library, do this:
$WHERE/Configure solaris64-sparcv9-gcc $WHERE/Configure solaris64-sparcv9-gcc
EOF EOF
maybe_abort(); maybe_abort();
}
} }
return { target => "solaris64-sparcv9" }
if $ISA64 ne "" && $KERNEL_BITS eq '64';
return { target => "solaris-sparcv9" };
} }
return "solaris64-sparcv9-$CC" if $ISA64 ne "" && $KERNEL_BITS eq '64'; ],
return "solaris-sparcv9-$CC"; [ 'sun4m-.*-solaris2', { target => "solaris-sparcv8" } ],
} [ 'sun4d-.*-solaris2', { target => "solaris-sparcv8" } ],
return "solaris-sparcv8-$CC" if $GUESSOS =~ 'sun4m-.*-solaris2'; [ 'sun4.*-.*-solaris2', { target => "solaris-sparcv7" } ],
return "solaris-sparcv8-$CC" if $GUESSOS =~ 'sun4d-.*-solaris2'; [ '.*86.*-.*-solaris2',
return "solaris-sparcv7-$CC" if $GUESSOS =~ 'sun4.*-.*-solaris2'; sub {
if ( $GUESSOS =~ '.*86.*-.*-solaris2' ) { my $KERNEL_BITS = $ENV{KERNEL_BITS};
my $ISA64 = `isainfo 2>/dev/null | grep amd64`; my $ISA64 = `isainfo 2>/dev/null | grep amd64`;
my $KB = $KERNEL_BITS // '64'; my $KB = $KERNEL_BITS // '64';
return "solaris64-x86_64-$CC" if $ISA64 ne "" && $KB eq '64'; return { target => "solaris64-x86_64" }
my $REL = uname('-r'); if $ISA64 ne "" && $KB eq '64';
$REL =~ s/5\.//; my $REL = uname('-r');
$options .= " no-sse2" if int($REL) < 10; $REL =~ s/5\.//;
return "solaris-x86-$CC"; my @tmp_disable = ();
} push @tmp_disable, 'sse2' if int($REL) < 10;
return "sunos-$CC" if $GUESSOS =~ '.*-.*-sunos4'; return { target => "solaris-x86",
if ( $GUESSOS =~ '.*86.*-.*-bsdi4' ) { disable => [ @tmp_disable ] };
$options .= " no-sse2";
$__CNF_LDFLAGS .= " -ldl";
return "BSD-x86-elf";
}
if ( $GUESSOS =~ 'alpha.*-.*-.*bsd.*' ) {
$__CNF_CPPFLAGS .= " -DL_ENDIAN";
return "BSD-generic64";
}
if ( $GUESSOS =~ 'powerpc64-.*-.*bsd.*' ) {
$__CNF_CPPFLAGS .= " -DB_ENDIAN";
return "BSD-generic64";
}
return "BSD-sparc64" if $GUESSOS =~ 'sparc64-.*-.*bsd.*';
return "BSD-ia64" if $GUESSOS =~ 'ia64-.*-.*bsd.*';
return "BSD-x86_64" if $GUESSOS =~ 'x86_64-.*-dragonfly.*';
return "BSD-x86_64" if $GUESSOS =~ 'amd64-.*-.*bsd.*';
if ( $GUESSOS =~ '.*86.*-.*-.*bsd.*' ) {
# mimic ld behaviour when it's looking for libc...
my $libc;
if ( -l "/usr/lib/libc.so" ) {
$libc = "/usr/lib/libc.so";
} else {
# ld searches for highest libc.so.* and so do we
$libc =
`(ls /usr/lib/libc.so.* /lib/libc.so.* | tail -1) 2>/dev/null`;
} }
my $what = `file -L $libc 2>/dev/null`; ],
return "BSD-x86-elf" if $what =~ /ELF/; # We don't have any sunos target in Configurations/*.conf, so why here?
$options .= " no-sse2"; [ '.*-.*-sunos4', { target => "sunos" } ],
return "BSD-x86"; [ '.*86.*-.*-bsdi4', { target => "BSD-x86-elf",
} lflags => [ '-ldl' ],
return "BSD-generic32" if $GUESSOS =~ '.*-.*-.*bsd.*'; disable => [ 'sse2' ] } ],
return "haiku-x86_64" if $GUESSOS =~ 'x86_64-.*-haiku'; [ 'alpha.*-.*-.*bsd.*', { target => "BSD-generic64",
return "haiku-x86" if $GUESSOS =~ '.*-.*-haiku'; defines => [ 'L_ENDIAN' ] } ],
return "osf1-alpha-cc" if $GUESSOS =~ '.*-.*-osf'; [ 'powerpc64-.*-.*bsd.*', { target => "BSD-generic64",
return "tru64-alpha-cc" if $GUESSOS =~ '.*-.*-tru64'; defines => [ 'B_ENDIAN' ] } ],
if ( $GUESSOS =~ '.*-.*-[Uu]nix[Ww]are7' ) { [ 'sparc64-.*-.*bsd.*', { target => "BSD-sparc64" } ],
$options .= "no-sse2"; [ 'ia64-.*-.*bsd.*', { target => "BSD-ia64" } ],
return "unixware-7-gcc" if $CCVENDOR eq "gnu"; [ 'x86_64-.*-dragonfly.*', { target => "BSD-x86_64" } ],
$__CNF_CPPFLAGS .= " -D__i386__"; [ 'amd64-.*-.*bsd.*', { target => "BSD-x86_64" } ],
return "unixware-7"; [ '.*86.*-.*-.*bsd.*',
} sub {
if ( $GUESSOS =~ '.*-.*-[Uu]nix[Ww]are20*' ) { # mimic ld behaviour when it's looking for libc...
$options .= " no-sse2 no-sha512"; my $libc;
return "unixware-2.0"; if ( -l "/usr/lib/libc.so" ) {
} $libc = "/usr/lib/libc.so";
if ( $GUESSOS =~ '.*-.*-[Uu]nix[Ww]are21*' ) { } else {
$options .= " no-sse2 no-sha512"; # ld searches for highest libc.so.* and so do we
return "unixware-2.1"; $libc =
} `(ls /usr/lib/libc.so.* /lib/libc.so.* | tail -1) 2>/dev/null`;
if ( $GUESSOS =~ '.*-.*-vos' ) { }
$options .= " no-threads no-shared no-asm no-dso"; my $what = `file -L $libc 2>/dev/null`;
return "vos-$CC"; return { target => "BSD-x86-elf" } if $what =~ /ELF/;
} return { target => "BSD-x86",
return "BS2000-OSD" if $GUESSOS =~ 'BS2000-siemens-sysv4'; disable => [ 'sse2' ] };
return "Cygwin-x86" if $GUESSOS =~ 'i[3456]86-.*-cygwin';
return "Cygwin-${MACHINE}" if $GUESSOS =~ '.*-.*-cygwin';
return "android-x86" if $GUESSOS =~ 'x86-.*-android|i.86-.*-android';
if ( $GUESSOS =~ 'armv[7-9].*-.*-android' ) {
$__CNF_CFLAGS .= " -march=armv7-a";
$__CNF_CXXFLAGS .= " -march=armv7-a";
return "android-armeabi";
}
return "android-armeabi" if $GUESSOS =~ 'arm.*-.*-android';
if ( $GUESSOS =~ '.*-hpux1.*' ) {
$OUT = "hpux64-parisc2-gcc" if $CCVENDOR eq "gnu" && $GCC_BITS eq '64';
$KERNEL_BITS //= `getconf KERNEL_BITS 2>/dev/null` // '32';
# See <sys/unistd.h> for further info on CPU_VERSION.
my $CPU_VERSION = `getconf CPU_VERSION 2>/dev/null` // 0;
$__CNF_CPPFLAGS .= " -D_REENTRANT";
if ( $CPU_VERSION >= 768 ) {
# IA-64 CPU
return "hpux64-ia64-cc" if $KERNEL_BITS eq '64' && ! $CCVENDOR;
return "hpux-ia64-cc"
} }
if ( $CPU_VERSION >= 532 ) { ],
# PA-RISC 2.x CPU [ '.*-.*-.*bsd.*', { target => "BSD-generic32" } ],
# PA-RISC 2.0 is no longer supported as separate 32-bit [ 'x86_64-.*-haiku', { target => "haiku-x86_64" } ],
# target. This is compensated for by run-time detection [ '.*-.*-haiku', { target => "haiku-x86" } ],
# in most critical assembly modules and taking advantage [ '.*-.*-osf', { target => "osf1-alpha" } ],
# of 2.0 architecture in PA-RISC 1.1 build. [ '.*-.*-tru64', { target => "tru64-alpha" } ],
$OUT //= "hpux-parisc1_1-${CC}"; [ '.*-.*-[Uu]nix[Ww]are7',
if ( $KERNEL_BITS eq '64' && ! $CCVENDOR ) { sub {
print <<EOF; return { target => "unixware-7",
disable => [ 'sse2' ] } if $CCVENDOR eq "gnu";
return { target => "unixware-7",
defines => [ '__i386__' ] };
}
],
[ '.*-.*-[Uu]nix[Ww]are20.*', { target => "unixware-2.0",
disable => [ 'sse2', 'sha512' ] } ],
[ '.*-.*-[Uu]nix[Ww]are21.*', { target => "unixware-2.1",
disable => [ 'sse2', 'sha512' ] } ],
[ '.*-.*-vos', { target => "vos",
disable => [ 'threads', 'shared', 'asm',
'dso' ] } ],
[ 'BS2000-siemens-sysv4', { target => "BS2000-OSD" } ],
[ 'i[3456]86-.*-cygwin', { target => "Cygwin-x86" } ],
[ '.*-.*-cygwin',
sub { return { target => "Cygwin-${MACHINE}" } } ],
[ 'x86-.*-android|i.86-.*-android', { target => "android-x86" } ],
[ 'armv[7-9].*-.*-android', { target => "android-armeabi",
cflags => [ '-march=armv7-a' ],
cxxflags => [ '-march=armv7-a' ] } ],
[ 'arm.*-.*-android', { target => "android-armeabi" } ],
[ '.*-hpux1.*',
sub {
my $KERNEL_BITS = $ENV{KERNEL_BITS};
my %common_return = ( defines => [ '_REENTRANT' ] );
$KERNEL_BITS ||= `getconf KERNEL_BITS 2>/dev/null` // '32';
# See <sys/unistd.h> for further info on CPU_VERSION.
my $CPU_VERSION = `getconf CPU_VERSION 2>/dev/null` // 0;
if ( $CPU_VERSION >= 768 ) {
# IA-64 CPU
return { target => "hpux64-ia64",
%common_return }
if $KERNEL_BITS eq '64' && ! $CCVENDOR;
return { target => "hpux-ia64",
%common_return };
}
if ( $CPU_VERSION >= 532 ) {
# PA-RISC 2.x CPU
# PA-RISC 2.0 is no longer supported as separate 32-bit
# target. This is compensated for by run-time detection
# in most critical assembly modules and taking advantage
# of 2.0 architecture in PA-RISC 1.1 build.
my $target = ($CCVENDOR eq "gnu" && $GCC_BITS eq '64')
? "hpux64-parisc2"
: "hpux-parisc1_1";
if ( $KERNEL_BITS eq '64' && ! $CCVENDOR ) {
print <<EOF;
WARNING! To build 64-bit package, do this: WARNING! To build 64-bit package, do this:
$WHERE/Configure hpux64-parisc2-cc $WHERE/Configure hpux64-parisc2-cc
EOF EOF
maybe_abort(); maybe_abort();
}
return { target => $target,
%common_return };
} }
return $OUT; # PA-RISC 1.1+ CPU?
return { target => "hpux-parisc1_1",
%common_return } if $CPU_VERSION >= 528;
# PA-RISC 1.0 CPU
return { target => "hpux-parisc",
%common_return } if $CPU_VERSION >= 523;
# Motorola(?) CPU
return { target => "hpux",
%common_return };
} }
# PA-RISC 1.1+ CPU? ],
return "hpux-parisc1_1-${CC}" if $CPU_VERSION >= 528; [ '.*-hpux', { target => "hpux-parisc" } ],
# PA-RISC 1.0 CPU [ '.*-aix',
return "hpux-parisc-${CC}" if $CPU_VERSION >= 523; sub {
# Motorola(?) CPU my %config = ();
return "hpux-$CC"; my $KERNEL_BITS = $ENV{KERNEL_BITS};
return $OUT; $KERNEL_BITS ||= `getconf KERNEL_BITMODE 2>/dev/null`;
} $KERNEL_BITS ||= '32';
return "hpux-parisc-$CC" if $GUESSOS =~ '.*-hpux'; my $OBJECT_MODE = $ENV{OBJECT_MODE};
if ( $GUESSOS =~ '.*-aix' ) { $OBJECT_MODE ||= 32;
$KERNEL_BITS //= `getconf KERNEL_BITMODE 2>/dev/null`; $config{target} = "aix";
$KERNEL_BITS //= '32';
my $OBJECT_MODE //= 32;
if ( $CCVENDOR eq "gcc" ) {
$OUT = "aix-gcc";
if ( $OBJECT_MODE == 64 ) { if ( $OBJECT_MODE == 64 ) {
print 'Your $OBJECT_MODE was found to be set to 64'; print 'Your $OBJECT_MODE was found to be set to 64';
$OUT = "aix64-gcc" $config{target} = "aix64";
} } else {
} elsif ( $OBJECT_MODE == 64 ) { if ( $CCVENDOR ne 'gnu' && $KERNEL_BITS eq '64' ) {
print 'Your $OBJECT_MODE was found to be set to 64'; print <<EOF;
$OUT = "aix64-cc";
} else {
$OUT = "aix-cc";
if ( $KERNEL_BITS eq '64' ) {
print <<EOF;
WARNING! To build 64-bit package, do this: WARNING! To build 64-bit package, do this:
$WHERE/Configure aix64-cc $WHERE/Configure aix64-cc
EOF EOF
maybe_abort(); maybe_abort();
}
} }
if ( okrun(
"lsattr -E -O -l `lsdev -c processor|awk '{print \$1;exit}'`",
'grep -i powerpc) >/dev/null 2>&1') ) {
# this applies even to Power3 and later, as they return
# PowerPC_POWER[345]
} else {
$config{disable} = [ 'asm' ];
}
return %config;
} }
if ( okrun( ],
"lsattr -E -O -l `lsdev -c processor|awk '{print \$1;exit}'`", ];
'grep -i powerpc) >/dev/null 2>&1') ) {
# this applies even to Power3 and later, as they return # Map GUESSOS into OpenSSL terminology.
# PowerPC_POWER[345] # Returns a hash table with diverse entries, most importantly 'target',
} else { # but also other entries that are fitting for Configure's %config
$config{disable} = [ 'asm' ]; # and MACHINE.
} # It would be nice to fix this so that this weren't necessary. :( XXX
return %config; sub map_guess {
my $GUESSOS = shift;
foreach my $tuple ( @$map_patterns ) {
my $pat = @$tuple[0];
next if $GUESSOS !~ /^${pat}$/;
my $result = @$tuple[1];
$result = $result->() if ref $result eq 'CODE';
return %$result;
} }
# Last case, return "z" from x-y-z # Last case, return "z" from x-y-z
@ -871,50 +919,20 @@ EOF
### MAIN PROCESSING ### MAIN PROCESSING
### ###
# Common part, does all the real work.
sub common {
my $showguess = shift;
get_machine_etc();
my $GUESSOS = guess_system();
print "Operating system: $GUESSOS\n" if $VERBOSE || $showguess;
$options .= " 386" if $GUESSOS =~ /i386-/;
remove_removed_crypto_directories();
determine_compiler_settings();
my $TARGET = map_guess($GUESSOS) // $CC;
$TARGET = check_solaris_sparc8($TARGET);
$TARGET = check_target_exists($TARGET);
$options .= " $CONFIG_OPTIONS" if $CONFIG_OPTIONS ne '';
return $TARGET;
}
## If called from Configure
sub get_platform { sub get_platform {
my $ref = shift; my %options = @_;
my %options = %{$ref};
$VERBOSE = 1 if defined $options{verbose}; $VERBOSE = 1 if defined $options{verbose};
$options .= " --debug" if defined $options{debug};
$WAIT = 0 if defined $options{nowait}; $WAIT = 0 if defined $options{nowait};
$CC = $options{CC};
$CROSS_COMPILE = $options{CROSS_COMPILE} // '';
my $TARGET = common(0); my $GUESSOS = guess_system();
determine_compiler_settings();
# Populate the environment settings. my %ret = map_guess($GUESSOS);
my %env; $ret{target} = check_solaris_sparc8($ret{target});
$env{__CNF_CPPDEFINES} = $__CNF_CPPDEFINES;
$env{__CNF_CPPINCLUDES} = $__CNF_CPPINCLUDES;
$env{__CNF_CPPFLAGS} = $__CNF_CPPFLAGS;
$env{__CNF_CFLAGS} = $__CNF_CFLAGS;
$env{__CNF_CXXFLAGS} = $__CNF_CXXFLAGS;
# Prepare results and return them
my %ret = {
'target' => $TARGET,
'options' => $options,
'envvars' => %env,
};
return %ret; return %ret;
} }
}
1; 1;