184 lines
5.4 KiB
Bash
184 lines
5.4 KiB
Bash
#!/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
|
|
# Change the version to match and run
|
|
|
|
VERSION="1.0.1m"
|
|
OPENSSL_VERSION="openssl-${VERSION}"
|
|
|
|
# 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 [iOS SDK version (defaults to xcrun --show-sdk-version]"
|
|
exit 127
|
|
}
|
|
|
|
if [ $1 -e "-h" ]; then
|
|
usage
|
|
fi
|
|
|
|
if [ -z $1 ]; then
|
|
SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version`
|
|
else
|
|
SDKVERSION=$1
|
|
fi
|
|
|
|
echo "SDK version $SDKVERSION"
|
|
|
|
CURRENTPATH=`pwd`
|
|
ARCHS="i386 x86_64 armv7 armv7s arm64"
|
|
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
|
|
case $DEVELOPER in
|
|
*\ * )
|
|
echo "Your Xcode path contains whitespaces, which is not supported."
|
|
exit 1
|
|
;;
|
|
esac
|
|
case $CURRENTPATH in
|
|
*\ * )
|
|
echo "Your path contains whitespaces, which is not supported by 'make install'."
|
|
exit 1
|
|
;;
|
|
esac
|
|
|
|
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
|
|
./Configure ${TARGET} --openssldir="${CURRENTPATH}/${OPENSSL_VERSION}-${ARCH}" &> "${CURRENTPATH}/${OPENSSL_VERSION}-${ARCH}.log"
|
|
make >> "${CURRENTPATH}/${OPENSSL_VERSION}-${ARCH}.log" 2>&1
|
|
make install >> "${CURRENTPATH}/${OPENSSL_VERSION}-${ARCH}.log" 2>&1
|
|
make clean >> "${CURRENTPATH}/${OPENSSL_VERSION}-${ARCH}.log" 2>&1
|
|
popd > /dev/null
|
|
}
|
|
|
|
buildIOS()
|
|
{
|
|
for ARCH in ${ARCHS}
|
|
do
|
|
if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]];
|
|
then
|
|
PLATFORM="iPhoneSimulator"
|
|
else
|
|
sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"
|
|
PLATFORM="iPhoneOS"
|
|
fi
|
|
|
|
export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
|
|
export CROSS_SDK="${PLATFORM}${SDKVERSION}.sdk"
|
|
export BUILD_TOOLS="${DEVELOPER}"
|
|
echo "Building openssl-${VERSION} for ${PLATFORM} ${SDKVERSION} ${ARCH}"
|
|
echo "Please stand by..."
|
|
export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}"
|
|
mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk"
|
|
LOG="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/build-openssl-${VERSION}.log"
|
|
set +e
|
|
if [[ "$VERSION" =~ 1.0.0. ]]; then
|
|
./Configure BSD-generic32 --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" > "${LOG}" 2>&1
|
|
elif [ "${ARCH}" == "x86_64" ]; then
|
|
./Configure darwin64-x86_64-cc --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" > "${LOG}" 2>&1
|
|
else
|
|
./Configure iphoneos-cross --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" > "${LOG}" 2>&1
|
|
fi
|
|
|
|
if [ $? != 0 ];
|
|
then
|
|
echo "Problem while configure - Please check ${LOG}"
|
|
exit 1
|
|
fi
|
|
# add -isysroot to CC=
|
|
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=7.0 !" "Makefile"
|
|
if [ "$1" == "verbose" ];
|
|
then
|
|
make
|
|
else
|
|
make >> "${LOG}" 2>&1
|
|
fi
|
|
|
|
if [ $? != 0 ];
|
|
then
|
|
echo "Problem while make - Please check ${LOG}"
|
|
exit 1
|
|
fi
|
|
|
|
set -e
|
|
make install >> "${LOG}" 2>&1
|
|
make clean >> "${LOG}" 2>&1
|
|
done
|
|
}
|
|
|
|
if [ ! -e ${OPENSSL_VERSION}.tar.gz ]; then
|
|
echo "Downloading ${OPENSSL_VERSION}.tar.gz"
|
|
curl -O http://www.openssl.org/source/${OPENSSL_VERSION}.tar.gz
|
|
else
|
|
echo "Using ${OPENSSL_VERSION}.tar.gz"
|
|
fi
|
|
|
|
echo "Unpacking openssl"
|
|
mkdir -p "${CURRENTPATH}/src"
|
|
mkdir -p "${CURRENTPATH}/bin"
|
|
mkdir -p "${CURRENTPATH}/lib/iOS"
|
|
mkdir -p "${CURRENTPATH}/lib/OSX"
|
|
|
|
tar zxf openssl-${VERSION}.tar.gz -C "${CURRENTPATH}/src"
|
|
cd "${CURRENTPATH}/src/openssl-${VERSION}"
|
|
|
|
buildMac "i386"
|
|
buildMac "x86_64"
|
|
|
|
echo "Building OSX libraries"
|
|
lipo \
|
|
"${CURRENTPATH}/${OPENSSL_VERSION}-i386/lib/libcrypto.a" \
|
|
"${CURRENTPATH}/${OPENSSL_VERSION}-x86_64/lib/libcrypto.a" \
|
|
-create -output ${CURRENTPATH}/lib/OSX/libcrypto.a
|
|
|
|
lipo \
|
|
"${CURRENTPATH}/${OPENSSL_VERSION}-i386/lib/libssl.a" \
|
|
"${CURRENTPATH}/${OPENSSL_VERSION}-x86_64/lib/libssl.a" \
|
|
-create -output ${CURRENTPATH}/lib/OSX/libssl.a
|
|
|
|
buildIOS
|
|
|
|
echo "Building iOS libraries"
|
|
lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/lib/libssl.a \
|
|
${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/lib/libssl.a \
|
|
${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/lib/libssl.a \
|
|
${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/lib/libssl.a \
|
|
${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/lib/libssl.a \
|
|
-output ${CURRENTPATH}/lib/iOS/libssl.a
|
|
|
|
lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/lib/libcrypto.a \
|
|
${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-x86_64.sdk/lib/libcrypto.a \
|
|
${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/lib/libcrypto.a \
|
|
${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7s.sdk/lib/libcrypto.a \
|
|
${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-arm64.sdk/lib/libcrypto.a \
|
|
-output ${CURRENTPATH}/lib/iOS/libcrypto.a
|
|
|
|
echo "Copying headers"
|
|
mkdir -p ${CURRENTPATH}/include
|
|
cp -R ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}-i386.sdk/include/openssl ${CURRENTPATH}/include/
|
|
echo "Building done."
|