3 # Copyright 2015 Thincast Technologies GmbH
5 # This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
6 # If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 # This script will download and build openssl for iOS and simulator - see ARCHS for architectures built
11 # openssl version to use
12 OPENSSLVERSION="1.0.2q"
13 SHA256SUM="5744cfcbcec2b1b48629f7354203bc1e5e9b5466998bbccc5b5fcde3b18eb684"
14 # SDK version to use - if not set latest version found is used
17 # Minimum SDK version the application supports
18 MIN_SDK_VERSION="10.0"
23 # Architectures to build
24 ARCHS="i386 x86_64 armv7 armv7s arm64"
26 # Use default SDK version if not set
27 if [ -z ${SDK_VERSION} ]; then
28 SDK_VERSION=`xcrun -sdk iphoneos --show-sdk-version`
31 CORES=`sysctl hw.ncpu | awk '{print $2}'`
33 # disable parallell builds since openssl build
37 DEVELOPER=`xcode-select -print-path`
38 if [ ! -d "$DEVELOPER" ]; then
39 echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)"
41 echo "sudo xcode-select -switch <xcode path>"
42 echo "for default installation:"
43 echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer"
50 if [ $status -ne 0 ]; then
51 echo "error with $@" >&2
60 if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]];
62 PLATFORM="iPhoneSimulator"
64 run sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"
68 run export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
69 run export CROSS_SDK="${PLATFORM}${SDK_VERSION}.sdk"
70 run export BUILD_TOOLS="${DEVELOPER}"
71 run export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}"
72 if [ ! -z $MIN_SDK_VERSION ]; then
73 run export CC="$CC -miphoneos-version-min=${MIN_SDK_VERSION}"
75 echo "Building openssl-${OPENSSLVERSION} for ${PLATFORM} ${SDK_VERSION} ${ARCH} (min SDK set: ${MIN_SDK_VERSION:-"none"})"
77 LOGFILE="BuildLog.darwin-${ARCH}.txt"
78 echo -n " Please wait ..."
79 if [[ "$OPENSSLVERSION" =~ 1.0.0. ]]; then
80 run ./Configure BSD-generic32 > "${LOGFILE}" 2>&1
81 elif [ "${ARCH}" == "x86_64" ]; then
82 run ./Configure darwin64-x86_64-cc > "${LOGFILE}" 2>&1
83 elif [ "${ARCH}" == "i386" ]; then
84 run ./Configure iphoneos-cross no-asm > "${LOGFILE}" 2>&1
86 run ./Configure iphoneos-cross > "${LOGFILE}" 2>&1
89 run make ${MAKEOPTS} >> ${LOGFILE} 2>&1
90 echo " Done. Build log saved in ${LOGFILE}"
91 run cp libcrypto.a ../../lib/libcrypto_${ARCH}.a
92 run cp libssl.a ../../lib/libssl_${ARCH}.a
93 run make clean >/dev/null 2>&1
99 if [ ! -d $INSTALLDIR ];then
100 echo "Install directory \"$INSTALLDIR\" does not exist"
106 if [ ! -d openssl ];then
110 CS=`shasum -a 256 "openssl-$OPENSSLVERSION.tar.gz" | cut -d ' ' -f1`
111 if [ ! "$CS" = "$SHA256SUM" ]; then
112 echo "Downloading OpenSSL Version $OPENSSLVERSION ..."
113 run rm -f "openssl-$OPENSSLVERSION.tar.gz"
114 run curl -o "openssl-$OPENSSLVERSION.tar.gz" https://www.openssl.org/source/openssl-$OPENSSLVERSION.tar.gz
116 CS=`shasum -a 256 "openssl-$OPENSSLVERSION.tar.gz" | cut -d ' ' -f1`
117 if [ ! "$CS" = "$SHA256SUM" ]; then
118 echo "Download failed or invalid checksum. Have a nice day."
123 # remove old build dir
124 run rm -rf openssltmp
128 echo "Unpacking OpenSSL ..."
129 run tar xfz "../openssl-$OPENSSLVERSION.tar.gz"
130 if [ ! $? = 0 ]; then
131 echo "Unpacking failed."
136 run cd "openssl-$OPENSSLVERSION"
140 echo "The build path (`pwd`) contains whitepsaces - fix this."
145 # Cleanup old build artifacts
146 run rm -rf ../../include
147 run mkdir -p ../../include
150 run mkdir -p ../../lib
152 for i in ${ARCHS}; do
156 echo "Copying header files ..."
157 run cp -r include/ ../../include/
160 echo "Combining to unversal binary"
161 run lipo -create ../../lib/libcrypto_*.a -o ../../lib/libcrypto.a
162 run lipo -create ../../lib/libssl_*.a -o ../../lib/libssl.a
164 echo "Finished. Please verify the contens of the openssl folder in \"$INSTALLDIR\""