3 # Copyright 2013 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 (armv7, armv7s) and simulator (i386)
10 # Settings and definitions
14 OPENSSLVERSION="1.0.0e"
15 MD5SUM="7040b89c4c58c7a1016c0dfa6e821c86"
16 OPENSSLPATCH="OpenSSL-iFreeRDP.diff"
20 # disable parallell builds since openssl build
23 CORES=`sysctl hw.ncpu | awk '{print $2}'`
24 SCRIPTDIR=$(dirname `cd ${0%/*} && echo $PWD/${0##*/}`)
27 OS_SDK_PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs"
28 SIM_SDK_PATH="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs"
33 LOGFILE="BuildLog.darwin-${ARCH}.txt"
34 echo "Building architecture ${ARCH}. Please wait ..."
35 ./Configure darwin-${ARCH}-cc > ${LOGFILE}
36 make ${MAKEOPTS} >> ${LOGFILE} 2>&1
37 echo "Done. Build log saved in ${LOGFILE}"
38 cp libcrypto.a ../../lib/libcrypto_${ARCH}.a
39 cp libssl.a ../../lib/libssl_${ARCH}.a
40 make clean >/dev/null 2>&1
47 if [ ! -d $INSTALLDIR ];then
48 echo "Install directory \"$INSTALLDIR\" does not exist"
53 echo "Detecting SDKs..."
54 if [ "x${USER_OS_SDK}" == "x" ];then
55 OS_SDK=`ls -1 ${OS_SDK_PATH} | sort -n | head -1`
56 if [ "x${OS_SDK}" == "x" ];then
57 echo "No iPhoneOS SDK found"
62 if [ ! -d "${OS_SDK_PATH}/${OS_SDK}" ];then
63 echo "User specified iPhoneOS SDK not found"
67 echo "Using iPhoneOS SDK: ${OS_SDK}"
69 if [ "x${USER_SIM_SDK}" == "x" ];then
70 SIM_SDK=`ls -1 ${SIM_SDK_PATH} | sort -n | head -1`
71 if [ "x${SIM_SDK}" == "x" ];then
72 echo "No iPhoneSimulator SDK found"
76 SIM_SDK=${USER_SIM_SDK}
77 if [ ! -d "${SIM_SDK_PATH}/${SIM_SDK}" ];then
78 echo "User specified iPhoneSimulator SDK not found"
82 echo "Using iPhoneSimulator SDK: ${SIM_SDK}"
86 if [ ! -d openssl ];then
90 CS=`md5 -q "openssl-$OPENSSLVERSION.tar.gz" 2>/dev/null`
91 if [ ! "$CS" = "$MD5SUM" ]; then
92 echo "Downloading OpenSSL Version $OPENSSLVERSION ..."
93 rm -f "openssl-$OPENSSLVERSION.tar.gz"
94 curl -o "openssl-$OPENSSLVERSION.tar.gz" http://www.openssl.org/source/openssl-$OPENSSLVERSION.tar.gz
96 CS=`md5 -q "openssl-$OPENSSLVERSION.tar.gz" 2>/dev/null`
97 if [ ! "$CS" = "$MD5SUM" ]; then
98 echo "Download failed or invalid checksum. Have a nice day."
103 # remove old build dir
108 echo "Unpacking OpenSSL ..."
109 tar xfz "../openssl-$OPENSSLVERSION.tar.gz"
110 if [ ! $? = 0 ]; then
111 echo "Unpacking failed."
116 echo "Applying iFreeRDP patch ..."
117 cd "openssl-$OPENSSLVERSION"
118 cp ${SCRIPTDIR}/${OPENSSLPATCH} .
119 sed -ie "s#__ISIMSDK__#${SIM_SDK}#" ${OPENSSLPATCH}
120 sed -ie "s#__IOSSDK__#${OS_SDK}#" ${OPENSSLPATCH}
122 patch -p1 < $OPENSSLPATCH
124 if [ ! $? = 0 ]; then
130 # Cleanup old build artifacts
131 mkdir -p ../../include/openssl
132 rm -f ../../include/openssl/*.h
137 echo "Copying header hiles ..."
138 cp include/openssl/*.h ../../include/openssl/
145 echo "Combining to unversal binary"
146 lipo -create ../../lib/libcrypto_*.a -o ../../lib/libcrypto.a
147 lipo -create ../../lib/libssl_*.a -o ../../lib/libssl.a
149 echo "Finished. Please verify the contens of the openssl folder in \"$INSTALLDIR\""