2022-05-03 15:33:23 +08:00
|
|
|
#!/bin/bash -xe
|
2013-02-14 21:59:12 +08:00
|
|
|
#
|
2015-06-08 22:17:39 +08:00
|
|
|
# Copyright 2015 Thincast Technologies GmbH
|
2013-02-14 21:59:12 +08:00
|
|
|
#
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
|
|
|
|
# If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
#
|
2015-06-08 22:17:39 +08:00
|
|
|
# This script will download and build openssl for iOS and simulator - see ARCHS for architectures built
|
2013-02-14 21:59:12 +08:00
|
|
|
|
2015-06-08 22:17:39 +08:00
|
|
|
## Settings
|
|
|
|
# openssl version to use
|
2022-05-03 15:33:23 +08:00
|
|
|
OPENSSLVERSION="3.0.2"
|
|
|
|
SHA256SUM="98e91ccead4d4756ae3c9cde5e09191a8e586d9f4d50838e7ec09d6411dfdb63"
|
2015-06-08 22:17:39 +08:00
|
|
|
# SDK version to use - if not set latest version found is used
|
|
|
|
SDK_VERSION=""
|
2013-10-06 19:47:21 +08:00
|
|
|
|
2015-06-08 22:17:39 +08:00
|
|
|
# Minimum SDK version the application supports
|
2022-05-03 15:33:23 +08:00
|
|
|
MIN_SDK_VERSION="15.0"
|
2015-06-08 22:17:39 +08:00
|
|
|
|
|
|
|
## Defaults
|
2013-10-06 19:47:21 +08:00
|
|
|
INSTALLDIR="external"
|
2013-02-14 21:59:12 +08:00
|
|
|
|
2015-06-08 22:17:39 +08:00
|
|
|
# Architectures to build
|
2022-05-03 15:33:23 +08:00
|
|
|
ARCHS="arm64 x86_64"
|
2015-06-08 22:17:39 +08:00
|
|
|
|
|
|
|
# Use default SDK version if not set
|
|
|
|
if [ -z ${SDK_VERSION} ]; then
|
2016-08-04 15:02:40 +08:00
|
|
|
SDK_VERSION=`xcrun -sdk iphoneos --show-sdk-version`
|
2015-06-08 22:17:39 +08:00
|
|
|
fi
|
|
|
|
|
|
|
|
CORES=`sysctl hw.ncpu | awk '{print $2}'`
|
2013-02-14 21:59:12 +08:00
|
|
|
MAKEOPTS="-j $CORES"
|
2015-06-08 22:17:39 +08:00
|
|
|
|
|
|
|
DEVELOPER=`xcode-select -print-path`
|
|
|
|
if [ ! -d "$DEVELOPER" ]; then
|
|
|
|
echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)"
|
|
|
|
echo "run"
|
|
|
|
echo "sudo xcode-select -switch <xcode path>"
|
|
|
|
echo "for default installation:"
|
|
|
|
echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer"
|
|
|
|
exit 1
|
|
|
|
fi
|
2016-08-04 15:16:54 +08:00
|
|
|
|
2013-10-06 18:42:54 +08:00
|
|
|
# Functions
|
2013-10-06 05:53:53 +08:00
|
|
|
function buildArch(){
|
2016-08-04 15:02:40 +08:00
|
|
|
ARCH=$1
|
|
|
|
if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]];
|
|
|
|
then
|
|
|
|
PLATFORM="iPhoneSimulator"
|
|
|
|
else
|
2022-05-03 15:33:23 +08:00
|
|
|
sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"
|
2016-08-04 15:02:40 +08:00
|
|
|
PLATFORM="iPhoneOS"
|
|
|
|
fi
|
|
|
|
|
2022-05-03 15:33:23 +08:00
|
|
|
export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
|
|
|
|
export CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk"
|
|
|
|
export BUILD_TOOLS="${DEVELOPER}"
|
|
|
|
export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}"
|
2016-08-04 15:02:40 +08:00
|
|
|
if [ ! -z $MIN_SDK_VERSION ]; then
|
2022-05-03 15:33:23 +08:00
|
|
|
export CC="$CC -miphoneos-version-min=${MIN_SDK_VERSION}"
|
2016-08-04 15:02:40 +08:00
|
|
|
fi
|
|
|
|
echo "Building openssl-${OPENSSLVERSION} for ${PLATFORM} ${SDK_VERSION} ${ARCH} (min SDK set: ${MIN_SDK_VERSION:-"none"})"
|
|
|
|
|
|
|
|
LOGFILE="BuildLog.darwin-${ARCH}.txt"
|
|
|
|
echo -n " Please wait ..."
|
|
|
|
if [[ "$OPENSSLVERSION" =~ 1.0.0. ]]; then
|
2022-05-03 15:33:23 +08:00
|
|
|
CONFIG_ARGS=BSD-generic32
|
2016-08-04 15:02:40 +08:00
|
|
|
elif [ "${ARCH}" == "x86_64" ]; then
|
2022-05-03 15:33:23 +08:00
|
|
|
CONFIG_ARGS=darwin64-x86_64-cc
|
2016-08-04 15:02:40 +08:00
|
|
|
elif [ "${ARCH}" == "i386" ]; then
|
2022-05-03 15:33:23 +08:00
|
|
|
CONFIG_ARGS="iphoneos-cross no-asm"
|
2016-08-04 15:02:40 +08:00
|
|
|
else
|
2022-05-03 15:33:23 +08:00
|
|
|
CONFIG_ARGS=iphoneos-cross
|
2016-08-04 15:02:40 +08:00
|
|
|
fi
|
|
|
|
|
2022-05-03 15:33:23 +08:00
|
|
|
./Configure $CONFIG_ARGS 2>&1 | tee ${LOGFILE}
|
|
|
|
|
|
|
|
make ${MAKEOPTS} 2>&1 | tee ${LOGFILE}
|
2016-08-04 15:02:40 +08:00
|
|
|
echo " Done. Build log saved in ${LOGFILE}"
|
2022-05-03 15:33:23 +08:00
|
|
|
cp libcrypto.a ../../lib/libcrypto_${ARCH}.a
|
|
|
|
cp libssl.a ../../lib/libssl_${ARCH}.a
|
|
|
|
make clean 2>&1 | tee ${LOGFILE}
|
2013-10-06 05:53:53 +08:00
|
|
|
}
|
|
|
|
|
2013-10-06 18:42:54 +08:00
|
|
|
# main
|
|
|
|
if [ $# -gt 0 ];then
|
2016-08-04 15:02:40 +08:00
|
|
|
INSTALLDIR=$1
|
|
|
|
if [ ! -d $INSTALLDIR ];then
|
|
|
|
echo "Install directory \"$INSTALLDIR\" does not exist"
|
|
|
|
exit 1
|
|
|
|
fi
|
2013-10-06 18:42:54 +08:00
|
|
|
fi
|
|
|
|
|
2013-10-06 05:53:53 +08:00
|
|
|
cd $INSTALLDIR
|
2013-02-14 21:59:12 +08:00
|
|
|
if [ ! -d openssl ];then
|
2022-05-03 15:33:23 +08:00
|
|
|
mkdir openssl
|
2013-02-14 21:59:12 +08:00
|
|
|
fi
|
2022-05-03 15:33:23 +08:00
|
|
|
cd openssl
|
2016-07-21 22:10:41 +08:00
|
|
|
CS=`shasum -a 256 "openssl-$OPENSSLVERSION.tar.gz" | cut -d ' ' -f1`
|
|
|
|
if [ ! "$CS" = "$SHA256SUM" ]; then
|
2013-02-14 21:59:12 +08:00
|
|
|
echo "Downloading OpenSSL Version $OPENSSLVERSION ..."
|
2022-05-03 15:33:23 +08:00
|
|
|
rm -f "openssl-$OPENSSLVERSION.tar.gz"
|
|
|
|
curl -o "openssl-$OPENSSLVERSION.tar.gz" https://www.openssl.org/source/openssl-$OPENSSLVERSION.tar.gz
|
2013-02-14 21:59:12 +08:00
|
|
|
|
2016-07-21 22:10:41 +08:00
|
|
|
CS=`shasum -a 256 "openssl-$OPENSSLVERSION.tar.gz" | cut -d ' ' -f1`
|
|
|
|
if [ ! "$CS" = "$SHA256SUM" ]; then
|
2016-08-04 15:02:40 +08:00
|
|
|
echo "Download failed or invalid checksum. Have a nice day."
|
|
|
|
exit 1
|
2013-02-14 21:59:12 +08:00
|
|
|
fi
|
|
|
|
fi
|
|
|
|
|
2013-10-06 05:53:53 +08:00
|
|
|
# remove old build dir
|
2022-05-03 15:33:23 +08:00
|
|
|
rm -rf openssltmp
|
|
|
|
mkdir openssltmp
|
|
|
|
cd openssltmp
|
2013-02-14 21:59:12 +08:00
|
|
|
|
|
|
|
echo "Unpacking OpenSSL ..."
|
2022-05-03 15:33:23 +08:00
|
|
|
tar xfz "../openssl-$OPENSSLVERSION.tar.gz"
|
2013-02-14 21:59:12 +08:00
|
|
|
if [ ! $? = 0 ]; then
|
|
|
|
echo "Unpacking failed."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
echo
|
|
|
|
|
2022-05-03 15:33:23 +08:00
|
|
|
cd "openssl-$OPENSSLVERSION"
|
2013-10-06 05:53:53 +08:00
|
|
|
|
2015-06-08 22:17:39 +08:00
|
|
|
case `pwd` in
|
|
|
|
*\ * )
|
2024-11-21 05:53:40 +08:00
|
|
|
echo "The build path (`pwd`) contains whitespaces - fix this."
|
2015-06-08 22:17:39 +08:00
|
|
|
exit 1
|
|
|
|
;;
|
|
|
|
esac
|
2013-02-14 21:59:12 +08:00
|
|
|
|
2013-10-06 05:53:53 +08:00
|
|
|
# Cleanup old build artifacts
|
2022-05-03 15:33:23 +08:00
|
|
|
rm -rf ../../include
|
|
|
|
mkdir -p ../../include
|
2013-02-14 21:59:12 +08:00
|
|
|
|
2022-05-03 15:33:23 +08:00
|
|
|
rm -rf ../../lib
|
|
|
|
mkdir -p ../../lib
|
2013-02-14 21:59:12 +08:00
|
|
|
|
2015-06-08 22:17:39 +08:00
|
|
|
for i in ${ARCHS}; do
|
2016-08-04 15:02:40 +08:00
|
|
|
buildArch $i
|
2015-06-08 22:17:39 +08:00
|
|
|
done
|
2013-02-14 21:59:12 +08:00
|
|
|
|
2016-08-04 15:16:54 +08:00
|
|
|
echo "Copying header files ..."
|
2022-05-03 15:33:23 +08:00
|
|
|
cp -r include/ ../../include/
|
2016-08-04 15:16:54 +08:00
|
|
|
echo
|
|
|
|
|
2024-11-21 05:53:40 +08:00
|
|
|
echo "Combining to universal binary"
|
2022-05-03 15:33:23 +08:00
|
|
|
lipo -create ../../lib/libcrypto_*.a -o ../../lib/libcrypto.a
|
|
|
|
lipo -create ../../lib/libssl_*.a -o ../../lib/libssl.a
|
2013-02-14 21:59:12 +08:00
|
|
|
|
2024-11-21 05:53:40 +08:00
|
|
|
echo "Finished. Please verify the contents of the openssl folder in \"$INSTALLDIR\""
|