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 [ sub { -d '/usr/apollo' }, 'whatever-apollo-whatever' ],
166 # Run a command, return true if exit zero else false.
167 # Multiple args are glued together into a pipeline.
168 # Name comes from OpenSSL tests, often written as "ok(run(...."
170 my $command = join(' | ', @_);
171 my $status = system($command) >> 8;
175 # Give user a chance to abort/interrupt if interactive if interactive.
177 if ( $WAIT && -t 1 ) {
179 local $SIG{ALRM} = sub { die "Timeout"; };
182 print "You have about five seconds to abort: ";
183 my $ignored = <STDIN>;
186 print "\n" if $@ =~ /Timeout/;
190 # Look for ISC/SCO with its unique uname program
192 open UNAME, "uname -X 2>/dev/null|" or return '';
196 $line = $_ if m@^Release@;
199 return "" if $line eq '';
200 my @fields = split($line);
207 if ( -f "/etc/kconfig" ) {
208 return "${MACHINE}-whatever-isc4" if $REL eq '4.0' || $REL eq '4.1';
210 return "whatever-whatever-sco3" if $REL eq '3.2v4.2';
211 return "whatever-whatever-sco5" if $REL =~ m@3\.2v5\.0.*@;
212 if ( $REL eq "4.2MP" ) {
213 return "whatever-whatever-unixware20" if $VERSION =~ m@2\.0.*@;
214 return "whatever-whatever-unixware21" if $VERSION =~ m@2\.1.*@;
215 return "whatever-whatever-unixware2" if $VERSION =~ m@2.*@;
217 return "whatever-whatever-unixware1" if $REL eq "4.2";
218 if ( $REL =~ m@5.*@ ) {
219 # We hardcode i586 in place of ${MACHINE} for the following
220 # reason: even though Pentium is minimum requirement for
221 # platforms in question, ${MACHINE} gets always assigned to
222 # i386. This means i386 gets passed to Configure, which will
223 # cause bad assembler code to be generated.
224 return "i586-sco-unixware7" if $VERSION =~ m@[678].*@;
229 # Return the cputype-vendor-osversion
231 ($SYSTEM, undef, $RELEASE, $VERSION, $MACHINE) = POSIX::uname();
232 my $sys = "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}";
234 # Special-cases for ISC, SCO, Unixware
235 my $REL = is_sco_uname();
237 my $result = get_sco_type($REL);
238 return eval "\"$result\"" if $result ne '';
244 foreach my $tuple ( @$guess_patterns ) {
245 my $pat = @$tuple[0];
246 my $check = ref $pat eq 'CODE' ? $pat->($sys) : $sys =~ /^(${pat})$/;
249 my $result = @$tuple[1];
250 $result = $result->() if ref $result eq 'CODE';
251 return eval "\"$result\"";
255 return "${MACHINE}-whatever-${SYSTEM}";
258 # We would use List::Util::pair() for this... unfortunately, that function
259 # only appeared in perl v5.19.3, and we claim to support perl v5.10 and on.
260 # Therefore, we implement a quick cheap variant of our own.
262 croak "Odd number of arguments" if @_ & 1;
267 my $x = [ shift, shift ];
273 # Figure out CC, GCCVAR, etc.
274 sub determine_compiler_settings {
275 # Make a copy and don't touch it. That helps determine if we're
276 # finding the compiler here
279 # Set certain default
280 $CCVER = 0; # Unknown
281 $CCVENDOR = ''; # Dunno, don't care (unless found later)
283 # Find a compiler if we don't already have one
285 foreach (@c_compilers) {
286 next unless IPC::Cmd::can_run("$CROSS_COMPILE$_");
292 # Find the compiler vendor and version number for certain compilers
293 foreach my $pair (_pairs @cc_version) {
294 # Try to get the version number.
295 # Failure gets us undef or an empty string
296 my ( $k, $v ) = @$pair;
299 # If we got a version number, process it
303 # The returned version is expected to be one of
307 # MAJOR.MINOR.{whatever}
309 # We don't care what comes after MAJOR.MINOR. All we need is to
310 # have them calculated into a single number, using this formula:
312 # MAJOR * 100 + MINOR
313 # Here are a few examples of what we should get:
318 my @numbers = split /\./, $v;
319 my @factors = (100, 1);
320 while (@numbers && @factors) {
321 $CCVER += shift(@numbers) * shift(@factors)
327 # If no C compiler has been determined at this point, we die. Hard.
330 No C compiler found, please specify one with the environment variable CC,
331 or configure with an explicit configuration target.
335 # Vendor specific overrides, only if we determined the compiler here
337 if ( ${SYSTEM} eq 'AIX' ) {
338 # favor vendor cc over gcc
339 if (IPC::Cmd::can_run('cc')) {
341 $CCVENDOR = ''; # Determine later
346 if ( $SYSTEM eq "SunOS" ) {
347 # check for WorkShop C, expected output is "cc: blah-blah C x.x"
348 my $v = `(cc -V 2>&1) 2>/dev/null | egrep -e '^cc: .* C [0-9]\.[0-9]'`;
350 $v =~ s/.* C \([0-9]\)\.\([0-9]\).*/$1.$2/;
351 my @numbers = split /\./, $v;
352 my @factors = (100, 1);
354 while (@numbers && @factors) {
355 $v += shift(@numbers) * shift(@factors)
358 if ( $v > 40000 && $MACHINE ne 'i86pc' ) {
360 $CCVENDOR = ''; # Determine later
363 if ( $CCVER == 50000 ) {
365 WARNING! Found WorkShop C 5.0.
366 Make sure you have patch #107357-01 or later applied.
374 # On some systems, we assume a cc vendor if it's not already determined
377 $CCVENDOR = 'aix' if $SYSTEM eq 'AIX';
378 $CCVENDOR = 'sun' if $SYSTEM eq 'SunOS';
381 # Some systems need to know extra details
383 if ( $SYSTEM eq "HP-UX" && $CCVENDOR eq 'gnu' ) {
384 # By default gcc is a ILP32 compiler (with long long == 64).
386 if ( $CCVER >= 300 ) {
387 # PA64 support only came in with gcc 3.0.x.
388 # We check if the preprocessor symbol __LP64__ is defined.
389 if ( okrun('echo __LP64__',
390 "$CC -v -E -x c - 2>/dev/null",
391 'grep "^__LP64__" 2>&1 >/dev/null') ) {
392 # __LP64__ has slipped through, it therefore is not defined
399 if ( $SYSTEM eq "SunOS" && $CCVENDOR eq 'gnu' ) {
400 if ( $CCVER >= 300 ) {
401 # 64-bit ABI isn't officially supported in gcc 3.0, but seems
402 # to be working; at the very least 'make test' passes.
403 if ( okrun("$CC -v -E -x c /dev/null 2>&1",
404 'grep __arch64__ >/dev/null') ) {
413 my $vendor = $CCVENDOR ? $CCVENDOR : "(undetermined)";
414 my $version = $CCVER ? $CCVER : "(undetermined)";
415 print "C compiler: $CC\n";
416 print "C compiler vendor: $vendor\n";
417 print "C compiler version: $version\n";
422 [ [ 'uClinux.*64.*', { target => 'uClinux-dist64' } ],
423 [ 'uClinux.*', { target => 'uClinux-dist' } ],
424 [ 'mips3-sgi-irix', { target => 'irix-mips3' } ],
425 [ 'mips4-sgi-irix64',
428 WARNING! To build 64-bit package, do this:
429 $WHERE/Configure irix64-mips4-$CC
432 return { target => "irix-mips3" };
435 [ 'ppc-apple-rhapsody', { target => "rhapsody-ppc" } ],
436 [ 'ppc-apple-darwin.*',
438 my $KERNEL_BITS = $ENV{KERNEL_BITS};
439 my $ISA64 = `sysctl -n hw.optional.64bitops 2>/dev/null`;
440 if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
442 WARNING! To build 64-bit package, do this:
443 $WHERE/Configure darwin64-ppc-cc
447 return { target => "darwin64-ppc" }
448 if $ISA64 == 1 && $KERNEL_BITS eq '64';
449 return { target => "darwin-ppc" };
452 [ 'i.86-apple-darwin.*',
454 my $KERNEL_BITS = $ENV{KERNEL_BITS};
455 my $ISA64 = `sysctl -n hw.optional.x86_64 2>/dev/null`;
456 if ( $ISA64 == 1 && $KERNEL_BITS eq '' ) {
458 WARNING! To build 64-bit package, do this:
459 KERNEL_BITS=64 $WHERE/Configure \[\[ options \]\]
463 return { target => "darwin64-x86_64" }
464 if $ISA64 == 1 && $KERNEL_BITS eq '64';
465 return { target => "darwin-i386" };
468 [ 'x86_64-apple-darwin.*',
470 my $KERNEL_BITS = $ENV{KERNEL_BITS};
471 return { target => "darwin-i386" } if $KERNEL_BITS eq '32';
474 WARNING! To build 32-bit package, do this:
475 KERNEL_BITS=32 $WHERE/Configure \[\[ options \]\]
478 return { target => "darwin64-x86_64" };
481 [ 'armv6\+7-.*-iphoneos',
482 { target => "iphoneos-cross",
483 cflags => [ qw(-arch armv6 -arch armv7) ],
484 cxxflags => [ qw(-arch armv6 -arch armv7) ] }
486 [ 'arm64-.*-iphoneos|.*-.*-ios64',
487 { target => "ios64-cross" }
490 sub { return { target => "iphoneos-cross",
491 cflags => [ "-arch ${MACHINE}" ],
492 cxxflags => [ "-arch ${MACHINE}" ] }; }
494 [ 'alpha-.*-linux2.*',
496 my $ISA = `awk '/cpu model/{print \$4;exit(0);}' /proc/cpuinfo`;
499 if ( $CCVENDOR eq "gnu" ) {
500 if ( $ISA =~ 'EV5|EV45' ) {
501 %config = ( cflags => [ '-mcpu=ev5' ],
502 cxxflags => [ '-mcpu=ev5' ] );
503 } elsif ( $ISA =~ 'EV56|PCA56' ) {
504 %config = ( cflags => [ '-mcpu=ev56' ],
505 cxxflags => [ '-mcpu=ev56' ] );
507 %config = ( cflags => [ '-mcpu=ev6' ],
508 cxxflags => [ '-mcpu=ev6' ] );
511 return { target => "linux-alpha",
517 my $KERNEL_BITS = $ENV{KERNEL_BITS};
518 if ( $KERNEL_BITS eq '' ) {
520 WARNING! To build 64-bit package, do this:
521 $WHERE/Configure linux-ppc64
525 return { target => "linux-ppc64" } if $KERNEL_BITS eq '64';
528 if (!okrun('echo __LP64__',
529 'gcc -E -x c - 2>/dev/null',
530 'grep "^__LP64__" 2>&1 >/dev/null') ) {
531 %config = ( cflags => [ '-m32' ],
532 cxxflags => [ '-m32' ] );
534 return { target => "linux-ppc",
538 [ 'ppc64le-.*-linux2', { target => "linux-ppc64le" } ],
539 [ 'ppc-.*-linux2', { target => "linux-ppc" } ],
540 [ 'mips64.*-*-linux2',
543 WARNING! To build 64-bit package, do this:
544 $WHERE/Configure linux64-mips64
547 return { target => "linux-mips64" };
550 [ 'mips.*-.*-linux2', { target => "linux-mips32" } ],
551 [ 'ppc60x-.*-vxworks.*', { target => "vxworks-ppc60x" } ],
552 [ 'ppcgen-.*-vxworks.*', { target => "vxworks-ppcgen" } ],
553 [ 'pentium-.*-vxworks.*', { target => "vxworks-pentium" } ],
554 [ 'simlinux-.*-vxworks.*', { target => "vxworks-simlinux" } ],
555 [ 'mips-.*-vxworks.*', { target => "vxworks-mips" } ],
556 [ 'e2k-.*-linux.*', { target => "linux-generic64",
557 defines => [ 'L_ENDIAN' ] } ],
558 [ 'ia64-.*-linux.', { target => "linux-ia64" } ],
559 [ 'sparc64-.*-linux2',
562 WARNING! If you *know* that your GNU C supports 64-bit/V9 ABI and you
563 want to build 64-bit library, do this:
564 $WHERE/Configure linux64-sparcv9
567 return { target => "linux-sparcv9" };
572 my $KARCH = `awk '/^type/{print \$3;exit(0);}' /proc/cpuinfo`;
574 return { target => "linux-sparcv9" } if $KARCH =~ 'sun4u.*';
575 return { target => "linux-sparcv8" } if $KARCH =~ 'sun4[md]';
576 return { target => "linux-generic32",
577 defines => [ 'L_ENDIAN' ] };
580 [ 'parisc.*-.*-linux2',
582 # 64-bit builds under parisc64 linux are not supported and
583 # compiler is expected to generate 32-bit objects...
585 `awk '/cpu family/{print substr(\$5,1,3); exit(0);}' /proc/cpuinfo`;
587 `awk '/^cpu.[ ]*: PA/{print substr(\$3,3); exit(0);}' /proc/cpuinfo`;
588 # TODO XXX Model transformations
589 # 0. CPU Architecture for the 1.1 processor has letter suffixes.
590 # We strip that off assuming no further arch. identification
591 # will ever be used by GCC.
592 # 1. I'm most concerned about whether is a 7300LC is closer to a
593 # 7100 versus a 7100LC.
594 # 2. The variant 64-bit processors cause concern should GCC support
595 # explicit schedulers for these chips in the future.
596 # PA7300LC -> 7100LC (1.1)
597 # PA8200 -> 8000 (2.0)
598 # PA8500 -> 8000 (2.0)
599 # PA8600 -> 8000 (2.0)
600 $CPUSCHEDULE =~ s/7300LC/7100LC/;
601 $CPUSCHEDULE =~ s/8.00/8000/;
603 { target => "linux-generic32",
604 defines => [ 'B_ENDIAN' ],
605 cflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ],
606 cxxflags => [ "-mschedule=$CPUSCHEDULE", "-march=$CPUARCH" ]
610 [ 'armv[1-3].*-.*-linux2', { target => "linux-generic32" } ],
611 [ 'armv[7-9].*-.*-linux2', { target => "linux-armv4",
612 cflags => [ '-march=armv7-a' ],
613 cxxflags => [ '-march=armv7-a' ] } ],
614 [ 'arm.*-.*-linux2', { target => "linux-armv4" } ],
615 [ 'aarch64-.*-linux2', { target => "linux-aarch64" } ],
616 [ 'sh.*b-.*-linux2', { target => "linux-generic32",
617 defines => [ 'B_ENDIAN' ] } ],
618 [ 'sh.*-.*-linux2', { target => "linux-generic32",
619 defines => [ 'L_ENDIAN' ] } ],
620 [ 'm68k.*-.*-linux2', { target => "linux-generic32",
621 defines => [ 'B_ENDIAN' ] } ],
622 [ 's390-.*-linux2', { target => "linux-generic32",
623 defines => [ 'B_ENDIAN' ] } ],
626 # Disabled until a glibc bug is fixed; see Configure.
628 || okrun('egrep -e \'^features.* highgprs\' /proc/cpuinfo >/dev/null') )
631 WARNING! To build "highgprs" 32-bit package, do this:
632 $WHERE/Configure linux32-s390x
636 return { target => "linux64-s390x" };
639 [ 'x86_64-.*-linux.',
641 return { target => "linux-x32" }
642 if okrun("$CC -dM -E -x c /dev/null 2>&1",
643 'grep -q ILP32 >/dev/null');
644 return { target => "linux-x86_64" };
649 # On machines where the compiler understands -m32, prefer a
650 # config target that uses it
651 return { target => "linux-x86" }
652 if okrun("$CC -m32 -E -x c /dev/null >/dev/null 2>&1");
653 return { target => "linux-elf" };
656 [ '.*86-.*-linux1', { target => "linux-aout" } ],
657 [ '.*-.*-linux.', { target => "linux-generic32" } ],
658 [ 'sun4[uv].*-.*-solaris2',
660 my $KERNEL_BITS = $ENV{KERNEL_BITS};
661 my $ISA64 = `isainfo 2>/dev/null | grep sparcv9`;
662 if ( $ISA64 ne "" && $KERNEL_BITS eq '' ) {
663 if ( $CCVENDOR eq "sun" && $CCVER >= 500 ) {
665 WARNING! To build 64-bit package, do this:
666 $WHERE/Configure solaris64-sparcv9-cc
669 } elsif ( $CCVENDOR eq "gnu" && $GCC_ARCH eq "-m64" ) {
670 # $GCC_ARCH denotes default ABI chosen by compiler driver
671 # (first one found on the $PATH). I assume that user
672 # expects certain consistency with the rest of his builds
673 # and therefore switch over to 64-bit. <appro>
675 WARNING! To build 32-bit package, do this:
676 $WHERE/Configure solaris-sparcv9-gcc
679 return { target => "solaris64-sparcv9" };
680 } elsif ( $GCC_ARCH eq "-m32" ) {
682 NOTICE! If you *know* that your GNU C supports 64-bit/V9 ABI and you wish
683 to build 64-bit library, do this:
684 $WHERE/Configure solaris64-sparcv9-gcc
689 return { target => "solaris64-sparcv9" }
690 if $ISA64 ne "" && $KERNEL_BITS eq '64';
691 return { target => "solaris-sparcv9" };
694 [ 'sun4m-.*-solaris2', { target => "solaris-sparcv8" } ],
695 [ 'sun4d-.*-solaris2', { target => "solaris-sparcv8" } ],
696 [ 'sun4.*-.*-solaris2', { target => "solaris-sparcv7" } ],
697 [ '.*86.*-.*-solaris2',
699 my $KERNEL_BITS = $ENV{KERNEL_BITS};
700 my $ISA64 = `isainfo 2>/dev/null | grep amd64`;
701 my $KB = $KERNEL_BITS // '64';
702 return { target => "solaris64-x86_64" }
703 if $ISA64 ne "" && $KB eq '64';
704 my $REL = uname('-r');
706 my @tmp_disable = ();
707 push @tmp_disable, 'sse2' if int($REL) < 10;
708 return { target => "solaris-x86",
709 disable => [ @tmp_disable ] };
712 # We don't have any sunos target in Configurations/*.conf, so why here?
713 [ '.*-.*-sunos4', { target => "sunos" } ],
714 [ '.*86.*-.*-bsdi4', { target => "BSD-x86-elf",
715 lflags => [ '-ldl' ],
716 disable => [ 'sse2' ] } ],
717 [ 'alpha.*-.*-.*bsd.*', { target => "BSD-generic64",
718 defines => [ 'L_ENDIAN' ] } ],
719 [ 'powerpc64-.*-.*bsd.*', { target => "BSD-generic64",
720 defines => [ 'B_ENDIAN' ] } ],
721 [ 'sparc64-.*-.*bsd.*', { target => "BSD-sparc64" } ],
722 [ 'ia64-.*-.*bsd.*', { target => "BSD-ia64" } ],
723 [ 'x86_64-.*-dragonfly.*', { target => "BSD-x86_64" } ],
724 [ 'amd64-.*-.*bsd.*', { target => "BSD-x86_64" } ],
725 [ '.*86.*-.*-.*bsd.*',
727 # mimic ld behaviour when it's looking for libc...
729 if ( -l "/usr/lib/libc.so" ) {
730 $libc = "/usr/lib/libc.so";
732 # ld searches for highest libc.so.* and so do we
734 `(ls /usr/lib/libc.so.* /lib/libc.so.* | tail -1) 2>/dev/null`;
736 my $what = `file -L $libc 2>/dev/null`;
737 return { target => "BSD-x86-elf" } if $what =~ /ELF/;
738 return { target => "BSD-x86",
739 disable => [ 'sse2' ] };
742 [ '.*-.*-.*bsd.*', { target => "BSD-generic32" } ],
743 [ 'x86_64-.*-haiku', { target => "haiku-x86_64" } ],
744 [ '.*-.*-haiku', { target => "haiku-x86" } ],
745 [ '.*-.*-osf', { target => "osf1-alpha" } ],
746 [ '.*-.*-tru64', { target => "tru64-alpha" } ],
747 [ '.*-.*-[Uu]nix[Ww]are7',
749 return { target => "unixware-7",
750 disable => [ 'sse2' ] } if $CCVENDOR eq "gnu";
751 return { target => "unixware-7",
752 defines => [ '__i386__' ] };
755 [ '.*-.*-[Uu]nix[Ww]are20.*', { target => "unixware-2.0",
756 disable => [ 'sse2', 'sha512' ] } ],
757 [ '.*-.*-[Uu]nix[Ww]are21.*', { target => "unixware-2.1",
758 disable => [ 'sse2', 'sha512' ] } ],
759 [ '.*-.*-vos', { target => "vos",
760 disable => [ 'threads', 'shared', 'asm',
762 [ 'BS2000-siemens-sysv4', { target => "BS2000-OSD" } ],
763 [ 'i[3456]86-.*-cygwin', { target => "Cygwin-x86" } ],
765 sub { return { target => "Cygwin-${MACHINE}" } } ],
766 [ 'x86-.*-android|i.86-.*-android', { target => "android-x86" } ],
767 [ 'armv[7-9].*-.*-android', { target => "android-armeabi",
768 cflags => [ '-march=armv7-a' ],
769 cxxflags => [ '-march=armv7-a' ] } ],
770 [ 'arm.*-.*-android', { target => "android-armeabi" } ],
773 my $KERNEL_BITS = $ENV{KERNEL_BITS};
774 my %common_return = ( defines => [ '_REENTRANT' ] );
775 $KERNEL_BITS ||= `getconf KERNEL_BITS 2>/dev/null` // '32';
776 # See <sys/unistd.h> for further info on CPU_VERSION.
777 my $CPU_VERSION = `getconf CPU_VERSION 2>/dev/null` // 0;
778 if ( $CPU_VERSION >= 768 ) {
780 return { target => "hpux64-ia64",
782 if $KERNEL_BITS eq '64' && ! $CCVENDOR;
783 return { target => "hpux-ia64",
786 if ( $CPU_VERSION >= 532 ) {
788 # PA-RISC 2.0 is no longer supported as separate 32-bit
789 # target. This is compensated for by run-time detection
790 # in most critical assembly modules and taking advantage
791 # of 2.0 architecture in PA-RISC 1.1 build.
792 my $target = ($CCVENDOR eq "gnu" && $GCC_BITS eq '64')
795 if ( $KERNEL_BITS eq '64' && ! $CCVENDOR ) {
797 WARNING! To build 64-bit package, do this:
798 $WHERE/Configure hpux64-parisc2-cc
802 return { target => $target,
806 return { target => "hpux-parisc1_1",
807 %common_return } if $CPU_VERSION >= 528;
809 return { target => "hpux-parisc",
810 %common_return } if $CPU_VERSION >= 523;
812 return { target => "hpux",
816 [ '.*-hpux', { target => "hpux-parisc" } ],
820 my $KERNEL_BITS = $ENV{KERNEL_BITS};
821 $KERNEL_BITS ||= `getconf KERNEL_BITMODE 2>/dev/null`;
822 $KERNEL_BITS ||= '32';
823 my $OBJECT_MODE = $ENV{OBJECT_MODE};
825 $config{target} = "aix";
826 if ( $OBJECT_MODE == 64 ) {
827 print 'Your $OBJECT_MODE was found to be set to 64';
828 $config{target} = "aix64";
830 if ( $CCVENDOR ne 'gnu' && $KERNEL_BITS eq '64' ) {
832 WARNING! To build 64-bit package, do this:
833 $WHERE/Configure aix64-cc
839 "lsattr -E -O -l `lsdev -c processor|awk '{print \$1;exit}'`",
840 'grep -i powerpc) >/dev/null 2>&1') ) {
841 # this applies even to Power3 and later, as they return
844 $config{disable} = [ 'asm' ];
850 # Windows values found by looking at Perl 5's win32/win32.c
851 [ 'amd64-.*?-Windows NT', { target => 'VC-WIN64A' } ],
852 [ 'ia64-.*?-Windows NT', { target => 'VC-WIN64I' } ],
853 [ 'x86-.*?-Windows NT', { target => 'VC-WIN32' } ],
855 # VMS values found by observation on existing machinery.
856 # Unfortunately, the machine part is a bit... overdone. It seems,
857 # though, that 'Alpha' exists in that part for Alphas, making it
858 # distinguishable from Itanium. It will be interesting to see what
859 # we'll get in the upcoming x86_64 port...
860 [ '.*Alpha.*?-.*?-OpenVMS', { target => 'vms-alpha' } ],
861 [ '.*?-.*?-OpenVMS', { target => 'vms-ia64' } ],
865 # Map GUESSOS into OpenSSL terminology.
866 # Returns a hash table with diverse entries, most importantly 'target',
867 # but also other entries that are fitting for Configure's %config
869 # It would be nice to fix this so that this weren't necessary. :( XXX
873 foreach my $tuple ( @$map_patterns ) {
874 my $pat = @$tuple[0];
875 next if $GUESSOS !~ /^${pat}$/;
876 my $result = @$tuple[1];
877 $result = $result->() if ref $result eq 'CODE';
881 # Last case, return "z" from x-y-z
882 my @fields = split(/-/, $GUESSOS);
883 return ( target => $fields[2] );
886 # gcc < 2.8 does not support -march=ultrasparc
887 sub check_solaris_sparc8 {
889 if ( $CCVENDOR eq 'gnu' && $CCVER < 208 ) {
890 if ( $OUT eq 'solaris-sparcv9-gcc' ) {
892 WARNING! Downgrading to solaris-sparcv8-gcc
893 Upgrade to gcc-2.8 or later.
896 return 'solaris-sparcv8-gcc';
898 if ( $OUT eq "linux-sparcv9" ) {
900 WARNING! Downgrading to linux-sparcv8
901 Upgrade to gcc-2.8 or later.
904 return 'linux-sparcv8';
917 $VERBOSE = 1 if defined $options{verbose};
918 $WAIT = 0 if defined $options{nowait};
920 $CROSS_COMPILE = $options{CROSS_COMPILE} // '';
922 my $GUESSOS = guess_system();
923 determine_compiler_settings();
925 my %ret = map_guess($GUESSOS);
926 $ret{target} = check_solaris_sparc8($ret{target});