Skip to content

Commit f57a086

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 3a56ade commit f57a086

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

1645-
ifndef CURL_LDFLAGS
1646-
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1650+
ifdef LAZYLOAD_LIBCURL
1651+
LAZYLOAD_LIBCURL_OBJ = compat/lazyload-curl.o
1652+
OBJECTS += $(LAZYLOAD_LIBCURL_OBJ)
1653+
# The `CURL_STATICLIB` constant must be defined to avoid seeing the functions
1654+
# declared as DLL imports
1655+
CURL_CFLAGS = -DCURL_STATICLIB
1656+
CURL_LIBCURL = -ldl
1657+
else
1658+
ifndef CURL_LDFLAGS
1659+
CURL_LDFLAGS = $(eval CURL_LDFLAGS := $$(shell $$(CURL_CONFIG) --libs))$(CURL_LDFLAGS)
1660+
endif
1661+
CURL_LIBCURL += $(CURL_LDFLAGS)
16471662
endif
1648-
CURL_LIBCURL += $(CURL_LDFLAGS)
16491663

16501664
ifndef CURL_CFLAGS
16511665
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1666,7 +1680,7 @@ else
16661680
endif
16671681
ifdef USE_CURL_FOR_IMAP_SEND
16681682
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1669-
IMAP_SEND_BUILDDEPS = http.o
1683+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16701684
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16711685
endif
16721686
ifndef NO_EXPAT
@@ -2876,10 +2890,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
28762890
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28772891
$(IMAP_SEND_LDFLAGS) $(LIBS)
28782892

2879-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2893+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28802894
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28812895
$(CURL_LIBCURL) $(LIBS)
2882-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2896+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28832897
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28842898
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28852899

@@ -2889,7 +2903,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
28892903
ln -s $< $@ 2>/dev/null || \
28902904
cp $< $@
28912905

2892-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2906+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.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

0 commit comments

Comments
 (0)