|
| 1 | +#!/bin/bash |
| 2 | +# Builds openssl for all three current iPhone targets: iPhoneSimulator-i386, |
| 3 | +# iPhoneOS-armv6, iPhoneOS-armv7. |
| 4 | +# |
| 5 | +# Copyright 2012 Mike Tigas <[email protected]> |
| 6 | +# |
| 7 | +# Based on work by Felix Schulze on 16.12.10. |
| 8 | +# Copyright 2010 Felix Schulze. All rights reserved. |
| 9 | +# |
| 10 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 11 | +# you may not use this file except in compliance with the License. |
| 12 | +# You may obtain a copy of the License at |
| 13 | +# |
| 14 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 15 | +# |
| 16 | +# Unless required by applicable law or agreed to in writing, software |
| 17 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 18 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 19 | +# See the License for the specific language governing permissions and |
| 20 | +# limitations under the License. |
| 21 | +# |
| 22 | +########################################################################### |
| 23 | +# Choose your openssl version and your currently-installed iOS SDK version: |
| 24 | +# |
| 25 | +VERSION="1.0.2j" |
| 26 | +SDKVERSION="10.2" |
| 27 | +MINIOSVERSION="6.0" |
| 28 | +VERIFYGPG=false |
| 29 | + |
| 30 | +########################################################################### |
| 31 | +# |
| 32 | +# Don't change anything under this line! |
| 33 | +# |
| 34 | +########################################################################### |
| 35 | + |
| 36 | +# No need to change this since xcode build will only compile in the |
| 37 | +# necessary bits from the libraries we create |
| 38 | +ARCHS="i386 x86_64 armv7 armv7s arm64" |
| 39 | + |
| 40 | +DEVELOPER=`xcode-select -print-path` |
| 41 | +#DEVELOPER="/Applications/Xcode.app/Contents/Developer" |
| 42 | + |
| 43 | +cd "`dirname \"$0\"`" |
| 44 | +REPOROOT=$(pwd) |
| 45 | + |
| 46 | +# Where we'll end up storing things in the end |
| 47 | +OUTPUTDIR="${REPOROOT}/dependencies" |
| 48 | +mkdir -p ${OUTPUTDIR}/include |
| 49 | +mkdir -p ${OUTPUTDIR}/lib |
| 50 | + |
| 51 | +BUILDDIR="${REPOROOT}/build" |
| 52 | + |
| 53 | +# where we will keep our sources and build from. |
| 54 | +SRCDIR="${BUILDDIR}/src" |
| 55 | +mkdir -p $SRCDIR |
| 56 | +# where we will store intermediary builds |
| 57 | +INTERDIR="${BUILDDIR}/built" |
| 58 | +mkdir -p $INTERDIR |
| 59 | + |
| 60 | +######################################## |
| 61 | + |
| 62 | +cd $SRCDIR |
| 63 | + |
| 64 | +# Exit the script if an error happens |
| 65 | +set -e |
| 66 | + |
| 67 | +if [ ! -e "${SRCDIR}/openssl-${VERSION}.tar.gz" ]; then |
| 68 | + echo "Downloading openssl-${VERSION}.tar.gz" |
| 69 | + curl -O http://www.openssl.org/source/openssl-${VERSION}.tar.gz |
| 70 | +fi |
| 71 | +echo "Using openssl-${VERSION}.tar.gz" |
| 72 | + |
| 73 | +# see https://www.openssl.org/about/, |
| 74 | +# up to you to set up `gpg` and add keys to your keychain |
| 75 | +if $VERIFYGPG; then |
| 76 | + if [ ! -e "${SRCDIR}/openssl-${VERSION}.tar.gz.asc" ]; then |
| 77 | + curl -O http://www.openssl.org/source/openssl-${VERSION}.tar.gz.asc |
| 78 | + fi |
| 79 | + echo "Using openssl-${VERSION}.tar.gz.asc" |
| 80 | + if out=$(gpg --status-fd 1 --verify "openssl-${VERSION}.tar.gz.asc" "openssl-${VERSION}.tar.gz" 2>/dev/null) && |
| 81 | + echo "$out" | grep -qs "^\[GNUPG:\] VALIDSIG"; then |
| 82 | + echo "$out" | egrep "GOODSIG|VALIDSIG" |
| 83 | + echo "Verified GPG signature for source..." |
| 84 | + else |
| 85 | + echo "$out" >&2 |
| 86 | + echo "COULD NOT VERIFY PACKAGE SIGNATURE..." |
| 87 | + exit 1 |
| 88 | + fi |
| 89 | +fi |
| 90 | + |
| 91 | +cd "${SRCDIR}/openssl-${VERSION}" |
| 92 | + |
| 93 | +set +e # don't bail out of bash script if ccache doesn't exist |
| 94 | +CCACHE=`which ccache` |
| 95 | +if [ $? == "0" ]; then |
| 96 | + echo "Building with ccache: $CCACHE" |
| 97 | + CCACHE="${CCACHE} " |
| 98 | +else |
| 99 | + echo "Building without ccache" |
| 100 | + CCACHE="" |
| 101 | +fi |
| 102 | +set -e # back to regular "bail out on error" mode |
| 103 | + |
| 104 | +export ORIGINALPATH=$PATH |
| 105 | + |
| 106 | +for ARCH in ${ARCHS} |
| 107 | +do |
| 108 | + if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ]; then |
| 109 | + PLATFORM="iPhoneSimulator" |
| 110 | + else |
| 111 | + sed -ie "s!static volatile sig_atomic_t intr_signal;!static volatile intr_signal;!" "crypto/ui/ui_openssl.c" |
| 112 | + PLATFORM="iPhoneOS" |
| 113 | + fi |
| 114 | + |
| 115 | + mkdir -p "${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" |
| 116 | + |
| 117 | + export PATH="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/usr/bin/:${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin:${DEVELOPER}/usr/bin:${ORIGINALPATH}" |
| 118 | + export CC="${CCACHE}`which gcc` -arch ${ARCH} -miphoneos-version-min=${MINIOSVERSION}" |
| 119 | + |
| 120 | + if [ "${ARCH}" == "x86_64" ] || [ "${ARCH}" == "arm64" ]; then |
| 121 | + ./configure BSD-generic64 no-asm enable-ec_nistp_64_gcc_128 \ |
| 122 | + --openssldir="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" |
| 123 | + else |
| 124 | + ./configure BSD-generic32 no-asm \ |
| 125 | + --openssldir="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk" |
| 126 | + fi |
| 127 | + |
| 128 | + # add -isysroot to configure-generated CFLAGS |
| 129 | + sed -ie "s!^CFLAG=!CFLAG=-isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk !" "Makefile" |
| 130 | + |
| 131 | + # Build the application and install it to the fake SDK intermediary dir |
| 132 | + # we have set up. Make sure to clean up afterward because we will re-use |
| 133 | + # this source tree to cross-compile other targets. |
| 134 | + make |
| 135 | + make install |
| 136 | + make clean |
| 137 | +done |
| 138 | + |
| 139 | +######################################## |
| 140 | + |
| 141 | +echo "Build library..." |
| 142 | +OUTPUT_LIBS="libssl.a libcrypto.a" |
| 143 | +for OUTPUT_LIB in ${OUTPUT_LIBS}; do |
| 144 | + INPUT_LIBS="" |
| 145 | + for ARCH in ${ARCHS}; do |
| 146 | + if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ]; then |
| 147 | + PLATFORM="iPhoneSimulator" |
| 148 | + else |
| 149 | + PLATFORM="iPhoneOS" |
| 150 | + fi |
| 151 | + INPUT_ARCH_LIB="${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/lib/${OUTPUT_LIB}" |
| 152 | + if [ -e $INPUT_ARCH_LIB ]; then |
| 153 | + INPUT_LIBS="${INPUT_LIBS} ${INPUT_ARCH_LIB}" |
| 154 | + fi |
| 155 | + done |
| 156 | + # Combine the three architectures into a universal library. |
| 157 | + if [ -n "$INPUT_LIBS" ]; then |
| 158 | + lipo -create $INPUT_LIBS \ |
| 159 | + -output "${OUTPUTDIR}/lib/${OUTPUT_LIB}" |
| 160 | + else |
| 161 | + echo "$OUTPUT_LIB does not exist, skipping (are the dependencies installed?)" |
| 162 | + fi |
| 163 | +done |
| 164 | + |
| 165 | +for ARCH in ${ARCHS}; do |
| 166 | + if [ "${ARCH}" == "i386" ] || [ "${ARCH}" == "x86_64" ]; then |
| 167 | + PLATFORM="iPhoneSimulator" |
| 168 | + else |
| 169 | + PLATFORM="iPhoneOS" |
| 170 | + fi |
| 171 | + cp -R ${INTERDIR}/${PLATFORM}${SDKVERSION}-${ARCH}.sdk/include/* ${OUTPUTDIR}/include/ |
| 172 | + if [ $? == "0" ]; then |
| 173 | + # We only need to copy the headers over once. (So break out of forloop |
| 174 | + # once we get first success.) |
| 175 | + break |
| 176 | + fi |
| 177 | +done |
| 178 | + |
| 179 | +echo "Building done." |
| 180 | +echo "Cleaning up..." |
| 181 | +rm -fr ${INTERDIR} |
| 182 | +echo "Done." |
0 commit comments