Skip to content

Commit 98f21f5

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 94f1f27 commit 98f21f5

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
@@ -471,6 +471,11 @@ include shared.mak
471471
#
472472
# CURL_LDFLAGS=-lcurl
473473
#
474+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
475+
# if Multiple libcurl versions exist (with different file names) that link to
476+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
477+
# such a scenario.
478+
#
474479
# === Optional library: libpcre2 ===
475480
#
476481
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1640,10 +1645,19 @@ else
16401645
CURL_LIBCURL =
16411646
endif
16421647

1643-
ifndef CURL_LDFLAGS
1644-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1648+
ifdef LAZYLOAD_LIBCURL
1649+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1650+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1651+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1652+
# declared as DLL imports
1653+
CURL_CFLAGS = -DCURL_STATICLIB
1654+
CURL_LIBCURL = -ldl
1655+
else
1656+
ifndef CURL_LDFLAGS
1657+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1658+
endif
1659+
CURL_LIBCURL += $(CURL_LDFLAGS)
16451660
endif
1646-
CURL_LIBCURL += $(CURL_LDFLAGS)
16471661

16481662
ifndef CURL_CFLAGS
16491663
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1664,7 +1678,7 @@ else
16641678
endif
16651679
ifdef USE_CURL_FOR_IMAP_SEND
16661680
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1667-
IMAP_SEND_BUILDDEPS = http.o
1681+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16681682
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16691683
endif
16701684
ifndef NO_EXPAT
@@ -2872,10 +2886,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28722886
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28732887
$(IMAP_SEND_LDFLAGS) $(LIBS)
28742888

2875-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2889+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28762890
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28772891
$(CURL_LIBCURL) $(LIBS)
2878-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2892+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28792893
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28802894
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28812895

@@ -2885,7 +2899,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28852899
ln -s $< $@ 2>/dev/null || \
28862900
cp $< $@
28872901

2888-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2902+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28892903
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28902904
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28912905

0 commit comments

Comments
 (0)