#! /usr/bin/env perl
# Copyright 1998-2020 The OpenSSL Project Authors. All Rights Reserved.
#
# Licensed under the Apache License 2.0 (the "License"). You may not use
# this file except in compliance with the License. You can obtain a copy
# in the file LICENSE in the source distribution or at
# https://www.openssl.org/source/license.html
# Determine the operating system and run ./Configure. Far descendant from
# Apache's minarch and GuessOS.
package OpenSSL::config;
use strict;
use warnings;
use Getopt::Std;
use File::Basename;
use IPC::Cmd;
use POSIX;
use Carp;
# These control our behavior.
my $DRYRUN;
my $VERBOSE;
my $WAIT = 1;
my $WHERE = dirname($0);
# Machine type, etc., used to determine the platform
my $MACHINE;
my $RELEASE;
my $SYSTEM;
my $VERSION;
my $CCVENDOR;
my $CCVER;
my $GCC_BITS;
my $GCC_ARCH;
# Some environment variables; they will affect Configure
my $PERL = $ENV{PERL} // $^X // 'perl';
my $CONFIG_OPTIONS = $ENV{CONFIG_OPTIONS} // '';
my $CC = $ENV{CC} // '';
my $CROSS_COMPILE = $ENV{CROSS_COMPILE} // "";
my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
# For determine_compiler_settings, the list of known compilers
my @c_compilers = qw(clang gcc cc);
# Methods to determine compiler version. The expected output is one of
# MAJOR or MAJOR.MINOR or MAJOR.MINOR.PATCH... or false if the compiler
# isn't of the given brand.
# This is a list to ensure that gnu comes last, as we've made it a fallback
my @cc_version =
(
clang => sub {
my $v = `$CROSS_COMPILE$CC -v 2>&1`;
$v =~ m/(?:(?:^clang|LLVM) version|.*based on LLVM)\s+([0-9]+\.[0-9]+)/;
return $1;
},
gnu => sub {
my $v = `$CROSS_COMPILE$CC -dumpversion 2>/dev/null`;
# Strip off whatever prefix egcs prepends the number with.
# Hopefully, this will work for any future prefixes as well.
$v =~ s/^[a-zA-Z]*\-//;
return $v;
},
);
# This is what we will set as the target for calling Configure.
my $options = '';
# Environment that will be passed to Configure
my $__CNF_CPPDEFINES = '';
my $__CNF_CPPINCLUDES = '';
my $__CNF_CPPFLAGS = '';
my $__CNF_CFLAGS = '';
my $__CNF_CXXFLAGS = '';
my $__CNF_LDFLAGS = '';
my $__CNF_LDLIBS = '';
# Pattern matches against "${SYSTEM}:${RELEASE}:${VERSION}:${MACHINE}"
my $simple_guess_patterns = [
[ 'A\/UX:', 'm68k-apple-aux3' ],
[ 'AIX:[3-9]:4:', '${MACHINE}-ibm-aix' ],
[ 'AIX:.*:[5-9]:', '${MACHINE}-ibm-aix' ],
[ 'AIX:', '${MACHINE}-ibm-aix3' ],
[ 'HI-UX:', '${MACHINE}-hi-hiux' ],
[ 'IRIX:6.', 'mips3-sgi-irix' ],
[ 'IRIX64:', 'mips4-sgi-irix64' ],
[ 'Linux:[2-9]', '${MACHINE}-whatever-linux2' ],
[ 'Linux:1', '${MACHINE}-whatever-linux1' ],
[ 'GNU', 'hurd-x86' ],
[ 'LynxOS:', '${MACHINE}-lynx-lynxos' ],
# BSD/OS always says 386
[ 'BSD\/OS:4.*', 'i486-whatever-bsdi4' ],
[ 'BSD\/386:.*|BSD\/OS:', '${MACHINE}-whatever-bsdi' ],
[ 'DragonFly:', '${MACHINE}-whatever-dragonfly' ],
[ 'FreeBSD:', '${MACHINE}-whatever-freebsd' ],
[ 'Haiku:', '${MACHINE}-whatever-haiku' ],
[ 'NetBSD:', '${MACHINE}-whatever-netbsd' ],
[ 'OpenBSD:', '${MACHINE}-whatever-openbsd' ],
[ 'OpenUNIX:', '${MACHINE}-unknown-OpenUNIX${VERSION}' ],
[ 'Paragon.*:', 'i860-intel-osf1' ],
[ 'Rhapsody:', 'ppc-apple-rhapsody' ],
[ 'SunOS:5.', '${MACHINE}-whatever-solaris2' ],
[ 'SunOS:', '${MACHINE}-sun-sunos4' ],
[ 'UNIX_System_V:4.*:', '${MACHINE}-whatever-sysv4' ],
[ 'VOS:.*:.*:i786', 'i386-stratus-vos' ],
[ 'VOS:.*:.*:', 'hppa1.1-stratus-vos' ],
[ '.*:4.*:R4.*:m88k', '${MACHINE}-whatever-sysv4' ],
[ 'DYNIX\/ptx:4.*:', '${MACHINE}-whatever-sysv4' ],
[ ':4.0:3.0:3[34]', 'i486-ncr-sysv4' ],
[ 'ULTRIX:', '${MACHINE}-unknown-ultrix' ],
[ 'POSIX-BC', 'BS2000-siemens-sysv4' ],
[ 'machten:', '${MACHINE}-tenon-${SYSTEM}' ],
[ 'library:', '${MACHINE}-ncr-sysv4' ],
[ 'ConvexOS:.*:11.0:', '${MACHINE}-v11-${SYSTEM}' ],
[ 'MINGW64.*:.*x86_64', '${MACHINE}-whatever-mingw64' ],
[ 'MINGW', '${MACHINE}-whatever-mingw' ],
[ 'CYGWIN', '${MACHINE}-pc-cygwin' ],
[ 'vxworks', '${MACHINE}-whatever-vxworks' ],
[ 'Darwin:.*Power', 'ppc-apple-darwin' ],
[ 'Darwin:.*x86_64', 'x86_64-apple-darwin' ],
[ 'Darwin:', 'i686-apple-darwin' ],
# Windows values found by looking at Perl 5's win32/win32.c
[ 'Windows NT:.*:amd64', 'VC-WIN64A' ],
[ 'Windows NT:.*:ia64', 'VC-WIN64I' ],
[ 'Windows NT:.*:x86', 'VC-WIN32' ],
# VMS values found by observation on