build: link with curl-defined linker flags

Adjusting the build process to rely more on curl-config to populate linker flags instead of manually populating flags based off detected features. Originally, a configure-invoked build would check for SSL-support in the target curl library. If enabled, NEEDS_SSL_WITH_CURL would be set and used in the Makefile to append additional libraries to link against. As for systems building solely with make, the defines NEEDS_IDN_WITH_CURL and NEEDS_SSL_WITH_CURL could be set to indirectly enable respective linker flags. Since both configure.ac and Makefile already rely on curl-config utility to provide curl-related build information, adjusting the respective assets to populate required linker flags using the utility (unless explicitly configured). Signed-off-by: James Knight <james.d.knight@live.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

James Knight committed Nov 3, 2018 at 05:12 UTC 23c4bbe28e61974577164db09cbd1d1c7e568ca4
3 files changed +22 -28
Makefile
+15 -15
@@ -59,6 +59,13 @@ all::
59 # Define CURL_CONFIG to curl's configuration program that prints information
60 # about the library (e.g., its version number). The default is 'curl-config'.
61 #
62 +# Define CURL_LDFLAGS to specify flags that you need to link when using libcurl,
63 +# if you do not want to rely on the libraries provided by CURL_CONFIG. The
64 +# default value is a result of `curl-config --libs`. An example value for
65 +# CURL_LDFLAGS is as follows:
66 +#
67 +# CURL_LDFLAGS=-lcurl
68 +#
69 # Define NO_EXPAT if you do not have expat installed. git-http-push is
70 # not built, and you cannot push using http:// and https:// transports (dumb).
71 #
@@ -183,10 +190,6 @@ all::
190 #
191 # Define NEEDS_SSL_WITH_CRYPTO if you need -lssl when using -lcrypto (Darwin).
192 #
186 -# Define NEEDS_SSL_WITH_CURL if you need -lssl with -lcurl (Minix).
187 -#
188 -# Define NEEDS_IDN_WITH_CURL if you need -lidn when using -lcurl (Minix).
189 -#
193 # Define NEEDS_LIBICONV if linking with libc is not enough (Darwin).
194 #
195 # Define NEEDS_LIBINTL_BEFORE_LIBICONV if you need libintl before libiconv.
@@ -1307,20 +1310,17 @@ else
1310 ifdef CURLDIR
1311 # Try "-Wl,-rpath=$(CURLDIR)/$(lib)" in such a case.
1312 BASIC_CFLAGS += -I$(CURLDIR)/include
1310 - CURL_LIBCURL = -L$(CURLDIR)/$(lib) $(CC_LD_DYNPATH)$(CURLDIR)/$(lib) -lcurl
1313 + CURL_LIBCURL = -L$(CURLDIR)/$(lib) $(CC_LD_DYNPATH)$(CURLDIR)/$(lib)
1314 else
1312 - CURL_LIBCURL = -lcurl
1313 - endif
1314 - ifdef NEEDS_SSL_WITH_CURL
1315 - CURL_LIBCURL += -lssl
1316 - ifdef NEEDS_CRYPTO_WITH_SSL
1317 - CURL_LIBCURL += -lcrypto
1318 - endif
1319 - endif
1320 - ifdef NEEDS_IDN_WITH_CURL
1321 - CURL_LIBCURL += -lidn
1315 + CURL_LIBCURL =
1316 endif
1317
1318 +ifdef CURL_LDFLAGS
1319 + CURL_LIBCURL += $(CURL_LDFLAGS)
1320 +else
1321 + CURL_LIBCURL += $(shell $(CURL_CONFIG) --libs)
1322 +endif
1323 +
1324 REMOTE_CURL_PRIMARY = git-remote-http$X
1325 REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X
1326 REMOTE_CURL_NAMES = $(REMOTE_CURL_PRIMARY) $(REMOTE_CURL_ALIASES)
config.mak.uname
-3
@@ -431,8 +431,6 @@ ifeq ($(uname_S),Minix)
431 NO_NSEC = YesPlease
432 NEEDS_LIBGEN =
433 NEEDS_CRYPTO_WITH_SSL = YesPlease
434 - NEEDS_IDN_WITH_CURL = YesPlease
435 - NEEDS_SSL_WITH_CURL = YesPlease
434 NEEDS_RESOLV =
435 NO_HSTRERROR = YesPlease
436 NO_MMAP = YesPlease
@@ -458,7 +456,6 @@ ifeq ($(uname_S),NONSTOP_KERNEL)
456 # Missdetected, hence commented out, see below.
457 #NO_CURL = YesPlease
458 # Added manually, see above.
461 - NEEDS_SSL_WITH_CURL = YesPlease
459 HAVE_LIBCHARSET_H = YesPlease
460 HAVE_STRINGS_H = YesPlease
461 NEEDS_LIBICONV = YesPlease
configure.ac
+7 -10
@@ -600,17 +600,14 @@ AC_CHECK_PROG([CURL_CONFIG], [curl-config],
600
601 if test $CURL_CONFIG != no; then
602 GIT_CONF_SUBST([CURL_CONFIG])
603 - if test -z "${NO_OPENSSL}"; then
604 - AC_MSG_CHECKING([if Curl supports SSL])
605 - if test $(curl-config --features|grep SSL) = SSL; then
606 - NEEDS_SSL_WITH_CURL=YesPlease
607 - AC_MSG_RESULT([yes])
608 - else
609 - NEEDS_SSL_WITH_CURL=
610 - AC_MSG_RESULT([no])
611 - fi
612 - GIT_CONF_SUBST([NEEDS_SSL_WITH_CURL])
603 +
604 + if test -z "$CURL_CONFIG_OPTS"; then
605 + CURL_CONFIG_OPTS="--libs"
606 fi
607 +
608 + CURL_LDFLAGS=$($CURL_CONFIG $CURL_CONFIG_OPTS)
609 + AC_MSG_NOTICE([Setting CURL_LDFLAGS to '$CURL_LDFLAGS'])
610 + GIT_CONF_SUBST([CURL_LDFLAGS], [$CURL_LDFLAGS])
611 fi
612
613 fi