Skip to content

Commit e054438

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 <johannes.schindelin@gmx.de>
1 parent 5ab942a commit e054438

File tree

2 files changed

+385
-7
lines changed

2 files changed

+385
-7
lines changed

Makefile

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -470,6 +470,11 @@ include shared.mak
470470
#
471471
# CURL_LDFLAGS=-lcurl
472472
#
473+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
474+
# if Multiple libcurl versions exist (with different file names) that link to
475+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
476+
# such a scenario.
477+
#
473478
# === Optional library: libpcre2 ===
474479
#
475480
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1734,10 +1739,19 @@ else
17341739
CURL_LIBCURL =
17351740
endif
17361741

1737-
ifndef CURL_LDFLAGS
1738-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1742+
ifdef LAZYLOAD_LIBCURL
1743+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1744+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1745+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1746+
# declared as DLL imports
1747+
CURL_CFLAGS = -DCURL_STATICLIB
1748+
CURL_LIBCURL = -ldl
1749+
else
1750+
ifndef CURL_LDFLAGS
1751+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1752+
endif
1753+
CURL_LIBCURL += $(CURL_LDFLAGS)
17391754
endif
1740-
CURL_LIBCURL += $(CURL_LDFLAGS)
17411755

17421756
ifndef CURL_CFLAGS
17431757
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1758,7 +1772,7 @@ else
17581772
endif
17591773
ifdef USE_CURL_FOR_IMAP_SEND
17601774
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1761-
IMAP_SEND_BUILDDEPS = http.o
1775+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
17621776
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
17631777
endif
17641778
ifndef NO_EXPAT
@@ -2939,10 +2953,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
29392953
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29402954
$(IMAP_SEND_LDFLAGS) $(LIBS)
29412955

2942-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2956+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29432957
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29442958
$(CURL_LIBCURL) $(LIBS)
2945-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2959+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29462960
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29472961
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29482962

@@ -2952,7 +2966,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29522966
ln -s $< $@ 2>/dev/null || \
29532967
cp $< $@
29542968

2955-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2969+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29562970
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29572971
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29582972

0 commit comments

Comments
 (0)