git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 1/2] Makefile: avoid running curl-config multiple times

From
Jeff King <peff@peff.net>
Date
Mar 26, 2020, 08:06 UTC
Message-ID
<20200326080645.GA2200716@coredump.intra.peff.net>
In-Reply-To
<20200326080540.GA2200522@coredump.intra.peff.net>

If the user hasn't set the CURL_LDFLAGS Makefile variable, we invoke curl-config like this:

  CURL_LIBCURL += $(shell $(CURL_CONFIG) --libs)

Because the shell function is run when the value is expanded, we invoke curl-config each time we need to link something (which generally ends up being four times for a full build).

Instead, let's use an immediate Makefile variable, which only needs expanding once. We can't combine that with the existing "+=", but since we only do this when CURL_LDFLAGS is undefined, we can just set that variable.

That also allows us to simplify our conditional a bit, since both sides will then put the result into CURL_LIBCURL. While we're touching it, let's fix the indentation to match the nearby code (we're inside an outer conditional, so everything else is indented one level).

Signed-off-by: Jeff King <peff@peff.net>
---
 Makefile | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/Makefile b/Makefile
index a5961113d8..93a8ef3a72 100644
--- a/Makefile
+++ b/Makefile
@@ -1365,11 +1365,10 @@ else
 		CURL_LIBCURL =
 	endif
 
-ifdef CURL_LDFLAGS
+	ifndef CURL_LDFLAGS
+		CURL_LDFLAGS := $(shell $(CURL_CONFIG) --libs)
+	endif
 	CURL_LIBCURL += $(CURL_LDFLAGS)
-else
-	CURL_LIBCURL += $(shell $(CURL_CONFIG) --libs)
-endif
 
 	REMOTE_CURL_PRIMARY = git-remote-http$X
 	REMOTE_CURL_ALIASES = git-remote-https$X git-remote-ftp$X git-remote-ftps$X
-- 
2.26.0.576.gb87790c3c1
Previous: Jeff KingNext: Jeff King
Message 2 of 13 in “use `curl-config --cflags`”
  1. 0/2 use `curl-config --cflags`Jeff King, Mar 26, 2020
  2. 1/2 Makefile: avoid running curl-config multiple timesJeff King, Mar 26, 2020
  3. 2/2 Makefile: use curl-config --cflagsJeff King, Mar 26, 2020
  4. Junio C HamanoMar 27, 2020
  5. Johannes SchindelinApr 4, 2020
  6. Makefile: avoid running curl-config unnecessarilyJeff King, Apr 4, 2020
  7. Eric SunshineApr 5, 2020
  8. Jeff KingApr 5, 2020
  9. Eric SunshineApr 5, 2020
  10. Johannes SchindelinApr 5, 2020
  11. Johannes SchindelinApr 5, 2020
  12. Junio C HamanoApr 15, 2020
  13. Jeff KingApr 15, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.