Skip to content

Commit c9be2c4

Browse files
dschoGit for Windows Build Agent
authored andcommitted
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 235b436 commit c9be2c4

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
@@ -1602,10 +1607,19 @@ else
16021607
CURL_LIBCURL =
16031608
endif
16041609

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

16101624
ifndef CURL_CFLAGS
16111625
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -2818,14 +2832,14 @@ headless-git$X: headless-git.o git.res GIT-LDFLAGS
28182832
git-%$X: %.o GIT-LDFLAGS $(GITLIBS)
28192833
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) $(LIBS)
28202834

2821-
git-imap-send$X: imap-send.o http.o GIT-LDFLAGS $(GITLIBS)
2835+
git-imap-send$X: imap-send.o http.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28222836
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28232837
$(IMAP_SEND_LDFLAGS) $(LIBS)
28242838

2825-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2839+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28262840
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28272841
$(CURL_LIBCURL) $(LIBS)
2828-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2842+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28292843
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28302844
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28312845

@@ -2835,7 +2849,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28352849
ln -s $< $@ 2>/dev/null || \
28362850
cp $< $@
28372851

2838-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2852+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28392853
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28402854
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28412855

0 commit comments

Comments
 (0)