-
-
Save foozmeat/5154962 to your computer and use it in GitHub Desktop.
#!/bin/bash | |
# This script builds the iOS and Mac openSSL libraries | |
# Download openssl http://www.openssl.org/source/ and place the tarball next to this script | |
# Credits: | |
# https://github.com/st3fan/ios-openssl | |
# https://github.com/x2on/OpenSSL-for-iPhone/blob/master/build-libssl.sh | |
set -e | |
usage () | |
{ | |
echo "usage: $0 [minimum iOS SDK version (default 8.2)]" | |
exit 127 | |
} | |
if [ $1 -e "-h" ]; then | |
usage | |
fi | |
if [ -z $1 ]; then | |
SDK_VERSION="8.2" | |
else | |
SDK_VERSION=$1 | |
fi | |
OPENSSL_VERSION="openssl-1.0.1m" | |
DEVELOPER=`xcode-select -print-path` | |
buildMac() | |
{ | |
ARCH=$1 | |
echo "Building ${OPENSSL_VERSION} for ${ARCH}" | |
TARGET="darwin-i386-cc" | |
if [[ $ARCH == "x86_64" ]]; then | |
TARGET="darwin64-x86_64-cc" | |
fi | |
pushd . > /dev/null | |
cd "${OPENSSL_VERSION}" | |
./Configure ${TARGET} --openssldir="/tmp/${OPENSSL_VERSION}-${ARCH}" &> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" | |
make >> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 2>&1 | |
make install >> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 2>&1 | |
make clean >> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 2>&1 | |
popd > /dev/null | |
} | |
buildIOS() | |
{ | |
ARCH=$1 | |
pushd . > /dev/null | |
cd "${OPENSSL_VERSION}" | |
if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; then | |
PLATFORM="iPhoneSimulator" | |
else | |
PLATFORM="iPhoneOS" | |
sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c" | |
fi | |
export $PLATFORM | |
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}" | |
echo "Building ${OPENSSL_VERSION} for ${PLATFORM} ${SDK_VERSION} ${ARCH}" | |
if [[ "${ARCH}" == "x86_64" ]]; then | |
./Configure darwin64-x86_64-cc --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log" | |
else | |
./Configure iphoneos-cross --openssldir="/tmp/${OPENSSL_VERSION}-iOS-${ARCH}" &> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log" | |
fi | |
# add -isysroot to CC= | |
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=${SDK_VERSION} !" "Makefile" | |
make >> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log" 2>&1 | |
make install >> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log" 2>&1 | |
make clean >> "/tmp/${OPENSSL_VERSION}-iOS-${ARCH}.log" 2>&1 | |
popd > /dev/null | |
} | |
echo "Cleaning up" | |
rm -rf include/openssl/* lib/* | |
mkdir -p lib/iOS | |
mkdir -p lib/Mac | |
mkdir -p include/openssl/ | |
rm -rf "/tmp/${OPENSSL_VERSION}-*" | |
rm -rf "/tmp/${OPENSSL_VERSION}-*.log" | |
rm -rf "${OPENSSL_VERSION}" | |
if [ ! -e ${OPENSSL_VERSION}.tar.gz ]; then | |
echo "Downloading ${OPENSSL_VERSION}.tar.gz" | |
curl -O https://www.openssl.org/source/${OPENSSL_VERSION}.tar.gz | |
else | |
echo "Using ${OPENSSL_VERSION}.tar.gz" | |
fi | |
echo "Unpacking openssl" | |
tar xfz "${OPENSSL_VERSION}.tar.gz" | |
buildMac "i386" | |
buildMac "x86_64" | |
echo "Copying headers" | |
cp /tmp/${OPENSSL_VERSION}-i386/include/openssl/* include/openssl/ | |
echo "Building Mac libraries" | |
lipo \ | |
"/tmp/${OPENSSL_VERSION}-i386/lib/libcrypto.a" \ | |
"/tmp/${OPENSSL_VERSION}-x86_64/lib/libcrypto.a" \ | |
-create -output lib/Mac/libcrypto.a | |
lipo \ | |
"/tmp/${OPENSSL_VERSION}-i386/lib/libssl.a" \ | |
"/tmp/${OPENSSL_VERSION}-x86_64/lib/libssl.a" \ | |
-create -output lib/Mac/libssl.a | |
buildIOS "armv7" | |
buildIOS "arm64" | |
buildIOS "x86_64" | |
buildIOS "i386" | |
echo "Building iOS libraries" | |
lipo \ | |
"/tmp/${OPENSSL_VERSION}-iOS-armv7/lib/libcrypto.a" \ | |
"/tmp/${OPENSSL_VERSION}-iOS-arm64/lib/libcrypto.a" \ | |
"/tmp/${OPENSSL_VERSION}-iOS-i386/lib/libcrypto.a" \ | |
"/tmp/${OPENSSL_VERSION}-iOS-x86_64/lib/libcrypto.a" \ | |
-create -output lib/iOS/libcrypto.a | |
lipo \ | |
"/tmp/${OPENSSL_VERSION}-iOS-armv7/lib/libssl.a" \ | |
"/tmp/${OPENSSL_VERSION}-iOS-arm64/lib/libssl.a" \ | |
"/tmp/${OPENSSL_VERSION}-iOS-i386/lib/libssl.a" \ | |
"/tmp/${OPENSSL_VERSION}-iOS-x86_64/lib/libssl.a" \ | |
-create -output lib/iOS/libssl.a | |
echo "Cleaning up" | |
rm -rf /tmp/${OPENSSL_VERSION}-* | |
rm -rf ${OPENSSL_VERSION} | |
echo "Done" |
Ok, I fixed it by #import /usr/include/openssl/bio.h, it must have been a problem of path.
Anyone able to get the script working for iOS 9 beta? I can't seem to get it properly working but I want to confirm that noone else can get it running.
I made a fork (https://gist.github.com/Norod/2f3ef9b6e3758dfc1433) with some changes:
- Updated built OpenSSL version to openssl-1.0.2d
- The script will now deduce the iOS SDK version by itself
- Added some additional log traces
- Embed bitcode (Xcode 7)
If you find anything useful in there, feel free to merge 😄
Thank you for this script! 👍
Where is ./Configure supposed to come from?
Thanks!
how to use this script? need openssl source code or just dump from macos lib?
When was the last time was updated or even tested..?
This is the 3rd "github" script I've tried...
None of them have worked...
It's virtually identical to 2 other Github openssl / curl projects.
This one makes it to:
Cleaning up
Using openssl-1.1.0c.tar.gz
Unpacking openssl
Building openssl-1.1.0c for i386
-- abruptly ends ---
$ Oh, back to command prompt...
For anyone interested. You can try this repo https://github.com/sinofool/build-openssl-ios I've had success with this.
My present problem is importing: openssl/bio.h, Xcode does not seem to find it, even after having included the libraries, and I need it to process the new inApp receipts.