Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
#!/bin/bash
# This script builds the iOS and Mac openSSL libraries
# It's expanded from https://github.com/st3fan/ios-openssl
set -xe
# Setup paths to stuff we need
OPENSSL_VERSION="1.0.1e"
DEVELOPER="/Applications/Xcode.app/Contents/Developer"
SDK_VERSION="6.1"
IPHONEOS_PLATFORM="${DEVELOPER}/Platforms/iPhoneOS.platform"
IPHONEOS_SDK="${IPHONEOS_PLATFORM}/Developer/SDKs/iPhoneOS${SDK_VERSION}.sdk"
IPHONEOS_GCC="${IPHONEOS_PLATFORM}/Developer/usr/bin/gcc"
IPHONESIMULATOR_PLATFORM="${DEVELOPER}/Platforms/iPhoneSimulator.platform"
IPHONESIMULATOR_SDK="${IPHONESIMULATOR_PLATFORM}/Developer/SDKs/iPhoneSimulator${SDK_VERSION}.sdk"
IPHONESIMULATOR_GCC="${IPHONESIMULATOR_PLATFORM}/Developer/usr/bin/gcc"
# Clean up whatever was left from our previous build
rm -rf include/openssl/* lib/*
rm -rf "/tmp/openssl-${OPENSSL_VERSION}-*"
rm -rf "/tmp/openssl-${OPENSSL_VERSION}-*.log"
buildMac()
{
ARCH=$1
TARGET="darwin-i386-cc"
if [[ $ARCH == "x86_64" ]]; then
TARGET="darwin64-x86_64-cc"
fi
rm -rf "openssl-${OPENSSL_VERSION}"
tar xfz "openssl-${OPENSSL_VERSION}.tar.gz"
pushd .
cd "openssl-${OPENSSL_VERSION}"
./Configure ${TARGET} --openssldir="/tmp/openssl-${OPENSSL_VERSION}-${ARCH}" &> "/tmp/openssl-${OPENSSL_VERSION}-${ARCH}.log"
make &> "/tmp/openssl-${OPENSSL_VERSION}-${ARCH}.log"
make install &> "/tmp/openssl-${OPENSSL_VERSION}-${ARCH}.log"
popd
rm -rf "openssl-${OPENSSL_VERSION}"
}
buildIOS()
{
ARCH=$1
GCC=$2
SDK=$3
rm -rf "openssl-${OPENSSL_VERSION}"
tar xfz "openssl-${OPENSSL_VERSION}.tar.gz"
pushd .
cd "openssl-${OPENSSL_VERSION}"
./Configure BSD-generic32 --openssldir="/tmp/openssl-${OPENSSL_VERSION}-${ARCH}" &> "/tmp/openssl-${OPENSSL_VERSION}-${ARCH}.log"
perl -i -pe 's|static volatile sig_atomic_t intr_signal|static volatile int intr_signal|' crypto/ui/ui_openssl.c
perl -i -pe "s|^CC= gcc|CC= ${GCC} -arch ${ARCH}|g" Makefile
perl -i -pe "s|^CFLAG= (.*)|CFLAG= -isysroot ${SDK} \$1|g" Makefile
make &> "/tmp/openssl-${OPENSSL_VERSION}-${ARCH}.log"
make install &> "/tmp/openssl-${OPENSSL_VERSION}-${ARCH}.log"
popd
rm -rf "openssl-${OPENSSL_VERSION}"
}
buildMac "i386"
buildMac "x86_64"
mkdir -p include/openssl/
cp /tmp/openssl-${OPENSSL_VERSION}-i386/include/openssl/* include/openssl/
mkdir -p lib
lipo \
"/tmp/openssl-${OPENSSL_VERSION}-i386/lib/libcrypto.a" \
"/tmp/openssl-${OPENSSL_VERSION}-x86_64/lib/libcrypto.a" \
-create -output lib/libcrypto_Mac.a
lipo \
"/tmp/openssl-${OPENSSL_VERSION}-i386/lib/libssl.a" \
"/tmp/openssl-${OPENSSL_VERSION}-x86_64/lib/libssl.a" \
-create -output lib/libssl_Mac.a
buildIOS "armv7" "${IPHONEOS_GCC}" "${IPHONEOS_SDK}"
buildIOS "armv7s" "${IPHONEOS_GCC}" "${IPHONEOS_SDK}"
buildIOS "i386" "${IPHONESIMULATOR_GCC}" "${IPHONESIMULATOR_SDK}"
lipo \
"/tmp/openssl-${OPENSSL_VERSION}-armv7/lib/libcrypto.a" \
"/tmp/openssl-${OPENSSL_VERSION}-armv7s/lib/libcrypto.a" \
"/tmp/openssl-${OPENSSL_VERSION}-i386/lib/libcrypto.a" \
-create -output lib/libcrypto_iOS.a
lipo \
"/tmp/openssl-${OPENSSL_VERSION}-armv7/lib/libssl.a" \
"/tmp/openssl-${OPENSSL_VERSION}-armv7s/lib/libssl.a" \
"/tmp/openssl-${OPENSSL_VERSION}-i386/lib/libssl.a" \
-create -output lib/libssl_iOS.a
rm -rf "/tmp/openssl-${OPENSSL_VERSION}-*"
rm -rf "/tmp/openssl-${OPENSSL_VERSION}-*.log"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment