Skip to content

Commit 81894c0

Browse files
committed
http: optionally load libcurl lazily
This compile-time option allows to ask Git to load libcurl dynamically at runtime. Together with a follow-up patch that optionally overrides the file name depending on the `http.sslBackend` setting, this kicks open the door for installing multiple libcurl flavors side by side, and load the one corresponding to the (runtime-)configured SSL/TLS backend. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 11e09f9 commit 81894c0

File tree

2 files changed

+375
-7
lines changed

2 files changed

+375
-7
lines changed

Makefile

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ include shared.mak
470470
#
471471
# CURL_LDFLAGS=-lcurl
472472
#
473+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
474+
# if Multiple libcurl versions exist (with different file names) that link to
475+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
476+
# such a scenario.
477+
#
473478
# === Optional library: libpcre2 ===
474479
#
475480
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1663,10 +1668,19 @@ else
16631668
CURL_LIBCURL =
16641669
endif
16651670

1666-
ifndef CURL_LDFLAGS
1667-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1671+
ifdef LAZYLOAD_LIBCURL
1672+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1673+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1674+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1675+
# declared as DLL imports
1676+
CURL_CFLAGS = -DCURL_STATICLIB
1677+
CURL_LIBCURL = -ldl
1678+
else
1679+
ifndef CURL_LDFLAGS
1680+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1681+
endif
1682+
CURL_LIBCURL += $(CURL_LDFLAGS)
16681683
endif
1669-
CURL_LIBCURL += $(CURL_LDFLAGS)
16701684

16711685
ifndef CURL_CFLAGS
16721686
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1687,7 +1701,7 @@ else
16871701
endif
16881702
ifdef USE_CURL_FOR_IMAP_SEND
16891703
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1690-
IMAP_SEND_BUILDDEPS = http.o
1704+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16911705
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16921706
endif
16931707
ifndef NO_EXPAT
@@ -2893,10 +2907,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28932907
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28942908
$(IMAP_SEND_LDFLAGS) $(LIBS)
28952909

2896-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2910+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28972911
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28982912
$(CURL_LIBCURL) $(LIBS)
2899-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2913+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29002914
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29012915
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29022916

@@ -2906,7 +2920,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29062920
ln -s $< $@ 2>/dev/null || \
29072921
cp $< $@
29082922

2909-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2923+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29102924
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29112925
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29122926

0 commit comments

Comments
 (0)