Skip to content

Commit 55b28f9

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 55b28f9

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
@@ -468,6 +468,11 @@ include shared.mak
468468
#
469469
# CURL_LDFLAGS=-lcurl
470470
#
471+
# Define LAZYLOAD_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,19 @@ 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 LAZYLOAD_LIBCURL
1612+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1613+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1614+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1615+
# declared as DLL imports
1616+
CURL_CFLAGS = -DCURL_STATICLIB
1617+
CURL_LIBCURL = -ldl
1618+
else
1619+
ifndef CURL_LDFLAGS
1620+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1621+
endif
1622+
CURL_LIBCURL += $(CURL_LDFLAGS)
16081623
endif
1609-
CURL_LIBCURL += $(CURL_LDFLAGS)
16101624

16111625
ifndef CURL_CFLAGS
16121626
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1627,7 +1641,7 @@ else
16271641
endif
16281642
ifdef USE_CURL_FOR_IMAP_SEND
16291643
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1630-
IMAP_SEND_BUILDDEPS = http.o
1644+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16311645
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16321646
endif
16331647
ifndef NO_EXPAT
@@ -2833,10 +2847,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28332847
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28342848
$(IMAP_SEND_LDFLAGS) $(LIBS)
28352849

2836-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2850+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28372851
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28382852
$(CURL_LIBCURL) $(LIBS)
2839-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2853+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28402854
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28412855
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28422856

@@ -2846,7 +2860,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28462860
ln -s $< $@ 2>/dev/null || \
28472861
cp $< $@
28482862

2849-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2863+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28502864
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28512865
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28522866

0 commit comments

Comments
 (0)