2010-12-16 19:08:02 +00:00
|
|
|
#!/bin/sh
|
|
|
|
|
2015-11-16 18:33:54 +00:00
|
|
|
# Automatic build script for libssl and libcrypto
|
2020-11-07 00:03:46 +00:00
|
|
|
# for Apple devices.
|
2010-12-16 19:08:02 +00:00
|
|
|
#
|
|
|
|
# Created by Felix Schulze on 16.12.10.
|
2017-01-27 21:21:12 +00:00
|
|
|
# Copyright 2010-2017 Felix Schulze. All rights reserved.
|
2010-12-16 19:08:02 +00:00
|
|
|
#
|
|
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
# you may not use this file except in compliance with the License.
|
|
|
|
# You may obtain a copy of the License at
|
|
|
|
#
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
#
|
|
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
# See the License for the specific language governing permissions and
|
|
|
|
# limitations under the License.
|
|
|
|
#
|
2016-09-18 14:14:11 +00:00
|
|
|
|
|
|
|
# -u Attempt to use undefined variable outputs error message, and forces an exit
|
|
|
|
set -u
|
|
|
|
|
2016-11-06 11:19:26 +00:00
|
|
|
# SCRIPT DEFAULTS
|
2016-09-18 14:14:11 +00:00
|
|
|
|
2016-11-06 11:19:26 +00:00
|
|
|
# Default version in case no version is specified
|
2020-11-07 11:55:53 +00:00
|
|
|
DEFAULTVERSION="1.1.1h"
|
2016-11-06 11:19:26 +00:00
|
|
|
|
2020-11-06 21:39:47 +00:00
|
|
|
# Default (=full) set of targets (OpenSSL >= 1.1.1) to build
|
2020-11-07 00:03:46 +00:00
|
|
|
DEFAULTTARGETS="ios-sim-cross-x86_64 ios64-cross-arm64 ios64-cross-arm64e tvos-sim-cross-x86_64 tvos64-cross-arm64 macos64-x86_64 watchos-cross-armv7k watchos-cross-arm64_32 watchos-sim-cross-i386 watchos-sim-cross-x86_64 mac-catalyst-x86_64"
|
2016-11-06 11:19:26 +00:00
|
|
|
|
|
|
|
# Minimum iOS/tvOS SDK version to build for
|
2020-03-01 21:42:28 +00:00
|
|
|
IOS_MIN_SDK_VERSION="12.0"
|
|
|
|
TVOS_MIN_SDK_VERSION="12.0"
|
|
|
|
MACOS_MIN_SDK_VERSION="10.15"
|
2020-11-07 00:03:46 +00:00
|
|
|
CATALYST_MIN_SDK_VERSION="10.15"
|
2019-09-26 07:39:59 +00:00
|
|
|
WATCHOS_MIN_SDK_VERSION="4.0"
|
2016-11-06 11:19:26 +00:00
|
|
|
|
|
|
|
# Init optional env variables (use available variable or default to empty string)
|
2016-09-18 14:14:11 +00:00
|
|
|
CURL_OPTIONS="${CURL_OPTIONS:-}"
|
|
|
|
CONFIG_OPTIONS="${CONFIG_OPTIONS:-}"
|
|
|
|
|
|
|
|
echo_help()
|
|
|
|
{
|
|
|
|
echo "Usage: $0 [options...]"
|
2016-11-06 11:19:26 +00:00
|
|
|
echo "Generic options"
|
2016-09-18 21:19:23 +00:00
|
|
|
echo " --branch=BRANCH Select OpenSSL branch to build. The script will determine and download the latest release for that branch"
|
2016-09-18 15:34:44 +00:00
|
|
|
echo " --cleanup Clean up build directories (bin, include/openssl, lib, src) before starting build"
|
2016-11-06 11:19:26 +00:00
|
|
|
echo " --ec-nistp-64-gcc-128 Enable configure option enable-ec_nistp_64_gcc_128 for 64 bit builds"
|
2016-09-18 14:14:11 +00:00
|
|
|
echo " -h, --help Print help (this message)"
|
2017-10-13 17:08:40 +00:00
|
|
|
echo " --macos-sdk=SDKVERSION Override macOS SDK version"
|
2020-11-07 00:03:46 +00:00
|
|
|
echo " --catalyst-sdk=SDKVERSION Override macOS SDK version for Catalyst"
|
2016-09-18 14:14:11 +00:00
|
|
|
echo " --ios-sdk=SDKVERSION Override iOS SDK version"
|
|
|
|
echo " --tvos-sdk=SDKVERSION Override tvOS SDK version"
|
2020-05-09 12:52:42 +00:00
|
|
|
echo " --watchos-sdk=SDKVERSION Override watchOS SDK version"
|
|
|
|
echo " --min-macos-sdk=SDKVERSION Set minimum macOS SDK version (default: $MACOS_MIN_SDK_VERSION)"
|
|
|
|
echo " --min-ios-sdk=SDKVERSION Set minimum iOS SDK version (default: $IOS_MIN_SDK_VERSION)"
|
|
|
|
echo " --min-tvos-sdk=SDKVERSION Set minimum tvOS SDK version (default: $TVOS_MIN_SDK_VERSION)"
|
|
|
|
echo " --min-watchos-sdk=SDKVERSION Set minimum watchOS SDK version (default: $WATCHOS_MIN_SDK_VERSION)"
|
|
|
|
echo " --noparallel Disable running make with parallel jobs (make -j)"
|
2019-09-26 07:39:59 +00:00
|
|
|
echo " --disable-bitcode Disable embedding Bitcode"
|
2016-09-18 14:14:11 +00:00
|
|
|
echo " -v, --verbose Enable verbose logging"
|
|
|
|
echo " --verbose-on-error Dump last 500 lines from log file if an error occurs (for Travis builds)"
|
2016-09-18 15:34:44 +00:00
|
|
|
echo " --version=VERSION OpenSSL version to build (defaults to ${DEFAULTVERSION})"
|
2016-11-06 11:19:26 +00:00
|
|
|
echo " --deprecated Exclude no-deprecated configure option and build with deprecated methods"
|
|
|
|
echo " --targets=\"TARGET TARGET ...\" Space-separated list of build targets"
|
|
|
|
echo " Options: ${DEFAULTTARGETS}"
|
2016-09-18 14:14:11 +00:00
|
|
|
echo
|
|
|
|
echo "For custom configure options, set variable CONFIG_OPTIONS"
|
|
|
|
echo "For custom cURL options, set variable CURL_OPTIONS"
|
|
|
|
echo " Example: CURL_OPTIONS=\"--proxy 192.168.1.1:8080\" ./build-libssl.sh"
|
|
|
|
}
|
|
|
|
|
2015-12-07 17:51:50 +00:00
|
|
|
spinner()
|
|
|
|
{
|
2016-01-06 03:08:17 +00:00
|
|
|
local pid=$!
|
|
|
|
local delay=0.75
|
|
|
|
local spinstr='|/-\'
|
|
|
|
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
|
|
|
|
local temp=${spinstr#?}
|
2016-11-06 11:19:26 +00:00
|
|
|
printf " [%c]" "$spinstr"
|
2016-01-06 03:08:17 +00:00
|
|
|
local spinstr=$temp${spinstr%"$temp"}
|
|
|
|
sleep $delay
|
2016-11-06 11:19:26 +00:00
|
|
|
printf "\b\b\b\b\b"
|
2016-01-06 03:08:17 +00:00
|
|
|
done
|
2016-09-17 22:34:08 +00:00
|
|
|
|
|
|
|
wait $pid
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2016-10-22 11:54:08 +00:00
|
|
|
# Prepare target and source dir in build loop
|
|
|
|
prepare_target_source_dirs()
|
|
|
|
{
|
|
|
|
# Prepare target dir
|
|
|
|
TARGETDIR="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk"
|
|
|
|
mkdir -p "${TARGETDIR}"
|
|
|
|
LOG="${TARGETDIR}/build-openssl-${VERSION}.log"
|
|
|
|
|
|
|
|
echo "Building openssl-${VERSION} for ${PLATFORM} ${SDKVERSION} ${ARCH}..."
|
|
|
|
echo " Logfile: ${LOG}"
|
|
|
|
|
|
|
|
# Prepare source dir
|
|
|
|
SOURCEDIR="${CURRENTPATH}/src/${PLATFORM}-${ARCH}"
|
|
|
|
mkdir -p "${SOURCEDIR}"
|
|
|
|
tar zxf "${CURRENTPATH}/${OPENSSL_ARCHIVE_FILE_NAME}" -C "${SOURCEDIR}"
|
2017-01-28 14:59:16 +00:00
|
|
|
cd "${SOURCEDIR}/${OPENSSL_ARCHIVE_BASE_NAME}"
|
2016-10-22 11:54:08 +00:00
|
|
|
chmod u+x ./Configure
|
|
|
|
}
|
|
|
|
|
2016-09-17 22:34:08 +00:00
|
|
|
# Check for error status
|
|
|
|
check_status()
|
|
|
|
{
|
|
|
|
local STATUS=$1
|
|
|
|
local COMMAND=$2
|
|
|
|
|
|
|
|
if [ "${STATUS}" != 0 ]; then
|
|
|
|
if [[ "${LOG_VERBOSE}" != "verbose"* ]]; then
|
|
|
|
echo "Problem during ${COMMAND} - Please check ${LOG}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Dump last 500 lines from log file for verbose-on-error
|
|
|
|
if [ "${LOG_VERBOSE}" == "verbose-on-error" ]; then
|
|
|
|
echo "Problem during ${COMMAND} - Dumping last 500 lines from log file"
|
|
|
|
echo
|
|
|
|
tail -n 500 "${LOG}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
exit 1
|
|
|
|
fi
|
2015-12-07 17:51:50 +00:00
|
|
|
}
|
2010-12-16 19:08:02 +00:00
|
|
|
|
2016-10-22 11:54:08 +00:00
|
|
|
# Run Configure in build loop
|
|
|
|
run_configure()
|
|
|
|
{
|
|
|
|
echo " Configure..."
|
|
|
|
set +e
|
|
|
|
if [ "${LOG_VERBOSE}" == "verbose" ]; then
|
2019-11-27 14:54:05 +00:00
|
|
|
./Configure ${LOCAL_CONFIG_OPTIONS} no-tests | tee "${LOG}"
|
2016-10-22 11:54:08 +00:00
|
|
|
else
|
2019-11-27 14:54:05 +00:00
|
|
|
(./Configure ${LOCAL_CONFIG_OPTIONS} no-tests > "${LOG}" 2>&1) & spinner
|
2016-10-22 11:54:08 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Check for error status
|
|
|
|
check_status $? "Configure"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Run make in build loop
|
|
|
|
run_make()
|
|
|
|
{
|
|
|
|
echo " Make (using ${BUILD_THREADS} thread(s))..."
|
|
|
|
if [ "${LOG_VERBOSE}" == "verbose" ]; then
|
|
|
|
make -j "${BUILD_THREADS}" | tee -a "${LOG}"
|
|
|
|
else
|
|
|
|
(make -j "${BUILD_THREADS}" >> "${LOG}" 2>&1) & spinner
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Check for error status
|
|
|
|
check_status $? "make"
|
|
|
|
}
|
|
|
|
|
|
|
|
# Cleanup and bookkeeping at end of build loop
|
|
|
|
finish_build_loop()
|
|
|
|
{
|
|
|
|
# Return to ${CURRENTPATH} and remove source dir
|
|
|
|
cd "${CURRENTPATH}"
|
|
|
|
rm -r "${SOURCEDIR}"
|
|
|
|
|
|
|
|
# Add references to library files to relevant arrays
|
|
|
|
if [[ "${PLATFORM}" == AppleTV* ]]; then
|
|
|
|
LIBSSL_TVOS+=("${TARGETDIR}/lib/libssl.a")
|
|
|
|
LIBCRYPTO_TVOS+=("${TARGETDIR}/lib/libcrypto.a")
|
2017-02-17 16:47:43 +00:00
|
|
|
OPENSSLCONF_SUFFIX="tvos_${ARCH}"
|
2019-09-26 07:39:59 +00:00
|
|
|
elif [[ "${PLATFORM}" == Watch* ]]; then
|
|
|
|
LIBSSL_WATCHOS+=("${TARGETDIR}/lib/libssl.a")
|
|
|
|
LIBCRYPTO_WATCHOS+=("${TARGETDIR}/lib/libcrypto.a")
|
|
|
|
OPENSSLCONF_SUFFIX="watchos_${ARCH}"
|
2017-10-13 17:08:40 +00:00
|
|
|
elif [[ "${PLATFORM}" == iPhone* ]]; then
|
2016-10-22 11:54:08 +00:00
|
|
|
LIBSSL_IOS+=("${TARGETDIR}/lib/libssl.a")
|
|
|
|
LIBCRYPTO_IOS+=("${TARGETDIR}/lib/libcrypto.a")
|
2017-02-17 16:47:43 +00:00
|
|
|
OPENSSLCONF_SUFFIX="ios_${ARCH}"
|
2020-11-07 00:03:46 +00:00
|
|
|
elif [[ "${PLATFORM}" == Catalyst* ]]; then
|
|
|
|
LIBSSL_CATALYST+=("${TARGETDIR}/lib/libssl.a")
|
|
|
|
LIBCRYPTO_CATALYST+=("${TARGETDIR}/lib/libcrypto.a")
|
|
|
|
OPENSSLCONF_SUFFIX="catalyst_${ARCH}"
|
2017-10-13 17:08:40 +00:00
|
|
|
else
|
|
|
|
LIBSSL_MACOS+=("${TARGETDIR}/lib/libssl.a")
|
|
|
|
LIBCRYPTO_MACOS+=("${TARGETDIR}/lib/libcrypto.a")
|
|
|
|
OPENSSLCONF_SUFFIX="macos_${ARCH}"
|
2016-10-22 11:54:08 +00:00
|
|
|
fi
|
|
|
|
|
2017-02-17 16:47:43 +00:00
|
|
|
# Copy opensslconf.h to bin directory and add to array
|
|
|
|
OPENSSLCONF="opensslconf_${OPENSSLCONF_SUFFIX}.h"
|
|
|
|
cp "${TARGETDIR}/include/openssl/opensslconf.h" "${CURRENTPATH}/bin/${OPENSSLCONF}"
|
|
|
|
OPENSSLCONF_ALL+=("${OPENSSLCONF}")
|
|
|
|
|
2016-10-22 11:54:08 +00:00
|
|
|
# Keep reference to first build target for include file
|
|
|
|
if [ -z "${INCLUDE_DIR}" ]; then
|
|
|
|
INCLUDE_DIR="${TARGETDIR}/include/openssl"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2016-09-18 14:14:11 +00:00
|
|
|
# Init optional command line vars
|
|
|
|
ARCHS=""
|
2016-09-18 21:19:23 +00:00
|
|
|
BRANCH=""
|
2016-09-18 15:34:44 +00:00
|
|
|
CLEANUP=""
|
2016-09-18 14:14:11 +00:00
|
|
|
CONFIG_ENABLE_EC_NISTP_64_GCC_128=""
|
2017-03-07 13:14:39 +00:00
|
|
|
CONFIG_DISABLE_BITCODE=""
|
2016-11-06 11:19:26 +00:00
|
|
|
CONFIG_NO_DEPRECATED=""
|
2017-10-13 17:08:40 +00:00
|
|
|
MACOS_SDKVERSION=""
|
2020-11-07 00:03:46 +00:00
|
|
|
CATALYST_SDKVERSION=""
|
2016-09-18 14:14:11 +00:00
|
|
|
IOS_SDKVERSION=""
|
2019-09-26 07:39:59 +00:00
|
|
|
WATCHOS_SDKVERSION=""
|
2016-09-18 14:14:11 +00:00
|
|
|
LOG_VERBOSE=""
|
2016-11-06 11:19:26 +00:00
|
|
|
PARALLEL=""
|
|
|
|
TARGETS=""
|
2016-09-18 14:14:11 +00:00
|
|
|
TVOS_SDKVERSION=""
|
|
|
|
VERSION=""
|
|
|
|
|
|
|
|
# Process command line arguments
|
|
|
|
for i in "$@"
|
|
|
|
do
|
|
|
|
case $i in
|
2016-09-18 21:19:23 +00:00
|
|
|
--branch=*)
|
|
|
|
BRANCH="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2016-09-18 15:34:44 +00:00
|
|
|
--cleanup)
|
|
|
|
CLEANUP="true"
|
|
|
|
;;
|
2016-11-06 11:19:26 +00:00
|
|
|
--deprecated)
|
|
|
|
CONFIG_NO_DEPRECATED="false"
|
|
|
|
;;
|
2016-09-18 14:14:11 +00:00
|
|
|
--ec-nistp-64-gcc-128)
|
|
|
|
CONFIG_ENABLE_EC_NISTP_64_GCC_128="true"
|
|
|
|
;;
|
2019-09-26 07:39:59 +00:00
|
|
|
--disable-bitcode)
|
|
|
|
CONFIG_DISABLE_BITCODE="true"
|
|
|
|
;;
|
2016-09-18 14:14:11 +00:00
|
|
|
-h|--help)
|
|
|
|
echo_help
|
|
|
|
exit
|
|
|
|
;;
|
2017-10-13 17:08:40 +00:00
|
|
|
--macos-sdk=*)
|
|
|
|
MACOS_SDKVERSION="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2020-11-07 00:03:46 +00:00
|
|
|
--catalyst-sdk=*)
|
|
|
|
CATALYST_SDKVERSION="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2016-09-18 14:14:11 +00:00
|
|
|
--ios-sdk=*)
|
|
|
|
IOS_SDKVERSION="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--noparallel)
|
|
|
|
PARALLEL="false"
|
2016-11-06 11:19:26 +00:00
|
|
|
;;
|
|
|
|
--targets=*)
|
|
|
|
TARGETS="${i#*=}"
|
2016-09-18 14:14:11 +00:00
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--tvos-sdk=*)
|
|
|
|
TVOS_SDKVERSION="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2019-09-26 07:39:59 +00:00
|
|
|
--watchos-sdk=*)
|
|
|
|
WATCHOS_SDKVERSION="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2020-05-09 12:52:42 +00:00
|
|
|
--min-macos-sdk=*)
|
|
|
|
MACOS_MIN_SDK_VERSION="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--min-ios-sdk=*)
|
|
|
|
IOS_MIN_SDK_VERSION="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--min-tvos-sdk=*)
|
|
|
|
TVOS_MIN_SDK_VERSION="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
--min-watchos-sdk=*)
|
|
|
|
WATCHOS_MIN_SDK_VERSION="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
2016-09-18 14:14:11 +00:00
|
|
|
-v|--verbose)
|
|
|
|
LOG_VERBOSE="verbose"
|
|
|
|
;;
|
|
|
|
--verbose-on-error)
|
|
|
|
LOG_VERBOSE="verbose-on-error"
|
|
|
|
;;
|
|
|
|
--version=*)
|
|
|
|
VERSION="${i#*=}"
|
|
|
|
shift
|
|
|
|
;;
|
|
|
|
*)
|
|
|
|
echo "Unknown argument: ${i}"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
2016-09-18 21:19:23 +00:00
|
|
|
# Don't mix version and branch
|
|
|
|
if [[ -n "${VERSION}" && -n "${BRANCH}" ]]; then
|
|
|
|
echo "Either select a branch (the script will determine and build the latest version) or select a specific version, but not both."
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
# Specific version: Verify version number format. Expected: dot notation
|
|
|
|
elif [[ -n "${VERSION}" && ! "${VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+[a-z]*$ ]]; then
|
|
|
|
echo "Unknown version number format. Examples: 1.0.2, 1.0.2h"
|
|
|
|
exit 1
|
|
|
|
|
|
|
|
# Specific branch
|
|
|
|
elif [ -n "${BRANCH}" ]; then
|
2016-09-18 14:14:11 +00:00
|
|
|
# Verify version number format. Expected: dot notation
|
2016-09-18 21:19:23 +00:00
|
|
|
if [[ ! "${BRANCH}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
|
2019-11-01 15:26:46 +00:00
|
|
|
echo "Unknown branch version number format. Examples: 1.0.2, 1.1.1"
|
2016-09-18 14:14:11 +00:00
|
|
|
exit 1
|
2016-09-19 17:59:20 +00:00
|
|
|
|
2016-09-18 21:19:23 +00:00
|
|
|
# Valid version number, determine latest version
|
|
|
|
else
|
2017-02-01 18:23:30 +00:00
|
|
|
echo "Checking latest version of ${BRANCH} branch on openssl.org..."
|
|
|
|
# Get directory content listing of /source/ (only contains latest version per branch), limit list to archives (so one archive per branch),
|
2017-01-28 14:59:16 +00:00
|
|
|
# filter for the requested branch, sort the list and get the last item (last two steps to ensure there is always 1 result)
|
2017-02-01 18:23:30 +00:00
|
|
|
VERSION=$(curl ${CURL_OPTIONS} -s https://ftp.openssl.org/source/ | grep -Eo '>openssl-[0-9]\.[0-9]\.[0-9][a-z]*\.tar\.gz<' | grep -Eo "${BRANCH//./\.}[a-z]*" | sort | tail -1)
|
2016-09-18 21:19:23 +00:00
|
|
|
|
|
|
|
# Verify result
|
2017-01-28 14:59:16 +00:00
|
|
|
if [ -z "${VERSION}" ]; then
|
2017-02-01 18:23:30 +00:00
|
|
|
echo "Could not determine latest version, please check https://www.openssl.org/source/ and use --version option"
|
2016-09-18 21:19:23 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2016-09-18 14:14:11 +00:00
|
|
|
fi
|
|
|
|
|
2016-09-18 21:19:23 +00:00
|
|
|
# Script default
|
2016-09-19 17:59:20 +00:00
|
|
|
elif [ -z "${VERSION}" ]; then
|
2016-09-18 15:34:44 +00:00
|
|
|
VERSION="${DEFAULTVERSION}"
|
2016-09-18 14:14:11 +00:00
|
|
|
fi
|
|
|
|
|
2020-11-06 21:39:47 +00:00
|
|
|
BUILD_TYPE="targets"
|
2016-11-06 11:19:26 +00:00
|
|
|
|
2020-11-06 21:39:47 +00:00
|
|
|
# Set default for TARGETS if not specified
|
|
|
|
if [ ! -n "${TARGETS}" ]; then
|
|
|
|
TARGETS="${DEFAULTTARGETS}"
|
|
|
|
fi
|
2016-11-06 11:19:26 +00:00
|
|
|
|
2020-11-06 21:39:47 +00:00
|
|
|
# Add no-deprecated config option (if not overwritten)
|
|
|
|
if [ "${CONFIG_NO_DEPRECATED}" != "false" ]; then
|
|
|
|
CONFIG_OPTIONS="${CONFIG_OPTIONS} no-deprecated"
|
2016-11-06 11:19:26 +00:00
|
|
|
fi
|
|
|
|
|
2016-09-18 14:14:11 +00:00
|
|
|
# Determine SDK versions
|
2017-10-13 17:08:40 +00:00
|
|
|
if [ ! -n "${MACOS_SDKVERSION}" ]; then
|
|
|
|
MACOS_SDKVERSION=$(xcrun -sdk macosx --show-sdk-version)
|
|
|
|
fi
|
2020-11-07 00:03:46 +00:00
|
|
|
if [ ! -n "${CATALYST_SDKVERSION}" ]; then
|
|
|
|
CATALYST_SDKVERSION=$(xcrun -sdk macosx --show-sdk-version)
|
|
|
|
fi
|
2016-09-18 14:14:11 +00:00
|
|
|
if [ ! -n "${IOS_SDKVERSION}" ]; then
|
|
|
|
IOS_SDKVERSION=$(xcrun -sdk iphoneos --show-sdk-version)
|
|
|
|
fi
|
|
|
|
if [ ! -n "${TVOS_SDKVERSION}" ]; then
|
|
|
|
TVOS_SDKVERSION=$(xcrun -sdk appletvos --show-sdk-version)
|
|
|
|
fi
|
2019-09-26 07:39:59 +00:00
|
|
|
if [ ! -n "${WATCHOS_SDKVERSION}" ]; then
|
|
|
|
WATCHOS_SDKVERSION=$(xcrun -sdk watchos --show-sdk-version)
|
|
|
|
fi
|
2016-09-18 14:14:11 +00:00
|
|
|
|
2020-04-18 12:58:40 +00:00
|
|
|
# Truncate to minor version
|
|
|
|
MINOR_VERSION=(${MACOS_SDKVERSION//./ })
|
|
|
|
MACOS_SDKVERSION="${MINOR_VERSION[0]}.${MINOR_VERSION[1]}"
|
2020-11-07 00:03:46 +00:00
|
|
|
MINOR_VERSION=(${CATALYST_SDKVERSION//./ })
|
|
|
|
CATALYST_SDKVERSION="${MINOR_VERSION[0]}.${MINOR_VERSION[1]}"
|
2020-04-18 12:58:40 +00:00
|
|
|
|
2016-09-18 10:15:15 +00:00
|
|
|
# Determine number of cores for (parallel) build
|
|
|
|
BUILD_THREADS=1
|
|
|
|
if [ "${PARALLEL}" != "false" ]; then
|
|
|
|
BUILD_THREADS=$(sysctl hw.ncpu | awk '{print $2}')
|
|
|
|
fi
|
|
|
|
|
2016-11-06 11:19:26 +00:00
|
|
|
# Determine script directory
|
|
|
|
SCRIPTDIR=$(cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd)
|
|
|
|
|
|
|
|
# Write files relative to current location and validate directory
|
2016-09-18 15:34:44 +00:00
|
|
|
CURRENTPATH=$(pwd)
|
2016-09-18 14:14:11 +00:00
|
|
|
case "${CURRENTPATH}" in
|
|
|
|
*\ * )
|
|
|
|
echo "Your path contains whitespaces, which is not supported by 'make install'."
|
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
cd "${CURRENTPATH}"
|
|
|
|
|
|
|
|
# Validate Xcode Developer path
|
|
|
|
DEVELOPER=$(xcode-select -print-path)
|
|
|
|
if [ ! -d "${DEVELOPER}" ]; then
|
|
|
|
echo "Xcode path is not set correctly ${DEVELOPER} does not exist"
|
2012-07-11 18:34:48 +00:00
|
|
|
echo "run"
|
2016-09-18 14:14:11 +00:00
|
|
|
echo "sudo xcode-select -switch <Xcode path>"
|
2012-07-11 18:34:48 +00:00
|
|
|
echo "for default installation:"
|
|
|
|
echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2016-09-18 14:14:11 +00:00
|
|
|
case "${DEVELOPER}" in
|
2016-01-06 03:08:17 +00:00
|
|
|
*\ * )
|
|
|
|
echo "Your Xcode path contains whitespaces, which is not supported."
|
|
|
|
exit 1
|
|
|
|
;;
|
2014-02-07 06:45:57 +00:00
|
|
|
esac
|
|
|
|
|
2016-09-18 14:14:11 +00:00
|
|
|
# Show build options
|
|
|
|
echo
|
|
|
|
echo "Build options"
|
|
|
|
echo " OpenSSL version: ${VERSION}"
|
2020-11-06 21:39:47 +00:00
|
|
|
echo " Targets: ${TARGETS}"
|
2020-05-09 12:52:42 +00:00
|
|
|
echo " macOS SDK: ${MACOS_SDKVERSION} (min ${MACOS_MIN_SDK_VERSION})"
|
2020-11-07 00:03:46 +00:00
|
|
|
echo " macOS SDK (Catalyst): ${CATALYST_SDKVERSION} (min ${CATALYST_MIN_SDK_VERSION})"
|
2020-05-09 12:52:42 +00:00
|
|
|
echo " iOS SDK: ${IOS_SDKVERSION} (min ${IOS_MIN_SDK_VERSION})"
|
|
|
|
echo " tvOS SDK: ${TVOS_SDKVERSION} (min ${TVOS_MIN_SDK_VERSION})"
|
|
|
|
echo " watchOS SDK: ${WATCHOS_SDKVERSION} (min ${WATCHOS_MIN_SDK_VERSION})"
|
2017-03-13 01:20:27 +00:00
|
|
|
if [ "${CONFIG_DISABLE_BITCODE}" == "true" ]; then
|
|
|
|
echo " Bitcode embedding disabled"
|
|
|
|
fi
|
2016-09-18 14:14:11 +00:00
|
|
|
echo " Number of make threads: ${BUILD_THREADS}"
|
|
|
|
if [ -n "${CONFIG_OPTIONS}" ]; then
|
|
|
|
echo " Configure options: ${CONFIG_OPTIONS}"
|
|
|
|
fi
|
2016-11-06 11:19:26 +00:00
|
|
|
echo " Build location: ${CURRENTPATH}"
|
2016-09-18 14:14:11 +00:00
|
|
|
echo
|
2013-10-12 12:42:23 +00:00
|
|
|
|
2016-09-17 22:34:08 +00:00
|
|
|
# Download OpenSSL when not present
|
2017-01-28 14:59:16 +00:00
|
|
|
OPENSSL_ARCHIVE_BASE_NAME="openssl-${VERSION}"
|
|
|
|
OPENSSL_ARCHIVE_FILE_NAME="${OPENSSL_ARCHIVE_BASE_NAME}.tar.gz"
|
2016-03-08 14:20:28 +00:00
|
|
|
if [ ! -e ${OPENSSL_ARCHIVE_FILE_NAME} ]; then
|
2016-09-18 14:14:11 +00:00
|
|
|
echo "Downloading ${OPENSSL_ARCHIVE_FILE_NAME}..."
|
2017-01-30 21:23:04 +00:00
|
|
|
OPENSSL_ARCHIVE_URL="https://www.openssl.org/source/${OPENSSL_ARCHIVE_FILE_NAME}"
|
2017-01-28 14:59:16 +00:00
|
|
|
|
2017-01-30 21:23:04 +00:00
|
|
|
# Check whether file exists here (this is the location of the latest version for each branch)
|
2017-01-28 14:59:16 +00:00
|
|
|
# -s be silent, -f return non-zero exit status on failure, -I get header (do not download)
|
2017-01-30 21:23:04 +00:00
|
|
|
curl ${CURL_OPTIONS} -sfI "${OPENSSL_ARCHIVE_URL}" > /dev/null
|
2016-11-06 11:19:26 +00:00
|
|
|
|
2017-01-28 14:59:16 +00:00
|
|
|
# If unsuccessful, try the archive
|
|
|
|
if [ $? -ne 0 ]; then
|
|
|
|
BRANCH=$(echo "${VERSION}" | grep -Eo '^[0-9]\.[0-9]\.[0-9]')
|
2017-01-30 21:23:04 +00:00
|
|
|
OPENSSL_ARCHIVE_URL="https://www.openssl.org/source/old/${BRANCH}/${OPENSSL_ARCHIVE_FILE_NAME}"
|
2017-01-28 14:59:16 +00:00
|
|
|
|
2017-01-30 21:23:04 +00:00
|
|
|
curl ${CURL_OPTIONS} -sfI "${OPENSSL_ARCHIVE_URL}" > /dev/null
|
2017-01-28 14:59:16 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Both attempts failed, so report the error
|
2016-09-19 17:59:20 +00:00
|
|
|
if [ $? -ne 0 ]; then
|
2017-01-30 21:23:04 +00:00
|
|
|
echo "An error occurred trying to find OpenSSL ${VERSION} on ${OPENSSL_ARCHIVE_URL}"
|
2017-01-28 14:59:16 +00:00
|
|
|
echo "Please verify that the version you are trying to build exists, check cURL's error message and/or your network connection."
|
2016-09-19 17:59:20 +00:00
|
|
|
exit 1
|
|
|
|
fi
|
2017-01-28 14:59:16 +00:00
|
|
|
|
2017-01-30 21:23:04 +00:00
|
|
|
# Archive was found, so proceed with download.
|
2017-01-28 14:59:16 +00:00
|
|
|
# -O Use server-specified filename for download
|
2017-01-30 21:23:04 +00:00
|
|
|
curl ${CURL_OPTIONS} -O "${OPENSSL_ARCHIVE_URL}"
|
2017-01-28 14:59:16 +00:00
|
|
|
|
2010-12-16 19:08:02 +00:00
|
|
|
else
|
2016-03-08 14:20:28 +00:00
|
|
|
echo "Using ${OPENSSL_ARCHIVE_FILE_NAME}"
|
2010-12-16 19:08:02 +00:00
|
|
|
fi
|
|
|
|
|
2019-11-01 15:26:46 +00:00
|
|
|
# Set reference to custom configuration (OpenSSL 1.1.1)
|
2016-10-22 11:16:18 +00:00
|
|
|
# See: https://github.com/openssl/openssl/commit/afce395cba521e395e6eecdaf9589105f61e4411
|
|
|
|
export OPENSSL_LOCAL_CONFIG_DIR="${SCRIPTDIR}/config"
|
|
|
|
|
2016-09-19 17:59:20 +00:00
|
|
|
# -e Abort script at first error, when a command exits with non-zero status (except in until or while loops, if-tests, list constructs)
|
|
|
|
# -o pipefail Causes a pipeline to return the exit status of the last command in the pipe that returned a non-zero return value
|
|
|
|
set -eo pipefail
|
|
|
|
|
2016-09-18 15:34:44 +00:00
|
|
|
# Clean up target directories if requested and present
|
|
|
|
if [ "${CLEANUP}" == "true" ]; then
|
2016-09-19 17:59:20 +00:00
|
|
|
if [ -d "${CURRENTPATH}/bin" ]; then
|
|
|
|
rm -r "${CURRENTPATH}/bin"
|
|
|
|
fi
|
|
|
|
if [ -d "${CURRENTPATH}/include/openssl" ]; then
|
|
|
|
rm -r "${CURRENTPATH}/include/openssl"
|
|
|
|
fi
|
|
|
|
if [ -d "${CURRENTPATH}/lib" ]; then
|
|
|
|
rm -r "${CURRENTPATH}/lib"
|
|
|
|
fi
|
|
|
|
if [ -d "${CURRENTPATH}/src" ]; then
|
|
|
|
rm -r "${CURRENTPATH}/src"
|
|
|
|
fi
|
2016-09-18 14:14:11 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# (Re-)create target directories
|
2012-01-28 19:20:37 +00:00
|
|
|
mkdir -p "${CURRENTPATH}/bin"
|
|
|
|
mkdir -p "${CURRENTPATH}/lib"
|
2016-09-18 14:14:11 +00:00
|
|
|
mkdir -p "${CURRENTPATH}/src"
|
2012-01-28 19:20:37 +00:00
|
|
|
|
2016-09-17 12:54:55 +00:00
|
|
|
# Init vars for library references
|
|
|
|
INCLUDE_DIR=""
|
2017-02-17 16:47:43 +00:00
|
|
|
OPENSSLCONF_ALL=()
|
2017-10-13 17:08:40 +00:00
|
|
|
LIBSSL_MACOS=()
|
|
|
|
LIBCRYPTO_MACOS=()
|
2020-11-07 00:03:46 +00:00
|
|
|
LIBSSL_CATALYST=()
|
|
|
|
LIBCRYPTO_CATALYST=()
|
2016-09-17 12:54:55 +00:00
|
|
|
LIBSSL_IOS=()
|
|
|
|
LIBCRYPTO_IOS=()
|
|
|
|
LIBSSL_TVOS=()
|
|
|
|
LIBCRYPTO_TVOS=()
|
2019-09-26 07:39:59 +00:00
|
|
|
LIBSSL_WATCHOS=()
|
|
|
|
LIBCRYPTO_WATCHOS=()
|
2016-09-17 12:54:55 +00:00
|
|
|
|
2020-11-06 21:39:47 +00:00
|
|
|
source "${SCRIPTDIR}/scripts/build-loop-targets.sh"
|
2010-12-16 19:08:02 +00:00
|
|
|
|
2019-09-26 07:39:59 +00:00
|
|
|
#Build macOS library if selected for build
|
2017-10-13 17:08:40 +00:00
|
|
|
if [ ${#LIBSSL_MACOS[@]} -gt 0 ]; then
|
|
|
|
echo "Build library for macOS..."
|
|
|
|
lipo -create ${LIBSSL_MACOS[@]} -output "${CURRENTPATH}/lib/libssl-MacOSX.a"
|
|
|
|
lipo -create ${LIBCRYPTO_MACOS[@]} -output "${CURRENTPATH}/lib/libcrypto-MacOSX.a"
|
|
|
|
fi
|
|
|
|
|
2020-11-07 00:03:46 +00:00
|
|
|
#Build Catalyst library if selected for build
|
|
|
|
if [ ${#LIBSSL_CATALYST[@]} -gt 0 ]; then
|
|
|
|
echo "Build library for Catalyst..."
|
|
|
|
lipo -create ${LIBSSL_CATALYST[@]} -output "${CURRENTPATH}/lib/libssl-Catalyst.a"
|
|
|
|
lipo -create ${LIBCRYPTO_CATALYST[@]} -output "${CURRENTPATH}/lib/libcrypto-Catalyst.a"
|
|
|
|
fi
|
|
|
|
|
2016-09-17 12:54:55 +00:00
|
|
|
# Build iOS library if selected for build
|
2017-02-17 16:47:43 +00:00
|
|
|
if [ ${#LIBSSL_IOS[@]} -gt 0 ]; then
|
2016-09-17 12:54:55 +00:00
|
|
|
echo "Build library for iOS..."
|
2017-10-01 12:02:31 +00:00
|
|
|
lipo -create ${LIBSSL_IOS[@]} -output "${CURRENTPATH}/lib/libssl-iPhone.a"
|
|
|
|
lipo -create ${LIBCRYPTO_IOS[@]} -output "${CURRENTPATH}/lib/libcrypto-iPhone.a"
|
2016-09-17 12:54:55 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
# Build tvOS library if selected for build
|
2017-02-17 16:47:43 +00:00
|
|
|
if [ ${#LIBSSL_TVOS[@]} -gt 0 ]; then
|
|
|
|
echo "Build library for tvOS..."
|
2017-10-01 12:02:31 +00:00
|
|
|
lipo -create ${LIBSSL_TVOS[@]} -output "${CURRENTPATH}/lib/libssl-AppleTV.a"
|
|
|
|
lipo -create ${LIBCRYPTO_TVOS[@]} -output "${CURRENTPATH}/lib/libcrypto-AppleTV.a"
|
2016-09-17 12:54:55 +00:00
|
|
|
fi
|
|
|
|
|
2019-09-26 07:39:59 +00:00
|
|
|
# Build tvOS library if selected for build
|
|
|
|
if [ ${#LIBSSL_WATCHOS[@]} -gt 0 ]; then
|
|
|
|
echo "Build library for watchOS..."
|
|
|
|
lipo -create ${LIBSSL_WATCHOS[@]} -output "${CURRENTPATH}/lib/libssl-WatchOS.a"
|
|
|
|
lipo -create ${LIBCRYPTO_WATCHOS[@]} -output "${CURRENTPATH}/lib/libcrypto-WatchOS.a"
|
|
|
|
fi
|
|
|
|
|
2016-09-17 12:54:55 +00:00
|
|
|
# Copy include directory
|
2017-02-17 16:47:43 +00:00
|
|
|
cp -R "${INCLUDE_DIR}" "${CURRENTPATH}/include/"
|
|
|
|
|
|
|
|
# Only create intermediate file when building for multiple targets
|
|
|
|
# For a single target, opensslconf.h is still present in $INCLUDE_DIR (and has just been copied to the target include dir)
|
|
|
|
if [ ${#OPENSSLCONF_ALL[@]} -gt 1 ]; then
|
|
|
|
|
|
|
|
# Prepare intermediate header file
|
|
|
|
# This overwrites opensslconf.h that was copied from $INCLUDE_DIR
|
|
|
|
OPENSSLCONF_INTERMEDIATE="${CURRENTPATH}/include/openssl/opensslconf.h"
|
|
|
|
cp "${CURRENTPATH}/include/opensslconf-template.h" "${OPENSSLCONF_INTERMEDIATE}"
|
|
|
|
|
|
|
|
# Loop all header files
|
|
|
|
LOOPCOUNT=0
|
|
|
|
for OPENSSLCONF_CURRENT in "${OPENSSLCONF_ALL[@]}" ; do
|
|
|
|
|
|
|
|
# Copy specific opensslconf file to include dir
|
|
|
|
cp "${CURRENTPATH}/bin/${OPENSSLCONF_CURRENT}" "${CURRENTPATH}/include/openssl"
|
|
|
|
|
|
|
|
# Determine define condition
|
|
|
|
case "${OPENSSLCONF_CURRENT}" in
|
2017-10-13 17:08:40 +00:00
|
|
|
*_macos_x86_64.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_OSX && TARGET_CPU_X86_64"
|
|
|
|
;;
|
|
|
|
*_macos_i386.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_OSX && TARGET_CPU_X86"
|
|
|
|
;;
|
2020-11-07 00:03:46 +00:00
|
|
|
*_catalyst_x86_64.h)
|
|
|
|
DEFINE_CONDITION="(TARGET_OS_MACCATALYST || (TARGET_OS_IOS && TARGET_OS_SIMULATOR)) && TARGET_CPU_X86_64"
|
|
|
|
;;
|
2017-02-17 16:47:43 +00:00
|
|
|
*_ios_x86_64.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_IOS && TARGET_OS_SIMULATOR && TARGET_CPU_X86_64"
|
|
|
|
;;
|
|
|
|
*_ios_i386.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_IOS && TARGET_OS_SIMULATOR && TARGET_CPU_X86"
|
|
|
|
;;
|
|
|
|
*_ios_arm64.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_IOS && TARGET_OS_EMBEDDED && TARGET_CPU_ARM64"
|
|
|
|
;;
|
2020-03-01 21:42:28 +00:00
|
|
|
*_ios_arm64e.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_IOS && TARGET_OS_EMBEDDED && TARGET_CPU_ARM64E"
|
|
|
|
;;
|
2017-02-17 16:47:43 +00:00
|
|
|
*_ios_armv7s.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_IOS && TARGET_OS_EMBEDDED && TARGET_CPU_ARM && defined(__ARM_ARCH_7S__)"
|
|
|
|
;;
|
|
|
|
*_ios_armv7.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_IOS && TARGET_OS_EMBEDDED && TARGET_CPU_ARM && !defined(__ARM_ARCH_7S__)"
|
|
|
|
;;
|
|
|
|
*_tvos_x86_64.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_TV && TARGET_OS_SIMULATOR && TARGET_CPU_X86_64"
|
|
|
|
;;
|
|
|
|
*_tvos_arm64.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_TV && TARGET_OS_EMBEDDED && TARGET_CPU_ARM64"
|
|
|
|
;;
|
2019-09-26 07:39:59 +00:00
|
|
|
*_watchos_armv7k.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_WATCHOS && TARGET_OS_EMBEDDED && TARGET_CPU_ARMV7K"
|
|
|
|
;;
|
|
|
|
*_watchos_arm64_32.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_WATCHOS && TARGET_OS_EMBEDDED && TARGET_CPU_ARM64_32"
|
|
|
|
;;
|
|
|
|
*_watchos_i386.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_SIMULATOR && TARGET_CPU_X86 || TARGET_OS_EMBEDDED"
|
|
|
|
;;
|
2020-10-14 14:49:39 +00:00
|
|
|
*_watchos_x86_64.h)
|
|
|
|
DEFINE_CONDITION="TARGET_OS_SIMULATOR && TARGET_CPU_X86_64 || TARGET_OS_EMBEDDED"
|
|
|
|
;;
|
2017-02-17 16:47:43 +00:00
|
|
|
*)
|
|
|
|
# Don't run into unexpected cases by setting the default condition to false
|
|
|
|
DEFINE_CONDITION="0"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
# Determine loopcount; start with if and continue with elif
|
|
|
|
LOOPCOUNT=$((LOOPCOUNT + 1))
|
|
|
|
if [ ${LOOPCOUNT} -eq 1 ]; then
|
|
|
|
echo "#if ${DEFINE_CONDITION}" >> "${OPENSSLCONF_INTERMEDIATE}"
|
|
|
|
else
|
|
|
|
echo "#elif ${DEFINE_CONDITION}" >> "${OPENSSLCONF_INTERMEDIATE}"
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Add include
|
|
|
|
echo "# include <openssl/${OPENSSLCONF_CURRENT}>" >> "${OPENSSLCONF_INTERMEDIATE}"
|
|
|
|
done
|
|
|
|
|
2017-03-04 12:06:21 +00:00
|
|
|
# Finish
|
|
|
|
echo "#else" >> "${OPENSSLCONF_INTERMEDIATE}"
|
|
|
|
echo '# error Unable to determine target or target not included in OpenSSL build' >> "${OPENSSLCONF_INTERMEDIATE}"
|
2017-02-17 16:47:43 +00:00
|
|
|
echo "#endif" >> "${OPENSSLCONF_INTERMEDIATE}"
|
|
|
|
fi
|
2016-01-06 08:44:27 +00:00
|
|
|
|
2012-07-11 18:34:48 +00:00
|
|
|
echo "Done."
|