openssl-apple/build-libssl.sh

223 lines
8.4 KiB
Bash
Raw Normal View History

2010-12-16 19:08:02 +00:00
#!/bin/sh
2015-11-16 18:33:54 +00:00
# Automatic build script for libssl and libcrypto
2010-12-16 19:08:02 +00:00
# for iPhoneOS and iPhoneSimulator
#
# Created by Felix Schulze on 16.12.10.
# Copyright 2010-2015 Felix Schulze. All rights reserved.
2010-12-16 19:08:02 +00:00
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
###########################################################################
# Change values here #
# #
VERSION="1.0.2e" #
IOS_SDKVERSION=`xcrun -sdk iphoneos --show-sdk-version` #
TVOS_SDKVERSION=`xcrun -sdk appletvos --show-sdk-version` #
CONFIG_OPTIONS="" #
CURL_OPTIONS="" #
# To set "enable-ec_nistp_64_gcc_128" configuration for x64 archs set next variable to "true"
ENABLE_EC_NISTP_64_GCC_128="" #
# #
2010-12-16 19:08:02 +00:00
###########################################################################
# #
# Don't change anything under this line! #
# #
2010-12-16 19:08:02 +00:00
###########################################################################
2015-12-07 17:51:50 +00:00
spinner()
{
local pid=$!
local delay=0.75
local spinstr='|/-\'
while [ "$(ps a | awk '{print $1}' | grep $pid)" ]; do
local temp=${spinstr#?}
printf " [%c] " "$spinstr"
local spinstr=$temp${spinstr%"$temp"}
sleep $delay
printf "\b\b\b\b\b\b"
done
printf " \b\b\b\b"
2015-12-07 17:51:50 +00:00
}
2010-12-16 19:08:02 +00:00
CURRENTPATH=`pwd`
2015-11-16 18:33:54 +00:00
ARCHS="i386 x86_64 armv7 armv7s arm64 tv_x86_64 tv_arm64"
2012-02-21 19:41:47 +00:00
DEVELOPER=`xcode-select -print-path`
2015-11-16 18:33:54 +00:00
IOS_MIN_SDK_VERSION="7.0"
TVOS_MIN_SDK_VERSION="9.0"
2015-08-06 06:02:24 +00:00
if [ ! -d "$DEVELOPER" ]; then
2015-11-16 18:33:54 +00:00
echo "xcode path is not set correctly $DEVELOPER does not exist"
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
2015-11-16 18:33:54 +00:00
case $DEVELOPER in
*\ * )
echo "Your Xcode path contains whitespaces, which is not supported."
exit 1
;;
esac
2015-11-16 18:33:54 +00:00
case $CURRENTPATH in
*\ * )
echo "Your path contains whitespaces, which is not supported by 'make install'."
exit 1
;;
esac
2010-12-16 19:08:02 +00:00
set -e
if [ ! -e openssl-${VERSION}.tar.gz ]; then
echo "Downloading openssl-${VERSION}.tar.gz"
curl ${CURL_OPTIONS} -O https://www.openssl.org/source/openssl-${VERSION}.tar.gz
2010-12-16 19:08:02 +00:00
else
echo "Using openssl-${VERSION}.tar.gz"
2010-12-16 19:08:02 +00:00
fi
mkdir -p "${CURRENTPATH}/src"
2012-01-28 19:20:37 +00:00
mkdir -p "${CURRENTPATH}/bin"
mkdir -p "${CURRENTPATH}/lib"
2010-12-16 19:08:02 +00:00
tar zxf openssl-${VERSION}.tar.gz -C "${CURRENTPATH}/src"
cd "${CURRENTPATH}/src/openssl-${VERSION}"
2012-01-28 19:20:37 +00:00
for ARCH in ${ARCHS}
do
2015-11-16 18:33:54 +00:00
if [[ "$ARCH" == tv* ]]; then
SDKVERSION=$TVOS_SDKVERSION
MIN_SDK_VERSION=$TVOS_MIN_SDK_VERSION
LC_ALL=C sed -i -- 's/define HAVE_FORK 1/define HAVE_FORK 0/' "./apps/speed.c"
LC_ALL=C sed -i -- 's/D\_REENTRANT\:iOS/D\_REENTRANT\:tvOS/' "./Configure"
chmod u+x ./Configure
else
SDKVERSION=$IOS_SDKVERSION
MIN_SDK_VERSION=$IOS_MIN_SDK_VERSION
fi
if [[ "${ARCH}" == "i386" || "${ARCH}" == "x86_64" ]]; then
PLATFORM="iPhoneSimulator"
2015-11-16 18:33:54 +00:00
elif [ "${ARCH}" == "tv_x86_64" ]; then
ARCH="x86_64"
PLATFORM="AppleTVSimulator"
elif [ "${ARCH}" == "tv_arm64" ]; then
ARCH="arm64"
sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"
PLATFORM="AppleTVOS"
else
sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c"
2015-11-16 18:33:54 +00:00
PLATFORM="iPhoneOS"
fi
2015-11-16 18:33:54 +00:00
export $PLATFORM
export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export CROSS_SDK="${PLATFORM}${SDKVERSION}.sdk"
export BUILD_TOOLS="${DEVELOPER}"
2015-12-07 17:41:03 +00:00
mkdir -p "${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk"
LOG="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/build-openssl-${VERSION}.log"
echo "Building openssl-${VERSION} for ${PLATFORM} ${SDKVERSION} ${ARCH}"
2015-12-07 17:41:03 +00:00
echo " Logfile: $LOG"
2012-01-28 19:20:37 +00:00
LOCAL_CONFIG_OPTIONS="${CONFIG_OPTIONS}"
if [ "${ENABLE_EC_NISTP_64_GCC_128}" == "true" ]; then
case "$ARCH" in
*64*)
LOCAL_CONFIG_OPTIONS="${LOCAL_CONFIG_OPTIONS} enable-ec_nistp_64_gcc_128"
;;
esac
fi
if [[ $SDKVERSION == 9.* ]]; then
export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH} -fembed-bitcode"
else
export CC="${BUILD_TOOLS}/usr/bin/gcc -arch ${ARCH}"
fi
2015-08-06 06:02:24 +00:00
2015-12-07 17:51:50 +00:00
echo " Configure...\c"
set +e
2015-12-08 17:24:38 +00:00
if [ "$1" == "verbose" ]; then
if [ "${ARCH}" == "x86_64" ]; then
./Configure no-asm darwin64-x86_64-cc --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" ${LOCAL_CONFIG_OPTIONS}
else
./Configure iphoneos-cross --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" ${LOCAL_CONFIG_OPTIONS}
fi
2015-12-08 17:24:38 +00:00
else
if [ "${ARCH}" == "x86_64" ]; then
(./Configure no-asm darwin64-x86_64-cc --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" ${LOCAL_CONFIG_OPTIONS} > "${LOG}" 2>&1) & spinner
else
(./Configure iphoneos-cross --openssldir="${CURRENTPATH}/bin/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" ${LOCAL_CONFIG_OPTIONS} > "${LOG}" 2>&1) & spinner
fi
2015-12-08 17:24:38 +00:00
fi
2015-11-16 18:33:54 +00:00
if [ $? != 0 ]; then
echo "Problem while configure - Please check ${LOG}"
exit 1
fi
2015-12-07 17:51:50 +00:00
echo "\n Patch..."
2015-11-16 18:33:54 +00:00
# add -isysroot to CC=
if [[ "${PLATFORM}" == "AppleTVSimulator" || "${PLATFORM}" == "AppleTVOS" ]]; then
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -mtvos-version-min=${TVOS_MIN_SDK_VERSION} !" "Makefile"
else
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=${MIN_SDK_VERSION} !" "Makefile"
fi
2015-12-07 17:51:50 +00:00
echo " Make...\c"
2015-12-07 17:41:03 +00:00
if [ "$1" == "verbose" ]; then
if [[ ! -z $CONFIG_OPTIONS ]]; then
make depend
fi
make
else
if [[ ! -z $CONFIG_OPTIONS ]]; then
make depend >> "${LOG}" 2>&1
fi
(make >> "${LOG}" 2>&1) & spinner
fi
2015-12-07 17:51:50 +00:00
echo "\n"
2015-11-16 18:33:54 +00:00
if [ $? != 0 ]; then
2015-11-16 18:33:54 +00:00
echo "Problem while make - Please check ${LOG}"
exit 1
fi
set -e
2015-12-08 17:24:38 +00:00
if [ "$1" == "verbose" ]; then
make install_sw
make clean
else
make install_sw >> "${LOG}" 2>&1
make clean >> "${LOG}" 2>&1
2015-12-08 17:24:38 +00:00
fi
2012-01-28 19:20:37 +00:00
done
2010-12-16 19:08:02 +00:00
2015-11-16 18:33:54 +00:00
echo "Build library for iOS..."
lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-i386.sdk/lib/libssl.a ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-x86_64.sdk/lib/libssl.a ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7.sdk/lib/libssl.a ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7s.sdk/lib/libssl.a ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-arm64.sdk/lib/libssl.a -output ${CURRENTPATH}/lib/libssl.a
lipo -create ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-i386.sdk/lib/libcrypto.a ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-x86_64.sdk/lib/libcrypto.a ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7.sdk/lib/libcrypto.a ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-armv7s.sdk/lib/libcrypto.a ${CURRENTPATH}/bin/iPhoneOS${IOS_SDKVERSION}-arm64.sdk/lib/libcrypto.a -output ${CURRENTPATH}/lib/libcrypto.a
2010-12-16 19:08:02 +00:00
2015-11-16 18:33:54 +00:00
echo "Build library for tvOS..."
lipo -create ${CURRENTPATH}/bin/AppleTVSimulator${TVOS_SDKVERSION}-x86_64.sdk/lib/libssl.a ${CURRENTPATH}/bin/AppleTVOS${TVOS_SDKVERSION}-arm64.sdk/lib/libssl.a -output ${CURRENTPATH}/lib/libssl-tvOS.a
lipo -create ${CURRENTPATH}/bin/AppleTVSimulator${TVOS_SDKVERSION}-x86_64.sdk/lib/libcrypto.a ${CURRENTPATH}/bin/AppleTVOS${TVOS_SDKVERSION}-arm64.sdk/lib/libcrypto.a -output ${CURRENTPATH}/lib/libcrypto-tvOS.a
2010-12-16 19:08:02 +00:00
mkdir -p ${CURRENTPATH}/include
cp -R ${CURRENTPATH}/bin/iPhoneSimulator${IOS_SDKVERSION}-x86_64.sdk/include/openssl ${CURRENTPATH}/include/
2010-12-16 19:08:02 +00:00
echo "Building done."
echo "Cleaning up..."
2012-01-28 19:20:37 +00:00
rm -rf ${CURRENTPATH}/src/openssl-${VERSION}
echo "Done."