-
Notifications
You must be signed in to change notification settings - Fork 0
/
build-openssl.sh
executable file
·202 lines (154 loc) · 6.18 KB
/
build-openssl.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/bin/bash
# This script builds the iOS and Mac openSSL libraries with Bitcode enabled
# 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
# Peter Steinberger, PSPDFKit GmbH, @steipete.
# Doron Adler, GlideTalk, @Norod78, @yangyubo
# Updated to work with Xcode 7 and iOS 9
# Updated to set macOS minimum deploy target version
set -e
pushd . > /dev/null
cd ./dist
###################################
# OpenSSL Version
###################################
OPENSSL_VERSION="openssl-1.0.2q"
###################################
###################################
# OpenSSL Version
###################################
MACOS_DIST_OUTPUT="${OPENSSL_VERSION}-macOS"
IOS_DIST_OUTPUT="${OPENSSL_VERSION}-iOS"
###################################
###################################
# SDK Version
###################################
IOS_SDK_VERSION=$(xcodebuild -version -sdk iphoneos | grep SDKVersion | cut -f2 -d ':' | tr -d '[[:space:]]')
MACOS_SDK_VERSION=$(xcodebuild -version -sdk macosx | grep SDKVersion | cut -f2 -d ':' | tr -d '[[:space:]]')
###################################
################################################
# Minimum deployment target version
################################################
MACOS_DEPLOYMENT_VERSION="10.10"
IOS_DEPLOYMENT_VERSION="8.0"
DEVELOPER=`xcode-select -print-path`
buildMac()
{
ARCH=$1
echo "Start Building ${OPENSSL_VERSION} for macOS ${MACOS_DEPLOYMENT_VERSION} ${ARCH}"
TARGET="darwin64-x86_64-cc"
export CC="${BUILD_TOOLS}/usr/bin/clang -mmacosx-version-min=${MACOS_DEPLOYMENT_VERSION}"
pushd . > /dev/null
cd "{OPENSSL_VERSION}"
echo "Configure"
./Configure ${TARGET} --openssldir="/tmp/${OPENSSL_VERSION}-${ARCH}" &> "/tmp/${OPENSSL_VERSION}-${ARCH}.log"
make >> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 2>&1
echo "make install"
make install >> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 2>&1
echo "make clean"
make clean >> "/tmp/${OPENSSL_VERSION}-${ARCH}.log" 2>&1
popd > /dev/null
echo "Done Building ${OPENSSL_VERSION} for macOS ${MACOS_SDK_VERSION} ${ARCH}"
}
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}${IOS_SDK_VERSION}.sdk"
export BUILD_TOOLS="${DEVELOPER}"
export CC="${BUILD_TOOLS}/usr/bin/gcc -fembed-bitcode -mios-version-min=${IOS_DEPLOYMENT_VERSION} -arch ${ARCH}"
echo "Start Building ${OPENSSL_VERSION} for ${PLATFORM} ${IOS_DEPLOYMENT_VERSION} ${ARCH}"
echo "Configure"
if [[ "${ARCH}" == "x86_64" ]]; then
./Configure darwin64-x86_64-cc --openssldir="/tmp/${IOS_DIST_OUTPUT}-${ARCH}" &> "/tmp/${IOS_DIST_OUTPUT}-${ARCH}.log"
else
./Configure iphoneos-cross --openssldir="/tmp/${IOS_DIST_OUTPUT}-${ARCH}" &> "/tmp/${IOS_DIST_OUTPUT}-${ARCH}.log"
fi
# add -isysroot to CC=
sed -ie "s!^CFLAG=!CFLAG=-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -mios-version-min=${IOS_DEPLOYMENT_VERSION} !" "Makefile"
echo "make"
make >> "/tmp/${IOS_DIST_OUTPUT}-${ARCH}.log" 2>&1
echo "make install"
make install >> "/tmp/${IOS_DIST_OUTPUT}-${ARCH}.log" 2>&1
echo "make clean"
make clean >> "/tmp/${IOS_DIST_OUTPUT}-${ARCH}.log" 2>&1
popd > /dev/null
echo "Done Building ${OPENSSL_VERSION} for ${PLATFORM} ${IOS_SDK_VERSION} ${ARCH}"
}
cleanUp()
{
echo "Cleaning up"
rm -rf ${IOS_DIST_OUTPUT}/* ${MACOS_DIST_OUTPUT}/*
mkdir -p ${IOS_DIST_OUTPUT}/lib
mkdir -p ${IOS_DIST_OUTPUT}/include/openssl/
mkdir -p ${MACOS_DIST_OUTPUT}/lib
mkdir -p ${MACOS_DIST_OUTPUT}/include/openssl/
rm -rf "/tmp/${OPENSSL_VERSION}-*"
rm -rf "/tmp/${OPENSSL_VERSION}-*.log"
rm -rf "${OPENSSL_VERSION}"
}
downloadAndUnpack()
{
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"
}
cleanUp
downloadAndUnpack
echo "----------------------------------------"
echo "OpenSSL version: ${OPENSSL_VERSION}"
echo "macOS SDK version: ${MACOS_SDK_VERSION}"
echo "macOS deployment target: ${MACOS_DEPLOYMENT_VERSION}"
echo "----------------------------------------"
echo " "
buildMac "x86_64"
echo "Copying macOS headers"
echo "cp /tmp/${OPENSSL_VERSION}-x86_64/include/openssl/* ${MACOS_DIST_OUTPUT}/include/openssl/"
cp /tmp/${OPENSSL_VERSION}-x86_64/include/openssl/* ${MACOS_DIST_OUTPUT}/include/openssl/
echo "Copying macOS libraries"
cp /tmp/${OPENSSL_VERSION}-x86_64/lib/libcrypto.a ${MACOS_DIST_OUTPUT}/lib/libcrypto.a
cp /tmp/${OPENSSL_VERSION}-x86_64/lib/libssl.a ${MACOS_DIST_OUTPUT}/lib/libssl.a
echo "Compress macOS libraries"
tar --exclude='*DS_Store' -zcf ${MACOS_DIST_OUTPUT}.tar.gz ${MACOS_DIST_OUTPUT}
echo "----------------------------------------"
echo "OpenSSL version: ${OPENSSL_VERSION}"
echo "iOS SDK version: ${IOS_SDK_VERSION}"
echo "iOS deployment target: ${IOS_DEPLOYMENT_VERSION}"
echo "----------------------------------------"
echo " "
buildIOS "arm64"
buildIOS "x86_64"
echo "Copying iOS headers"
cp /tmp/${IOS_DIST_OUTPUT}-arm64/include/openssl/* ${IOS_DIST_OUTPUT}/include/openssl/
echo "Building iOS libraries"
lipo \
"/tmp/${IOS_DIST_OUTPUT}-arm64/lib/libcrypto.a" \
"/tmp/${IOS_DIST_OUTPUT}-x86_64/lib/libcrypto.a" \
-create -output ${IOS_DIST_OUTPUT}/lib/libcrypto.a
lipo \
"/tmp/${IOS_DIST_OUTPUT}-arm64/lib/libssl.a" \
"/tmp/${IOS_DIST_OUTPUT}-x86_64/lib/libssl.a" \
-create -output ${IOS_DIST_OUTPUT}/lib/libssl.a
echo "Compress iOS libraries"
tar --exclude='*DS_Store' -zcf ${IOS_DIST_OUTPUT}.tar.gz ${IOS_DIST_OUTPUT}
echo "Cleaning up"
rm -rf /tmp/${OPENSSL_VERSION}-*
rm -rf ${OPENSSL_VERSION}
popd > /dev/null
echo "Done"