Skip to content

Commit 6f296a1

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 b528f18 commit 6f296a1

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
@@ -467,6 +467,11 @@ include shared.mak
467467
#
468468
# CURL_LDFLAGS=-lcurl
469469
#
470+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
471+
# if Multiple libcurl versions exist (with different file names) that link to
472+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
473+
# such a scenario.
474+
#
470475
# === Optional library: libpcre2 ===
471476
#
472477
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1616,10 +1621,19 @@ else
16161621
CURL_LIBCURL =
16171622
endif
16181623

1619-
ifndef CURL_LDFLAGS
1620-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1624+
ifdef LAZYLOAD_LIBCURL
1625+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1626+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1627+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1628+
# declared as DLL imports
1629+
CURL_CFLAGS = -DCURL_STATICLIB
1630+
CURL_LIBCURL = -ldl
1631+
else
1632+
ifndef CURL_LDFLAGS
1633+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1634+
endif
1635+
CURL_LIBCURL += $(CURL_LDFLAGS)
16211636
endif
1622-
CURL_LIBCURL += $(CURL_LDFLAGS)
16231637

16241638
ifndef CURL_CFLAGS
16251639
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1640,7 +1654,7 @@ else
16401654
endif
16411655
ifdef USE_CURL_FOR_IMAP_SEND
16421656
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1643-
IMAP_SEND_BUILDDEPS = http.o
1657+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16441658
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16451659
endif
16461660
ifndef NO_EXPAT
@@ -2831,10 +2845,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28312845
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28322846
$(IMAP_SEND_LDFLAGS) $(LIBS)
28332847

2834-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2848+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28352849
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28362850
$(CURL_LIBCURL) $(LIBS)
2837-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2851+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28382852
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28392853
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28402854

@@ -2844,7 +2858,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28442858
ln -s $< $@ 2>/dev/null || \
28452859
cp $< $@
28462860

2847-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2861+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28482862
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28492863
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28502864

0 commit comments

Comments
 (0)