forked from jasonacox/Build-OpenSSL-cURL
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·206 lines (189 loc) · 6.11 KB
/
build.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
203
204
205
206
#!/bin/bash
# This script builds openssl+libcurl libraries for MacOS, iOS and tvOS
#
# Jason Cox, @jasonacox
# https://github.com/jasonacox/Build-OpenSSL-cURL
#
################################################
# EDIT this section to Select Default Versions #
################################################
OPENSSL="1.1.1g" # https://www.openssl.org/source/
LIBCURL="7.71.1" # https://curl.haxx.se/download.html
NGHTTP2="1.41.0" # https://nghttp2.org/
IOS_SDK_VERSION=$(xcrun --sdk iphoneos --show-sdk-version)
TVOS_SDK_VERSION=$(xcrun --sdk appletvos --show-sdk-version)
BUILD_LIST=("Mac-x86_64" "iOS-armv7" "iOS-armv7s" "iOS-arm64" "iOS-arm64e" "iOS-x86_64" "iOS-i386" "tvOS-arm64" "tvOS-x86_64")
################################################
# Global flags
engine=""
buildnghttp2="-n"
disablebitcode=""
colorflag=""
# Formatting
default="\033[39m"
wihte="\033[97m"
green="\033[32m"
red="\033[91m"
yellow="\033[33m"
bold="\033[0m${white}\033[1m"
subbold="\033[0m${green}"
normal="${white}\033[0m"
dim="\033[0m${white}\033[2m"
alert="\033[0m${red}\033[1m"
alertdim="\033[0m${red}\033[2m"
usage ()
{
echo
echo -e "${bold}Usage:${normal}"
echo
echo -e " ${subbold}$0${normal} [-o ${dim}<OpenSSL version>${normal}] [-c ${dim}<curl version>${normal}] [-n ${dim}<nghttp2 version>${normal}] [-d] [-e] [-x] [-h]"
echo
echo " -o <version> Build OpenSSL version (default $OPENSSL)"
echo " -c <version> Build curl version (default $LIBCURL)"
echo " -n <version> Build nghttp2 version (default $NGHTTP2)"
echo " -s <version> iOS SDK version (default $IOS_SDK_VERSION)"
echo " -t <version> tvOS SDK version (default $TVOS_SDK_VERSION)"
echo " -l space separated list to restrict targets to build: eg. \"iOS-arm64 iOS-x86_64 tvOS-armV7 Mac-arm64\""
echo " -d Compile without HTTP2 support"
echo " -e Compile with OpenSSL engine support"
echo " -b Compile without bitcode"
echo " -x No color output"
echo " -h Show usage"
echo
exit 127
}
while getopts "o:c:n:s:t:l:debxh\?" o; do
case "${o}" in
o)
OPENSSL="${OPTARG}"
;;
c)
LIBCURL="${OPTARG}"
;;
n)
NGHTTP2="${OPTARG}"
;;
s)
IOS_SDK_VERSION="${OPTARG}"
;;
t)
TVOS_SDK_VERSION="${OPTARG}"
;;
l)
BUILD_LIST=()
BUILD_LIST="${OPTARG}"
;;
d)
buildnghttp2=""
;;
e)
engine="-e"
;;
b)
disablebitcode="-b"
;;
x)
bold=""
subbold=""
normal=""
dim=""
alert=""
alertdim=""
colorflag="-x"
;;
*)
usage
;;
esac
done
shift $((OPTIND-1))
## Welcome
echo -e "${bold}Build-OpenSSL-cURL${dim}"
echo "This script builds OpenSSL, nghttp2 and libcurl for MacOS (OS X), iOS and tvOS devices."
echo "Targets: x86_64, armv7, armv7s, arm64 and arm64e"
echo
## OpenSSL Build
echo
cd openssl
echo -e "${bold}Building OpenSSL${normal}"
./openssl-build.sh -v "$OPENSSL" $engine $colorflag -s "$IOS_SDK_VERSION" -t "$TVOS_SDK_VERSION" -l "$BUILD_LIST"
cd ..
## Nghttp2 Build
if [ "$buildnghttp2" == "" ]; then
NGHTTP2="NONE"
else
echo
echo -e "${bold}Building nghttp2 for HTTP2 support${normal}"
cd nghttp2
./nghttp2-build.sh -v "$NGHTTP2" $colorflag -s "$IOS_SDK_VERSION" -t "$TVOS_SDK_VERSION" -l "$BUILD_LIST"
cd ..
fi
## Curl Build
echo
echo -e "${bold}Building Curl${normal}"
cd curl
./libcurl-build.sh -v "$LIBCURL" $disablebitcode $colorflag $buildnghttp2 -s "$IOS_SDK_VERSION" -t "$TVOS_SDK_VERSION" -l "$BUILD_LIST"
cd ..
echo
echo -e "${bold}Libraries...${normal}"
echo
echo -e "${subbold}openssl${normal} [${dim}$OPENSSL${normal}]${dim}"
xcrun -sdk iphoneos lipo -info openssl/*/lib/*.a
echo
echo -e "${subbold}nghttp2 (rename to libnghttp2.a)${normal} [${dim}$NGHTTP2${normal}]${dim}"
xcrun -sdk iphoneos lipo -info nghttp2/lib/*.a
echo
echo -e "${subbold}libcurl (rename to libcurl.a)${normal} [${dim}$LIBCURL${normal}]${dim}"
xcrun -sdk iphoneos lipo -info curl/lib/*.a
EXAMPLE="example/iOS Test App"
ARCHIVE="archive/libcurl-$LIBCURL-openssl-$OPENSSL-nghttp2-$NGHTTP2"
echo
echo -e "${bold}Creating archive for release v$LIBCURL...${dim}"
echo " See $ARCHIVE"
mkdir -p "$ARCHIVE"
mkdir -p "$ARCHIVE/include/openssl"
mkdir -p "$ARCHIVE/include/curl"
mkdir -p "$ARCHIVE/lib/iOS"
mkdir -p "$ARCHIVE/lib/MacOS"
mkdir -p "$ARCHIVE/lib/tvOS"
mkdir -p "$ARCHIVE/bin"
# archive libraries
cp curl/lib/libcurl_iOS.a $ARCHIVE/lib/iOS/libcurl.a
cp curl/lib/libcurl_tvOS.a $ARCHIVE/lib/tvOS/libcurl.a
cp curl/lib/libcurl_Mac.a $ARCHIVE/lib/MacOS/libcurl.a
cp openssl/iOS/lib/libcrypto.a $ARCHIVE/lib/iOS/libcrypto.a
cp openssl/tvOS/lib/libcrypto.a $ARCHIVE/lib/tvOS/libcrypto.a
cp openssl/Mac/lib/libcrypto.a $ARCHIVE/lib/MacOS/libcrypto.a
cp openssl/iOS/lib/libssl.a $ARCHIVE/lib/iOS/libssl.a
cp openssl/tvOS/lib/libssl.a $ARCHIVE/lib/tvOS/libssl.a
cp openssl/Mac/lib/libssl.a $ARCHIVE/lib/MacOS/libssl.a
cp nghttp2/lib/libnghttp2_iOS.a $ARCHIVE/lib/iOS/libnghttp2.a
cp nghttp2/lib/libnghttp2_tvOS.a $ARCHIVE/lib/tvOS/libnghttp2.a
cp nghttp2/lib/libnghttp2_Mac.a $ARCHIVE/lib/MacOS/libnghttp2.a
# archive header files
cp openssl/iOS/include/openssl/* "$ARCHIVE/include/openssl"
cp curl/include/curl/* "$ARCHIVE/include/curl"
# archive root certs
curl -s https://curl.haxx.se/ca/cacert.pem > $ARCHIVE/cacert.pem
sed -e "s/ZZZLIBCURL/$LIBCURL/g" -e "s/ZZZOPENSSL/$OPENSSL/g" -e "s/ZZZNGHTTP2/$NGHTTP2/g" archive/release-template.md > $ARCHIVE/README.md
echo
echo -e "${bold}Copying libraries to Test App ...${dim}"
echo " See $EXAMPLE"
cp openssl/iOS/lib/libcrypto.a "$EXAMPLE/libs/libcrypto.a"
cp openssl/iOS/lib/libssl.a "$EXAMPLE/libs/libssl.a"
cp openssl/iOS/include/openssl/* "$EXAMPLE/include/openssl/"
cp curl/include/curl/* "$EXAMPLE/include/curl/"
cp curl/lib/libcurl_iOS.a "$EXAMPLE/libs/libcurl.a"
cp nghttp2/lib/libnghttp2_iOS.a "$EXAMPLE/libs/libnghttp2.a"
cp $ARCHIVE/cacert.pem "$EXAMPLE/cacert.pem"
echo
echo -e "${bold}Archiving Mac binaries for curl and openssl...${dim}"
echo " See $ARCHIVE/bin"
mv /tmp/curl $ARCHIVE/bin
mv /tmp/openssl $ARCHIVE/bin
echo
echo -e "${bold}Testing Mac curl binary...${dim}"
$ARCHIVE/bin/curl -V
echo
echo -e "${normal}Done"
rm -f $NOHTTP2