2 # Copyright 1998-2023 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;
24 # These control our behavior.
27 my $WHERE = dirname($0);
30 # Machine type, etc., used to determine the platform
41 # Some environment variables; they will affect Configure
42 my $CONFIG_OPTIONS = $ENV{CONFIG_OPTIONS} // '';
46 # For determine_compiler_settings, the list of known compilers
47 my @c_compilers = qw(clang gcc cc);
48 # Methods to determine compiler version. The expected output is one of
49 # MAJOR or MAJOR.MINOR or MAJOR.MINOR.PATCH... or false if the compiler
50 # isn't of the given brand.
51 # This is a list to ensure that gnu comes last, as we've made it a fallback
55 return undef unless IPC::Cmd::can_run("$CROSS_COMPILE$CC");
56 my $v = `$CROSS_COMPILE$CC -v 2>&1`;
57 $v =~ m/(?:(?:clang|LLVM) version|.*based on LLVM)\s+([0-9]+\.[0-9]+)/;
61 return undef unless IPC::Cmd::can_run("$CROSS_COMPILE$CC");
62 my $nul = File::Spec->devnull();
63 my $v = `$CROSS_COMPILE$CC -dumpversion 2> $nul`;
64 # Strip off whatever prefix egcs prepends the number with.
65 # Hopefully, this will work for any future prefixes as well.
66 $v =~ s/^[a-zA-Z]*\-//;
71 # This is what we will set as the target for calling Configure.
74 # Pattern matches against "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}"
75 # The patterns are assumed to be wrapped like this: /^(${pattern})$/
76 my $guess_patterns = [
77 [ 'A\/UX:.*', 'm68k-apple-aux3' ],
78 [ 'AIX:[3-9]:4:.*', '${MACHINE}-ibm-aix' ],
79 [ 'AIX:.*?:[5-9]:.*', '${MACHINE}-ibm-aix' ],
80 [ 'AIX:.*', '${MACHINE}-ibm-aix3' ],
81 [ 'HI-UX:.*', '${MACHINE}-hi-hiux' ],
84 my $HPUXVER = $RELEASE;
85 $HPUXVER =~ s/[^.]*.[0B]*//;
86 # HPUX 10 and 11 targets are unified
87 return "${MACHINE}-hp-hpux1x" if $HPUXVER =~ m@1[0-9]@;
88 return "${MACHINE}-hp-hpux";
91 [ 'IRIX:6\..*', 'mips3-sgi-irix' ],
92 [ 'IRIX64:.*', 'mips4-sgi-irix64' ],
93 [ 'Linux:[2-9]\..*', '${MACHINE}-whatever-linux2' ],
94 [ 'Linux:1\..*', '${MACHINE}-whatever-linux1' ],
95 [ 'GNU:.*86-AT386', 'hurd-x86' ],
96 [ 'GNU:.*86_64-AT386', 'hurd-x86_64' ],
97 [ 'LynxOS:.*', '${MACHINE}-lynx-lynxos' ],
98 # BSD/OS always says 386
99 [ 'BSD\/OS:4\..*', 'i486-whatever-bsdi4' ],
100 # Order is important, this has to appear before 'BSD\/386:'
101 [ 'BSD/386:.*?:.*?:.*486.*|BSD/OS:.*?:.*?:.*?:.*486.*',
103 my $BSDVAR = `/sbin/sysctl -n hw.model`;
104 return "i586-whatever-bsdi" if $BSDVAR =~ m@Pentium@;
105 return "i386-whatever-bsdi";
108 [ 'BSD\/386:.*|BSD\/OS:.*', '${MACHINE}-whatever-bsdi' ],
109 # Order is important, this has to appear before 'FreeBSD:'
110 [ 'FreeBSD:.*?:.*?:.*386.*',
114 my $MACH = `sysctl -n hw.model`;
115 $MACH = "i386" if $MACH =~ m@386@;
116 $MACH = "i486" if $MACH =~ m@486@;
117 $MACH = "i686" if $MACH =~ m@Pentium II@;
118 $MACH = "i586" if $MACH =~ m@Pentium@;
119 $MACH = "$MACHINE" if $MACH !~ /i.86/;
120 my $ARCH = 'whatever';
121 $ARCH = "pc" if $MACH =~ m@i[0-9]86@;
122 return "${MACH}-${ARCH}-freebsd${VERS}";
125 [ 'DragonFly:.*', '${MACHINE}-whatever-dragonfly' ],
126 [ 'FreeBSD:.*', '${MACHINE}-whatever-freebsd' ],
127 [ 'Haiku:.*', '${MACHINE}-whatever-haiku' ],
128 # Order is important, this has to appear before 'NetBSD:.*'
129 [ 'NetBSD:.*?:.*?:.*386.*',
131 my $hw = `/usr/sbin/sysctl -n hw.model || /sbin/sysctl -n hw.model`;
132 $hw =~ s@.*(.)86-class.*@i${1}86@;
133 return "${hw}-whatever-netbsd";
136 [ 'NetBSD:.*', '${MACHINE}-whatever-netbsd' ],
137 [ 'OpenBSD:.*', '${MACHINE}-whatever-openbsd' ],
138 [ 'OpenUNIX:.*', '${MACHINE}-unknown-OpenUNIX${VERSION}' ],
139 [ 'OSF1:.*?:.*?:.*alpha.*',
141 my $OSFMAJOR = $RELEASE;
142 $OSFMAJOR =~ 's/^V([0-9]*)\..*$/\1/';
143 return "${MACHINE}-dec-tru64" if $OSFMAJOR =~ m@[45]@;
144 return "${MACHINE}-dec-osf";
147 [ 'Paragon.*?:.*', 'i860-intel-osf1' ],
148 [ 'Rhapsody:.*', 'ppc-apple-rhapsody' ],
149 [ 'Darwin:.*?:.*?:Power.*', 'ppc-apple-darwin' ],
150 [ 'Darwin:.*', '${MACHINE}-apple-darwin' ],
151 [ 'SunOS:5\..*', '${MACHINE}-whatever-solaris2' ],
152 [ 'SunOS:.*', '${MACHINE}-sun-sunos4' ],
153 [ 'UNIX_System_V:4\..*?:.*', '${MACHINE}-whatever-sysv4' ],
154 [ 'VOS:.*?:.*?:i786', 'i386-stratus-vos' ],
155 [ 'VOS:.*?:.*?:.*', 'hppa1.1-stratus-vos' ],
156 [ '.*?:4.*?:R4.*?:m88k', '${MACHINE}-whatever-sysv4' ],
157 [ 'DYNIX\/ptx:4.*?:.*', '${MACHINE}-whatever-sysv4' ],
158 [ '.*?:4\.0:3\.0:3[34]..(,.*)?', 'i486-ncr-sysv4' ],
159 [ 'ULTRIX:.*', '${MACHINE}-unknown-ultrix' ],
160 [ 'POSIX-BC.*', 'BS2000-siemens-sysv4' ],
161 [ 'machten:.*', '${MACHINE}-tenon-${SYSTEM}' ],
162 [ 'library:.*', '${MACHINE}-ncr-sysv4' ],
163 [ 'ConvexOS:.*?:11\.0:.*', '${MACHINE}-v11-${SYSTEM}' ],
164 [ 'MINGW64.*?:.*?:.*?:x86_64', '${MACHINE}-whatever-mingw64' ],
165 [ 'MINGW.*', '${MACHINE}-whatever-mingw' ],
166 [ 'CYGWIN.*', '${MACHINE}-pc-cygwin' ],
167 [ 'vxworks.*', '${MACHINE}-whatever-vxworks' ],
169 # The MACHINE part of the array POSIX::uname() returns on VMS isn't
170 # worth the bits wasted on it. It's better, then, to rely on perl's
171 # %Config, which has a trustworthy item 'archname', especially since
172 # VMS installation aren't multiarch (yet)
173 [ 'OpenVMS:.*', "$Config{archname}-whatever-OpenVMS" ],
175 # Note: there's also NEO and NSR, but they are old and unsupported
176 [ 'NONSTOP_KERNEL:.*:NSE-.*?', 'nse-tandem-nsk${RELEASE}' ],
177 [ 'NONSTOP_KERNEL:.*:NSV-.*?', 'nsv-tandem-nsk${RELEASE}' ],
178 [ 'NONSTOP_KERNEL:.*:NSX-.*?', 'nsx-tandem-nsk${RELEASE}' ],
180 [ sub { -d '/usr/apollo' }, 'whatever-apollo-whatever' ],
183 # Run a command, return true if exit zero else false.
184 # Multiple args are glued together into a pipeline.
185 # Name comes from OpenSSL tests, often written as "ok(run(...."
187 my $command = join(' | ', @_);
188 my $status = system($command) >> 8;
192 # Give user a chance to abort/interrupt if interactive if interactive.
194 if ( $WAIT && -t 1 ) {
196 local $SIG{ALRM} = sub { die "Timeout"; };
199 print "You have about five seconds to abort: ";
200 my $ignored = <STDIN>;
203 print "\n" if $@ =~ /Timeout/;
207 # Look for ISC/SCO with its unique uname program
209 return undef unless IPC::Cmd::can_run('uname');
211 open UNAME, "uname -X 2>/dev/null|" or return '';
216 $line = $_ if m@^Release@;
217 $os = $_ if m@^System@;
221 return undef if $line eq '' or $os eq 'System = SunOS';
223 my @fields = split(/\s+/, $line);
230 if ( -f "/etc/kconfig" ) {
231 return "${MACHINE}-whatever-isc4" if $REL eq '4.0' || $REL eq '4.1';
233 return "whatever-whatever-sco3" if $REL eq '3.2v4.2';
234 return "whatever-whatever-sco5" if $REL =~ m@3\.2v5\.0.*@;
235 if ( $REL eq "4.2MP" ) {
236 return "whatever-whatever-unixware20" if $VERSION =~ m@2\.0.*@;
237 return "whatever-whatever-unixware21" if $VERSION =~ m@2\.1.*@;
238 return "whatever-whatever-unixware2" if $VERSION =~ m@2.*@;
240 return "whatever-whatever-unixware1" if $REL eq "4.2";
241 if ( $REL =~ m@5.*@ ) {
242 # We hardcode i586 in place of ${MACHINE} for the following
243 # reason: even though Pentium is minimum requirement for
244 # platforms in question, ${MACHINE} gets always assigned to
245 # i386. This means i386 gets passed to Configure, which will
246 # cause bad assembler code to be generated.
247 return "i586-sco-unixware7" if $VERSION =~ m@[678].*@;
252 # Return the cputype-vendor-osversion
254 ($SYSTEM, undef, $RELEASE, $VERSION, $MACHINE) = POSIX::uname();
255 my $sys = "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}";
257 # Special-cases for ISC, SCO, Unixware
258 my $REL = is_sco_uname();
259 if ( defined $REL ) {
260 my $result = get_sco_type($REL);
261 return eval "\"$result\"" if $result ne '';
267 foreach my $tuple ( @$guess_patterns ) {
268 my $pat = @$tuple[0];
269 my $check = ref $pat eq 'CODE' ? $pat->($sys) : $sys =~ /^(${pat})$/;
272 my $result = @$tuple[1];
273 $result = $result->() if ref $result eq 'CODE';
274 return eval "\"$result\"";
278 return "${MACHINE}-whatever-${SYSTEM}";
281 # We would use List::Util::pair() for this... unfortunately, that function
282 # only appeared in perl v5.19.3, and we claim to support perl v5.10 and on.
283 # Therefore, we implement a quick cheap variant of our own.
285 croak "Odd number of arguments" if @_ & 1;
290 my $x = [ shift, shift ];
296 # Figure out CC, GCCVAR, etc.
297 sub determine_compiler_settings {
298 # Make a copy and don't touch it. That helps determine if we're finding
299 # the compiler here (false), or if it was set by the user (true.
302 # Set certain default
303 $CCVER = 0; # Unknown
304 $CCVENDOR = ''; # Dunno, don't care (unless found later)
306 # Find a compiler if we don't already have one
308 foreach (@c_compilers) {
309 next unless IPC::Cmd::can_run("$CROSS_COMPILE$_");
316 # Find the compiler vendor and version number for certain compilers
317 foreach my $pair (_pairs @cc_version) {
318 # Try to get the version number.
319 # Failure gets us undef or an empty string
320 my ( $k, $v ) = @$pair;
323 # If we got a version number, process it
325 $v =~ s/[^.]*.0*// if $SYSTEM eq 'HP-UX';
328 # The returned version is expected to be one of
332 # MAJOR.MINOR.{whatever}
334 # We don't care what comes after MAJOR.MINOR. All we need is
335 # to have them calculated into a single number, using this
338 # MAJOR * 100 + MINOR
339 # Here are a few examples of what we should get:
344 my @numbers = split /\./, $v;
345 my @factors = (100, 1);
346 while (@numbers && @factors) {
347 $CCVER += shift(@numbers) * shift(@factors)
354 # Vendor specific overrides, only if we didn't determine the compiler here
356 if ( $SYSTEM eq 'OpenVMS' ) {
357 my $v = `CC/VERSION NLA0:`;
359 # The normal releases have a version number prefixed with a V.
360 # However, other letters have been seen as well (for example X),
361 # and it's documented that HP (now VSI) reserve the letter W, X,
362 # Y and Z for their own uses.
363 my ($vendor, $arch, $version, $extra) =
365 ([A-Z]+) # Usually VSI
367 (?:\s+(.*?))? # Possible build arch
368 \s+ [VWXYZ]([0-9\.-]+) # Version
369 (?:\s+\((.*?)\))? # Possible extra data
372 my ($major, $minor, $patch) =
373 ( $version =~ m/^([0-9]+)\.([0-9]+)-0*?(0|[1-9][0-9]*)$/ );
376 $CCVER = ( $major * 100 + $minor ) * 100 + $patch;
380 if ( ${SYSTEM} eq 'AIX' ) {
381 # favor vendor cc over gcc
382 if (IPC::Cmd::can_run('cc')) {
384 $CCVENDOR = ''; # Determine later
389 if ( $SYSTEM eq "SunOS" ) {
390 # check for Oracle Developer Studio, expected output is "cc: blah-blah C x.x blah-blah"
391 my $v = `(cc -V 2>&1) 2>/dev/null | egrep -e '^cc: .* C [0-9]\.[0-9]'`;
393 ( $v =~ m/^.* C ([0-9]+)\.([0-9]+) .*/ );
394 my @factors = (100, 1);
396 while (@numbers && @factors) {
397 $v += shift(@numbers) * shift(@factors)
407 # 'Windows NT' is the system name according to POSIX::uname()!
408 if ( $SYSTEM eq "Windows NT" ) {
409 # favor vendor cl over gcc
410 if (IPC::Cmd::can_run('cl')) {
412 $CCVENDOR = ''; # Determine later
416 if ( $v =~ /Microsoft .* Version ([0-9\.]+) for (x86|x64|ARM|ia64)/ ) {
424 # If no C compiler has been determined at this point, we die. Hard.
427 No C compiler found, please specify one with the environment variable CC,
428 or configure with an explicit configuration target.
432 # On some systems, we assume a cc vendor if it's not already determined
435 $CCVENDOR = 'aix' if $SYSTEM eq 'AIX';
436 $CCVENDOR = 'sun' if $SYSTEM eq 'SunOS';
439 # Some systems need to know extra details
441 if ( $SYSTEM eq "HP-UX" && $CCVENDOR eq 'gnu' ) {
442 # By default gcc is a ILP32 compiler (with long long == 64).
444 if ( $CCVER >= 300 ) {
445 # PA64 support only came in with gcc 3.0.x.
446 # We check if the preprocessor symbol __LP64__ is defined.
447 if ( okrun('echo __LP64__',
448 "$CC -v -E -x c - 2>/dev/null",
449 'grep "^__LP64__" 2>&1 >/dev/null') ) {
450 # __LP64__ has slipped through, it therefore is not defined
457 if ( $SYSTEM eq "SunOS" && $CCVENDOR eq 'gnu' ) {
458 if ( $CCVER >= 300 ) {
459 # 64-bit ABI isn't officially supported in gcc 3.0, but seems
460 # to be working; at the very least 'make test' passes.
461 if ( okrun("$CC -v -E -x c /dev/null 2>&1",
462 'grep __arch64__ >/dev/null') ) {
471 my $vendor = $CCVENDOR ? $CCVENDOR : "(undetermined)";
472 my $version = $CCVER ? $CCVER : "(undetermined)";
473 print "C compiler: $CC\n";
474 print "C compiler vendor: $vendor\n";
475 print "C compiler version: $version\n";
480 [ [ 'uClinux.*64.*', { target => 'uClinux-dist64' } ],
481 [ 'uClinux.*', { target => 'uClinux-dist' } ],
482 [ 'mips3-sgi-irix', { target => 'irix-mips3' } ],
483 [ 'mips4-sgi-irix64',
486 WARNING! To build 64-bit package, do this:
487 $WHERE/Configure irix64-mips4-$CC
490 return { target => "irix-mips3" };
493 [ 'ppc-apple-rhapsody', { target => "rhapsody-ppc" } ],
494 [ 'ppc-apple-darwin.*',
496 my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
497 my $ISA64 = `sysctl -n hw.optional.64bitops 2>/dev/null`;
498 if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
500 WARNING! To build 64-bit package, do this:
501 $WHERE/Configure darwin64-ppc-cc
505 return { target => "darwin64-ppc" }
506 if $ISA64 == 1 && $KERNEL_BITS eq '64';
507 return { target => "darwin-ppc" };
510 [ 'i.86-apple-darwin.*',
512 my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
513 my $ISA64 = `sysctl -n hw.optional.x86_64 2>/dev/null`;
514 if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
516 WARNING! To build 64-bit package, do this:
517 KERNEL_BITS=64 $WHERE/Configure [options...]
521 return { target => "darwin64-x86_64" }
522 if $ISA64 == 1 && $KERNEL_BITS eq '64';
523 return { target => "darwin-i386" };
526 [ 'x86_64-apple-darwin.*',
528 my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
529 # macOS >= 10.15 is 64-bit only
530 my $SW_VERS = `sw_vers -productVersion 2>/dev/null`;
531 if ($SW_VERS =~ /^(\d+)\.(\d+)\.(\d+)$/) {
532 if ($1 > 10 || ($1 == 10 && $2 >= 15)) {
533 die "32-bit applications not supported on macOS 10.15 or later\n" if $KERNEL_BITS eq '32';
534 return { target => "darwin64-x86_64" };
537 return { target => "darwin-i386" } if $KERNEL_BITS eq '32';
540 WARNING! To build 32-bit package, do this:
541 KERNEL_BITS=32 $WHERE/Configure [options...]
544 return { target => "darwin64-x86_64" };
547 [ 'arm64-apple-darwin.*', { target => "darwin64-arm64" } ],
548 [ 'armv6\+7-.*-iphoneos',
549 { target => "iphoneos-cross",
550 cflags => [ qw(-arch armv6 -arch armv7) ],
551 cxxflags => [ qw(-arch armv6 -arch armv7) ] }
553 [ 'arm64-.*-iphoneos|.*-.*-ios64',
554 { target => "ios64-cross" }
557 sub { return { target => "iphoneos-cross",
558 cflags => [ "-arch ${MACHINE}" ],
559 cxxflags => [ "-arch ${MACHINE}" ] }; }
561 [ 'alpha-.*-linux2.*',
563 my $ISA = `awk '/cpu model/{print \$4;exit(0);}' /proc/cpuinfo`;
566 if ( $CCVENDOR eq "gnu" ) {
567 if ( $ISA =~ 'EV5|EV45' ) {
568 %config = ( cflags => [ '-mcpu=ev5' ],
569 cxxflags => [ '-mcpu=ev5' ] );
570 } elsif ( $ISA =~ 'EV56|PCA56' ) {
571 %config = ( cflags => [ '-mcpu=ev56' ],
572 cxxflags => [ '-mcpu=ev56' ] );
574 %config = ( cflags => [ '-mcpu=ev6' ],
575 cxxflags => [ '-mcpu=ev6' ] );
578 return { target => "linux-alpha",
584 my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
585 if ( $KERNEL_BITS eq '' ) {
587 WARNING! To build 64-bit package, do this:
588 $WHERE/Configure linux-ppc64
592 return { target => "linux-ppc64" } if $KERNEL_BITS eq '64';
595 if (!okrun('echo __LP64__',
596 'gcc -E -x c - 2>/dev/null',
597 'grep "^__LP64__" 2>&1 >/dev/null') ) {
598 %config = ( cflags => [ '-m32' ],
599 cxxflags => [ '-m32' ] );
601 return { target => "linux-ppc",
605 [ 'ppc64le-.*-linux2', { target => "linux-ppc64le" } ],
606 [ 'ppc-.*-linux2', { target => "linux-ppc" } ],
607 [ 'mips64.*-*-linux2',
610 WARNING! To build 64-bit package, do this:
611 $WHERE/Configure linux64-mips64
614 return { target => "linux-mips64" };
617 [ 'mips.*-.*-linux2', { target => "linux-mips32" } ],
618 [ 'ppc60x-.*-vxworks.*', { target => "vxworks-ppc60x" } ],
619 [ 'ppcgen-.*-vxworks.*', { target => "vxworks-ppcgen" } ],
620 [ 'pentium-.*-vxworks.*', { target => "vxworks-pentium" } ],
621 [ 'simlinux-.*-vxworks.*', { target => "vxworks-simlinux" } ],
622 [ 'mips-.*-vxworks.*', { target => "vxworks-mips" } ],
623 [ 'e2k-.*-linux.*', { target => "linux-generic64",
624 defines => [ 'L_ENDIAN' ] } ],
625 [ 'ia64-.*-linux.', { target => "linux-ia64" } ],
626 [ 'sparc64-.*-linux2',
629 WARNING! If you *know* that your GNU C supports 64-bit/V9 ABI and you
630 want to build 64-bit library, do this:
631 $WHERE/Configure linux64-sparcv9
634 return { target => "linux-sparcv9" };
639 my $KARCH = `awk '/^type/{print \$3;exit(0);}' /proc/cpuinfo`;
641 return { target => "linux-sparcv9" } if $KARCH =~ 'sun4u.*';
642 return { target => "linux-sparcv8" } if $KARCH =~ 'sun4[md]';
643 return { target => "linux-generic32",
644 defines => [ 'L_ENDIAN' ] };
647 [ 'parisc.*-.*-linux2',
649 # 64-bit builds under parisc64 linux are not supported and
650 # compiler is expected to generate 32-bit objects...
652 `awk '/cpu family/{print substr(\$5,1,3); exit(0);}' /proc/cpuinfo`;
654 `awk '/^cpu.[ ]*: PA/{print substr(\$3,3); exit(0);}' /proc/cpuinfo`;
655 # TODO XXX Model transformations
656 # 0. CPU Architecture for the 1.1 processor has letter suffixes.
657 # We strip that off assuming no further arch. identification
658 # will ever be used by GCC.
659 # 1. I'm most concerned about whether is a 7300LC is closer to a
660 # 7100 versus a 7100LC.
661 # 2. The variant 64-bit processors cause concern should GCC support
662 # explicit schedulers for these chips in the future.
663 # PA7300LC -> 7100LC (1.1)
664 # PA8200 -> 8000 (2.0)
665 # PA8500 -> 8000 (2.0)
666 # PA8600 -> 8000 (2.0)
667 $CPUSCHEDULE =~ s/7300LC/7100LC/;
668 $CPUSCHEDULE =~ s/8.00/8000/;
670 { target => "linux-generic32",
671 defines => [ 'B_ENDIAN' ],
672 cflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ],
673 cxxflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ]
677 [ 'armv[1-3].*-.*-linux2', { target => "linux-generic32" } ],
678 [ 'armv[7-9].*-.*-linux2', { target => "linux-armv4",
679 cflags => [ '-march=armv7-a' ],
680 cxxflags => [ '-march=armv7-a' ] } ],
681 [ 'arm.*-.*-linux2', { target => "linux-armv4" } ],
682 [ 'aarch64-.*-linux2', { target => "linux-aarch64" } ],
683 [ 'sh.*b-.*-linux2', { target => "linux-generic32",
684 defines => [ 'B_ENDIAN' ] } ],
685 [ 'sh.*-.*-linux2', { target => "linux-generic32",
686 defines => [ 'L_ENDIAN' ] } ],
687 [ 'loongarch64-.*-linux2',
689 my $disable = [ 'asm' ];
690 if ( okrun('echo xvadd.w \$xr0,\$xr0,\$xr0',
691 "$CC -c -x assembler - -o /dev/null 2>/dev/null") ) {
694 return { target => "linux64-loongarch64",
695 disable => $disable, };
698 [ 'm68k.*-.*-linux2', { target => "linux-generic32",
699 defines => [ 'B_ENDIAN' ] } ],
700 [ 's390-.*-linux2', { target => "linux-generic32",
701 defines => [ 'B_ENDIAN' ] } ],
704 # Disabled until a glibc bug is fixed; see Configure.
706 || okrun('egrep -e \'^features.* highgprs\' /proc/cpuinfo >/dev/null') )
709 WARNING! To build "highgprs" 32-bit package, do this:
710 $WHERE/Configure linux32-s390x
714 return { target => "linux64-s390x" };
717 [ 'x86_64-.*-linux.',
719 return { target => "linux-x32" }
720 if okrun("$CC -dM -E -x c /dev/null 2>&1",
721 'grep -q ILP32 >/dev/null');
722 return { target => "linux-x86_64" };
727 # On machines where the compiler understands -m32, prefer a
728 # config target that uses it
729 return { target => "linux-x86" }
730 if okrun("$CC -m32 -E -x c /dev/null >/dev/null 2>&1");
731 return { target => "linux-elf" };
734 [ '.*86-.*-linux1', { target => "linux-aout" } ],
735 [ 'riscv64-.*-linux.', { target => "linux64-riscv64" } ],
736 [ '.*-.*-linux.', { target => "linux-generic32" } ],
737 [ 'sun4[uv].*-.*-solaris2',
739 my $KERNEL_BITS = $ENV{KERNEL_BITS};
740 my $ISA64 = `isainfo 2>/dev/null | grep sparcv9`;
741 my $KB = $KERNEL_BITS // '64';
742 if ( $ISA64 ne "" && $KB eq '64' ) {
743 if ( $CCVENDOR eq "sun" && $CCVER >= 500 ) {
745 WARNING! To build 32-bit package, do this:
746 $WHERE/Configure solaris-sparcv9-cc
749 } elsif ( $CCVENDOR eq "gnu" && $GCC_ARCH eq "-m64" ) {
750 # $GCC_ARCH denotes default ABI chosen by compiler driver
751 # (first one found on the $PATH). I assume that user
752 # expects certain consistency with the rest of his builds
753 # and therefore switch over to 64-bit. <appro>
755 WARNING! To build 32-bit package, do this:
756 $WHERE/Configure solaris-sparcv9-gcc
759 return { target => "solaris64-sparcv9-gcc" };
760 } elsif ( $GCC_ARCH eq "-m32" ) {
762 NOTICE! If you *know* that your GNU C supports 64-bit/V9 ABI and you wish
763 to build 64-bit library, do this:
764 $WHERE/Configure solaris64-sparcv9-gcc
769 return { target => "solaris64-sparcv9-cc" }
770 if $ISA64 ne "" && $KB eq '64';
771 return { target => "solaris-sparcv9-cc" };
774 [ 'sun4m-.*-solaris2', { target => "solaris-sparcv8" } ],
775 [ 'sun4d-.*-solaris2', { target => "solaris-sparcv8" } ],
776 [ 'sun4.*-.*-solaris2', { target => "solaris-sparcv7" } ],
777 [ '.*86.*-.*-solaris2',
779 my $KERNEL_BITS = $ENV{KERNEL_BITS};
780 my $ISA64 = `isainfo 2>/dev/null | grep amd64`;
781 my $KB = $KERNEL_BITS // '64';
782 if ($ISA64 ne "" && $KB eq '64') {
783 return { target => "solaris64-x86_64-gcc" } if $CCVENDOR eq "gnu";
784 return { target => "solaris64-x86_64-cc" };
786 my $REL = uname('-r');
788 my @tmp_disable = ();
789 push @tmp_disable, 'sse2' if int($REL) < 10;
790 #There is no solaris-x86-cc target
791 return { target => "solaris-x86-gcc",
792 disable => [ @tmp_disable ] };
795 # We don't have any sunos target in Configurations/*.conf, so why here?
796 [ '.*-.*-sunos4', { target => "sunos" } ],
797 [ '.*86.*-.*-bsdi4', { target => "BSD-x86-elf",
798 lflags => [ '-ldl' ],
799 disable => [ 'sse2' ] } ],
800 [ 'alpha.*-.*-.*bsd.*', { target => "BSD-generic64",
801 defines => [ 'L_ENDIAN' ] } ],
802 [ 'powerpc-.*-.*bsd.*', { target => "BSD-ppc" } ],
803 [ 'powerpc64-.*-.*bsd.*', { target => "BSD-ppc64" } ],
804 [ 'powerpc64le-.*-.*bsd.*', { target => "BSD-ppc64le" } ],
805 [ 'riscv64-.*-.*bsd.*', { target => "BSD-riscv64" } ],
806 [ 'sparc64-.*-.*bsd.*', { target => "BSD-sparc64" } ],
807 [ 'ia64-.*-openbsd.*', { target => "BSD-nodef-ia64" } ],
808 [ 'ia64-.*-.*bsd.*', { target => "BSD-ia64" } ],
809 [ 'x86_64-.*-dragonfly.*', { target => "BSD-x86_64" } ],
810 [ 'amd64-.*-openbsd.*', { target => "BSD-nodef-x86_64" } ],
811 [ 'amd64-.*-.*bsd.*', { target => "BSD-x86_64" } ],
812 [ 'arm64-.*-.*bsd.*', { target => "BSD-aarch64" } ],
813 [ 'armv6-.*-.*bsd.*', { target => "BSD-armv4" } ],
814 [ 'armv7-.*-.*bsd.*', { target => "BSD-armv4" } ],
815 [ '.*86.*-.*-.*bsd.*',
817 # mimic ld behaviour when it's looking for libc...
819 if ( -l "/usr/lib/libc.so" ) {
820 $libc = "/usr/lib/libc.so";
822 # ld searches for highest libc.so.* and so do we
824 `(ls /usr/lib/libc.so.* /lib/libc.so.* | tail -1) 2>/dev/null`;
826 my $what = `file -L $libc 2>/dev/null`;
827 return { target => "BSD-x86-elf" } if $what =~ /ELF/;
828 return { target => "BSD-x86",
829 disable => [ 'sse2' ] };
832 [ '.*-.*-openbsd.*', { target => "BSD-nodef-generic32" } ],
833 [ '.*-.*-.*bsd.*', { target => "BSD-generic32" } ],
834 [ 'x86_64-.*-haiku', { target => "haiku-x86_64" } ],
835 [ '.*-.*-haiku', { target => "haiku-x86" } ],
836 [ '.*-.*-osf', { target => "osf1-alpha" } ],
837 [ '.*-.*-tru64', { target => "tru64-alpha" } ],
838 [ '.*-.*-[Uu]nix[Ww]are7',
840 return { target => "unixware-7",
841 disable => [ 'sse2' ] } if $CCVENDOR eq "gnu";
842 return { target => "unixware-7",
843 defines => [ '__i386__' ] };
846 [ '.*-.*-[Uu]nix[Ww]are20.*', { target => "unixware-2.0",
847 disable => [ 'sse2', 'sha512' ] } ],
848 [ '.*-.*-[Uu]nix[Ww]are21.*', { target => "unixware-2.1",
849 disable => [ 'sse2', 'sha512' ] } ],
850 [ '.*-.*-vos', { target => "vos",
851 disable => [ 'threads', 'shared', 'asm',
853 [ 'BS2000-siemens-sysv4', { target => "BS2000-OSD" } ],
854 [ 'i[3456]86-.*-cygwin', { target => "Cygwin-x86" } ],
856 sub { return { target => "Cygwin-${MACHINE}" } } ],
857 [ 'x86-.*-android|i.86-.*-android', { target => "android-x86" } ],
858 [ 'armv[7-9].*-.*-android', { target => "android-armeabi",
859 cflags => [ '-march=armv7-a' ],
860 cxxflags => [ '-march=armv7-a' ] } ],
861 [ 'arm.*-.*-android', { target => "android-armeabi" } ],
862 [ 'riscv64-.*-android', { target => "android-riscv64" } ],
865 my $KERNEL_BITS = $ENV{KERNEL_BITS};
866 my %common_return = ( defines => [ '_REENTRANT' ] );
867 $KERNEL_BITS ||= `getconf KERNEL_BITS 2>/dev/null` // '32';
868 # See <sys/unistd.h> for further info on CPU_VERSION.
869 my $CPU_VERSION = `getconf CPU_VERSION 2>/dev/null` // 0;
870 if ( $CPU_VERSION >= 768 ) {
872 return { target => "hpux64-ia64",
874 if $KERNEL_BITS eq '64' && ! $CCVENDOR;
875 return { target => "hpux-ia64",
878 if ( $CPU_VERSION >= 532 ) {
880 # PA-RISC 2.0 is no longer supported as separate 32-bit
881 # target. This is compensated for by run-time detection
882 # in most critical assembly modules and taking advantage
883 # of 2.0 architecture in PA-RISC 1.1 build.
884 my $target = ($CCVENDOR eq "gnu" && $GCC_BITS eq '64')
887 if ( $KERNEL_BITS eq '64' && ! $CCVENDOR ) {
889 WARNING! To build 64-bit package, do this:
890 $WHERE/Configure hpux64-parisc2-cc
894 return { target => $target,
898 return { target => "hpux-parisc1_1",
899 %common_return } if $CPU_VERSION >= 528;
901 return { target => "hpux-parisc",
902 %common_return } if $CPU_VERSION >= 523;
904 return { target => "hpux",
908 [ '.*-hpux', { target => "hpux-parisc" } ],
912 my $KERNEL_BITS = $ENV{KERNEL_BITS};
913 $KERNEL_BITS ||= `getconf KERNEL_BITMODE 2>/dev/null`;
914 $KERNEL_BITS ||= '32';
915 my $OBJECT_MODE = $ENV{OBJECT_MODE};
917 $config{target} = "aix";
918 if ( $OBJECT_MODE == 64 ) {
919 print 'Your $OBJECT_MODE was found to be set to 64';
920 $config{target} = "aix64";
922 if ( $CCVENDOR ne 'gnu' && $KERNEL_BITS eq '64' ) {
924 WARNING! To build 64-bit package, do this:
925 $WHERE/Configure aix64-cc
931 "(lsattr -E -O -l `lsdev -c processor|awk '{print \$1;exit}'`",
932 'grep -i powerpc) >/dev/null 2>&1') ) {
933 # this applies even to Power3 and later, as they return
936 $config{disable} = [ 'asm' ];
942 # Windows values found by looking at Perl 5's win32/win32.c
943 [ '(amd64|ia64|x86|ARM)-.*?-Windows NT',
945 # If we determined the arch by asking cl, take that value,
946 # otherwise the SYSTEM we got from from POSIX::uname().
947 my $arch = $CL_ARCH // $1;
951 $config = { 'amd64' => { target => 'VC-WIN64A' },
952 'ia64' => { target => 'VC-WIN64I' },
953 'x86' => { target => 'VC-WIN32' },
954 'x64' => { target => 'VC-WIN64A' },
955 'ARM' => { target => 'VC-WIN64-ARM' },
957 die <<_____ unless defined $config;
959 I do not know how to handle ${arch}.
962 die <<_____ unless defined $config;
964 Could not figure out the architecture.
971 # VMS values found by observation on existing machinery.
972 [ 'VMS_AXP-.*?-OpenVMS', { target => 'vms-alpha' } ],
973 [ 'VMS_IA64-.*?-OpenVMS', { target => 'vms-ia64' } ],
974 [ 'VMS_x86_64-.*?-OpenVMS', { target => 'vms-x86_64' } ],
976 # TODO: There are a few more choices among OpenSSL config targets, but
977 # reaching them involves a bit more than just a host tripet. Select
978 # environment variables could do the job to cover for more granular
979 # build options such as data model (ILP32 or LP64), thread support
980 # model (PUT, SPT or nothing), target execution environment (OSS or
981 # GUARDIAN). And still, there must be some kind of default when
982 # nothing else is said.
984 # nsv is a virtual x86 environment, equivalent to nsx, so we enforce
986 [ 'nse-tandem-nsk.*', { target => 'nonstop-nse' } ],
987 [ 'nsv-tandem-nsk.*', { target => 'nonstop-nsx' } ],
988 [ 'nsx-tandem-nsk.*', { target => 'nonstop-nsx' } ],
992 # Map GUESSOS into OpenSSL terminology.
993 # Returns a hash table with diverse entries, most importantly 'target',
994 # but also other entries that are fitting for Configure's %config
996 # It would be nice to fix this so that this weren't necessary. :( XXX
1000 foreach my $tuple ( @$map_patterns ) {
1001 my $pat = @$tuple[0];
1002 next if $GUESSOS !~ /^${pat}$/;
1003 my $result = @$tuple[1];
1004 $result = $result->() if ref $result eq 'CODE';
1008 # Last case, return "z" from x-y-z
1009 my @fields = split(/-/, $GUESSOS);
1010 return ( target => $fields[2] );
1013 # gcc < 2.8 does not support -march=ultrasparc
1014 sub check_solaris_sparc8 {
1016 if ( $CCVENDOR eq 'gnu' && $CCVER < 208 ) {
1017 if ( $OUT eq 'solaris-sparcv9-gcc' ) {
1019 WARNING! Downgrading to solaris-sparcv8-gcc
1020 Upgrade to gcc-2.8 or later.
1023 return 'solaris-sparcv8-gcc';
1025 if ( $OUT eq "linux-sparcv9" ) {
1027 WARNING! Downgrading to linux-sparcv8
1028 Upgrade to gcc-2.8 or later.
1031 return 'linux-sparcv8';
1044 $VERBOSE = 1 if defined $options{verbose};
1045 $WAIT = 0 if defined $options{nowait};
1047 $CROSS_COMPILE = $options{CROSS_COMPILE} // '';
1049 my $GUESSOS = guess_system();
1050 determine_compiler_settings();
1052 my %ret = map_guess($GUESSOS);
1053 $ret{target} = check_solaris_sparc8($ret{target});