#! /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;
# 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 $CCVER;
my $GCCVER;
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} // 'cc';
my $CROSS_COMPILE = $ENV{CROSS_COMPILE} // "";
my $KERNEL_BITS = $ENV{KERNEL_BITS} // '';
# 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' ],
];
# More complex cases that require run-time code.
my $complex_sys_list = [
[ 'HP-UX:', sub {
my $HPUXVER = $RELEASE;
$HPUXVER = s/[^.]*.[0B]*//;
# HPUX 10 and 11 targets are unified
return "${MACHINE}-hp-hpux1x" if $HPUXVER =~ m@1[0-9]@;
return "${MACHINE}-hp-hpux";
} ],
[ 'BSD/386:.*:.*:.*486.*|BSD/OS:.*:.*:.*:.*486', sub {
my $BSDVAR = `/sbin/sysctl -n hw.model`;
return "i586-whatever-bsdi" if $BSDVAR =~ m@Pentium@;
return "i386-whatever-bsdi";
} ],
[ 'FreeBSD:.*:.*:.*386', sub {
my $VERS = $RELEASE;
$VERS =~ s/[-(].*//;
my $MACH = `sysctl -n hw.model`;
$MACH = "i386" if $MACH =~ m@386@;
$MACH = "i486" if $MACH =~ m@486@;
$MACH = "i686" if $MACH =~ m@Pentium II@;
$MACH =