Skip to content

Commit 248c658

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 2ddd89c commit 248c658

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
@@ -472,6 +472,11 @@ include shared.mak
472472
#
473473
# CURL_LDFLAGS=-lcurl
474474
#
475+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
476+
# if Multiple libcurl versions exist (with different file names) that link to
477+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
478+
# such a scenario.
479+
#
475480
# === Optional library: libpcre2 ===
476481
#
477482
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1665,10 +1670,19 @@ else
16651670
CURL_LIBCURL =
16661671
endif
16671672

1668-
ifndef CURL_LDFLAGS
1669-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1673+
ifdef LAZYLOAD_LIBCURL
1674+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1675+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1676+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1677+
# declared as DLL imports
1678+
CURL_CFLAGS = -DCURL_STATICLIB
1679+
CURL_LIBCURL = -ldl
1680+
else
1681+
ifndef CURL_LDFLAGS
1682+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1683+
endif
1684+
CURL_LIBCURL += $(CURL_LDFLAGS)
16701685
endif
1671-
CURL_LIBCURL += $(CURL_LDFLAGS)
16721686

16731687
ifndef CURL_CFLAGS
16741688
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1689,7 +1703,7 @@ else
16891703
endif
16901704
ifdef USE_CURL_FOR_IMAP_SEND
16911705
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1692-
IMAP_SEND_BUILDDEPS = http.o
1706+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16931707
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16941708
endif
16951709
ifndef NO_EXPAT
@@ -2898,10 +2912,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28982912
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28992913
$(IMAP_SEND_LDFLAGS) $(LIBS)
29002914

2901-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2915+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29022916
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29032917
$(CURL_LIBCURL) $(LIBS)
2904-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2918+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29052919
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29062920
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29072921

@@ -2911,7 +2925,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29112925
ln -s $< $@ 2>/dev/null || \
29122926
cp $< $@
29132927

2914-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2928+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29152929
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29162930
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29172931

0 commit comments

Comments
 (0)