Skip to content

Commit d02c45a

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 e5838a4 commit d02c45a

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
@@ -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
@@ -1667,10 +1672,19 @@ else
16671672
CURL_LIBCURL =
16681673
endif
16691674

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

16751689
ifndef CURL_CFLAGS
16761690
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1691,7 +1705,7 @@ else
16911705
endif
16921706
ifdef USE_CURL_FOR_IMAP_SEND
16931707
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1694-
IMAP_SEND_BUILDDEPS = http.o
1708+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16951709
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16961710
endif
16971711
ifndef NO_EXPAT
@@ -2903,10 +2917,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
29032917
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29042918
$(IMAP_SEND_LDFLAGS) $(LIBS)
29052919

2906-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2920+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29072921
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29082922
$(CURL_LIBCURL) $(LIBS)
2909-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2923+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29102924
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29112925
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29122926

@@ -2916,7 +2930,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
29162930
ln -s $< $@ 2>/dev/null || \
29172931
cp $< $@
29182932

2919-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2933+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
29202934
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
29212935
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
29222936

0 commit comments

Comments
 (0)