Skip to content

Commit fc3c59d

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 41206aa commit fc3c59d

File tree

2 files changed

+375
-7
lines changed

2 files changed

+375
-7
lines changed

Makefile

+21-7
Original file line numberDiff line numberDiff line change
@@ -475,6 +475,11 @@ include shared.mak
475475
#
476476
# CURL_LDFLAGS=-lcurl
477477
#
478+
# Define LAZYLOAD_LIBCURL to dynamically load the libcurl; This can be useful
479+
# if Multiple libcurl versions exist (with different file names) that link to
480+
# various SSL/TLS backends, to support the `http.sslBackend` runtime switch in
481+
# such a scenario.
482+
#
478483
# === Optional library: libpcre2 ===
479484
#
480485
# Define USE_LIBPCRE if you have and want to use libpcre. Various
@@ -1661,10 +1666,19 @@ else
16611666
CURL_LIBCURL =
16621667
endif
16631668

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

16691683
ifndef CURL_CFLAGS
16701684
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1685,7 +1699,7 @@ else
16851699
endif
16861700
ifdef USE_CURL_FOR_IMAP_SEND
16871701
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1688-
IMAP_SEND_BUILDDEPS = http.o
1702+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16891703
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16901704
endif
16911705
ifndef NO_EXPAT
@@ -2886,10 +2900,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28862900
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28872901
$(IMAP_SEND_LDFLAGS) $(LIBS)
28882902

2889-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2903+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28902904
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28912905
$(CURL_LIBCURL) $(LIBS)
2892-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2906+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28932907
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28942908
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28952909

@@ -2899,7 +2913,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28992913
ln -s $< $@ 2>/dev/null || \
29002914
cp $< $@
29012915

2902-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2916+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29032917
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29042918
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29052919

0 commit comments

Comments
 (0)