-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-apple.sh
executable file
·239 lines (187 loc) · 7.11 KB
/
build-apple.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/bin/sh
if [ -z "$1" ]; then
echo "Usage: $0 <CURL Version>"
exit 1
fi
OPENSSL_VERSION="openssl-3.4.0"
VERSION=$1
shift
BUILD_ARGS="$@"
BUILD_ARGS="--disable-shared --enable-static --with-openssl --without-libpsl --without-libidn2 --without-nghttp2 ${BUILD_ARGS}"
cd "$(dirname "$0")" || exit
ROOT="$(pwd -P)"
BUILDDIR="$ROOT/build"
rm -rf "$BUILDDIR"
mkdir -p "$BUILDDIR"
cd "$BUILDDIR" || exit
build_libssl() {
SDK=$1
ARCH=$2
MIN=$3
SOURCE="$BUILDDIR/openssl"
LOG="$BUILDDIR/libssl-$SDK-$ARCH.log"
if [ ! -d "$SOURCE" ]; then
echo "- Check out OpenSSL $OPENSSL_VERSION"
git clone --recursive --shallow-submodules --depth 1 --branch "$OPENSSL_VERSION" https://github.com/openssl/openssl.git >> "$LOG" 2>&1
fi
echo "- Build OpenSSL for $ARCH ($SDK)"
cd "$SOURCE" || exit
make distclean >> "$LOG" 2>&1
if [ "$SDK" = "iphoneos" ]; then
if [ "$ARCH" = "arm64" ]; then
PLATFORM_FLAGS="no-async zlib-dynamic enable-ec_nistp_64_gcc_128"
CONFIG="ios64-xcrun"
elif [ "$ARCH" = "armv7" ]; then
PLATFORM_FLAGS="no-async zlib-dynamic"
CONFIG="ios-xcrun"
else
echo "OpenSSL configuration error: $ARCH on $SDK not supported!"
fi
elif [ "$SDK" = "iphonesimulator" ]; then
if [ "$ARCH" = "arm64" ]; then
PLATFORM_FLAGS="no-async zlib-dynamic enable-ec_nistp_64_gcc_128"
CONFIG="iossimulator-xcrun"
elif [ "$ARCH" = "i386" ]; then
PLATFORM_FLAGS="no-asm"
CONFIG="iossimulator-xcrun"
elif [ "$ARCH" = "x86_64" ]; then
PLATFORM_FLAGS="no-asm enable-ec_nistp_64_gcc_128"
CONFIG="iossimulator-xcrun"
else
echo "OpenSSL configuration error: $ARCH on $SDK not supported!"
fi
elif [ "$SDK" = "macosx" ]; then
if [ "$ARCH" = "i386" ]; then
PLATFORM_FLAGS="no-asm"
CONFIG="darwin-i386-cc"
elif [ "$ARCH" = "x86_64" ]; then
PLATFORM_FLAGS="no-asm enable-ec_nistp_64_gcc_128"
CONFIG="darwin64-x86_64-cc"
elif [ "$ARCH" = "arm64" ]; then
PLATFORM_FLAGS="no-asm enable-ec_nistp_64_gcc_128"
CONFIG="darwin64-arm64-cc"
else
echo "OpenSSL configuration error: $ARCH on $SDK not supported!"
fi
fi
if [ -n "$CONFIG" ]; then
./Configure \
no-shared \
${PLATFORM_FLAGS} \
--prefix="$BUILDDIR/$SDK/libssl-$ARCH" \
${CONFIG} \
CC="$(xcrun --sdk $SDK --find clang) -isysroot $(xcrun --sdk $SDK --show-sdk-path) -arch ${ARCH} -m$SDK-version-min=$MIN -fembed-bitcode" \
>> "$LOG" 2>&1
make depend >> "$LOG" 2>&1
make "-j$(sysctl -n hw.logicalcpu_max)" build_libs >> "$LOG" 2>&1
make install_dev >> "$LOG" 2>&1
fi
}
build_libcurl() {
SDK=$1
ARCH=$2
MIN=$3
SOURCE="$BUILDDIR/libcurl"
LOG="$BUILDDIR/libcurl-$SDK-$ARCH.log"
ARCHIVE="$BUILDDIR/curl-$VERSION.tar.gz"
if [ ! -f "$ARCHIVE" ]; then
echo "- Download libcurl $VERSION"
curl "https://curl.se/download/curl-$VERSION.tar.gz" > "$ARCHIVE"
fi
if [ -n "$GPG_VERIFY" ]; then
echo "- Verify signature for curl-$VERSION.tar.gz"
rm -f "$ARCHIVE.asc"
curl "https://curl.se/download/curl-$VERSION.tar.gz.asc" > "$ARCHIVE.asc"
gpg --verify "$ARCHIVE.asc" "$ARCHIVE" >/dev/null || exit
fi
# https://curl.se/docs/caextract.html
CERTS="$BUILDDIR/cacert.pem"
if [ ! -f "$CERTS" ]; then
echo "- Download cacert file"
curl "https://curl.se/ca/cacert.pem" > "$CERTS"
fi
echo "- Build libcurl for $ARCH ($SDK)"
# curl build writes compiled files into source dir, so clean up, by removing and unpacking again.
rm -rf "$SOURCE"
mkdir -p "$SOURCE"
tar -xzf "$ARCHIVE" -C "$SOURCE" --strip-components 1
cd "$SOURCE" || exit
for FILE in $(find "$ROOT/patches" -name '*.patch' 2>/dev/null); do
patch -p1 < "$FILE"
done
SDKDIR=$(xcrun --sdk "$SDK" --show-sdk-path)
echo "configure parameters: $BUILD_ARGS" >> "$LOG"
HOST="$ARCH"
if [ "$ARCH" = "arm64" ]; then
HOST="arm"
fi
./configure \
--host="$HOST-apple-darwin" \
$BUILD_ARGS \
--prefix "$BUILDDIR/$SDK/libcurl-$ARCH" \
CC="$(xcrun -find -sdk $SDK gcc)" \
CFLAGS="-arch $ARCH -pipe -Os -gdwarf-2 -isysroot $SDKDIR -m$SDK-version-min=$MIN" \
CPPFLAGS="-I$BUILDDIR/$SDK/libssl-$ARCH/include" \
LDFLAGS="-arch $ARCH -isysroot $SDKDIR -L$BUILDDIR/$SDK/libssl-$ARCH/lib" \
>> "$LOG" 2>&1
make "-j$(sysctl -n hw.logicalcpu_max)" >> "$LOG" 2>&1
make install >> "${LOG}" 2>&1
}
fatten() {
SDK=$1
NAME=$2
LIB=${3:-$NAME}
echo "- Fatten $LIB in $NAME ($SDK)"
mkdir -p "$BUILDDIR/$SDK/$NAME/lib"
lipo \
-arch arm64 "$BUILDDIR/$SDK/$NAME-arm64/lib/$LIB.a" \
-arch x86_64 "$BUILDDIR/$SDK/$NAME-x86_64/lib/$LIB.a" \
-create -output "$BUILDDIR/$SDK/$NAME/lib/$LIB.a"
}
create_framework() {
SDK=$1
IS_FAT=$2
mkdir -p "$BUILDDIR/$SDK/curl.framework/Headers"
mkdir -p "$BUILDDIR/$SDK/curl.framework/Resources"
if [ -z "$IS_FAT" ]; then
echo "- Create framework for $SDK"
POSTFIX="-arm64"
else
echo "- Create framework for fat $SDK"
POSTFIX=""
fi
LIBS=("$BUILDDIR/$SDK/libssl$POSTFIX/lib/libssl.a" \
"$BUILDDIR/$SDK/libssl$POSTFIX/lib/libcrypto.a" \
"$BUILDDIR/$SDK/libcurl$POSTFIX/lib/libcurl.a")
libtool -no_warning_for_no_symbols -static -o "$BUILDDIR/$SDK/curl.framework/curl" "${LIBS[@]}"
HEADERS=("$BUILDDIR/$SDK/libssl-arm64/include"/* \
"$BUILDDIR/$SDK/libcurl-arm64/include/curl"/*)
cp -r "${HEADERS[@]}" "$BUILDDIR/$SDK/curl.framework/Headers"
cp "$BUILDDIR/cacert.pem" "$BUILDDIR/$SDK/curl.framework/Resources"
}
build_libssl iphoneos arm64 12.0
build_libcurl iphoneos arm64 12.0
create_framework iphoneos
build_libssl iphonesimulator arm64 12.0
build_libssl iphonesimulator x86_64 12.0
fatten iphonesimulator libssl
fatten iphonesimulator libssl libcrypto
build_libcurl iphonesimulator arm64 12.0
build_libcurl iphonesimulator x86_64 12.0
fatten iphonesimulator libcurl
create_framework iphonesimulator fat
build_libssl macosx arm64 10.13
build_libssl macosx x86_64 10.13
fatten macosx libssl
fatten macosx libssl libcrypto
build_libcurl macosx arm64 10.13
build_libcurl macosx x86_64 10.13
fatten macosx libcurl
create_framework macosx fat
rm -rf "$ROOT/curl.xcframework"
xcodebuild -create-xcframework \
-framework "$BUILDDIR/iphoneos/curl.framework" \
-framework "$BUILDDIR/iphonesimulator/curl.framework" \
-framework "$BUILDDIR/macosx/curl.framework" \
-output "$ROOT/curl.xcframework"
plutil -insert CFBundleVersion -string "$VERSION" "$ROOT/curl.xcframework/Info.plist"