2 # Copyright 1998-2020 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;
22 # These control our behavior.
26 my $WHERE = dirname($0);
28 # Machine type, etc., used to determine the platform
38 # Some environment variables; they will affect Configure
39 my $CONFIG_OPTIONS = $ENV{CONFIG_OPTIONS} // '';
43 # For determine_compiler_settings, the list of known compilers
44 my @c_compilers = qw(clang gcc cc);
45 # Methods to determine compiler version. The expected output is one of
46 # MAJOR or MAJOR.MINOR or MAJOR.MINOR.PATCH... or false if the compiler
47 # isn't of the given brand.
48 # This is a list to ensure that gnu comes last, as we've made it a fallback
52 my $v = `$CROSS_COMPILE$CC -v 2>&1`;
53 $v =~ m/(?:(?:clang|LLVM) version|.*based on LLVM)\s+([0-9]+\.[0-9]+)/;
57 my $v = `$CROSS_COMPILE$CC -dumpversion 2>/dev/null`;
58 # Strip off whatever prefix egcs prepends the number with.
59 # Hopefully, this will work for any future prefixes as well.
60 $v =~ s/^[a-zA-Z]*\-//;
65 # This is what we will set as the target for calling Configure.
68 # Pattern matches against "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}"
69 # The patterns are assumed to be wrapped like this: /^(${pattern})$/
70 my $guess_patterns = [
71 [ 'A\/UX:.*', 'm68k-apple-aux3' ],
72 [ 'AIX:[3-9]:4:.*', '${MACHINE}-ibm-aix' ],
73 [ 'AIX:.*?:[5-9]:.*', '${MACHINE}-ibm-aix' ],
74 [ 'AIX:.*', '${MACHINE}-ibm-aix3' ],
75 [ 'HI-UX:.*', '${MACHINE}-hi-hiux' ],
78 my $HPUXVER = $RELEASE;
79 $HPUXVER = s/[^.]*.[0B]*//;
80 # HPUX 10 and 11 targets are unified
81 return "${MACHINE}-hp-hpux1x" if $HPUXVER =~ m@1[0-9]@;
82 return "${MACHINE}-hp-hpux";
85 [ 'IRIX:6\..*', 'mips3-sgi-irix' ],
86 [ 'IRIX64:.*', 'mips4-sgi-irix64' ],
87 [ 'Linux:[2-9]\..*', '${MACHINE}-whatever-linux2' ],
88 [ 'Linux:1\..*', '${MACHINE}-whatever-linux1' ],
89 [ 'GNU.*', 'hurd-x86' ],
90 [ 'LynxOS:.*', '${MACHINE}-lynx-lynxos' ],
91 # BSD/OS always says 386
92 [ 'BSD\/OS:4\..*', 'i486-whatever-bsdi4' ],
93 # Order is important, this has to appear before 'BSD\/386:'
94 [ 'BSD/386:.*?:.*?:.*486.*|BSD/OS:.*?:.*?:.*?:.*486.*',
96 my $BSDVAR = `/sbin/sysctl -n hw.model`;
97 return "i586-whatever-bsdi" if $BSDVAR =~ m@Pentium@;
98 return "i386-whatever-bsdi";
101 [ 'BSD\/386:.*|BSD\/OS:.*', '${MACHINE}-whatever-bsdi' ],
102 # Order is important, this has to appear before 'FreeBSD:'
103 [ 'FreeBSD:.*?:.*?:.*386.*',
107 my $MACH = `sysctl -n hw.model`;
108 $MACH = "i386" if $MACH =~ m@386@;
109 $MACH = "i486" if $MACH =~ m@486@;
110 $MACH = "i686" if $MACH =~ m@Pentium II@;
111 $MACH = "i586" if $MACH =~ m@Pentium@;
112 $MACH = "$MACHINE" if $MACH !~ /i.86/;
113 my $ARCH = 'whatever';
114 $ARCH = "pc" if $MACH =~ m@i[0-9]86@;
115 return "${MACH}-${ARCH}-freebsd${VERS}";
118 [ 'DragonFly:.*', '${MACHINE}-whatever-dragonfly' ],
119 [ 'FreeBSD:.*', '${MACHINE}-whatever-freebsd' ],
120 [ 'Haiku:.*', '${MACHINE}-whatever-haiku' ],
121 # Order is important, this has to appear before 'NetBSD:.*'
122 [ 'NetBSD:.*?:.*?:.*386.*',
124 my $hw = `/usr/sbin/sysctl -n hw.model || /sbin/sysctl -n hw.model`;
125 $hw =~ s@.*(.)86-class.*@i${1}86@;
126 return "${hw}-whatever-netbsd";
129 [ 'NetBSD:.*', '${MACHINE}-whatever-netbsd' ],
130 [ 'OpenBSD:.*', '${MACHINE}-whatever-openbsd' ],
131 [ 'OpenUNIX:.*', '${MACHINE}-unknown-OpenUNIX${VERSION}' ],
132 [ 'OSF1:.*?:.*?:.*alpha.*',
134 my $OSFMAJOR = $RELEASE;
135 $OSFMAJOR =~ 's/^V([0-9]*)\..*$/\1/';
136 return "${MACHINE}-dec-tru64" if $OSFMAJOR =~ m@[45]@;
137 return "${MACHINE}-dec-osf";
140 [ 'Paragon.*?:.*', 'i860-intel-osf1' ],
141 [ 'Rhapsody:.*', 'ppc-apple-rhapsody' ],
142 [ 'Darwin:.*?:.*?:Power.*', 'ppc-apple-darwin' ],
143 [ 'Darwin:.*?:.*?:x86_64', 'x86_64-apple-darwin' ],
144 [ 'Darwin:.*', 'i686-apple-darwin' ],
145 [ 'SunOS:5\..*', '${MACHINE}-whatever-solaris2' ],
146 [ 'SunOS:.*', '${MACHINE}-sun-sunos4' ],
147 [ 'UNIX_System_V:4\..*?:.*', '${MACHINE}-whatever-sysv4' ],
148 [ 'VOS:.*?:.*?:i786', 'i386-stratus-vos' ],
149 [ 'VOS:.*?:.*?:.*', 'hppa1.1-stratus-vos' ],
150 [ '.*?:4.*?:R4.*?:m88k', '${MACHINE}-whatever-sysv4' ],
151 [ 'DYNIX\/ptx:4.*?:.*', '${MACHINE}-whatever-sysv4' ],
152 [ '.*?:4\.0:3\.0:3[34]..(,.*)?', 'i486-ncr-sysv4' ],
153 [ 'ULTRIX:.*', '${MACHINE}-unknown-ultrix' ],
154 [ 'POSIX-BC.*', 'BS2000-siemens-sysv4' ],
155 [ 'machten:.*', '${MACHINE}-tenon-${SYSTEM}' ],
156 [ 'library:.*', '${MACHINE}-ncr-sysv4' ],
157 [ 'ConvexOS:.*?:11\.0:.*', '${MACHINE}-v11-${SYSTEM}' ],
158 [ 'MINGW64.*?:.*?:.*?:x86_64', '${MACHINE}-whatever-mingw64' ],
159 [ 'MINGW.*', '${MACHINE}-whatever-mingw' ],
160 [ 'CYGWIN.*', '${MACHINE}-pc-cygwin' ],
161 [ 'vxworks.*', '${MACHINE}-whatever-vxworks' ],
163 # Note: there's also NEO and NSR, but they are old and unsupported
164 [ 'NONSTOP_KERNEL:.*:NSE-.*?', 'nse-tandem-nsk${RELEASE}' ],
165 [ 'NONSTOP_KERNEL:.*:NSV-.*?', 'nsv-tandem-nsk${RELEASE}' ],
166 [ 'NONSTOP_KERNEL:.*:NSX-.*?', 'nsx-tandem-nsk${RELEASE}' ],
168 [ sub { -d '/usr/apollo' }, 'whatever-apollo-whatever' ],
171 # Run a command, return true if exit zero else false.
172 # Multiple args are glued together into a pipeline.
173 # Name comes from OpenSSL tests, often written as "ok(run(...."
175 my $command = join(' | ', @_);
176 my $status = system($command) >> 8;
180 # Give user a chance to abort/interrupt if interactive if interactive.
182 if ( $WAIT && -t 1 ) {
184 local $SIG{ALRM} = sub { die "Timeout"; };
187 print "You have about five seconds to abort: ";
188 my $ignored = <STDIN>;
191 print "\n" if $@ =~ /Timeout/;
195 # Look for ISC/SCO with its unique uname program
197 open UNAME, "uname -X 2>/dev/null|" or return '';
201 $line = $_ if m@^Release@;
204 return "" if $line eq '';
205 my @fields = split(/\s+/, $line);
206 return $fields[2] // '';
212 if ( -f "/etc/kconfig" ) {
213 return "${MACHINE}-whatever-isc4" if $REL eq '4.0' || $REL eq '4.1';
215 return "whatever-whatever-sco3" if $REL eq '3.2v4.2';
216 return "whatever-whatever-sco5" if $REL =~ m@3\.2v5\.0.*@;
217 if ( $REL eq "4.2MP" ) {
218 return "whatever-whatever-unixware20" if $VERSION =~ m@2\.0.*@;
219 return "whatever-whatever-unixware21" if $VERSION =~ m@2\.1.*@;
220 return "whatever-whatever-unixware2" if $VERSION =~ m@2.*@;
222 return "whatever-whatever-unixware1" if $REL eq "4.2";
223 if ( $REL =~ m@5.*@ ) {
224 # We hardcode i586 in place of ${MACHINE} for the following
225 # reason: even though Pentium is minimum requirement for
226 # platforms in question, ${MACHINE} gets always assigned to
227 # i386. This means i386 gets passed to Configure, which will
228 # cause bad assembler code to be generated.
229 return "i586-sco-unixware7" if $VERSION =~ m@[678].*@;
234 # Return the cputype-vendor-osversion
236 ($SYSTEM, undef, $RELEASE, $VERSION, $MACHINE) = POSIX::uname();
237 my $sys = "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}";
239 # Special-cases for ISC, SCO, Unixware
240 my $REL = is_sco_uname();
242 my $result = get_sco_type($REL);
243 return eval "\"$result\"" if $result ne '';
249 foreach my $tuple ( @$guess_patterns ) {
250 my $pat = @$tuple[0];
251 my $check = ref $pat eq 'CODE' ? $pat->($sys) : $sys =~ /^(${pat})$/;
254 my $result = @$tuple[1];
255 $result = $result->() if ref $result eq 'CODE';
256 return eval "\"$result\"";
260 return "${MACHINE}-whatever-${SYSTEM}";
263 # We would use List::Util::pair() for this... unfortunately, that function
264 # only appeared in perl v5.19.3, and we claim to support perl v5.10 and on.
265 # Therefore, we implement a quick cheap variant of our own.
267 croak "Odd number of arguments" if @_ & 1;
272 my $x = [ shift, shift ];
278 # Figure out CC, GCCVAR, etc.
279 sub determine_compiler_settings {
280 # Make a copy and don't touch it. That helps determine if we're
281 # finding the compiler here
284 # Set certain default
285 $CCVER = 0; # Unknown
286 $CCVENDOR = ''; # Dunno, don't care (unless found later)
288 # Find a compiler if we don't already have one
290 foreach (@c_compilers) {
291 next unless IPC::Cmd::can_run("$CROSS_COMPILE$_");
297 # Find the compiler vendor and version number for certain compilers
298 foreach my $pair (_pairs @cc_version) {
299 # Try to get the version number.
300 # Failure gets us undef or an empty string
301 my ( $k, $v ) = @$pair;
304 # If we got a version number, process it
308 # The returned version is expected to be one of
312 # MAJOR.MINOR.{whatever}
314 # We don't care what comes after MAJOR.MINOR. All we need is to
315 # have them calculated into a single number, using this formula:
317 # MAJOR * 100 + MINOR
318 # Here are a few examples of what we should get:
323 my @numbers = split /\./, $v;
324 my @factors = (100, 1);
325 while (@numbers && @factors) {
326 $CCVER += shift(@numbers) * shift(@factors)
332 # If no C compiler has been determined at this point, we die. Hard.
335 No C compiler found, please specify one with the environment variable CC,
336 or configure with an explicit configuration target.
340 # Vendor specific overrides, only if we determined the compiler here
342 if ( ${SYSTEM} eq 'AIX' ) {
343 # favor vendor cc over gcc
344 if (IPC::Cmd::can_run('cc')) {
346 $CCVENDOR = ''; # Determine later
351 if ( $SYSTEM eq "SunOS" ) {
352 # check for WorkShop C, expected output is "cc: blah-blah C x.x"
353 my $v = `(cc -V 2>&1) 2>/dev/null | egrep -e '^cc: .* C [0-9]\.[0-9]'`;
355 $v =~ s/.* C \([0-9]\)\.\([0-9]\).*/$1.$2/;
356 my @numbers = split /\./, $v;
357 my @factors = (100, 1);
359 while (@numbers && @factors) {
360 $v += shift(@numbers) * shift(@factors)
363 if ( $v > 40000 && $MACHINE ne 'i86pc' ) {
365 $CCVENDOR = ''; # Determine later
368 if ( $CCVER == 50000 ) {
370 WARNING! Found WorkShop C 5.0.
371 Make sure you have patch #107357-01 or later applied.
379 # On some systems, we assume a cc vendor if it's not already determined
382 $CCVENDOR = 'aix' if $SYSTEM eq 'AIX';
383 $CCVENDOR = 'sun' if $SYSTEM eq 'SunOS';
386 # Some systems need to know extra details
388 if ( $SYSTEM eq "HP-UX" && $CCVENDOR eq 'gnu' ) {
389 # By default gcc is a ILP32 compiler (with long long == 64).
391 if ( $CCVER >= 300 ) {
392 # PA64 support only came in with gcc 3.0.x.
393 # We check if the preprocessor symbol __LP64__ is defined.
394 if ( okrun('echo __LP64__',
395 "$CC -v -E -x c - 2>/dev/null",
396 'grep "^__LP64__" 2>&1 >/dev/null') ) {
397 # __LP64__ has slipped through, it therefore is not defined
404 if ( $SYSTEM eq "SunOS" && $CCVENDOR eq 'gnu' ) {
405 if ( $CCVER >= 300 ) {
406 # 64-bit ABI isn't officially supported in gcc 3.0, but seems
407 # to be working; at the very least 'make test' passes.
408 if ( okrun("$CC -v -E -x c /dev/null 2>&1",
409 'grep __arch64__ >/dev/null') ) {
418 my $vendor = $CCVENDOR ? $CCVENDOR : "(undetermined)";
419 my $version = $CCVER ? $CCVER : "(undetermined)";
420 print "C compiler: $CC\n";
421 print "C compiler vendor: $vendor\n";
422 print "C compiler version: $version\n";
427 [ [ 'uClinux.*64.*', { target => 'uClinux-dist64' } ],
428 [ 'uClinux.*', { target => 'uClinux-dist' } ],
429 [ 'mips3-sgi-irix', { target => 'irix-mips3' } ],
430 [ 'mips4-sgi-irix64',
433 WARNING! To build 64-bit package, do this:
434 $WHERE/Configure irix64-mips4-$CC
437 return { target => "irix-mips3" };
440 [ 'ppc-apple-rhapsody', { target => "rhapsody-ppc" } ],
441 [ 'ppc-apple-darwin.*',
443 my $KERNEL_BITS = $ENV{KERNEL_BITS};
444 my $ISA64 = `sysctl -n hw.optional.64bitops 2>/dev/null`;
445 if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
447 WARNING! To build 64-bit package, do this:
448 $WHERE/Configure darwin64-ppc-cc
452 return { target => "darwin64-ppc" }
453 if $ISA64 == 1 && $KERNEL_BITS eq '64';
454 return { target => "darwin-ppc" };
457 [ 'i.86-apple-darwin.*',
459 my $KERNEL_BITS = $ENV{KERNEL_BITS};
460 my $ISA64 = `sysctl -n hw.optional.x86_64 2>/dev/null`;
461 if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
463 WARNING! To build 64-bit package, do this:
464 KERNEL_BITS=64 $WHERE/Configure \[\[ options \]\]
468 return { target => "darwin64-x86_64" }
469 if $ISA64 == 1 && $KERNEL_BITS eq '64';
470 return { target => "darwin-i386" };
473 [ 'x86_64-apple-darwin.*',
475 my $KERNEL_BITS = $ENV{KERNEL_BITS};
476 return { target => "darwin-i386" } if $KERNEL_BITS eq '32';
479 WARNING! To build 32-bit package, do this:
480 KERNEL_BITS=32 $WHERE/Configure \[\[ options \]\]
483 return { target => "darwin64-x86_64" };
486 [ 'armv6\+7-.*-iphoneos',
487 { target => "iphoneos-cross",
488 cflags => [ qw(-arch armv6 -arch armv7) ],
489 cxxflags => [ qw(-arch armv6 -arch armv7) ] }
491 [ 'arm64-.*-iphoneos|.*-.*-ios64',
492 { target => "ios64-cross" }
495 sub { return { target => "iphoneos-cross",
496 cflags => [ "-arch ${MACHINE}" ],
497 cxxflags => [ "-arch ${MACHINE}" ] }; }
499 [ 'alpha-.*-linux2.*',
501 my $ISA = `awk '/cpu model/{print \$4;exit(0);}' /proc/cpuinfo`;
504 if ( $CCVENDOR eq "gnu" ) {
505 if ( $ISA =~ 'EV5|EV45' ) {
506 %config = ( cflags => [ '-mcpu=ev5' ],
507 cxxflags => [ '-mcpu=ev5' ] );
508 } elsif ( $ISA =~ 'EV56|PCA56' ) {
509 %config = ( cflags => [ '-mcpu=ev56' ],
510 cxxflags => [ '-mcpu=ev56' ] );
512 %config = ( cflags => [ '-mcpu=ev6' ],
513 cxxflags => [ '-mcpu=ev6' ] );
516 return { target => "linux-alpha",
522 my $KERNEL_BITS = $ENV{KERNEL_BITS};
523 if ( $KERNEL_BITS eq '' ) {
525 WARNING! To build 64-bit package, do this:
526 $WHERE/Configure linux-ppc64
530 return { target => "linux-ppc64" } if $KERNEL_BITS eq '64';
533 if (!okrun('echo __LP64__',
534 'gcc -E -x c - 2>/dev/null',
535 'grep "^__LP64__" 2>&1 >/dev/null') ) {
536 %config = ( cflags => [ '-m32' ],
537 cxxflags => [ '-m32' ] );
539 return { target => "linux-ppc",
543 [ 'ppc64le-.*-linux2', { target => "linux-ppc64le" } ],
544 [ 'ppc-.*-linux2', { target => "linux-ppc" } ],
545 [ 'mips64.*-*-linux2',
548 WARNING! To build 64-bit package, do this:
549 $WHERE/Configure linux64-mips64
552 return { target => "linux-mips64" };
555 [ 'mips.*-.*-linux2', { target => "linux-mips32" } ],
556 [ 'ppc60x-.*-vxworks.*', { target => "vxworks-ppc60x" } ],
557 [ 'ppcgen-.*-vxworks.*', { target => "vxworks-ppcgen" } ],
558 [ 'pentium-.*-vxworks.*', { target => "vxworks-pentium" } ],
559 [ 'simlinux-.*-vxworks.*', { target => "vxworks-simlinux" } ],
560 [ 'mips-.*-vxworks.*', { target => "vxworks-mips" } ],
561 [ 'e2k-.*-linux.*', { target => "linux-generic64",
562 defines => [ 'L_ENDIAN' ] } ],
563 [ 'ia64-.*-linux.', { target => "linux-ia64" } ],
564 [ 'sparc64-.*-linux2',
567 WARNING! If you *know* that your GNU C supports 64-bit/V9 ABI and you
568 want to build 64-bit library, do this:
569 $WHERE/Configure linux64-sparcv9
572 return { target => "linux-sparcv9" };
577 my $KARCH = `awk '/^type/{print \$3;exit(0);}' /proc/cpuinfo`;
579 return { target => "linux-sparcv9" } if $KARCH =~ 'sun4u.*';
580 return { target => "linux-sparcv8" } if $KARCH =~ 'sun4[md]';
581 return { target => "linux-generic32",
582 defines => [ 'L_ENDIAN' ] };
585 [ 'parisc.*-.*-linux2',
587 # 64-bit builds under parisc64 linux are not supported and
588 # compiler is expected to generate 32-bit objects...
590 `awk '/cpu family/{print substr(\$5,1,3); exit(0);}' /proc/cpuinfo`;
592 `awk '/^cpu.[ ]*: PA/{print substr(\$3,3); exit(0);}' /proc/cpuinfo`;
593 # TODO XXX Model transformations
594 # 0. CPU Architecture for the 1.1 processor has letter suffixes.
595 # We strip that off assuming no further arch. identification
596 # will ever be used by GCC.
597 # 1. I'm most concerned about whether is a 7300LC is closer to a
598 # 7100 versus a 7100LC.
599 # 2. The variant 64-bit processors cause concern should GCC support
600 # explicit schedulers for these chips in the future.
601 # PA7300LC -> 7100LC (1.1)
602 # PA8200 -> 8000 (2.0)
603 # PA8500 -> 8000 (2.0)
604 # PA8600 -> 8000 (2.0)
605 $CPUSCHEDULE =~ s/7300LC/7100LC/;
606 $CPUSCHEDULE =~ s/8.00/8000/;
608 { target => "linux-generic32",
609 defines => [ 'B_ENDIAN' ],
610 cflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ],
611 cxxflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ]
615 [ 'armv[1-3].*-.*-linux2', { target => "linux-generic32" } ],
616 [ 'armv[7-9].*-.*-linux2', { target => "linux-armv4",
617 cflags => [ '-march=armv7-a' ],
618 cxxflags => [ '-march=armv7-a' ] } ],
619 [ 'arm.*-.*-linux2', { target => "linux-armv4" } ],
620 [ 'aarch64-.*-linux2', { target => "linux-aarch64" } ],
621 [ 'sh.*b-.*-linux2', { target => "linux-generic32",
622 defines => [ 'B_ENDIAN' ] } ],
623 [ 'sh.*-.*-linux2', { target => "linux-generic32",
624 defines => [ 'L_ENDIAN' ] } ],
625 [ 'm68k.*-.*-linux2', { target => "linux-generic32",
626 defines => [ 'B_ENDIAN' ] } ],
627 [ 's390-.*-linux2', { target => "linux-generic32",
628 defines => [ 'B_ENDIAN' ] } ],
631 # Disabled until a glibc bug is fixed; see Configure.
633 || okrun('egrep -e \'^features.* highgprs\' /proc/cpuinfo >/dev/null') )
636 WARNING! To build "highgprs" 32-bit package, do this:
637 $WHERE/Configure linux32-s390x
641 return { target => "linux64-s390x" };
644 [ 'x86_64-.*-linux.',
646 return { target => "linux-x32" }
647 if okrun("$CC -dM -E -x c /dev/null 2>&1",
648 'grep -q ILP32 >/dev/null');
649 return { target => "linux-x86_64" };
654 # On machines where the compiler understands -m32, prefer a
655 # config target that uses it
656 return { target => "linux-x86" }
657 if okrun("$CC -m32 -E -x c /dev/null >/dev/null 2>&1");
658 return { target => "linux-elf" };
661 [ '.*86-.*-linux1', { target => "linux-aout" } ],
662 [ '.*-.*-linux.', { target => "linux-generic32" } ],
663 [ 'sun4[uv].*-.*-solaris2',
665 my $KERNEL_BITS = $ENV{KERNEL_BITS};
666 my $ISA64 = `isainfo 2>/dev/null | grep sparcv9`;
667 if ( $ISA64 ne "" && $KERNEL_BITS eq '' ) {
668 if ( $CCVENDOR eq "sun" && $CCVER >= 500 ) {
670 WARNING! To build 64-bit package, do this:
671 $WHERE/Configure solaris64-sparcv9-cc
674 } elsif ( $CCVENDOR eq "gnu" && $GCC_ARCH eq "-m64" ) {
675 # $GCC_ARCH denotes default ABI chosen by compiler driver
676 # (first one found on the $PATH). I assume that user
677 # expects certain consistency with the rest of his builds
678 # and therefore switch over to 64-bit. <appro>
680 WARNING! To build 32-bit package, do this:
681 $WHERE/Configure solaris-sparcv9-gcc
684 return { target => "solaris64-sparcv9" };
685 } elsif ( $GCC_ARCH eq "-m32" ) {
687 NOTICE! If you *know* that your GNU C supports 64-bit/V9 ABI and you wish
688 to build 64-bit library, do this:
689 $WHERE/Configure solaris64-sparcv9-gcc
694 return { target => "solaris64-sparcv9" }
695 if $ISA64 ne "" && $KERNEL_BITS eq '64';
696 return { target => "solaris-sparcv9" };
699 [ 'sun4m-.*-solaris2', { target => "solaris-sparcv8" } ],
700 [ 'sun4d-.*-solaris2', { target => "solaris-sparcv8" } ],
701 [ 'sun4.*-.*-solaris2', { target => "solaris-sparcv7" } ],
702 [ '.*86.*-.*-solaris2',
704 my $KERNEL_BITS = $ENV{KERNEL_BITS};
705 my $ISA64 = `isainfo 2>/dev/null | grep amd64`;
706 my $KB = $KERNEL_BITS // '64';
707 return { target => "solaris64-x86_64" }
708 if $ISA64 ne "" && $KB eq '64';
709 my $REL = uname('-r');
711 my @tmp_disable = ();
712 push @tmp_disable, 'sse2' if int($REL) < 10;
713 return { target => "solaris-x86",
714 disable => [ @tmp_disable ] };
717 # We don't have any sunos target in Configurations/*.conf, so why here?
718 [ '.*-.*-sunos4', { target => "sunos" } ],
719 [ '.*86.*-.*-bsdi4', { target => "BSD-x86-elf",
720 lflags => [ '-ldl' ],
721 disable => [ 'sse2' ] } ],
722 [ 'alpha.*-.*-.*bsd.*', { target => "BSD-generic64",
723 defines => [ 'L_ENDIAN' ] } ],
724 [ 'powerpc64-.*-.*bsd.*', { target => "BSD-generic64",
725 defines => [ 'B_ENDIAN' ] } ],
726 [ 'sparc64-.*-.*bsd.*', { target => "BSD-sparc64" } ],
727 [ 'ia64-.*-.*bsd.*', { target => "BSD-ia64" } ],
728 [ 'x86_64-.*-dragonfly.*', { target => "BSD-x86_64" } ],
729 [ 'amd64-.*-.*bsd.*', { target => "BSD-x86_64" } ],
730 [ '.*86.*-.*-.*bsd.*',
732 # mimic ld behaviour when it's looking for libc...
734 if ( -l "/usr/lib/libc.so" ) {
735 $libc = "/usr/lib/libc.so";
737 # ld searches for highest libc.so.* and so do we
739 `(ls /usr/lib/libc.so.* /lib/libc.so.* | tail -1) 2>/dev/null`;
741 my $what = `file -L $libc 2>/dev/null`;
742 return { target => "BSD-x86-elf" } if $what =~ /ELF/;
743 return { target => "BSD-x86",
744 disable => [ 'sse2' ] };
747 [ '.*-.*-.*bsd.*', { target => "BSD-generic32" } ],
748 [ 'x86_64-.*-haiku', { target => "haiku-x86_64" } ],
749 [ '.*-.*-haiku', { target => "haiku-x86" } ],
750 [ '.*-.*-osf', { target => "osf1-alpha" } ],
751 [ '.*-.*-tru64', { target => "tru64-alpha" } ],
752 [ '.*-.*-[Uu]nix[Ww]are7',
754 return { target => "unixware-7",
755 disable => [ 'sse2' ] } if $CCVENDOR eq "gnu";
756 return { target => "unixware-7",
757 defines => [ '__i386__' ] };
760 [ '.*-.*-[Uu]nix[Ww]are20.*', { target => "unixware-2.0",
761 disable => [ 'sse2', 'sha512' ] } ],
762 [ '.*-.*-[Uu]nix[Ww]are21.*', { target => "unixware-2.1",
763 disable => [ 'sse2', 'sha512' ] } ],
764 [ '.*-.*-vos', { target => "vos",
765 disable => [ 'threads', 'shared', 'asm',
767 [ 'BS2000-siemens-sysv4', { target => "BS2000-OSD" } ],
768 [ 'i[3456]86-.*-cygwin', { target => "Cygwin-x86" } ],
770 sub { return { target => "Cygwin-${MACHINE}" } } ],
771 [ 'x86-.*-android|i.86-.*-android', { target => "android-x86" } ],
772 [ 'armv[7-9].*-.*-android', { target => "android-armeabi",
773 cflags => [ '-march=armv7-a' ],
774 cxxflags => [ '-march=armv7-a' ] } ],
775 [ 'arm.*-.*-android', { target => "android-armeabi" } ],
778 my $KERNEL_BITS = $ENV{KERNEL_BITS};
779 my %common_return = ( defines => [ '_REENTRANT' ] );
780 $KERNEL_BITS ||= `getconf KERNEL_BITS 2>/dev/null` // '32';
781 # See <sys/unistd.h> for further info on CPU_VERSION.
782 my $CPU_VERSION = `getconf CPU_VERSION 2>/dev/null` // 0;
783 if ( $CPU_VERSION >= 768 ) {
785 return { target => "hpux64-ia64",
787 if $KERNEL_BITS eq '64' && ! $CCVENDOR;
788 return { target => "hpux-ia64",
791 if ( $CPU_VERSION >= 532 ) {
793 # PA-RISC 2.0 is no longer supported as separate 32-bit
794 # target. This is compensated for by run-time detection
795 # in most critical assembly modules and taking advantage
796 # of 2.0 architecture in PA-RISC 1.1 build.
797 my $target = ($CCVENDOR eq "gnu" && $GCC_BITS eq '64')
800 if ( $KERNEL_BITS eq '64' && ! $CCVENDOR ) {
802 WARNING! To build 64-bit package, do this:
803 $WHERE/Configure hpux64-parisc2-cc
807 return { target => $target,
811 return { target => "hpux-parisc1_1",
812 %common_return } if $CPU_VERSION >= 528;
814 return { target => "hpux-parisc",
815 %common_return } if $CPU_VERSION >= 523;
817 return { target => "hpux",
821 [ '.*-hpux', { target => "hpux-parisc" } ],
825 my $KERNEL_BITS = $ENV{KERNEL_BITS};
826 $KERNEL_BITS ||= `getconf KERNEL_BITMODE 2>/dev/null`;
827 $KERNEL_BITS ||= '32';
828 my $OBJECT_MODE = $ENV{OBJECT_MODE};
830 $config{target} = "aix";
831 if ( $OBJECT_MODE == 64 ) {
832 print 'Your $OBJECT_MODE was found to be set to 64';
833 $config{target} = "aix64";
835 if ( $CCVENDOR ne 'gnu' && $KERNEL_BITS eq '64' ) {
837 WARNING! To build 64-bit package, do this:
838 $WHERE/Configure aix64-cc
844 "lsattr -E -O -l `lsdev -c processor|awk '{print \$1;exit}'`",
845 'grep -i powerpc) >/dev/null 2>&1') ) {
846 # this applies even to Power3 and later, as they return
849 $config{disable} = [ 'asm' ];
855 # Windows values found by looking at Perl 5's win32/win32.c
856 [ 'amd64-.*?-Windows NT', { target => 'VC-WIN64A' } ],
857 [ 'ia64-.*?-Windows NT', { target => 'VC-WIN64I' } ],
858 [ 'x86-.*?-Windows NT', { target => 'VC-WIN32' } ],
860 # VMS values found by observation on existing machinery.
861 # Unfortunately, the machine part is a bit... overdone. It seems,
862 # though, that 'Alpha' exists in that part for Alphas, making it
863 # distinguishable from Itanium. It will be interesting to see what
864 # we'll get in the upcoming x86_64 port...
865 [ '.*Alpha.*?-.*?-OpenVMS', { target => 'vms-alpha' } ],
866 [ '.*?-.*?-OpenVMS', { target => 'vms-ia64' } ],
868 # TODO: There are a few more choices among OpenSSL config targets, but
869 # reaching them involves a bit more than just a host tripet. Select
870 # environment variables could do the job to cover for more granular
871 # build options such as data model (ILP32 or LP64), thread support
872 # model (PUT, SPT or nothing), target execution environment (OSS or
873 # GUARDIAN). And still, there must be some kind of default when
874 # nothing else is said.
876 # nsv is a virtual x86 environment, equivalent to nsx, so we enforce
878 [ 'nse-tandem-nsk.*', { target => 'nonstop-nse' } ],
879 [ 'nsv-tandem-nsk.*', { target => 'nonstop-nsx' } ],
880 [ 'nsx-tandem-nsk.*', { target => 'nonstop-nsx' } ],
884 # Map GUESSOS into OpenSSL terminology.
885 # Returns a hash table with diverse entries, most importantly 'target',
886 # but also other entries that are fitting for Configure's %config
888 # It would be nice to fix this so that this weren't necessary. :( XXX
892 foreach my $tuple ( @$map_patterns ) {
893 my $pat = @$tuple[0];
894 next if $GUESSOS !~ /^${pat}$/;
895 my $result = @$tuple[1];
896 $result = $result->() if ref $result eq 'CODE';
900 # Last case, return "z" from x-y-z
901 my @fields = split(/-/, $GUESSOS);
902 return ( target => $fields[2] );
905 # gcc < 2.8 does not support -march=ultrasparc
906 sub check_solaris_sparc8 {
908 if ( $CCVENDOR eq 'gnu' && $CCVER < 208 ) {
909 if ( $OUT eq 'solaris-sparcv9-gcc' ) {
911 WARNING! Downgrading to solaris-sparcv8-gcc
912 Upgrade to gcc-2.8 or later.
915 return 'solaris-sparcv8-gcc';
917 if ( $OUT eq "linux-sparcv9" ) {
919 WARNING! Downgrading to linux-sparcv8
920 Upgrade to gcc-2.8 or later.
923 return 'linux-sparcv8';
936 $VERBOSE = 1 if defined $options{verbose};
937 $WAIT = 0 if defined $options{nowait};
939 $CROSS_COMPILE = $options{CROSS_COMPILE} // '';
941 my $GUESSOS = guess_system();
942 determine_compiler_settings();
944 my %ret = map_guess($GUESSOS);
945 $ret{target} = check_solaris_sparc8($ret{target});