Skip to contentSkip to conversation

Makefile: default to -lcurl when no CURL_CONFIG or CURLDIR

PATCH In review Dave Borowitz 3 participants 10 messages Jun 15, 2016 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Makefile: default to -lcurl when no CURL_CONFIG or CURLDIR

The original implementation of CURL_CONFIG support did not match the original behavior of using -lcurl when CURLDIR was not set. This broke implementations that were lacking curl-config but did have libcurl installed along system libraries, such as MSysGit. In other words, the assumption that curl-config is always installed was incorrect.

Instead, if CURL_CONFIG is empty or returns an empty result (e.g. due to curl-config being missing), use the old behavior of falling back to -lcurl.

---
 Makefile | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)
Makefile +25 -11
index 74a929b..79b7442 100644
@@ -35,7 +35,9 @@ all::
 # transports (neither smart nor dumb).
 #
 # Define CURL_CONFIG to the path to a curl-config binary other than the
-# default 'curl-config'.
+# default 'curl-config'. If CURL_CONFIG is unset or points to a binary that
+# is not found, defaults to the CURLDIR behavior, or if CURLDIR is not set,
+# uses -lcurl with no additional library detection.
 #
 # Define CURL_STATIC to statically link libcurl.  Only applies if
 # CURL_CONFIG is used.
@@ -1127,9 +1129,27 @@ ifdef NO_CURL
 	REMOTE_CURL_NAMES =
 else
 	ifdef CURLDIR
-		# Try "-Wl,-rpath=$(CURLDIR)/$(lib)" in such a case.
-		BASIC_CFLAGS += -I$(CURLDIR)/include
-		CURL_LIBCURL = -L$(CURLDIR)/$(lib) $(CC_LD_DYNPATH)$(CURLDIR)/$(lib) -lcurl
+		CURL_LIBCURL=
+	else
+		CURL_CONFIG ?= curl-config
+		ifeq "$(CURL_CONFIG)" ""
+			CURL_LIBCURL =
+		else
+			CURL_LIBCURL := $(shell $(CURL_CONFIG) --libs)
+		endif
+	endif
+
+	ifeq "$(CURL_LIBCURL)" ""
+		ifdef CURL_STATIC
+                        $(error "CURL_STATIC must be used with CURL_CONFIG")
+		endif
+		ifdef CURLDIR
+			# Try "-Wl,-rpath=$(CURLDIR)/$(lib)" in such a case.
+			BASIC_CFLAGS += -I$(CURLDIR)/include
+			CURL_LIBCURL = -L$(CURLDIR)/$(lib) $(CC_LD_DYNPATH)$(CURLDIR)/$(lib) -lcurl
+		else
+			CURL_LIBCURL = -lcurl
+		endif
 		ifdef NEEDS_SSL_WITH_CURL
 			CURL_LIBCURL += -lssl
 			ifdef NEEDS_CRYPTO_WITH_SSL
@@ -1140,17 +1160,11 @@ else
 			CURL_LIBCURL += -lidn
 		endif
 	else
-		CURL_CONFIG ?= curl-config
 		BASIC_CFLAGS += $(shell $(CURL_CONFIG) --cflags)
 		ifdef CURL_STATIC
 			CURL_LIBCURL = $(shell $(CURL_CONFIG) --static-libs)
 			ifeq "$(CURL_LIBCURL)" ""
-				$(error libcurl not detected or not compiled with static support)
-			endif
-		else
-			CURL_LIBCURL = $(shell $(CURL_CONFIG) --libs)
-			ifeq "$(CURL_LIBCURL)" ""
-				$(error libcurl not detected; try setting CURLDIR)
+                                $(error libcurl not detected or not compiled with static support)
 			endif
 		endif
 	endif
Signature · 1 line
1.9.1.423.g4596e3a
Reviewed-by on v1 1/1
#1 lore raw
Quoted 6 lines · Dave Borowitz

Instead, if CURL_CONFIG is empty or returns an empty result (e.g. due to curl-config being missing), use the old behavior of falling back to -lcurl.

---
 Makefile | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

Sign-off?

[...]

Makefile all:: · line 40

Quoted 9 lines

+++ b/Makefile

Makefile +3 -1
@@ -35,7 +35,9 @@ all::
 # transports (neither smart nor dumb).
 #
 # Define CURL_CONFIG to the path to a curl-config binary other than the
-# default 'curl-config'.
+# default 'curl-config'. If CURL_CONFIG is unset or points to a binary that
+# is not found, defaults to the CURLDIR behavior, or if CURLDIR is not set,
+# uses -lcurl with no additional library detection.

I'm having a little trouble parsing this but don't have any better suggestion.

[...]

Makefile ifdef NO_CURL · line 1132

Quoted 8 lines
Makefile +1 -3
@@ -1127,9 +1129,27 @@ ifdef NO_CURL
 	REMOTE_CURL_NAMES =
 else
 	ifdef CURLDIR
-		# Try "-Wl,-rpath=$(CURLDIR)/$(lib)" in such a case.
-		BASIC_CFLAGS += -I$(CURLDIR)/include
-		CURL_LIBCURL = -L$(CURLDIR)/$(lib) $(CC_LD_DYNPATH)$(CURLDIR)/$(lib) -lcurl
+		CURL_LIBCURL=

Tiny nit: elsewhere the makefile seems to prefer having a space before the '='.

If I explicitly set CURL_LIBCURL to the empty string and CURLDIR was set then my setting will still override the setting below and the behavior is unchanged from before this patch --- good.

If I explicitly set CURL_LIBCURL to empty and CURLDIR was unset then that used to produce an error so it was an invalid configuration and couldn't regress.

So this should be safe --- good.

Makefile ifdef NO_CURL · line 1134

Quoted 2 lines
Makefile +2 -0
+	else
+		CURL_CONFIG ?= curl-config

Not about this patch, but the above '?=' should probably be plain '=' for consistency with the rest of the makefile's behavior wrt envvars.

[...]

Makefile else · line 1167

Quoted 2 lines
Makefile +1 -1
-				$(error libcurl not detected; try setting CURLDIR)
+                                $(error libcurl not detected or not compiled with static support)

Whitespace damage.

Except for the whitespace issues,

Thanks.

#2 lore raw
Quoted 10 lines · Jonathan Nieder
Quoted 6 lines · Dave Borowitz

Instead, if CURL_CONFIG is empty or returns an empty result (e.g. due to curl-config being missing), use the old behavior of falling back to -lcurl.

---
 Makefile | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)

Sign-off?

Oops.

Quoted 13 lines

[...]

Makefile all:: · line 40

Quoted 9 lines

+++ b/Makefile

Makefile +3 -1
@@ -35,7 +35,9 @@ all::
 # transports (neither smart nor dumb).
 #
 # Define CURL_CONFIG to the path to a curl-config binary other than the
-# default 'curl-config'.
+# default 'curl-config'. If CURL_CONFIG is unset or points to a binary that
+# is not found, defaults to the CURLDIR behavior, or if CURLDIR is not set,
+# uses -lcurl with no additional library detection.

I'm having a little trouble parsing this but don't have any better suggestion.

How about:
"If CURL_CONFIG is unset or points to a binary that is not found, defaults to the CURLDIR behavior. If CURLDIR is not set, this means using -lcurl with no additional library detection (other than NEEDS_*_WITH_CURL).

[...]

Quoted 4 lines

Makefile else · line 1167

Quoted 2 lines
Makefile +1 -1
-                             $(error libcurl not detected; try setting CURLDIR)
+                                $(error libcurl not detected or not compiled with static support)

Whitespace damage.

Yes, but intentional, because Makefile parsing is weird.

$ echo -e 'ifndef FOO\n\t$(error bad things)\nendif\n\nfoo:\n\ttouch
foo' > mk1 && make -f mk1 foo
mk1:2: *** commands commence before first target.  Stop.
$ echo -e 'ifndef FOO\n  $(error bad things)\nendif\n\nfoo:\n\ttouch
foo' > mk2 && make -f mk2 foo
mk2:2: *** bad things.  Stop.

See also:
http://stackoverflow.com/questions/4713663/gnu-make-yields-commands-commence-before-first-target-error

Quoted 4 lines

Except for the whitespace issues,

Thanks.

#3 lore raw
Quoted 16 lines · Dave Borowitz
Quoted 14 lines · Jonathan Nieder

Makefile all:: · line 40

Quoted 9 lines · Dave Borowitz

+++ b/Makefile

Makefile +3 -1
@@ -35,7 +35,9 @@ all::
 # transports (neither smart nor dumb).
 #
 # Define CURL_CONFIG to the path to a curl-config binary other than the
-# default 'curl-config'.
+# default 'curl-config'. If CURL_CONFIG is unset or points to a binary that
+# is not found, defaults to the CURLDIR behavior, or if CURLDIR is not set,
+# uses -lcurl with no additional library detection.

I'm having a little trouble parsing this but don't have any better suggestion.

Quoted 5 lines

How about:
"If CURL_CONFIG is unset or points to a binary that is not found, defaults to the CURLDIR behavior. If CURLDIR is not set, this means using -lcurl with no additional library detection (other than NEEDS_*_WITH_CURL).

Yep, that's clearer.

Quoted 6 lines

[...]

Quoted 4 lines

Makefile else · line 1167

Quoted 2 lines
Makefile +1 -1
-                             $(error libcurl not detected; try setting CURLDIR)
+                                $(error libcurl not detected or not compiled with static support)

Whitespace damage.

Quoted 8 lines

Yes, but intentional, because Makefile parsing is weird.

$ echo -e 'ifndef FOO\n\t$(error bad things)\nendif\n\nfoo:\n\ttouch
foo' > mk1 && make -f mk1 foo
mk1:2: *** commands commence before first target.  Stop.
$ echo -e 'ifndef FOO\n  $(error bad things)\nendif\n\nfoo:\n\ttouch
foo' > mk2 && make -f mk2 foo
mk2:2: *** bad things.  Stop.

Gah. Maybe it should be left-justified to avoid accentally breaking it again.

Thanks.
Jonathan

#4 lore raw
Quoted 9 lines · Jonathan Nieder
Quoted 6 lines
$ echo -e 'ifndef FOO\n\t$(error bad things)\nendif\n\nfoo:\n\ttouch
foo' > mk1 && make -f mk1 foo
mk1:2: *** commands commence before first target.  Stop.
$ echo -e 'ifndef FOO\n  $(error bad things)\nendif\n\nfoo:\n\ttouch
foo' > mk2 && make -f mk2 foo
mk2:2: *** bad things.  Stop.

Gah. Maybe it should be left-justified to avoid accentally breaking it again.

I am ok with that on the basis that it is better to be ugly but obvious. I suspect if the Makefile were more littered with conditional $(error)s we would reconsider using tabs as indentation.

Quoted 2 lines

Thanks.
Jonathan

#5 lore raw
In reply to Jonathan Nieder
Quoted 2 lines · Jonathan Nieder

Gah. Maybe it should be left-justified to avoid accentally breaking it again.

;-). Yes, $(error) is not the usual part of "to build this target, follow this recipe" part.

But let's take the last round as-is and go with it for 2.0.

Tahnks.

#6 lore raw
In reply to Dave Borowitz
Quoted 5 lines · Dave Borowitz

How about:
"If CURL_CONFIG is unset or points to a binary that is not found, defaults to the CURLDIR behavior. If CURLDIR is not set, this means using -lcurl with no additional library detection (other than NEEDS_*_WITH_CURL).

Even better, I'll move the blurb about CURLDIR behavior to CURLDIR.

#7 lore raw
In reply to Dave Borowitz
Quoted 10 lines · Dave Borowitz
Quoted 9 lines · Jonathan Nieder
Quoted 6 lines · Dave Borowitz

Instead, if CURL_CONFIG is empty or returns an empty result (e.g. due to curl-config being missing), use the old behavior of falling back to -lcurl.

---
 Makefile | 36 +++++++++++++++++++++++++-----------
 1 file changed, 25 insertions(+), 11 deletions(-)
Quoted 3 lines
Quoted 1 line

Sign-off?

Oops.

Will forge your sign-off while queuing ;-)

Quoted 6 lines

How about:
"If CURL_CONFIG is unset or points to a binary that is not found, defaults to the CURLDIR behavior. If CURLDIR is not set, this means using -lcurl with no additional library detection (other than NEEDS_*_WITH_CURL).

... with this rephrasing.

Quoted 6 lines
Quoted 4 lines

Makefile else · line 1167

Quoted 2 lines
Makefile +1 -1
-                             $(error libcurl not detected; try setting CURLDIR)
+                                $(error libcurl not detected or not compiled with static support)

Whitespace damage.

Yes, but intentional, because Makefile parsing is weird.

Thanks.

#8 lore raw
In reply to Dave Borowitz
Quoted 10 lines · Dave Borowitz

The original implementation of CURL_CONFIG support did not match the original behavior of using -lcurl when CURLDIR was not set. This broke implementations that were lacking curl-config but did have libcurl installed along system libraries, such as MSysGit. In other words, the assumption that curl-config is always installed was incorrect.

Instead, if CURL_CONFIG is empty or returns an empty result (e.g. due to curl-config being missing), use the old behavior of falling back to -lcurl.
---

Sign-off?

I still think the implementation of "If CURL_CONFIG is unset" bit is a bit redundant, though.

Makefile ifdef NO_CURL · line 1139

Quoted 6 lines
Makefile +6 -0
+		CURL_CONFIG ?= curl-config
+		ifeq "$(CURL_CONFIG)" ""
+			CURL_LIBCURL =
+		else
+			CURL_LIBCURL := $(shell $(CURL_CONFIG) --libs)
+		endif

Other than that, the remainder of the change looks correct to me.

Thanks.

#9 lore raw
Quoted 2 lines · Junio C Hamano

I still think the implementation of "If CURL_CONFIG is unset" bit is a bit redundant, though.

If CURL_CONFIG is unset, then $(shell $(CURL_CONFIG) --libs) produces "make: --libs: Command not found", which may be confusing.