forked from JCMais/node-libcurl
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathbuild-libcurl.sh
executable file
·288 lines (240 loc) · 8.41 KB
/
build-libcurl.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
#!/usr/bin/env bash
# If running this from a macOS, you will need pkgconfig
# brew install pkgconfig
# <release> <dest_folder>
set -euo pipefail
build_folder=$2/build/$1
curr_dirname=$(dirname "$0")
. $curr_dirname/utils/gsort.sh
mkdir -p $build_folder
mkdir -p $2/source
FORCE_REBUILD=${FORCE_REBUILD:-}
FORCE_REBUILD_LIBCURL=${FORCE_REBUILD_LIBCURL:-}
RUNNER_OS=${RUNNER_OS:-}
# @TODO force rebuild on macOS, remove this later
if [ "${RUNNER_OS}" == "macOS" ]; then
FORCE_REBUILD_LIBCURL="true"
fi
# @TODO We are explicitly checking the static lib
if [[ -f $build_folder/lib/libcurl.a ]] && [[ -z $FORCE_REBUILD || $FORCE_REBUILD != "true" ]] && [[ -z $FORCE_REBUILD_LIBCURL || $FORCE_REBUILD_LIBCURL != "true" ]]; then
echo "Skipping rebuild of libcurl because lib file already exists"
exit 0
fi
version_with_dashes=$(echo $1 | sed 's/\./_/g')
echo "Preparing release for libcurl $1"
# Libs build folders
LIBIDN2_BUILD_FOLDER=${LIBIDN2_BUILD_FOLDER:-}
LIBUNISTRING_BUILD_FOLDER=${LIBUNISTRING_BUILD_FOLDER:-}
KERBEROS_BUILD_FOLDER=${KERBEROS_BUILD_FOLDER:-}
HEIMDAL_BUILD_FOLDER=${HEIMDAL_BUILD_FOLDER:-}
OPENLDAP_BUILD_FOLDER=${OPENLDAP_BUILD_FOLDER:-}
LIBSSH2_BUILD_FOLDER=${LIBSSH2_BUILD_FOLDER:-}
NGHTTP2_BUILD_FOLDER=${NGHTTP2_BUILD_FOLDER:-}
OPENSSL_BUILD_FOLDER=${OPENSSL_BUILD_FOLDER:-}
CARES_BUILD_FOLDER=${CARES_BUILD_FOLDER:-}
BROTLI_BUILD_FOLDER=${BROTLI_BUILD_FOLDER:-}
ZLIB_BUILD_FOLDER=${ZLIB_BUILD_FOLDER:-}
LIBS=${LIBS:-}
CPPFLAGS=${CPPFLAGS:-}
LDFLAGS=${LDFLAGS:-}
libcurl_args=()
# libcurl only started having proper releases only with 7.54
# Up to 7.53.1 only source tarballs were available, so the url
# needs to be changed to something like: https://github.com/curl/curl/archive/curl-7_53_1.tar.gz
# And as it is just a source tarball, we must also create the ./configure script
is_less_than_7_54_0=0
(printf '%s\n%s' "7.54.0" "$1" | $gsort -CV) || is_less_than_7_54_0=$?
if [ ! -d $2/source/$1 ]; then
if [ "$is_less_than_7_54_0" == "1" ]; then
echo "Using source tarball instead of release because this libcurl version does not have releases"
$curr_dirname/download-and-unpack.sh \
https://github.com/curl/curl/archive/curl-$version_with_dashes.tar.gz \
$2
mv $2/curl-curl-$version_with_dashes $2/source/$1
cd $2/source/$1
./buildconf
else
echo "Using release tarball"
$curr_dirname/download-and-unpack.sh \
https://github.com/curl/curl/releases/download/curl-$version_with_dashes/curl-$1.tar.gz \
$2
mv $2/curl-$1 $2/source/$1
cd $2/source/$1
fi
else
cd $2/source/$1
if [ -f ./configure ]; then
make distclean || true;
else
./buildconf
fi
fi
# https://github.com/curl/curl/pull/1427#issuecomment-295783852
# The detection for ldl was broken for libcurl < 7.54.1
# pthread is only needed if using OpenSSL >= 1.1.0, however we are just addind it anyway as required
# no harm done
is_less_than_7_54_1=0
(printf '%s\n%s' "7.54.1" "$1" | $gsort -CV) || is_less_than_7_54_1=$?
if [ "$is_less_than_7_54_1" == "1" ]; then
LIBS="$LIBS -ldl -lpthread"
fi
# --with-libidn2 was added on 7.53.0
# So this script only adds libidn2 for versions >= that one.
is_less_than_7_53_0=0
(printf '%s\n%s' "7.53.0" "$1" | $gsort -CV) || is_less_than_7_53_0=$?
# @TODO Will need to add libiconv here if we start building it too
if [ "$is_less_than_7_53_0" == "0" ]; then
if [[ ! -z $LIBIDN2_BUILD_FOLDER && ! -z $LIBUNISTRING_BUILD_FOLDER ]]; then
LIBS="$LIBS -lunistring"
LDFLAGS="$LDFLAGS -L$LIBUNISTRING_BUILD_FOLDER/lib"
libcurl_args+=("--with-libidn2=$LIBIDN2_BUILD_FOLDER")
# on mac we also need to link to iconv, since it's not available on std lib
if [ "$(uname)" == "Darwin" ]; then
LIBS="$LIBS -liconv"
fi
else
libcurl_args+=("--without-libidn2")
fi
fi
# --with-zstd was added on 7.72.0
# So this script only adds libidn2 for versions >= that one.
is_less_than_7_72_0=0
(printf '%s\n%s' "7.72.0" "$1" | $gsort -CV) || is_less_than_7_72_0=$?
if [ "$is_less_than_7_72_0" == "0" ]; then
if [[ ! -z $ZSTD_BUILD_FOLDER ]]; then
libcurl_args+=("--with-zstd=$ZSTD_BUILD_FOLDER")
else
libcurl_args+=("--without-zstd")
fi
fi
# metalink options were removed from libcurl on 7.78.0
is_less_than_7_78_0=0
(printf '%s\n%s' "7.78.0" "$1" | $gsort -CV) || is_less_than_7_78_0=$?
if [ "$is_less_than_7_78_0" == "1" ]; then
libcurl_args+=("--without-libmetalink")
fi
#####
# ssl
####
if [ ! -z "$OPENSSL_BUILD_FOLDER" ]; then
CPPFLAGS="$CPPFLAGS -I$OPENSSL_BUILD_FOLDER/include"
LDFLAGS="$LDFLAGS -L$OPENSSL_BUILD_FOLDER/lib -Wl,-rpath,$OPENSSL_BUILD_FOLDER/lib"
libcurl_args+=("--with-ssl=$OPENSSL_BUILD_FOLDER")
else
libcurl_args+=("--without-ssl")
fi
######
# gss-api
#####
if [ ! -z "$KERBEROS_BUILD_FOLDER" ]; then
libcurl_args+=("--with-gssapi=$KERBEROS_BUILD_FOLDER")
LDFLAGS="$LDFLAGS -L$KERBEROS_BUILD_FOLDER/lib -Wl,-rpath,$KERBEROS_BUILD_FOLDER/lib"
if [ "$(uname)" == "Darwin" ]; then
# libcurl does not uses krb5-config on macOS
# and even if it did, it would return more flags than needed
# because the bin there is built with shared libraries:
# -L/Users/jcm/deps/kerberos/build/1.17/lib -dynamic \
# -mmacosx-version-min=10.15 -L/Users/jcm/deps/openssl/build/1.1.0j/lib \
# -Wl,-rpath,/Users/jcm/deps/openssl/build/1.1.0j/lib -Wl,-search_paths_first \
# -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err
# Currently it only links against -lgssapi_krb5 -lresolv
LIBS="-lkrb5 -lk5crypto -lcom_err -lkrb5support $LIBS"
else
# On other *nix systems, those are needed for static build of kerberos
# libcurl only links against -lgssapi_krb5 -lkrb5 -lk5crypto -lcom_err
LIBS="-lkrb5support -lresolv $LIBS"
fi
elif [ ! -z "$HEIMDAL_BUILD_FOLDER" ]; then
libcurl_args+=("--with-gssapi=$HEIMDAL_BUILD_FOLDER")
# On mac its bugged, see:
# https://github.com/curl/curl/issues/3841
if [ "$(uname)" == "Darwin" ]; then
libcurl_args+=("--with-gssapi-libs=$HEIMDAL_BUILD_FOLDER/lib")
libcurl_args+=("--with-gssapi-includes=$HEIMDAL_BUILD_FOLDER/include")
fi
# missing link against those
# `krb5-config --libs gssapi` (the tool libcurl uses to retrieve the deps) does not add them
CPPFLAGS="$CPPFLAGS -I$HEIMDAL_BUILD_FOLDER/include"
LDFLAGS="$LDFLAGS -L$HEIMDAL_BUILD_FOLDER/lib -Wl,-rpath,$HEIMDAL_BUILD_FOLDER/lib"
LIBS="-lkrb5 -lhx509 -lasn1 -lhcrypto -lheimsqlite -lheimntlm -lheimbase -lroken -lwind -lcom_err $LIBS"
else
libcurl_args+=("--without-gssapi")
fi
######
# ldap
#####
if [ ! -z "$OPENLDAP_BUILD_FOLDER" ]; then
# Only libcurl >= 7.64.1 has the check for ldap built with OpenSSL, so if we ever start building openldap with SSL
# We will also need to add ldl and lcrypto here as lib
# https://github.com/curl/curl/commit/66637b4d8fbc52aa1b57845cf45c7ccc7a95880f
CPPFLAGS="$CPPFLAGS -I$OPENLDAP_BUILD_FOLDER/include"
LDFLAGS="$LDFLAGS -L$OPENLDAP_BUILD_FOLDER/lib -Wl,-rpath,$OPENLDAP_BUILD_FOLDER/lib"
libcurl_args+=("--enable-ldap")
libcurl_args+=("--enable-ldaps")
else
libcurl_args+=("--disable-ldap")
libcurl_args+=("--disable-ldaps")
fi
#####
# libssh2
####
if [ ! -z "$LIBSSH2_BUILD_FOLDER" ]; then
libcurl_args+=("--with-libssh2=$LIBSSH2_BUILD_FOLDER")
else
libcurl_args+=("--without-libssh2")
fi
#####
# nghttp2
####
if [ ! -z "$NGHTTP2_BUILD_FOLDER" ]; then
libcurl_args+=("--with-nghttp2=$NGHTTP2_BUILD_FOLDER")
else
libcurl_args+=("--without-nghttp2")
fi
#####
# c-ares
####
if [ ! -z "$CARES_BUILD_FOLDER" ]; then
libcurl_args+=("--enable-ares=$CARES_BUILD_FOLDER")
if [ "$(uname)" == "Darwin" ]; then
# libcurl does not add this c-ares dependency automatically on macOS
LIBS="-lresolv $LIBS"
fi
fi
#####
# Brotli
####
if [ ! -z "$BROTLI_BUILD_FOLDER" ]; then
CPPFLAGS="$CPPFLAGS -I$BROTLI_BUILD_FOLDER/include"
LDFLAGS="$LDFLAGS -L$BROTLI_BUILD_FOLDER/lib -Wl,-rpath,$BROTLI_BUILD_FOLDER/lib"
LIBS="-lbrotlicommon $LIBS"
libcurl_args+=("--with-brotli=$BROTLI_BUILD_FOLDER")
else
libcurl_args+=("--without-brotli")
fi
#####
# zlib
####
if [ ! -z "$ZLIB_BUILD_FOLDER" ]; then
libcurl_args+=("--with-zlib=$ZLIB_BUILD_FOLDER")
else
libcurl_args+=("--without-zlib")
fi
export LIBS=$LIBS
export CPPFLAGS=$CPPFLAGS
export LDFLAGS=$LDFLAGS
# Debug
# --enable-debug \
# Release - Static
./configure \
--without-nss \
--without-libpsl \
--without-librtmp \
--without-libidn \
--disable-manual \
--disable-shared \
--prefix=$build_folder \
"${libcurl_args[@]}" \
"${@:3}"
# Release - Both
make && make install