Skip to content

Commit 2d1ad10

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 bc3743d commit 2d1ad10

File tree

2 files changed

+356
-7
lines changed

2 files changed

+356
-7
lines changed

Makefile

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,11 @@ include shared.mak
468468
#
469469
# CURL_LDFLAGS=-lcurl
470470
#
471+
# Define LAZY_LOAD_LIBCURL to dynamically load the libcurl; This can be useful
472+
# if Multiple libcurl versions exist (with different file names) that link to
473+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
474+
# such a scenario.
475+
#
471476
# === Optional library: libpcre2 ===
472477
#
473478
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1603,10 +1608,17 @@ else
16031608
CURL_LIBCURL =
16041609
endif
16051610

1606-
ifndef CURL_LDFLAGS
1607-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1611+
ifdef LAZY_LOAD_LIBCURL
1612+
LAZY_LOAD_LIBCURL_OBJ = compat/lazy-load-curl.o
1613+
OBJECTS += $(LAZY_LOAD_LIBCURL_OBJ)
1614+
CURL_CFLAGS = -DCURL_STATICLIB
1615+
CURL_LIBCURL = -ldl
1616+
else
1617+
ifndef CURL_LDFLAGS
1618+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1619+
endif
1620+
CURL_LIBCURL += $(CURL_LDFLAGS)
16081621
endif
1609-
CURL_LIBCURL += $(CURL_LDFLAGS)
16101622

16111623
ifndef CURL_CFLAGS
16121624
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1627,7 +1639,7 @@ else
16271639
endif
16281640
ifdef USE_CURL_FOR_IMAP_SEND
16291641
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1630-
IMAP_SEND_BUILDDEPS = http.o
1642+
IMAP_SEND_BUILDDEPS = http.o $(LAZY_LOAD_LIBCURL_OBJ)
16311643
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16321644
endif
16331645
ifndef NO_EXPAT
@@ -2833,10 +2845,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28332845
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28342846
$(IMAP_SEND_LDFLAGS) $(LIBS)
28352847

2836-
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 $(LAZY_LOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28372849
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28382850
$(CURL_LIBCURL) $(LIBS)
2839-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2851+
git-http-push$X: http.o http-push.o $(LAZY_LOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28402852
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28412853
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28422854

@@ -2846,7 +2858,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28462858
ln -s $< $@ 2>/dev/null || \
28472859
cp $< $@
28482860

2849-
$(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 $(LAZY_LOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28502862
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28512863
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28522864

0 commit comments

Comments
 (0)