Skip to content

Commit 19c62ef

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 1730921 commit 19c62ef

File tree

2 files changed

+365
-7
lines changed

2 files changed

+365
-7
lines changed

Makefile

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,11 @@ include shared.mak
464464
#
465465
# CURL_LDFLAGS=-lcurl
466466
#
467+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
468+
# if Multiple libcurl versions exist (with different file names) that link to
469+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
470+
# such a scenario.
471+
#
467472
# === Optional library: libpcre2 ===
468473
#
469474
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1599,10 +1604,19 @@ else
15991604
CURL_LIBCURL =
16001605
endif
16011606

1602-
ifndef CURL_LDFLAGS
1603-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1607+
ifdef LAZYLOAD_LIBCURL
1608+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1609+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1610+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1611+
# declared as DLL imports
1612+
CURL_CFLAGS = -DCURL_STATICLIB
1613+
CURL_LIBCURL = -ldl
1614+
else
1615+
ifndef CURL_LDFLAGS
1616+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1617+
endif
1618+
CURL_LIBCURL += $(CURL_LDFLAGS)
16041619
endif
1605-
CURL_LIBCURL += $(CURL_LDFLAGS)
16061620

16071621
ifndef CURL_CFLAGS
16081622
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1623,7 +1637,7 @@ else
16231637
endif
16241638
ifdef USE_CURL_FOR_IMAP_SEND
16251639
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1626-
IMAP_SEND_BUILDDEPS = http.o
1640+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16271641
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16281642
endif
16291643
ifndef NO_EXPAT
@@ -2829,10 +2843,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28292843
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28302844
$(IMAP_SEND_LDFLAGS) $(LIBS)
28312845

2832-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2846+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28332847
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28342848
$(CURL_LIBCURL) $(LIBS)
2835-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2849+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28362850
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28372851
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28382852

@@ -2842,7 +2856,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28422856
ln -s $< $@ 2>/dev/null || \
28432857
cp $< $@
28442858

2845-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2859+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28462860
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28472861
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28482862

0 commit comments

Comments
 (0)