Skip to content

Commit b240320

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 0aa0c12 commit b240320

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
@@ -1598,10 +1603,19 @@ else
15981603
CURL_LIBCURL =
15991604
endif
16001605

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

16061620
ifndef CURL_CFLAGS
16071621
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1622,7 +1636,7 @@ else
16221636
endif
16231637
ifdef USE_CURL_FOR_IMAP_SEND
16241638
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1625-
IMAP_SEND_BUILDDEPS = http.o
1639+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16261640
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16271641
endif
16281642
ifndef NO_EXPAT
@@ -2793,10 +2807,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
27932807
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
27942808
$(IMAP_SEND_LDFLAGS) $(LIBS)
27952809

2796-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2810+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
27972811
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
27982812
$(CURL_LIBCURL) $(LIBS)
2799-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2813+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28002814
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28012815
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28022816

@@ -2806,7 +2820,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28062820
ln -s $< $@ 2>/dev/null || \
28072821
cp $< $@
28082822

2809-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2823+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28102824
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28112825
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28122826

0 commit comments

Comments
 (0)