Skip to content

Commit ed69bf5

Browse files
dschomjcheetham
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 a72fc0e commit ed69bf5

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
@@ -1597,10 +1602,19 @@ else
15971602
CURL_LIBCURL =
15981603
endif
15991604

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

16051619
ifndef CURL_CFLAGS
16061620
CURL_CFLAGS = $(eval CURL_CFLAGS := $$(shell $$(CURL_CONFIG) --cflags))$(CURL_CFLAGS)
@@ -1621,7 +1635,7 @@ else
16211635
endif
16221636
ifdef USE_CURL_FOR_IMAP_SEND
16231637
BASIC_CFLAGS += -DUSE_CURL_FOR_IMAP_SEND
1624-
IMAP_SEND_BUILDDEPS = http.o
1638+
IMAP_SEND_BUILDDEPS = http.o $(LAZYLOAD_LIBCURL_OBJ)
16251639
IMAP_SEND_LDFLAGS += $(CURL_LIBCURL)
16261640
endif
16271641
ifndef NO_EXPAT
@@ -2785,10 +2799,10 @@ git-imap-send$X: imap-send.o $(IMAP_SEND_BUILDDEPS) GIT-LDFLAGS $(GITLIBS)
27852799
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
27862800
$(IMAP_SEND_LDFLAGS) $(LIBS)
27872801

2788-
git-http-fetch$X: http.o http-walker.o http-fetch.o GIT-LDFLAGS $(GITLIBS)
2802+
git-http-fetch$X: http.o http-walker.o http-fetch.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
27892803
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
27902804
$(CURL_LIBCURL) $(LIBS)
2791-
git-http-push$X: http.o http-push.o GIT-LDFLAGS $(GITLIBS)
2805+
git-http-push$X: http.o http-push.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
27922806
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
27932807
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
27942808

@@ -2798,7 +2812,7 @@ $(REMOTE_CURL_ALIASES): $(REMOTE_CURL_PRIMARY)
27982812
ln -s $< $@ 2>/dev/null || \
27992813
cp $< $@
28002814

2801-
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o GIT-LDFLAGS $(GITLIBS)
2815+
$(REMOTE_CURL_PRIMARY): remote-curl.o http.o http-walker.o $(LAZYLOAD_LIBCURL_OBJ) GIT-LDFLAGS $(GITLIBS)
28022816
$(QUIET_LINK)$(CC) $(ALL_CFLAGS) -o $@ $(ALL_LDFLAGS) $(filter %.o,$^) \
28032817
$(CURL_LIBCURL) $(EXPAT_LIBEXPAT) $(LIBS)
28042818

0 commit comments

Comments
 (0)