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:.*', '${MACHINE}-apple-darwin' ],
144 [ 'SunOS:5\..*', '${MACHINE}-whatever-solaris2' ],
145 [ 'SunOS:.*', '${MACHINE}-sun-sunos4' ],
146 [ 'UNIX_System_V:4\..*?:.*', '${MACHINE}-whatever-sysv4' ],
147 [ 'VOS:.*?:.*?:i786', 'i386-stratus-vos' ],
148 [ 'VOS:.*?:.*?:.*', 'hppa1.1-stratus-vos' ],
149 [ '.*?:4.*?:R4.*?:m88k', '${MACHINE}-whatever-sysv4' ],
150 [ 'DYNIX\/ptx:4.*?:.*', '${MACHINE}-whatever-sysv4' ],
151 [ '.*?:4\.0:3\.0:3[34]..(,.*)?', 'i486-ncr-sysv4' ],
152 [ 'ULTRIX:.*', '${MACHINE}-unknown-ultrix' ],
153 [ 'POSIX-BC.*', 'BS2000-siemens-sysv4' ],
154 [ 'machten:.*', '${MACHINE}-tenon-${SYSTEM}' ],
155 [ 'library:.*', '${MACHINE}-ncr-sysv4' ],
156 [ 'ConvexOS:.*?:11\.0:.*', '${MACHINE}-v11-${SYSTEM}' ],
157 [ 'MINGW64.*?:.*?:.*?:x86_64', '${MACHINE}-whatever-mingw64' ],
158 [ 'MINGW.*', '${MACHINE}-whatever-mingw' ],
159 [ 'CYGWIN.*', '${MACHINE}-pc-cygwin' ],
160 [ 'vxworks.*', '${MACHINE}-whatever-vxworks' ],
162 # Note: there's also NEO and NSR, but they are old and unsupported
163 [ 'NONSTOP_KERNEL:.*:NSE-.*?', 'nse-tandem-nsk${RELEASE}' ],
164 [ 'NONSTOP_KERNEL:.*:NSV-.*?', 'nsv-tandem-nsk${RELEASE}' ],
165 [ 'NONSTOP_KERNEL:.*:NSX-.*?', 'nsx-tandem-nsk${RELEASE}' ],
167 [ sub { -d '/usr/apollo' }, 'whatever-apollo-whatever' ],
170 # Run a command, return true if exit zero else false.
171 # Multiple args are glued together into a pipeline.
172 # Name comes from OpenSSL tests, often written as "ok(run(...."
174 my $command = join(' | ', @_);
175 my $status = system($command) >> 8;
179 # Give user a chance to abort/interrupt if interactive if interactive.
181 if ( $WAIT && -t 1 ) {
183 local $SIG{ALRM} = sub { die "Timeout"; };
186 print "You have about five seconds to abort: ";
187 my $ignored = <STDIN>;
190 print "\n" if $@ =~ /Timeout/;
194 # Look for ISC/SCO with its unique uname program
196 return undef unless IPC::Cmd::can_run('uname');
198 open UNAME, "uname -X 2>/dev/null|" or return '';
202 $line = $_ if m@^Release@;
206 return undef if $line eq '';
208 my @fields = split(/\s+/, $line);
215 if ( -f "/etc/kconfig" ) {
216 return "${MACHINE}-whatever-isc4" if $REL eq '4.0' || $REL eq '4.1';
218 return "whatever-whatever-sco3" if $REL eq '3.2v4.2';
219 return "whatever-whatever-sco5" if $REL =~ m@3\.2v5\.0.*@;
220 if ( $REL eq "4.2MP" ) {
221 return "whatever-whatever-unixware20" if $VERSION =~ m@2\.0.*@;
222 return "whatever-whatever-unixware21" if $VERSION =~ m@2\.1.*@;
223 return "whatever-whatever-unixware2" if $VERSION =~ m@2.*@;
225 return "whatever-whatever-unixware1" if $REL eq "4.2";
226 if ( $REL =~ m@5.*@ ) {
227 # We hardcode i586 in place of ${MACHINE} for the following
228 # reason: even though Pentium is minimum requirement for
229 # platforms in question, ${MACHINE} gets always assigned to
230 # i386. This means i386 gets passed to Configure, which will
231 # cause bad assembler code to be generated.
232 return "i586-sco-unixware7" if $VERSION =~ m@[678].*@;
237 # Return the cputype-vendor-osversion
239 ($SYSTEM, undef, $RELEASE, $VERSION, $MACHINE) = POSIX::uname();
240 my $sys = "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}";
242 # Special-cases for ISC, SCO, Unixware
243 my $REL = is_sco_uname();
244 if ( defined $REL ) {
245 my $result = get_sco_type($REL);
246 return eval "\"$result\"" if $result ne '';
252 foreach my $tuple ( @$guess_patterns ) {
253 my $pat = @$tuple[0];
254 my $check = ref $pat eq 'CODE' ? $pat->($sys) : $sys =~ /^(${pat})$/;
257 my $result = @$tuple[1];
258 $result = $result->() if ref $result eq 'CODE';
259 return eval "\"$result\"";
263 return "${MACHINE}-whatever-${SYSTEM}";
266 # We would use List::Util::pair() for this... unfortunately, that function
267 # only appeared in perl v5.19.3, and we claim to support perl v5.10 and on.
268 # Therefore, we implement a quick cheap variant of our own.
270 croak "Odd number of arguments" if @_ & 1;
275 my $x = [ shift, shift ];
281 # Figure out CC, GCCVAR, etc.
282 sub determine_compiler_settings {
283 # Make a copy and don't touch it. That helps determine if we're finding
284 # the compiler here (false), or if it was set by the user (true.
287 # Set certain default
288 $CCVER = 0; # Unknown
289 $CCVENDOR = ''; # Dunno, don't care (unless found later)
291 # Find a compiler if we don't already have one
293 foreach (@c_compilers) {
294 next unless IPC::Cmd::can_run("$CROSS_COMPILE$_");
301 # Find the compiler vendor and version number for certain compilers
302 foreach my $pair (_pairs @cc_version) {
303 # Try to get the version number.
304 # Failure gets us undef or an empty string
305 my ( $k, $v ) = @$pair;
308 # If we got a version number, process it
312 # The returned version is expected to be one of
316 # MAJOR.MINOR.{whatever}
318 # We don't care what comes after MAJOR.MINOR. All we need is
319 # to have them calculated into a single number, using this
322 # MAJOR * 100 + MINOR
323 # Here are a few examples of what we should get:
328 my @numbers = split /\./, $v;
329 my @factors = (100, 1);
330 while (@numbers && @factors) {
331 $CCVER += shift(@numbers) * shift(@factors)
338 # Vendor specific overrides, only if we didn't determine the compiler here
340 if ( ${SYSTEM} eq 'AIX' ) {
341 # favor vendor cc over gcc
342 if (IPC::Cmd::can_run('cc')) {
344 $CCVENDOR = ''; # Determine later
349 if ( $SYSTEM eq "SunOS" ) {
350 # check for WorkShop C, expected output is "cc: blah-blah C x.x"
351 my $v = `(cc -V 2>&1) 2>/dev/null | egrep -e '^cc: .* C [0-9]\.[0-9]'`;
353 $v =~ s/.* C \([0-9]\)\.\([0-9]\).*/$1.$2/;
354 my @numbers = split /\./, $v;
355 my @factors = (100, 1);
357 while (@numbers && @factors) {
358 $v += shift(@numbers) * shift(@factors)
361 if ( $v > 40000 && $MACHINE ne 'i86pc' ) {
363 $CCVENDOR = ''; # Determine later
366 if ( $CCVER == 50000 ) {
368 WARNING! Found WorkShop C 5.0.
369 Make sure you have patch #107357-01 or later applied.
377 # If no C compiler has been determined at this point, we die. Hard.
380 No C compiler found, please specify one with the environment variable CC,
381 or configure with an explicit configuration target.
385 # On some systems, we assume a cc vendor if it's not already determined
388 $CCVENDOR = 'aix' if $SYSTEM eq 'AIX';
389 $CCVENDOR = 'sun' if $SYSTEM eq 'SunOS';
392 # Some systems need to know extra details
394 if ( $SYSTEM eq "HP-UX" && $CCVENDOR eq 'gnu' ) {
395 # By default gcc is a ILP32 compiler (with long long == 64).
397 if ( $CCVER >= 300 ) {
398 # PA64 support only came in with gcc 3.0.x.
399 # We check if the preprocessor symbol __LP64__ is defined.
400 if ( okrun('echo __LP64__',
401 "$CC -v -E -x c - 2>/dev/null",
402 'grep "^__LP64__" 2>&1 >/dev/null') ) {
403 # __LP64__ has slipped through, it therefore is not defined
410 if ( $SYSTEM eq "SunOS" && $CCVENDOR eq 'gnu' ) {
411 if ( $CCVER >= 300 ) {
412 # 64-bit ABI isn't officially supported in gcc 3.0, but seems
413 # to be working; at the very least 'make test' passes.
414 if ( okrun("$CC -v -E -x c /dev/null 2>&1",
415 'grep __arch64__ >/dev/null') ) {
424 my $vendor = $CCVENDOR ? $CCVENDOR : "(undetermined)";
425 my $version = $CCVER ? $CCVER : "(undetermined)";
426 print "C compiler: $CC\n";
427 print "C compiler vendor: $vendor\n";
428 print "C compiler version: $version\n";
433 [ [ 'uClinux.*64.*', { target => 'uClinux-dist64' } ],
434 [ 'uClinux.*', { target => 'uClinux-dist' } ],
435 [ 'mips3-sgi-irix', { target => 'irix-mips3' } ],
436 [ 'mips4-sgi-irix64',
439 WARNING! To build 64-bit package, do this:
440 $WHERE/Configure irix64-mips4-$CC
443 return { target => "irix-mips3" };
446 [ 'ppc-apple-rhapsody', { target => "rhapsody-ppc" } ],
447 [ 'ppc-apple-darwin.*',
449 my $KERNEL_BITS = $ENV{KERNEL_BITS};
450 my $ISA64 = `sysctl -n hw.optional.64bitops 2>/dev/null`;
451 if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
453 WARNING! To build 64-bit package, do this:
454 $WHERE/Configure darwin64-ppc-cc
458 return { target => "darwin64-ppc" }
459 if $ISA64 == 1 && $KERNEL_BITS eq '64';
460 return { target => "darwin-ppc" };
463 [ 'i.86-apple-darwin.*',
465 my $KERNEL_BITS = $ENV{KERNEL_BITS};
466 my $ISA64 = `sysctl -n hw.optional.x86_64 2>/dev/null`;
467 if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
469 WARNING! To build 64-bit package, do this:
470 KERNEL_BITS=64 $WHERE/Configure \[\[ options \]\]
474 return { target => "darwin64-x86_64" }
475 if $ISA64 == 1 && $KERNEL_BITS eq '64';
476 return { target => "darwin-i386" };
479 [ 'x86_64-apple-darwin.*',
481 my $KERNEL_BITS = $ENV{KERNEL_BITS};
482 return { target => "darwin-i386" } if $KERNEL_BITS eq '32';
485 WARNING! To build 32-bit package, do this:
486 KERNEL_BITS=32 $WHERE/Configure \[\[ options \]\]
489 return { target => "darwin64-x86_64" };
492 [ 'arm64-apple-darwin.*', { target => "darwin64-arm64" } ],
493 [ 'armv6\+7-.*-iphoneos',
494 { target => "iphoneos-cross",
495 cflags => [ qw(-arch armv6 -arch armv7) ],
496 cxxflags => [ qw(-arch armv6 -arch armv7) ] }
498 [ 'arm64-.*-iphoneos|.*-.*-ios64',
499 { target => "ios64-cross" }
502 sub { return { target => "iphoneos-cross",
503 cflags => [ "-arch ${MACHINE}" ],
504 cxxflags => [ "-arch ${MACHINE}" ] }; }
506 [ 'alpha-.*-linux2.*',
508 my $ISA = `awk '/cpu model/{print \$4;exit(0);}' /proc/cpuinfo`;
511 if ( $CCVENDOR eq "gnu" ) {
512 if ( $ISA =~ 'EV5|EV45' ) {
513 %config = ( cflags => [ '-mcpu=ev5' ],
514 cxxflags => [ '-mcpu=ev5' ] );
515 } elsif ( $ISA =~ 'EV56|PCA56' ) {
516 %config = ( cflags => [ '-mcpu=ev56' ],
517 cxxflags => [ '-mcpu=ev56' ] );
519 %config = ( cflags => [ '-mcpu=ev6' ],
520 cxxflags => [ '-mcpu=ev6' ] );
523 return { target => "linux-alpha",
529 my $KERNEL_BITS = $ENV{KERNEL_BITS};
530 if ( $KERNEL_BITS eq '' ) {
532 WARNING! To build 64-bit package, do this:
533 $WHERE/Configure linux-ppc64
537 return { target => "linux-ppc64" } if $KERNEL_BITS eq '64';
540 if (!okrun('echo __LP64__',
541 'gcc -E -x c - 2>/dev/null',
542 'grep "^__LP64__" 2>&1 >/dev/null') ) {
543 %config = ( cflags => [ '-m32' ],
544 cxxflags => [ '-m32' ] );
546 return { target => "linux-ppc",
550 [ 'ppc64le-.*-linux2', { target => "linux-ppc64le" } ],
551 [ 'ppc-.*-linux2', { target => "linux-ppc" } ],
552 [ 'mips64.*-*-linux2',
555 WARNING! To build 64-bit package, do this:
556 $WHERE/Configure linux64-mips64
559 return { target => "linux-mips64" };
562 [ 'mips.*-.*-linux2', { target => "linux-mips32" } ],
563 [ 'ppc60x-.*-vxworks.*', { target => "vxworks-ppc60x" } ],
564 [ 'ppcgen-.*-vxworks.*', { target => "vxworks-ppcgen" } ],
565 [ 'pentium-.*-vxworks.*', { target => "vxworks-pentium" } ],
566 [ 'simlinux-.*-vxworks.*', { target => "vxworks-simlinux" } ],
567 [ 'mips-.*-vxworks.*', { target => "vxworks-mips" } ],
568 [ 'e2k-.*-linux.*', { target => "linux-generic64",
569 defines => [ 'L_ENDIAN' ] } ],
570 [ 'ia64-.*-linux.', { target => "linux-ia64" } ],
571 [ 'sparc64-.*-linux2',
574 WARNING! If you *know* that your GNU C supports 64-bit/V9 ABI and you
575 want to build 64-bit library, do this:
576 $WHERE/Configure linux64-sparcv9
579 return { target => "linux-sparcv9" };
584 my $KARCH = `awk '/^type/{print \$3;exit(0);}' /proc/cpuinfo`;
586 return { target => "linux-sparcv9" } if $KARCH =~ 'sun4u.*';
587 return { target => "linux-sparcv8" } if $KARCH =~ 'sun4[md]';
588 return { target => "linux-generic32",
589 defines => [ 'L_ENDIAN' ] };
592 [ 'parisc.*-.*-linux2',
594 # 64-bit builds under parisc64 linux are not supported and
595 # compiler is expected to generate 32-bit objects...
597 `awk '/cpu family/{print substr(\$5,1,3); exit(0);}' /proc/cpuinfo`;
599 `awk '/^cpu.[ ]*: PA/{print substr(\$3,3); exit(0);}' /proc/cpuinfo`;
600 # TODO XXX Model transformations
601 # 0. CPU Architecture for the 1.1 processor has letter suffixes.
602 # We strip that off assuming no further arch. identification
603 # will ever be used by GCC.
604 # 1. I'm most concerned about whether is a 7300LC is closer to a
605 # 7100 versus a 7100LC.
606 # 2. The variant 64-bit processors cause concern should GCC support
607 # explicit schedulers for these chips in the future.
608 # PA7300LC -> 7100LC (1.1)
609 # PA8200 -> 8000 (2.0)
610 # PA8500 -> 8000 (2.0)
611 # PA8600 -> 8000 (2.0)
612 $CPUSCHEDULE =~ s/7300LC/7100LC/;
613 $CPUSCHEDULE =~ s/8.00/8000/;
615 { target => "linux-generic32",
616 defines => [ 'B_ENDIAN' ],
617 cflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ],
618 cxxflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ]
622 [ 'armv[1-3].*-.*-linux2', { target => "linux-generic32" } ],
623 [ 'armv[7-9].*-.*-linux2', { target => "linux-armv4",
624 cflags => [ '-march=armv7-a' ],
625 cxxflags => [ '-march=armv7-a' ] } ],
626 [ 'arm.*-.*-linux2', { target => "linux-armv4" } ],
627 [ 'aarch64-.*-linux2', { target => "linux-aarch64" } ],
628 [ 'sh.*b-.*-linux2', { target => "linux-generic32",
629 defines => [ 'B_ENDIAN' ] } ],
630 [ 'sh.*-.*-linux2', { target => "linux-generic32",
631 defines => [ 'L_ENDIAN' ] } ],
632 [ 'm68k.*-.*-linux2', { target => "linux-generic32",
633 defines => [ 'B_ENDIAN' ] } ],
634 [ 's390-.*-linux2', { target => "linux-generic32",
635 defines => [ 'B_ENDIAN' ] } ],
638 # Disabled until a glibc bug is fixed; see Configure.
640 || okrun('egrep -e \'^features.* highgprs\' /proc/cpuinfo >/dev/null') )
643 WARNING! To build "highgprs" 32-bit package, do this:
644 $WHERE/Configure linux32-s390x
648 return { target => "linux64-s390x" };
651 [ 'x86_64-.*-linux.',
653 return { target => "linux-x32" }
654 if okrun("$CC -dM -E -x c /dev/null 2>&1",
655 'grep -q ILP32 >/dev/null');
656 return { target => "linux-x86_64" };
661 # On machines where the compiler understands -m32, prefer a
662 # config target that uses it
663 return { target => "linux-x86" }
664 if okrun("$CC -m32 -E -x c /dev/null >/dev/null 2>&1");
665 return { target => "linux-elf" };
668 [ '.*86-.*-linux1', { target => "linux-aout" } ],
669 [ '.*-.*-linux.', { target => "linux-generic32" } ],
670 [ 'sun4[uv].*-.*-solaris2',
672 my $KERNEL_BITS = $ENV{KERNEL_BITS};
673 my $ISA64 = `isainfo 2>/dev/null | grep sparcv9`;
674 if ( $ISA64 ne "" && $KERNEL_BITS eq '' ) {
675 if ( $CCVENDOR eq "sun" && $CCVER >= 500 ) {
677 WARNING! To build 64-bit package, do this:
678 $WHERE/Configure solaris64-sparcv9-cc
681 } elsif ( $CCVENDOR eq "gnu" && $GCC_ARCH eq "-m64" ) {
682 # $GCC_ARCH denotes default ABI chosen by compiler driver
683 # (first one found on the $PATH). I assume that user
684 # expects certain consistency with the rest of his builds
685 # and therefore switch over to 64-bit. <appro>
687 WARNING! To build 32-bit package, do this:
688 $WHERE/Configure solaris-sparcv9-gcc
691 return { target => "solaris64-sparcv9" };
692 } elsif ( $GCC_ARCH eq "-m32" ) {
694 NOTICE! If you *know* that your GNU C supports 64-bit/V9 ABI and you wish
695 to build 64-bit library, do this:
696 $WHERE/Configure solaris64-sparcv9-gcc
701 return { target => "solaris64-sparcv9" }
702 if $ISA64 ne "" && $KERNEL_BITS eq '64';
703 return { target => "solaris-sparcv9" };
706 [ 'sun4m-.*-solaris2', { target => "solaris-sparcv8" } ],
707 [ 'sun4d-.*-solaris2', { target => "solaris-sparcv8" } ],
708 [ 'sun4.*-.*-solaris2', { target => "solaris-sparcv7" } ],
709 [ '.*86.*-.*-solaris2',
711 my $KERNEL_BITS = $ENV{KERNEL_BITS};
712 my $ISA64 = `isainfo 2>/dev/null | grep amd64`;
713 my $KB = $KERNEL_BITS // '64';
714 if ($ISA64 ne "" && $KB eq '64') {
715 return { target => "solaris64-x86_64-gcc" } if $CCVENDOR eq "gnu";
716 return { target => "solaris64-x86_64-cc" };
718 my $REL = uname('-r');
720 my @tmp_disable = ();
721 push @tmp_disable, 'sse2' if int($REL) < 10;
722 #There is no solaris-x86-cc target
723 return { target => "solaris-x86-gcc",
724 disable => [ @tmp_disable ] };
727 # We don't have any sunos target in Configurations/*.conf, so why here?
728 [ '.*-.*-sunos4', { target => "sunos" } ],
729 [ '.*86.*-.*-bsdi4', { target => "BSD-x86-elf",
730 lflags => [ '-ldl' ],
731 disable => [ 'sse2' ] } ],
732 [ 'alpha.*-.*-.*bsd.*', { target => "BSD-generic64",
733 defines => [ 'L_ENDIAN' ] } ],
734 [ 'powerpc64-.*-.*bsd.*', { target => "BSD-generic64",
735 defines => [ 'B_ENDIAN' ] } ],
736 [ 'sparc64-.*-.*bsd.*', { target => "BSD-sparc64" } ],
737 [ 'ia64-.*-.*bsd.*', { target => "BSD-ia64" } ],
738 [ 'x86_64-.*-dragonfly.*', { target => "BSD-x86_64" } ],
739 [ 'amd64-.*-.*bsd.*', { target => "BSD-x86_64" } ],
740 [ '.*86.*-.*-.*bsd.*',
742 # mimic ld behaviour when it's looking for libc...
744 if ( -l "/usr/lib/libc.so" ) {
745 $libc = "/usr/lib/libc.so";
747 # ld searches for highest libc.so.* and so do we
749 `(ls /usr/lib/libc.so.* /lib/libc.so.* | tail -1) 2>/dev/null`;
751 my $what = `file -L $libc 2>/dev/null`;
752 return { target => "BSD-x86-elf" } if $what =~ /ELF/;
753 return { target => "BSD-x86",
754 disable => [ 'sse2' ] };
757 [ '.*-.*-.*bsd.*', { target => "BSD-generic32" } ],
758 [ 'x86_64-.*-haiku', { target => "haiku-x86_64" } ],
759 [ '.*-.*-haiku', { target => "haiku-x86" } ],
760 [ '.*-.*-osf', { target => "osf1-alpha" } ],
761 [ '.*-.*-tru64', { target => "tru64-alpha" } ],
762 [ '.*-.*-[Uu]nix[Ww]are7',
764 return { target => "unixware-7",
765 disable => [ 'sse2' ] } if $CCVENDOR eq "gnu";
766 return { target => "unixware-7",
767 defines => [ '__i386__' ] };
770 [ '.*-.*-[Uu]nix[Ww]are20.*', { target => "unixware-2.0",
771 disable => [ 'sse2', 'sha512' ] } ],
772 [ '.*-.*-[Uu]nix[Ww]are21.*', { target => "unixware-2.1",
773 disable => [ 'sse2', 'sha512' ] } ],
774 [ '.*-.*-vos', { target => "vos",
775 disable => [ 'threads', 'shared', 'asm',
777 [ 'BS2000-siemens-sysv4', { target => "BS2000-OSD" } ],
778 [ 'i[3456]86-.*-cygwin', { target => "Cygwin-x86" } ],
780 sub { return { target => "Cygwin-${MACHINE}" } } ],
781 [ 'x86-.*-android|i.86-.*-android', { target => "android-x86" } ],
782 [ 'armv[7-9].*-.*-android', { target => "android-armeabi",
783 cflags => [ '-march=armv7-a' ],
784 cxxflags => [ '-march=armv7-a' ] } ],
785 [ 'arm.*-.*-android', { target => "android-armeabi" } ],
788 my $KERNEL_BITS = $ENV{KERNEL_BITS};
789 my %common_return = ( defines => [ '_REENTRANT' ] );
790 $KERNEL_BITS ||= `getconf KERNEL_BITS 2>/dev/null` // '32';
791 # See <sys/unistd.h> for further info on CPU_VERSION.
792 my $CPU_VERSION = `getconf CPU_VERSION 2>/dev/null` // 0;
793 if ( $CPU_VERSION >= 768 ) {
795 return { target => "hpux64-ia64",
797 if $KERNEL_BITS eq '64' && ! $CCVENDOR;
798 return { target => "hpux-ia64",
801 if ( $CPU_VERSION >= 532 ) {
803 # PA-RISC 2.0 is no longer supported as separate 32-bit
804 # target. This is compensated for by run-time detection
805 # in most critical assembly modules and taking advantage
806 # of 2.0 architecture in PA-RISC 1.1 build.
807 my $target = ($CCVENDOR eq "gnu" && $GCC_BITS eq '64')
810 if ( $KERNEL_BITS eq '64' && ! $CCVENDOR ) {
812 WARNING! To build 64-bit package, do this:
813 $WHERE/Configure hpux64-parisc2-cc
817 return { target => $target,
821 return { target => "hpux-parisc1_1",
822 %common_return } if $CPU_VERSION >= 528;
824 return { target => "hpux-parisc",
825 %common_return } if $CPU_VERSION >= 523;
827 return { target => "hpux",
831 [ '.*-hpux', { target => "hpux-parisc" } ],
835 my $KERNEL_BITS = $ENV{KERNEL_BITS};
836 $KERNEL_BITS ||= `getconf KERNEL_BITMODE 2>/dev/null`;
837 $KERNEL_BITS ||= '32';
838 my $OBJECT_MODE = $ENV{OBJECT_MODE};
840 $config{target} = "aix";
841 if ( $OBJECT_MODE == 64 ) {
842 print 'Your $OBJECT_MODE was found to be set to 64';
843 $config{target} = "aix64";
845 if ( $CCVENDOR ne 'gnu' && $KERNEL_BITS eq '64' ) {
847 WARNING! To build 64-bit package, do this:
848 $WHERE/Configure aix64-cc
854 "lsattr -E -O -l `lsdev -c processor|awk '{print \$1;exit}'`",
855 'grep -i powerpc) >/dev/null 2>&1') ) {
856 # this applies even to Power3 and later, as they return
859 $config{disable} = [ 'asm' ];
865 # Windows values found by looking at Perl 5's win32/win32.c
866 [ 'amd64-.*?-Windows NT', { target => 'VC-WIN64A' } ],
867 [ 'ia64-.*?-Windows NT', { target => 'VC-WIN64I' } ],
868 [ 'x86-.*?-Windows NT', { target => 'VC-WIN32' } ],
870 # VMS values found by observation on existing machinery.
871 # Unfortunately, the machine part is a bit... overdone. It seems,
872 # though, that 'Alpha' exists in that part for Alphas, making it
873 # distinguishable from Itanium. It will be interesting to see what
874 # we'll get in the upcoming x86_64 port...
875 [ '.*Alpha.*?-.*?-OpenVMS', { target => 'vms-alpha' } ],
876 [ '.*?-.*?-OpenVMS', { target => 'vms-ia64' } ],
878 # TODO: There are a few more choices among OpenSSL config targets, but
879 # reaching them involves a bit more than just a host tripet. Select
880 # environment variables could do the job to cover for more granular
881 # build options such as data model (ILP32 or LP64), thread support
882 # model (PUT, SPT or nothing), target execution environment (OSS or
883 # GUARDIAN). And still, there must be some kind of default when
884 # nothing else is said.
886 # nsv is a virtual x86 environment, equivalent to nsx, so we enforce
888 [ 'nse-tandem-nsk.*', { target => 'nonstop-nse' } ],
889 [ 'nsv-tandem-nsk.*', { target => 'nonstop-nsx' } ],
890 [ 'nsx-tandem-nsk.*', { target => 'nonstop-nsx' } ],
894 # Map GUESSOS into OpenSSL terminology.
895 # Returns a hash table with diverse entries, most importantly 'target',
896 # but also other entries that are fitting for Configure's %config
898 # It would be nice to fix this so that this weren't necessary. :( XXX
902 foreach my $tuple ( @$map_patterns ) {
903 my $pat = @$tuple[0];
904 next if $GUESSOS !~ /^${pat}$/;
905 my $result = @$tuple[1];
906 $result = $result->() if ref $result eq 'CODE';
910 # Last case, return "z" from x-y-z
911 my @fields = split(/-/, $GUESSOS);
912 return ( target => $fields[2] );
915 # gcc < 2.8 does not support -march=ultrasparc
916 sub check_solaris_sparc8 {
918 if ( $CCVENDOR eq 'gnu' && $CCVER < 208 ) {
919 if ( $OUT eq 'solaris-sparcv9-gcc' ) {
921 WARNING! Downgrading to solaris-sparcv8-gcc
922 Upgrade to gcc-2.8 or later.
925 return 'solaris-sparcv8-gcc';
927 if ( $OUT eq "linux-sparcv9" ) {
929 WARNING! Downgrading to linux-sparcv8
930 Upgrade to gcc-2.8 or later.
933 return 'linux-sparcv8';
946 $VERBOSE = 1 if defined $options{verbose};
947 $WAIT = 0 if defined $options{nowait};
949 $CROSS_COMPILE = $options{CROSS_COMPILE} // '';
951 my $GUESSOS = guess_system();
952 determine_compiler_settings();
954 my %ret = map_guess($GUESSOS);
955 $ret{target} = check_solaris_sparc8($ret{target});