2 # Copyright 1998-2022 The OpenSSL Project Authors. All Rights Reserved.
4 # Licensed under the Apache License 2.0 (the "License"). You may not use
5 # this file except in compliance with the License. You can obtain a copy
6 # in the file LICENSE in the source distribution or at
7 # https://www.openssl.org/source/license.html
9 # Determine the operating system and run ./Configure. Far descendant from
10 # Apache's minarch and GuessOS.
12 package OpenSSL::config;
23 # These control our behavior.
26 my $WHERE = dirname($0);
29 # Machine type, etc., used to determine the platform
40 # Some environment variables; they will affect Configure
41 my $CONFIG_OPTIONS = $ENV{CONFIG_OPTIONS} // '';
45 # For determine_compiler_settings, the list of known compilers
46 my @c_compilers = qw(clang gcc cc);
47 # Methods to determine compiler version. The expected output is one of
48 # MAJOR or MAJOR.MINOR or MAJOR.MINOR.PATCH... or false if the compiler
49 # isn't of the given brand.
50 # This is a list to ensure that gnu comes last, as we've made it a fallback
54 my $v = `$CROSS_COMPILE$CC -v 2>&1`;
55 $v =~ m/(?:(?:clang|LLVM) version|.*based on LLVM)\s+([0-9]+\.[0-9]+)/;
59 my $v = `$CROSS_COMPILE$CC -dumpversion 2>/dev/null`;
60 # Strip off whatever prefix egcs prepends the number with.
61 # Hopefully, this will work for any future prefixes as well.
62 $v =~ s/^[a-zA-Z]*\-//;
67 # This is what we will set as the target for calling Configure.
70 # Pattern matches against "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}"
71 # The patterns are assumed to be wrapped like this: /^(${pattern})$/
72 my $guess_patterns = [
73 [ 'A\/UX:.*', 'm68k-apple-aux3' ],
74 [ 'AIX:[3-9]:4:.*', '${MACHINE}-ibm-aix' ],
75 [ 'AIX:.*?:[5-9]:.*', '${MACHINE}-ibm-aix' ],
76 [ 'AIX:.*', '${MACHINE}-ibm-aix3' ],
77 [ 'HI-UX:.*', '${MACHINE}-hi-hiux' ],
80 my $HPUXVER = $RELEASE;
81 $HPUXVER = s/[^.]*.[0B]*//;
82 # HPUX 10 and 11 targets are unified
83 return "${MACHINE}-hp-hpux1x" if $HPUXVER =~ m@1[0-9]@;
84 return "${MACHINE}-hp-hpux";
87 [ 'IRIX:6\..*', 'mips3-sgi-irix' ],
88 [ 'IRIX64:.*', 'mips4-sgi-irix64' ],
89 [ 'Linux:[2-9]\..*', '${MACHINE}-whatever-linux2' ],
90 [ 'Linux:1\..*', '${MACHINE}-whatever-linux1' ],
91 [ 'GNU.*', 'hurd-x86' ],
92 [ 'LynxOS:.*', '${MACHINE}-lynx-lynxos' ],
93 # BSD/OS always says 386
94 [ 'BSD\/OS:4\..*', 'i486-whatever-bsdi4' ],
95 # Order is important, this has to appear before 'BSD\/386:'
96 [ 'BSD/386:.*?:.*?:.*486.*|BSD/OS:.*?:.*?:.*?:.*486.*',
98 my $BSDVAR = `/sbin/sysctl -n hw.model`;
99 return "i586-whatever-bsdi" if $BSDVAR =~ m@Pentium@;
100 return "i386-whatever-bsdi";
103 [ 'BSD\/386:.*|BSD\/OS:.*', '${MACHINE}-whatever-bsdi' ],
104 # Order is important, this has to appear before 'FreeBSD:'
105 [ 'FreeBSD:.*?:.*?:.*386.*',
109 my $MACH = `sysctl -n hw.model`;
110 $MACH = "i386" if $MACH =~ m@386@;
111 $MACH = "i486" if $MACH =~ m@486@;
112 $MACH = "i686" if $MACH =~ m@Pentium II@;
113 $MACH = "i586" if $MACH =~ m@Pentium@;
114 $MACH = "$MACHINE" if $MACH !~ /i.86/;
115 my $ARCH = 'whatever';
116 $ARCH = "pc" if $MACH =~ m@i[0-9]86@;
117 return "${MACH}-${ARCH}-freebsd${VERS}";
120 [ 'DragonFly:.*', '${MACHINE}-whatever-dragonfly' ],
121 [ 'FreeBSD:.*', '${MACHINE}-whatever-freebsd' ],
122 [ 'Haiku:.*', '${MACHINE}-whatever-haiku' ],
123 # Order is important, this has to appear before 'NetBSD:.*'
124 [ 'NetBSD:.*?:.*?:.*386.*',
126 my $hw = `/usr/sbin/sysctl -n hw.model || /sbin/sysctl -n hw.model`;
127 $hw =~ s@.*(.)86-class.*@i${1}86@;
128 return "${hw}-whatever-netbsd";
131 [ 'NetBSD:.*', '${MACHINE}-whatever-netbsd' ],
132 [ 'OpenBSD:.*', '${MACHINE}-whatever-openbsd' ],
133 [ 'OpenUNIX:.*', '${MACHINE}-unknown-OpenUNIX${VERSION}' ],
134 [ 'OSF1:.*?:.*?:.*alpha.*',
136 my $OSFMAJOR = $RELEASE;
137 $OSFMAJOR =~ 's/^V([0-9]*)\..*$/\1/';
138 return "${MACHINE}-dec-tru64" if $OSFMAJOR =~ m@[45]@;
139 return "${MACHINE}-dec-osf";
142 [ 'Paragon.*?:.*', 'i860-intel-osf1' ],
143 [ 'Rhapsody:.*', 'ppc-apple-rhapsody' ],
144 [ 'Darwin:.*?:.*?:Power.*', 'ppc-apple-darwin' ],
145 [ 'Darwin:.*', '${MACHINE}-apple-darwin' ],
146 [ 'SunOS:5\..*', '${MACHINE}-whatever-solaris2' ],
147 [ 'SunOS:.*', '${MACHINE}-sun-sunos4' ],
148 [ 'UNIX_System_V:4\..*?:.*', '${MACHINE}-whatever-sysv4' ],
149 [ 'VOS:.*?:.*?:i786', 'i386-stratus-vos' ],
150 [ 'VOS:.*?:.*?:.*', 'hppa1.1-stratus-vos' ],
151 [ '.*?:4.*?:R4.*?:m88k', '${MACHINE}-whatever-sysv4' ],
152 [ 'DYNIX\/ptx:4.*?:.*', '${MACHINE}-whatever-sysv4' ],
153 [ '.*?:4\.0:3\.0:3[34]..(,.*)?', 'i486-ncr-sysv4' ],
154 [ 'ULTRIX:.*', '${MACHINE}-unknown-ultrix' ],
155 [ 'POSIX-BC.*', 'BS2000-siemens-sysv4' ],
156 [ 'machten:.*', '${MACHINE}-tenon-${SYSTEM}' ],
157 [ 'library:.*', '${MACHINE}-ncr-sysv4' ],
158 [ 'ConvexOS:.*?:11\.0:.*', '${MACHINE}-v11-${SYSTEM}' ],
159 [ 'MINGW64.*?:.*?:.*?:x86_64', '${MACHINE}-whatever-mingw64' ],
160 [ 'MINGW.*', '${MACHINE}-whatever-mingw' ],
161 [ 'CYGWIN.*', '${MACHINE}-pc-cygwin' ],
162 [ 'vxworks.*', '${MACHINE}-whatever-vxworks' ],
164 # The MACHINE part of the array POSIX::uname() returns on VMS isn't
165 # worth the bits wasted on it. It's better, then, to rely on perl's
166 # %Config, which has a trustworthy item 'archname', especially since
167 # VMS installation aren't multiarch (yet)
168 [ 'OpenVMS:.*', "$Config{archname}-whatever-OpenVMS" ],
170 # Note: there's also NEO and NSR, but they are old and unsupported
171 [ 'NONSTOP_KERNEL:.*:NSE-.*?', 'nse-tandem-nsk${RELEASE}' ],
172 [ 'NONSTOP_KERNEL:.*:NSV-.*?', 'nsv-tandem-nsk${RELEASE}' ],
173 [ 'NONSTOP_KERNEL:.*:NSX-.*?', 'nsx-tandem-nsk${RELEASE}' ],
175 [ sub { -d '/usr/apollo' }, 'whatever-apollo-whatever' ],
178 # Run a command, return true if exit zero else false.
179 # Multiple args are glued together into a pipeline.
180 # Name comes from OpenSSL tests, often written as "ok(run(...."
182 my $command = join(' | ', @_);
183 my $status = system($command) >> 8;
187 # Give user a chance to abort/interrupt if interactive if interactive.
189 if ( $WAIT && -t 1 ) {
191 local $SIG{ALRM} = sub { die "Timeout"; };
194 print "You have about five seconds to abort: ";
195 my $ignored = <STDIN>;
198 print "\n" if $@ =~ /Timeout/;
202 # Look for ISC/SCO with its unique uname program
204 return undef unless IPC::Cmd::can_run('uname');
206 open UNAME, "uname -X 2>/dev/null|" or return '';
211 $line = $_ if m@^Release@;
212 $os = $_ if m@^System@;
216 return undef if $line eq '' or $os eq 'System = SunOS';
218 my @fields = split(/\s+/, $line);
225 if ( -f "/etc/kconfig" ) {
226 return "${MACHINE}-whatever-isc4" if $REL eq '4.0' || $REL eq '4.1';
228 return "whatever-whatever-sco3" if $REL eq '3.2v4.2';
229 return "whatever-whatever-sco5" if $REL =~ m@3\.2v5\.0.*@;
230 if ( $REL eq "4.2MP" ) {
231 return "whatever-whatever-unixware20" if $VERSION =~ m@2\.0.*@;
232 return "whatever-whatever-unixware21" if $VERSION =~ m@2\.1.*@;
233 return "whatever-whatever-unixware2" if $VERSION =~ m@2.*@;
235 return "whatever-whatever-unixware1" if $REL eq "4.2";
236 if ( $REL =~ m@5.*@ ) {
237 # We hardcode i586 in place of ${MACHINE} for the following
238 # reason: even though Pentium is minimum requirement for
239 # platforms in question, ${MACHINE} gets always assigned to
240 # i386. This means i386 gets passed to Configure, which will
241 # cause bad assembler code to be generated.
242 return "i586-sco-unixware7" if $VERSION =~ m@[678].*@;
247 # Return the cputype-vendor-osversion
249 ($SYSTEM, undef, $RELEASE, $VERSION, $MACHINE) = POSIX::uname();
250 my $sys = "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}";
252 # Special-cases for ISC, SCO, Unixware
253 my $REL = is_sco_uname();
254 if ( defined $REL ) {
255 my $result = get_sco_type($REL);
256 return eval "\"$result\"" if $result ne '';
262 foreach my $tuple ( @$guess_patterns ) {
263 my $pat = @$tuple[0];
264 my $check = ref $pat eq 'CODE' ? $pat->($sys) : $sys =~ /^(${pat})$/;
267 my $result = @$tuple[1];
268 $result = $result->() if ref $result eq 'CODE';
269 return eval "\"$result\"";
273 return "${MACHINE}-whatever-${SYSTEM}";
276 # We would use List::Util::pair() for this... unfortunately, that function
277 # only appeared in perl v5.19.3, and we claim to support perl v5.10 and on.
278 # Therefore, we implement a quick cheap variant of our own.
280 croak "Odd number of arguments" if @_ & 1;
285 my $x = [ shift, shift ];
291 # Figure out CC, GCCVAR, etc.
292 sub determine_compiler_settings {
293 # Make a copy and don't touch it. That helps determine if we're finding
294 # the compiler here (false), or if it was set by the user (true.
297 # Set certain default
298 $CCVER = 0; # Unknown
299 $CCVENDOR = ''; # Dunno, don't care (unless found later)
301 # Find a compiler if we don't already have one
303 foreach (@c_compilers) {
304 next unless IPC::Cmd::can_run("$CROSS_COMPILE$_");
311 # Find the compiler vendor and version number for certain compilers
312 foreach my $pair (_pairs @cc_version) {
313 # Try to get the version number.
314 # Failure gets us undef or an empty string
315 my ( $k, $v ) = @$pair;
318 # If we got a version number, process it
322 # The returned version is expected to be one of
326 # MAJOR.MINOR.{whatever}
328 # We don't care what comes after MAJOR.MINOR. All we need is
329 # to have them calculated into a single number, using this
332 # MAJOR * 100 + MINOR
333 # Here are a few examples of what we should get:
338 my @numbers = split /\./, $v;
339 my @factors = (100, 1);
340 while (@numbers && @factors) {
341 $CCVER += shift(@numbers) * shift(@factors)
348 # Vendor specific overrides, only if we didn't determine the compiler here
350 if ( $SYSTEM eq 'OpenVMS' ) {
351 my $v = `CC/VERSION NLA0:`;
353 my ($vendor, $version) =
354 ( $v =~ m/^([A-Z]+) C V([0-9\.-]+) on / );
355 my ($major, $minor, $patch) =
356 ( $version =~ m/^([0-9]+)\.([0-9]+)-0*?(0|[1-9][0-9]*)$/ );
359 $CCVER = ( $major * 100 + $minor ) * 100 + $patch;
363 if ( ${SYSTEM} eq 'AIX' ) {
364 # favor vendor cc over gcc
365 if (IPC::Cmd::can_run('cc')) {
367 $CCVENDOR = ''; # Determine later
372 if ( $SYSTEM eq "SunOS" ) {
373 # check for Oracle Developer Studio, expected output is "cc: blah-blah C x.x blah-blah"
374 my $v = `(cc -V 2>&1) 2>/dev/null | egrep -e '^cc: .* C [0-9]\.[0-9]'`;
376 ( $v =~ m/^.* C ([0-9]+)\.([0-9]+) .*/ );
377 my @factors = (100, 1);
379 while (@numbers && @factors) {
380 $v += shift(@numbers) * shift(@factors)
390 # 'Windows NT' is the system name according to POSIX::uname()!
391 if ( $SYSTEM eq "Windows NT" ) {
392 # favor vendor cl over gcc
393 if (IPC::Cmd::can_run('cl')) {
395 $CCVENDOR = ''; # Determine later
399 if ( $v =~ /Microsoft .* Version ([0-9\.]+) for (x86|x64|ARM|ia64)/ ) {
407 # If no C compiler has been determined at this point, we die. Hard.
410 No C compiler found, please specify one with the environment variable CC,
411 or configure with an explicit configuration target.
415 # On some systems, we assume a cc vendor if it's not already determined
418 $CCVENDOR = 'aix' if $SYSTEM eq 'AIX';
419 $CCVENDOR = 'sun' if $SYSTEM eq 'SunOS';
422 # Some systems need to know extra details
424 if ( $SYSTEM eq "HP-UX" && $CCVENDOR eq 'gnu' ) {
425 # By default gcc is a ILP32 compiler (with long long == 64).
427 if ( $CCVER >= 300 ) {
428 # PA64 support only came in with gcc 3.0.x.
429 # We check if the preprocessor symbol __LP64__ is defined.
430 if ( okrun('echo __LP64__',
431 "$CC -v -E -x c - 2>/dev/null",
432 'grep "^__LP64__" 2>&1 >/dev/null') ) {
433 # __LP64__ has slipped through, it therefore is not defined
440 if ( $SYSTEM eq "SunOS" && $CCVENDOR eq 'gnu' ) {
441 if ( $CCVER >= 300 ) {
442 # 64-bit ABI isn't officially supported in gcc 3.0, but seems
443 # to be working; at the very least 'make test' passes.
444 if ( okrun("$CC -v -E -x c /dev/null 2>&1",
445 'grep __arch64__ >/dev/null') ) {
454 my $vendor = $CCVENDOR ? $CCVENDOR : "(undetermined)";
455 my $version = $CCVER ? $CCVER : "(undetermined)";
456 print "C compiler: $CC\n";
457 print "C compiler vendor: $vendor\n";
458 print "C compiler version: $version\n";
463 [ [ 'uClinux.*64.*', { target => 'uClinux-dist64' } ],
464 [ 'uClinux.*', { target => 'uClinux-dist' } ],
465 [ 'mips3-sgi-irix', { target => 'irix-mips3' } ],
466 [ 'mips4-sgi-irix64',
469 WARNING! To build 64-bit package, do this:
470 $WHERE/Configure irix64-mips4-$CC
473 return { target => "irix-mips3" };
476 [ 'ppc-apple-rhapsody', { target => "rhapsody-ppc" } ],
477 [ 'ppc-apple-darwin.*',
479 my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
480 my $ISA64 = `sysctl -n hw.optional.64bitops 2>/dev/null`;
481 if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
483 WARNING! To build 64-bit package, do this:
484 $WHERE/Configure darwin64-ppc-cc
488 return { target => "darwin64-ppc" }
489 if $ISA64 == 1 && $KERNEL_BITS eq '64';
490 return { target => "darwin-ppc" };
493 [ 'i.86-apple-darwin.*',
495 my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
496 my $ISA64 = `sysctl -n hw.optional.x86_64 2>/dev/null`;
497 if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
499 WARNING! To build 64-bit package, do this:
500 KERNEL_BITS=64 $WHERE/Configure \[\[ options \]\]
504 return { target => "darwin64-x86_64" }
505 if $ISA64 == 1 && $KERNEL_BITS eq '64';
506 return { target => "darwin-i386" };
509 [ 'x86_64-apple-darwin.*',
511 my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
512 # macOS >= 10.15 is 64-bit only
513 my $SW_VERS = `sw_vers -productVersion 2>/dev/null`;
514 if ($SW_VERS =~ /^(\d+)\.(\d+)\.(\d+)$/) {
515 if ($1 > 10 || ($1 == 10 && $2 >= 15)) {
516 die "32-bit applications not supported on macOS 10.15 or later\n" if $KERNEL_BITS eq '32';
517 return { target => "darwin64-x86_64" };
520 return { target => "darwin-i386" } if $KERNEL_BITS eq '32';
523 WARNING! To build 32-bit package, do this:
524 KERNEL_BITS=32 $WHERE/Configure \[\[ options \]\]
527 return { target => "darwin64-x86_64" };
530 [ 'arm64-apple-darwin.*', { target => "darwin64-arm64" } ],
531 [ 'armv6\+7-.*-iphoneos',
532 { target => "iphoneos-cross",
533 cflags => [ qw(-arch armv6 -arch armv7) ],
534 cxxflags => [ qw(-arch armv6 -arch armv7) ] }
536 [ 'arm64-.*-iphoneos|.*-.*-ios64',
537 { target => "ios64-cross" }
540 sub { return { target => "iphoneos-cross",
541 cflags => [ "-arch ${MACHINE}" ],
542 cxxflags => [ "-arch ${MACHINE}" ] }; }
544 [ 'alpha-.*-linux2.*',
546 my $ISA = `awk '/cpu model/{print \$4;exit(0);}' /proc/cpuinfo`;
549 if ( $CCVENDOR eq "gnu" ) {
550 if ( $ISA =~ 'EV5|EV45' ) {
551 %config = ( cflags => [ '-mcpu=ev5' ],
552 cxxflags => [ '-mcpu=ev5' ] );
553 } elsif ( $ISA =~ 'EV56|PCA56' ) {
554 %config = ( cflags => [ '-mcpu=ev56' ],
555 cxxflags => [ '-mcpu=ev56' ] );
557 %config = ( cflags => [ '-mcpu=ev6' ],
558 cxxflags => [ '-mcpu=ev6' ] );
561 return { target => "linux-alpha",
567 my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
568 if ( $KERNEL_BITS eq '' ) {
570 WARNING! To build 64-bit package, do this:
571 $WHERE/Configure linux-ppc64
575 return { target => "linux-ppc64" } if $KERNEL_BITS eq '64';
578 if (!okrun('echo __LP64__',
579 'gcc -E -x c - 2>/dev/null',
580 'grep "^__LP64__" 2>&1 >/dev/null') ) {
581 %config = ( cflags => [ '-m32' ],
582 cxxflags => [ '-m32' ] );
584 return { target => "linux-ppc",
588 [ 'ppc64le-.*-linux2', { target => "linux-ppc64le" } ],
589 [ 'ppc-.*-linux2', { target => "linux-ppc" } ],
590 [ 'mips64.*-*-linux2',
593 WARNING! To build 64-bit package, do this:
594 $WHERE/Configure linux64-mips64
597 return { target => "linux-mips64" };
600 [ 'mips.*-.*-linux2', { target => "linux-mips32" } ],
601 [ 'ppc60x-.*-vxworks.*', { target => "vxworks-ppc60x" } ],
602 [ 'ppcgen-.*-vxworks.*', { target => "vxworks-ppcgen" } ],
603 [ 'pentium-.*-vxworks.*', { target => "vxworks-pentium" } ],
604 [ 'simlinux-.*-vxworks.*', { target => "vxworks-simlinux" } ],
605 [ 'mips-.*-vxworks.*', { target => "vxworks-mips" } ],
606 [ 'e2k-.*-linux.*', { target => "linux-generic64",
607 defines => [ 'L_ENDIAN' ] } ],
608 [ 'ia64-.*-linux.', { target => "linux-ia64" } ],
609 [ 'sparc64-.*-linux2',
612 WARNING! If you *know* that your GNU C supports 64-bit/V9 ABI and you
613 want to build 64-bit library, do this:
614 $WHERE/Configure linux64-sparcv9
617 return { target => "linux-sparcv9" };
622 my $KARCH = `awk '/^type/{print \$3;exit(0);}' /proc/cpuinfo`;
624 return { target => "linux-sparcv9" } if $KARCH =~ 'sun4u.*';
625 return { target => "linux-sparcv8" } if $KARCH =~ 'sun4[md]';
626 return { target => "linux-generic32",
627 defines => [ 'L_ENDIAN' ] };
630 [ 'parisc.*-.*-linux2',
632 # 64-bit builds under parisc64 linux are not supported and
633 # compiler is expected to generate 32-bit objects...
635 `awk '/cpu family/{print substr(\$5,1,3); exit(0);}' /proc/cpuinfo`;
637 `awk '/^cpu.[ ]*: PA/{print substr(\$3,3); exit(0);}' /proc/cpuinfo`;
638 # TODO XXX Model transformations
639 # 0. CPU Architecture for the 1.1 processor has letter suffixes.
640 # We strip that off assuming no further arch. identification
641 # will ever be used by GCC.
642 # 1. I'm most concerned about whether is a 7300LC is closer to a
643 # 7100 versus a 7100LC.
644 # 2. The variant 64-bit processors cause concern should GCC support
645 # explicit schedulers for these chips in the future.
646 # PA7300LC -> 7100LC (1.1)
647 # PA8200 -> 8000 (2.0)
648 # PA8500 -> 8000 (2.0)
649 # PA8600 -> 8000 (2.0)
650 $CPUSCHEDULE =~ s/7300LC/7100LC/;
651 $CPUSCHEDULE =~ s/8.00/8000/;
653 { target => "linux-generic32",
654 defines => [ 'B_ENDIAN' ],
655 cflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ],
656 cxxflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ]
660 [ 'armv[1-3].*-.*-linux2', { target => "linux-generic32" } ],
661 [ 'armv[7-9].*-.*-linux2', { target => "linux-armv4",
662 cflags => [ '-march=armv7-a' ],
663 cxxflags => [ '-march=armv7-a' ] } ],
664 [ 'arm.*-.*-linux2', { target => "linux-armv4" } ],
665 [ 'aarch64-.*-linux2', { target => "linux-aarch64" } ],
666 [ 'sh.*b-.*-linux2', { target => "linux-generic32",
667 defines => [ 'B_ENDIAN' ] } ],
668 [ 'sh.*-.*-linux2', { target => "linux-generic32",
669 defines => [ 'L_ENDIAN' ] } ],
670 [ 'm68k.*-.*-linux2', { target => "linux-generic32",
671 defines => [ 'B_ENDIAN' ] } ],
672 [ 's390-.*-linux2', { target => "linux-generic32",
673 defines => [ 'B_ENDIAN' ] } ],
676 # Disabled until a glibc bug is fixed; see Configure.
678 || okrun('egrep -e \'^features.* highgprs\' /proc/cpuinfo >/dev/null') )
681 WARNING! To build "highgprs" 32-bit package, do this:
682 $WHERE/Configure linux32-s390x
686 return { target => "linux64-s390x" };
689 [ 'x86_64-.*-linux.',
691 return { target => "linux-x32" }
692 if okrun("$CC -dM -E -x c /dev/null 2>&1",
693 'grep -q ILP32 >/dev/null');
694 return { target => "linux-x86_64" };
699 # On machines where the compiler understands -m32, prefer a
700 # config target that uses it
701 return { target => "linux-x86" }
702 if okrun("$CC -m32 -E -x c /dev/null >/dev/null 2>&1");
703 return { target => "linux-elf" };
706 [ '.*86-.*-linux1', { target => "linux-aout" } ],
707 [ 'riscv64-.*-linux.', { target => "linux64-riscv64" } ],
708 [ '.*-.*-linux.', { target => "linux-generic32" } ],
709 [ 'sun4[uv].*-.*-solaris2',
711 my $KERNEL_BITS = $ENV{KERNEL_BITS};
712 my $ISA64 = `isainfo 2>/dev/null | grep sparcv9`;
713 my $KB = $KERNEL_BITS // '64';
714 if ( $ISA64 ne "" && $KB eq '64' ) {
715 if ( $CCVENDOR eq "sun" && $CCVER >= 500 ) {
717 WARNING! To build 32-bit package, do this:
718 $WHERE/Configure solaris-sparcv9-cc
721 } elsif ( $CCVENDOR eq "gnu" && $GCC_ARCH eq "-m64" ) {
722 # $GCC_ARCH denotes default ABI chosen by compiler driver
723 # (first one found on the $PATH). I assume that user
724 # expects certain consistency with the rest of his builds
725 # and therefore switch over to 64-bit. <appro>
727 WARNING! To build 32-bit package, do this:
728 $WHERE/Configure solaris-sparcv9-gcc
731 return { target => "solaris64-sparcv9-gcc" };
732 } elsif ( $GCC_ARCH eq "-m32" ) {
734 NOTICE! If you *know* that your GNU C supports 64-bit/V9 ABI and you wish
735 to build 64-bit library, do this:
736 $WHERE/Configure solaris64-sparcv9-gcc
741 return { target => "solaris64-sparcv9-cc" }
742 if $ISA64 ne "" && $KB eq '64';
743 return { target => "solaris-sparcv9-cc" };
746 [ 'sun4m-.*-solaris2', { target => "solaris-sparcv8" } ],
747 [ 'sun4d-.*-solaris2', { target => "solaris-sparcv8" } ],
748 [ 'sun4.*-.*-solaris2', { target => "solaris-sparcv7" } ],
749 [ '.*86.*-.*-solaris2',
751 my $KERNEL_BITS = $ENV{KERNEL_BITS};
752 my $ISA64 = `isainfo 2>/dev/null | grep amd64`;
753 my $KB = $KERNEL_BITS // '64';
754 if ($ISA64 ne "" && $KB eq '64') {
755 return { target => "solaris64-x86_64-gcc" } if $CCVENDOR eq "gnu";
756 return { target => "solaris64-x86_64-cc" };
758 my $REL = uname('-r');
760 my @tmp_disable = ();
761 push @tmp_disable, 'sse2' if int($REL) < 10;
762 #There is no solaris-x86-cc target
763 return { target => "solaris-x86-gcc",
764 disable => [ @tmp_disable ] };
767 # We don't have any sunos target in Configurations/*.conf, so why here?
768 [ '.*-.*-sunos4', { target => "sunos" } ],
769 [ '.*86.*-.*-bsdi4', { target => "BSD-x86-elf",
770 lflags => [ '-ldl' ],
771 disable => [ 'sse2' ] } ],
772 [ 'alpha.*-.*-.*bsd.*', { target => "BSD-generic64",
773 defines => [ 'L_ENDIAN' ] } ],
774 [ 'powerpc64-.*-.*bsd.*', { target => "BSD-generic64",
775 defines => [ 'B_ENDIAN' ] } ],
776 [ 'riscv64-.*-.*bsd.*', { target => "BSD-riscv64" } ],
777 [ 'sparc64-.*-.*bsd.*', { target => "BSD-sparc64" } ],
778 [ 'ia64-.*-.*bsd.*', { target => "BSD-ia64" } ],
779 [ 'x86_64-.*-dragonfly.*', { target => "BSD-x86_64" } ],
780 [ 'amd64-.*-.*bsd.*', { target => "BSD-x86_64" } ],
781 [ 'arm64-.*-.*bsd.*', { target => "BSD-aarch64" } ],
782 [ '.*86.*-.*-.*bsd.*',
784 # mimic ld behaviour when it's looking for libc...
786 if ( -l "/usr/lib/libc.so" ) {
787 $libc = "/usr/lib/libc.so";
789 # ld searches for highest libc.so.* and so do we
791 `(ls /usr/lib/libc.so.* /lib/libc.so.* | tail -1) 2>/dev/null`;
793 my $what = `file -L $libc 2>/dev/null`;
794 return { target => "BSD-x86-elf" } if $what =~ /ELF/;
795 return { target => "BSD-x86",
796 disable => [ 'sse2' ] };
799 [ '.*-.*-.*bsd.*', { target => "BSD-generic32" } ],
800 [ 'x86_64-.*-haiku', { target => "haiku-x86_64" } ],
801 [ '.*-.*-haiku', { target => "haiku-x86" } ],
802 [ '.*-.*-osf', { target => "osf1-alpha" } ],
803 [ '.*-.*-tru64', { target => "tru64-alpha" } ],
804 [ '.*-.*-[Uu]nix[Ww]are7',
806 return { target => "unixware-7",
807 disable => [ 'sse2' ] } if $CCVENDOR eq "gnu";
808 return { target => "unixware-7",
809 defines => [ '__i386__' ] };
812 [ '.*-.*-[Uu]nix[Ww]are20.*', { target => "unixware-2.0",
813 disable => [ 'sse2', 'sha512' ] } ],
814 [ '.*-.*-[Uu]nix[Ww]are21.*', { target => "unixware-2.1",
815 disable => [ 'sse2', 'sha512' ] } ],
816 [ '.*-.*-vos', { target => "vos",
817 disable => [ 'threads', 'shared', 'asm',
819 [ 'BS2000-siemens-sysv4', { target => "BS2000-OSD" } ],
820 [ 'i[3456]86-.*-cygwin', { target => "Cygwin-x86" } ],
822 sub { return { target => "Cygwin-${MACHINE}" } } ],
823 [ 'x86-.*-android|i.86-.*-android', { target => "android-x86" } ],
824 [ 'armv[7-9].*-.*-android', { target => "android-armeabi",
825 cflags => [ '-march=armv7-a' ],
826 cxxflags => [ '-march=armv7-a' ] } ],
827 [ 'arm.*-.*-android', { target => "android-armeabi" } ],
830 my $KERNEL_BITS = $ENV{KERNEL_BITS};
831 my %common_return = ( defines => [ '_REENTRANT' ] );
832 $KERNEL_BITS ||= `getconf KERNEL_BITS 2>/dev/null` // '32';
833 # See <sys/unistd.h> for further info on CPU_VERSION.
834 my $CPU_VERSION = `getconf CPU_VERSION 2>/dev/null` // 0;
835 if ( $CPU_VERSION >= 768 ) {
837 return { target => "hpux64-ia64",
839 if $KERNEL_BITS eq '64' && ! $CCVENDOR;
840 return { target => "hpux-ia64",
843 if ( $CPU_VERSION >= 532 ) {
845 # PA-RISC 2.0 is no longer supported as separate 32-bit
846 # target. This is compensated for by run-time detection
847 # in most critical assembly modules and taking advantage
848 # of 2.0 architecture in PA-RISC 1.1 build.
849 my $target = ($CCVENDOR eq "gnu" && $GCC_BITS eq '64')
852 if ( $KERNEL_BITS eq '64' && ! $CCVENDOR ) {
854 WARNING! To build 64-bit package, do this:
855 $WHERE/Configure hpux64-parisc2-cc
859 return { target => $target,
863 return { target => "hpux-parisc1_1",
864 %common_return } if $CPU_VERSION >= 528;
866 return { target => "hpux-parisc",
867 %common_return } if $CPU_VERSION >= 523;
869 return { target => "hpux",
873 [ '.*-hpux', { target => "hpux-parisc" } ],
877 my $KERNEL_BITS = $ENV{KERNEL_BITS};
878 $KERNEL_BITS ||= `getconf KERNEL_BITMODE 2>/dev/null`;
879 $KERNEL_BITS ||= '32';
880 my $OBJECT_MODE = $ENV{OBJECT_MODE};
882 $config{target} = "aix";
883 if ( $OBJECT_MODE == 64 ) {
884 print 'Your $OBJECT_MODE was found to be set to 64';
885 $config{target} = "aix64";
887 if ( $CCVENDOR ne 'gnu' && $KERNEL_BITS eq '64' ) {
889 WARNING! To build 64-bit package, do this:
890 $WHERE/Configure aix64-cc
896 "(lsattr -E -O -l `lsdev -c processor|awk '{print \$1;exit}'`",
897 'grep -i powerpc) >/dev/null 2>&1') ) {
898 # this applies even to Power3 and later, as they return
901 $config{disable} = [ 'asm' ];
907 # Windows values found by looking at Perl 5's win32/win32.c
908 [ '(amd64|ia64|x86|ARM)-.*?-Windows NT',
910 # If we determined the arch by asking cl, take that value,
911 # otherwise the SYSTEM we got from from POSIX::uname().
912 my $arch = $CL_ARCH // $1;
916 $config = { 'amd64' => { target => 'VC-WIN64A' },
917 'ia64' => { target => 'VC-WIN64I' },
918 'x86' => { target => 'VC-WIN32' },
919 'x64' => { target => 'VC-WIN64A' },
920 'ARM' => { target => 'VC-WIN64-ARM' },
922 die <<_____ unless defined $config;
924 I do not know how to handle ${arch}.
927 die <<_____ unless defined $config;
929 Could not figure out the architecture.
936 # VMS values found by observation on existing machinery.
937 [ 'VMS_AXP-.*?-OpenVMS', { target => 'vms-alpha' } ],
938 [ 'VMS_IA64-.*?-OpenVMS', { target => 'vms-ia64' } ],
939 [ 'VMS_x86_64-.*?-OpenVMS', { target => 'vms-x86_64' } ],
941 # TODO: There are a few more choices among OpenSSL config targets, but
942 # reaching them involves a bit more than just a host tripet. Select
943 # environment variables could do the job to cover for more granular
944 # build options such as data model (ILP32 or LP64), thread support
945 # model (PUT, SPT or nothing), target execution environment (OSS or
946 # GUARDIAN). And still, there must be some kind of default when
947 # nothing else is said.
949 # nsv is a virtual x86 environment, equivalent to nsx, so we enforce
951 [ 'nse-tandem-nsk.*', { target => 'nonstop-nse' } ],
952 [ 'nsv-tandem-nsk.*', { target => 'nonstop-nsx' } ],
953 [ 'nsx-tandem-nsk.*', { target => 'nonstop-nsx' } ],
957 # Map GUESSOS into OpenSSL terminology.
958 # Returns a hash table with diverse entries, most importantly 'target',
959 # but also other entries that are fitting for Configure's %config
961 # It would be nice to fix this so that this weren't necessary. :( XXX
965 foreach my $tuple ( @$map_patterns ) {
966 my $pat = @$tuple[0];
967 next if $GUESSOS !~ /^${pat}$/;
968 my $result = @$tuple[1];
969 $result = $result->() if ref $result eq 'CODE';
973 # Last case, return "z" from x-y-z
974 my @fields = split(/-/, $GUESSOS);
975 return ( target => $fields[2] );
978 # gcc < 2.8 does not support -march=ultrasparc
979 sub check_solaris_sparc8 {
981 if ( $CCVENDOR eq 'gnu' && $CCVER < 208 ) {
982 if ( $OUT eq 'solaris-sparcv9-gcc' ) {
984 WARNING! Downgrading to solaris-sparcv8-gcc
985 Upgrade to gcc-2.8 or later.
988 return 'solaris-sparcv8-gcc';
990 if ( $OUT eq "linux-sparcv9" ) {
992 WARNING! Downgrading to linux-sparcv8
993 Upgrade to gcc-2.8 or later.
996 return 'linux-sparcv8';
1009 $VERBOSE = 1 if defined $options{verbose};
1010 $WAIT = 0 if defined $options{nowait};
1012 $CROSS_COMPILE = $options{CROSS_COMPILE} // '';
1014 my $GUESSOS = guess_system();
1015 determine_compiler_settings();
1017 my %ret = map_guess($GUESSOS);
1018 $ret{target} = check_solaris_sparc8($ret{target});