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