-
Notifications
You must be signed in to change notification settings - Fork 29
/
curl-static-mac.sh
669 lines (548 loc) · 20.5 KB
/
curl-static-mac.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
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
#!/bin/bash
# To compile locally, clone the Git repository, navigate to the repository directory,
# and then execute the following command:
# ARCHES="x86_64 arm64" CURL_VERSION=8.6.0 TLS_LIB=openssl QUICTLS_VERSION=3.1.5 bash curl-static-mac.sh
shopt -s expand_aliases;
alias grep=rg;
alias sed=gsed;
alias awk=gawk;
alias stat=gstat;
alias make=gmake;
init_env() {
local number
export DIR="${DIR:-${HOME}/build}"
export RELEASE_DIR=${RELEASE_DIR:-${HOME}};
number=$(sysctl -n hw.ncpu 2>/dev/null)
export CPU_CORES=${number:-1}
case "${ENABLE_DEBUG}" in
true|1|yes|on|y|Y)
ENABLE_DEBUG="--enable-debug" ;;
*)
ENABLE_DEBUG="" ;;
esac
echo "Source directory: ${DIR}"
echo "Release directory: ${RELEASE_DIR}"
echo "cURL version: ${CURL_VERSION}"
echo "TLS Library: ${TLS_LIB}"
echo "QuicTLS version: ${QUICTLS_VERSION}"
echo "OpenSSL version: ${OPENSSL_VERSION}"
echo "ngtcp2 version: ${NGTCP2_VERSION}"
echo "nghttp3 version: ${NGHTTP3_VERSION}"
echo "nghttp2 version: ${NGHTTP2_VERSION}"
echo "zlib version: ${ZLIB_VERSION}"
echo "libunistring version: ${LIBUNISTRING_VERSION}"
echo "libidn2 version: ${LIBIDN2_VERSION}"
echo "libpsl version: ${LIBPSL_VERSION}"
echo "brotli version: ${BROTLI_VERSION}"
echo "zstd version: ${ZSTD_VERSION}"
echo "libssh2 version: ${LIBSSH2_VERSION}"
echo "c-ares version: ${ARES_VERSION}"
export LDFLAGS="-framework CoreFoundation -framework SystemConfiguration"
export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
mkdir -p "${DIR}"
}
install_packages() {
brew install --quiet automake autoconf libtool binutils pkg-config coreutils homebrew/core/cmake make llvm \
curl wget git jq xz ripgrep gnu-sed gawk groff gnupg pcre2 cunit ca-certificates;
}
_clang_path() {
# find the path of clang
clang_path=$(which /usr/local/opt/llvm/bin/clang || which /opt/homebrew/opt/llvm/bin/clang \
|| which /Library/Developer/CommandLineTools/usr/bin/clang || which clang || true)
clang_pp_path=$(which /usr/local/opt/llvm/bin/clang++ || which /opt/homebrew/opt/llvm/bin/clang++ \
|| which /Library/Developer/CommandLineTools/usr/bin/clang++ || which clang++ || true)
if [ -z "${clang_path}" ] || [ -z "${clang_pp_path}" ]; then
echo "clang not found"
exit 1
fi
}
arch_variants() {
echo "Setting up the ARCH and OpenSSL arch"
_clang_path;
[ -z "${ARCH}" ] && ARCH="$(uname -m)"
case "${ARCH}" in
x86_64) ARCHFLAGS="-arch x86_64"
OPENSSL_ARCH="darwin64-x86_64"
TARGET="x86_64-apple-darwin"
export CC="${clang_path} -target x86_64-apple-macos11"
export CXX="${clang_pp_path} -target x86_64-apple-macos11"
;;
arm64) ARCHFLAGS="-arch arm64"
OPENSSL_ARCH="darwin64-arm64"
TARGET="aarch64-apple-darwin"
export CC="${clang_path} -target arm64-apple-macos11"
export CXX="${clang_pp_path} -target arm64-apple-macos11"
;;
esac
}
_get_github() {
local repo release_file auth_header status_code size_of
repo=$1
release_file="github-${repo#*/}.json"
# GitHub API has a limit of 60 requests per hour, cache the results.
echo "Downloading ${repo} releases from GitHub"
echo "URL: https://api.github.com/repos/${repo}/releases"
# get token from github settings
auth_header=""
set +o xtrace
if [ -n "${TOKEN_READ}" ]; then
auth_header="token ${TOKEN_READ}"
fi
status_code=$(curl --retry 5 --retry-max-time 120 "https://api.github.com/repos/${repo}/releases" \
-w "%{http_code}" \
-o "${release_file}" \
-H "Authorization: ${auth_header}" \
-s -L --compressed)
set -o xtrace
size_of=$(stat -c "%s" "${release_file}")
if [ "${size_of}" -lt 200 ] || [ "${status_code}" -ne 200 ]; then
echo "The release of ${repo} is empty, download tags instead."
set +o xtrace
status_code=$(curl --retry 5 --retry-max-time 120 "https://api.github.com/repos/${repo}/tags" \
-w "%{http_code}" \
-o "${release_file}" \
-H "Authorization: ${auth_header}" \
-s -L --compressed)
set -o xtrace
fi
auth_header=""
if [ "${status_code}" -ne 200 ]; then
echo "ERROR. Failed to download ${repo} releases from GitHub, status code: ${status_code}"
cat "${release_file}"
exit 1
fi
}
_get_tag() {
# Function to get the latest tag based on given criteria
jq -c -r "[.[] | select(${2})][0]" "${1}" > /tmp/tmp_release.json;
}
_get_latest_tag() {
local release_file release_json
release_file=$1
# Get the latest tag that is not a draft and not a pre-release
_get_tag "${release_file}" "(.prerelease != true) and (.draft != true)"
release_json=$(cat /tmp/tmp_release.json)
# If no tag found, get the latest tag that is not a draft
if [ "${release_json}" = "null" ] || [ -z "${release_json}" ]; then
_get_tag "${release_file}" ".draft != true"
release_json=$(cat /tmp/tmp_release.json)
fi
# If still no tag found, get the first tag
if [ "${release_json}" = "null" ] || [ -z "${release_json}" ]; then
_get_tag "${release_file}" "."
fi
}
url_from_github() {
local browser_download_urls browser_download_url url repo version tag_name release_file
repo=$1
version=$2
release_file="github-${repo#*/}.json"
if [ ! -f "${release_file}" ]; then
_get_github "${repo}"
fi
if [ -z "${version}" ]; then
_get_latest_tag "${release_file}"
else
jq -c -r "map(select(.tag_name == \"${version}\")
// select(.tag_name | startswith(\"${version}\"))
// select(.tag_name | endswith(\"${version}\"))
// select(.tag_name | contains(\"${version}\"))
// select(.name == \"${version}\")
// select(.name | startswith(\"${version}\"))
// select(.name | endswith(\"${version}\"))
// select(.name | contains(\"${version}\")))[0]" \
"${release_file}" > /tmp/tmp_release.json
fi
browser_download_urls=$(jq -r '.assets[]' /tmp/tmp_release.json | grep browser_download_url || true)
if [ -n "${browser_download_urls}" ]; then
suffixes="tar.xz tar.gz tar.bz2 tgz"
for suffix in ${suffixes}; do
browser_download_url=$(printf "%s" "${browser_download_urls}" | grep "${suffix}\"" || true)
[ -n "$browser_download_url" ] && break
done
url=$(printf "%s" "${browser_download_url}" | head -1 | awk '{print $2}' | sed 's/"//g' || true)
fi
if [ -z "${url}" ]; then
tag_name=$(jq -r '.tag_name // .name' /tmp/tmp_release.json | head -1)
# get from "Source Code" of releases
if [ "${tag_name}" = "null" ] || [ "${tag_name}" = "" ]; then
echo "ERROR. Failed to get the ${version} from ${repo} of GitHub"
exit 1
fi
url="https://github.com/${repo}/archive/refs/tags/${tag_name}.tar.gz"
fi
rm -f /tmp/tmp_release.json;
URL="${url}"
}
download_and_extract() {
echo "Downloading $1"
local url
url="$1"
FILENAME=${url##*/}
if [ ! -f "${FILENAME}" ]; then
wget -c --no-verbose --content-disposition "${url}";
FILENAME=$(curl --retry 5 --retry-max-time 120 -sIL "${url}" | sed -n -e 's/^Content-Disposition:.*filename=//ip' | \
tail -1 | sed 's/\r//g; s/\n//g; s/\"//g' | grep -oP '[\x20-\x7E]+' || true)
if [ "${FILENAME}" = "" ]; then
FILENAME=${url##*/}
fi
echo "Downloaded ${FILENAME}"
else
echo "Already downloaded ${FILENAME}"
fi
# If the file is a tarball, extract it
if echo "${FILENAME}" | grep -qP '.*\.(tar\.xz|tar\.gz|tar\.bz2|tgz)$'; then
# SOURCE_DIR=$(echo "${FILENAME}" | sed -E "s/\.tar\.(xz|bz2|gz)//g" | sed 's/\.tgz//g')
SOURCE_DIR=$(tar -tf "${FILENAME}" | head -n 1 | cut -d'/' -f1)
[ -d "${SOURCE_DIR}" ] && rm -rf "${SOURCE_DIR}"
tar -xf "${FILENAME}"
cd "${SOURCE_DIR}"
fi
}
change_dir() {
mkdir -p "${DIR}";
cd "${DIR}";
}
_copy_license() {
# $1: original file name; $2: target file name
mkdir -p "${PREFIX}/licenses/";
cp -p "${1}" "${PREFIX}/licenses/${2}";
}
compile_zlib() {
echo "Compiling zlib, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
url_from_github madler/zlib "${ZLIB_VERSION}"
url="${URL}"
download_and_extract "${url}"
./configure --prefix="${PREFIX}" --static;
make -j "${CPU_CORES}";
make install;
_copy_license LICENSE zlib;
}
compile_libunistring() {
echo "Compiling libunistring, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
[ -z "${LIBUNISTRING_VERSION}" ] && LIBUNISTRING_VERSION="latest"
url="https://mirrors.kernel.org/gnu/libunistring/libunistring-${LIBUNISTRING_VERSION}.tar.xz"
download_and_extract "${url}"
./configure --host="${TARGET}" --prefix="${PREFIX}" --disable-rpath --disable-shared;
make -j "${CPU_CORES}";
make install;
_copy_license COPYING libunistring;
}
compile_libidn2() {
echo "Compiling libidn2, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
[ -z "${LIBIDN2_VERSION}" ] && LIBIDN2_VERSION="latest"
url="https://mirrors.kernel.org/gnu/libidn/libidn2-${LIBIDN2_VERSION}.tar.gz"
download_and_extract "${url}"
PKG_CONFIG="pkg-config --static" \
./configure \
--host="${TARGET}" \
--with-libunistring-prefix="${PREFIX}" \
--prefix="${PREFIX}" \
--disable-shared;
make -j "${CPU_CORES}";
make install;
_copy_license COPYING libidn2;
}
compile_libpsl() {
echo "Compiling libpsl, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
url_from_github rockdaboot/libpsl "${LIBPSL_VERSION}"
url="${URL}"
download_and_extract "${url}"
PKG_CONFIG="pkg-config --static --with-path=${PREFIX}/lib/pkgconfig:${PREFIX}/lib64/pkgconfig" \
LDFLAGS="-L${PREFIX}/lib -L${PREFIX}/lib64 ${LDFLAGS}" \
./configure --host="${TARGET}" --prefix="${PREFIX}" \
--enable-static --enable-shared=no --enable-builtin --disable-runtime;
make -j "${CPU_CORES}";
make install;
_copy_license LICENSE libpsl;
}
compile_ares() {
echo "Compiling c-ares, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
url_from_github c-ares/c-ares "${ARES_VERSION}"
url="${URL}"
download_and_extract "${url}"
./configure --host="${TARGET}" --prefix="${PREFIX}" --enable-static --disable-shared;
make -j "$(nproc)";
make install;
_copy_license LICENSE.md c-ares;
}
compile_tls() {
echo "Compiling ${TLS_LIB}, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
if [ "${TLS_LIB}" = "openssl" ]; then
url_from_github openssl/openssl "${OPENSSL_VERSION}"
else
url_from_github quictls/openssl "${QUICTLS_VERSION}"
fi
url="${URL}"
download_and_extract "${url}"
./Configure \
${OPENSSL_ARCH} \
-fPIC \
--prefix="${PREFIX}" \
--openssldir=/etc/ssl \
threads no-shared \
enable-ktls \
enable-ec_nistp_64_gcc_128 \
enable-tls1_3 \
enable-ssl3 enable-ssl3-method \
enable-des enable-rc4 \
enable-weak-ssl-ciphers;
make -j "${CPU_CORES}";
make install_sw;
_copy_license LICENSE.txt openssl;
}
compile_libssh2() {
echo "Compiling libssh2, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
url_from_github libssh2/libssh2 "${LIBSSH2_VERSION}"
url="${URL}"
download_and_extract "${url}"
autoreconf -fi
PKG_CONFIG="pkg-config --static" \
LDFLAGS="-L${PREFIX}/lib ${LDFLAGS}" CFLAGS="-O3" \
./configure --host="${TARGET}" --prefix="${PREFIX}" --enable-static --enable-shared=no \
--with-crypto=openssl --with-libssl-prefix="${PREFIX}";
make -j "${CPU_CORES}";
make install;
_copy_license COPYING libssh2;
}
compile_nghttp2() {
echo "Compiling nghttp2, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
url_from_github nghttp2/nghttp2 "${NGHTTP2_VERSION}"
url="${URL}"
download_and_extract "${url}"
autoreconf -i --force
PKG_CONFIG="pkg-config --static" \
./configure --host="${TARGET}" --prefix="${PREFIX}" --enable-static --enable-http3 \
--enable-lib-only --enable-shared=no;
make -j "${CPU_CORES}";
make install;
_copy_license COPYING nghttp2;
}
compile_ngtcp2() {
echo "Compiling ngtcp2, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
if [ "${TLS_LIB}" = "openssl" ]; then
return
fi
local url
change_dir;
url_from_github ngtcp2/ngtcp2 "${NGTCP2_VERSION}"
url="${URL}"
download_and_extract "${url}"
autoreconf -i --force
PKG_CONFIG="pkg-config --static" \
./configure --host="${TARGET}" --prefix="${PREFIX}" --enable-static --with-openssl="${PREFIX}" \
--with-libnghttp3="${PREFIX}" --enable-lib-only --enable-shared=no;
make -j "${CPU_CORES}";
make install;
cp -a crypto/includes/ngtcp2/ngtcp2_crypto_quictls.h crypto/includes/ngtcp2/ngtcp2_crypto.h \
"${PREFIX}/include/ngtcp2/"
_copy_license COPYING ngtcp2;
}
compile_nghttp3() {
echo "Compiling nghttp3, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
url_from_github ngtcp2/nghttp3 "${NGHTTP3_VERSION}"
url="${URL}"
download_and_extract "${url}"
autoreconf -i --force
PKG_CONFIG="pkg-config --static" \
./configure --host="${TARGET}" --prefix="${PREFIX}" --enable-static --enable-shared=no \
--enable-lib-only --disable-dependency-tracking;
make -j "${CPU_CORES}";
make install;
_copy_license COPYING nghttp3;
}
compile_brotli() {
echo "Compiling brotli, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
url_from_github google/brotli "${BROTLI_VERSION}"
url="${URL}"
download_and_extract "${url}"
mkdir -p out
cd out/
PKG_CONFIG="pkg-config --static" \
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX="${PREFIX}" -DBUILD_SHARED_LIBS=OFF \
-DCMAKE_OSX_ARCHITECTURES:STRING="${ARCH}" ..;
PKG_CONFIG="pkg-config --static" \
cmake --build . --config Release --target install;
_copy_license ../LICENSE brotli;
cd "${PREFIX}/lib/"
if [ -f libbrotlidec-static.a ] && [ ! -f libbrotlidec.a ]; then ln -f libbrotlidec-static.a libbrotlidec.a; fi
if [ -f libbrotlienc-static.a ] && [ ! -f libbrotlienc.a ]; then ln -f libbrotlienc-static.a libbrotlienc.a; fi
if [ -f libbrotlicommon-static.a ] && [ ! -f libbrotlicommon.a ]; then ln -f libbrotlicommon-static.a libbrotlicommon.a; fi
}
compile_zstd() {
echo "Compiling zstd, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
url_from_github facebook/zstd "${ZSTD_VERSION}"
url="${URL}"
download_and_extract "${url}"
PKG_CONFIG="pkg-config --static" \
make -j "${CPU_CORES}" PREFIX="${PREFIX}";
make install;
_copy_license LICENSE zstd
}
curl_config() {
echo "Configuring curl, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local with_openssl_quic
# --with-openssl-quic and --with-ngtcp2 are mutually exclusive
with_openssl_quic=""
if [ "${TLS_LIB}" = "openssl" ]; then
with_openssl_quic="--with-openssl-quic"
else
with_openssl_quic="--with-ngtcp2"
fi
if [ ! -f configure ]; then
autoreconf -fi;
fi
PKG_CONFIG="pkg-config --static" \
./configure \
--host="${ARCH}-apple-darwin" \
--prefix="${PREFIX}" \
--disable-shared --enable-static \
--with-openssl "${with_openssl_quic}" --with-brotli --with-zstd \
--with-nghttp2 --with-nghttp3 \
--with-libidn2 --with-libssh2 \
--enable-hsts --enable-mime --enable-cookies \
--enable-http-auth --enable-manual \
--enable-proxy --enable-file --enable-http \
--enable-ftp --enable-telnet --enable-tftp \
--enable-pop3 --enable-imap --enable-smtp \
--enable-gopher --enable-mqtt \
--enable-doh --enable-dateparse --enable-verbose \
--enable-alt-svc --enable-websockets \
--enable-ipv6 --enable-unix-sockets --enable-socketpair \
--enable-headers-api --enable-versioned-symbols \
--enable-threaded-resolver --enable-optimize --enable-pthreads \
--enable-warnings --enable-werror \
--enable-curldebug --enable-dict --enable-netrc \
--enable-bearer-auth --enable-tls-srp --enable-dnsshuffle \
--enable-get-easy-options --enable-progress-meter \
--with-ca-bundle=/etc/ssl/cert.pem \
--with-ca-path=/etc/ssl/certs \
--with-ca-fallback --enable-ares \
--disable-ldap --disable-ldaps --disable-rtsp \
--disable-rtmp --disable-rtmps "${ENABLE_DEBUG}" \
CFLAGS="-I${PREFIX}/include" \
CPPFLAGS="-I${PREFIX}/include";
}
compile_curl() {
echo "Compiling cURL, Arch: ${ARCH}" | tee "${RELEASE_DIR}/running"
local url
change_dir;
# move the dylib
mkdir -p "${PREFIX}/lib/dylib"
mv "${PREFIX}/lib/"*.dylib "${PREFIX}/lib/dylib/"
if [ "${CURL_VERSION}" = "dev" ]; then
if [ ! -d "curl-dev" ]; then
git clone --depth 1 https://github.com/curl/curl.git curl-dev;
fi
cd curl-dev;
make clean || true;
else
url_from_github curl/curl "${CURL_VERSION}";
url="${URL}";
download_and_extract "${url}";
[ -z "${CURL_VERSION}" ] && CURL_VERSION=$(echo "${SOURCE_DIR}" | cut -d'-' -f 2);
fi
if [ ! -f src/.checksrc ]; then echo "enable STDERR" > src/.checksrc; fi
curl_config;
LDFLAGS="-L${PREFIX}/lib -static -all-static -Wl,-s ${LDFLAGS}" \
CFLAGS="-I${PREFIX}/include -I${PREFIX}/include/brotli" \
CPPFLAGS="-I${PREFIX}/include -I${PREFIX}/include/brotli" \
make -j "${CPU_CORES}";
_copy_license COPYING curl;
make install;
}
install_curl() {
mkdir -p "${RELEASE_DIR}/release/bin/"
ls -l "${PREFIX}"/bin/curl;
cp -pf "${PREFIX}/bin/curl" "${RELEASE_DIR}/release/bin/curl-macos-${ARCH}";
${PREFIX}/bin/curl -V || true
if [ ! -f "${RELEASE_DIR}/version.txt" ]; then
echo "${CURL_VERSION}" > "${RELEASE_DIR}/version.txt"
fi
XZ_OPT=-9 tar -Jcf "${RELEASE_DIR}/release/curl-macos-${ARCH}-dev-${CURL_VERSION}.tar.xz" -C "${DIR}" "curl-${ARCH}"
}
_arch_match() {
local arch_search="$1"
local arch_array="$2"
for element in ${arch_array}; do
if [ "${element}" = "${arch_search}" ]; then
return 0 # in the array
fi
done
return 1 # not in the array
}
_arch_valid() {
local arches="x86_64 arm64"
return $(_arch_match "${ARCH}" "${arches}")
}
compile() {
arch_variants;
compile_tls;
compile_zlib;
compile_zstd;
compile_libunistring;
compile_libidn2;
compile_libpsl;
compile_ares;
compile_libssh2;
compile_nghttp3;
compile_ngtcp2;
compile_nghttp2;
compile_brotli;
compile_curl;
install_curl;
}
main() {
local arch_temp
if [ "${ARCHES}" = "" ] && [ "${ARCHS}" = "" ] && [ "${ARCH}" = "" ]; then
ARCHES="$(uname -m)";
elif [ "${ARCHES}" = "" ] && [ "${ARCHS}" != "" ]; then
ARCHES="${ARCHS}"; # previous misspellings, keep this parameter for compatibility
elif [ "${ARCHES}" = "" ] && [ "${ARCH}" != "" ]; then
ARCHES="${ARCH}";
fi
init_env; # Initialize the build env
install_packages; # Install dependencies
set -o errexit -o xtrace;
echo "Compiling for all ARCHes: ${ARCHES}"
for arch_temp in ${ARCHES}; do
# Set the ARCH, PREFIX and PKG_CONFIG_PATH env variables
export ARCH=${arch_temp}
export PREFIX="${DIR}/curl-${ARCH}"
export PKG_CONFIG_PATH="${PREFIX}/lib/pkgconfig"
echo "Architecture: ${ARCH}"
echo "Prefix directory: ${PREFIX}"
if _arch_valid; then
compile;
else
echo "Unsupported architecture ${ARCH}";
fi
done
}
# If the first argument is not "--source-only" then run the script,
# otherwise just provide the functions
if [ "$1" != "--source-only" ]; then
main "$@";
fi