{"thread":{"id":"60824","subject":"[PATCH 2/2] Makefile: simplify output of the libpath_template","startedAt":"2024-01-31T17:42:28Z","lastAt":"2024-01-31T22:59:51Z","messageCount":4,"participants":["Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"487649","messageId":"20240131174220.4160560-3-gitster@pobox.com","threadId":"60824","inReplyTo":"20240131174220.4160560-1-gitster@pobox.com","subject":"[PATCH 2/2] Makefile: simplify output of the libpath_template","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-01-31T17:42:20Z","receivedAt":"2024-01-31T17:42:28Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"If a platform lacks the support to specify the dynamic library path,\nthere is no suitable value to give to the CC_LD_DYNPATH variable.\nAllow them to be set to an empty string to signal that they do not\nneed to add the usual -Wl,-rpath, or -R or whatever option followed\nby a directory name.  This way,\n\n    $(call libpath_tempate,$(SOMELIBDIR))\n\nwould expand to just a single mention of that directory, i.e.\n\n    -L$(SOMELIBDIR)\n\nwhen CC_LD_DYNPATH is set to an empty string (or a \"-L\", which\nwould have repeated the same \"-L$(SOMELIBDIR)\" twice without any\nill effect).\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n * This obviously makes it impossible to set CC_LD_DYNPATH to an\n   empty string to say \"-L /usr/local/lib /usr/local/lib\" on the\n   linker's command line.  I do not think it would serve any useful\n   purpose to be able to have just a directory name on the command\n   line of the linker there, so it would not regress anything on\n   exotic platforms, I hope ;-).\n\n shared.mak | 2 +-\n 1 file changed, 1 insertion(+), 1 deletion(-)\n\ndiff --git a/shared.mak b/shared.mak\nindex f33cab8a4e..c59cea75a1 100644\n--- a/shared.mak\n+++ b/shared.mak\n@@ -112,5 +112,5 @@ endef\n ## Getting sick of writing -L$(SOMELIBDIR) $(CC_LD_DYNPATH)$(SOMELIBDIR)?\n ## Write $(call libpath_template,$(SOMELIBDIR)) instead, perhaps?\n define libpath_template\n--L$(1) $(CC_LD_DYNPATH)$(1)\n+-L$(1) $(if $(filter-out -L,$(CC_LD_DYNPATH)),$(CC_LD_DYNPATH)$(1))\n endef\n-- \n2.43.0-493-gbc7ee2e5e1\n\n"},{"id":"487650","messageId":"20240131174220.4160560-1-gitster@pobox.com","threadId":"60824","inReplyTo":null,"subject":"[PATCH 0/2] CC_LD_DYNPATH improvements","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-01-31T17:42:18Z","receivedAt":"2024-01-31T17:42:29Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"We seem to repeat ourselves many times in Makefile with lines like\nthis:\n\n  EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)\n\nbut we should be able to express ourselves without repeating the\nsame long string twice, perhaps like so:\n\n  EXTLIBS += $(call libpath_template,$(LIBPCREDIR)/$(lib))\n\nI originally wrote this as a practice to use the $(call template)\npattern in Makefile, but it may make porting to a platform without\ndynamic library path support simpler.\n\n\nJunio C Hamano (2):\n  Makefile: reduce repetitive library paths\n  Makefile: simplify output of the libpath_template\n\n Makefile   | 12 ++++++------\n shared.mak |  6 ++++++\n 2 files changed, 12 insertions(+), 6 deletions(-)\n\n-- \n2.43.0-493-gbc7ee2e5e1\n\n"},{"id":"487651","messageId":"20240131174220.4160560-2-gitster@pobox.com","threadId":"60824","inReplyTo":"20240131174220.4160560-1-gitster@pobox.com","subject":"[PATCH 1/2] Makefile: reduce repetitive library paths","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-01-31T17:42:19Z","receivedAt":"2024-01-31T17:42:30Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When we take a library package we depend on (e.g., LIBPCRE) from a\ndirectory other than the default location of the system, we add the\nsame directory twice on the linker command like, like so:\n\n  EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)\n\nIntroduce a template \"libpath_template\" that takes the path to the\ndirectory, which can be used like so:\n\n  EXTLIBS += $(call libpath_template,$(LIBPCREDIR)/$(lib))\n\nand expand it into the \"-L$(DIR) $(CC_LD_DYNPATH)$(DIR)\" form.\nHopefully we can reduce the chance of typoes this way.\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n Makefile   | 12 ++++++------\n shared.mak |  6 ++++++\n 2 files changed, 12 insertions(+), 6 deletions(-)\n\ndiff --git a/Makefile b/Makefile\nindex 03adcb5a48..13f256ca13 100644\n--- a/Makefile\n+++ b/Makefile\n@@ -1575,7 +1575,7 @@ endif\n \n ifdef LIBPCREDIR\n \tBASIC_CFLAGS += -I$(LIBPCREDIR)/include\n-\tEXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)\n+\tEXTLIBS += $(call libpath_template,$(LIBPCREDIR)/$(lib))\n endif\n \n ifdef HAVE_ALLOCA_H\n@@ -1595,7 +1595,7 @@ else\n \tifdef CURLDIR\n \t\t# Try \"-Wl,-rpath=$(CURLDIR)/$(lib)\" in such a case.\n \t\tCURL_CFLAGS = -I$(CURLDIR)/include\n-\t\tCURL_LIBCURL = -L$(CURLDIR)/$(lib) $(CC_LD_DYNPATH)$(CURLDIR)/$(lib)\n+\t\tCURL_LIBCURL = $(call libpath_template,$(CURLDIR)/$(lib))\n \telse\n \t\tCURL_CFLAGS =\n \t\tCURL_LIBCURL =\n@@ -1631,7 +1631,7 @@ else\n \tifndef NO_EXPAT\n \t\tifdef EXPATDIR\n \t\t\tBASIC_CFLAGS += -I$(EXPATDIR)/include\n-\t\t\tEXPAT_LIBEXPAT = -L$(EXPATDIR)/$(lib) $(CC_LD_DYNPATH)$(EXPATDIR)/$(lib) -lexpat\n+\t\t\tEXPAT_LIBEXPAT = $(call libpath_template,$(EXPATDIR)/$(lib)) -lexpat\n \t\telse\n \t\t\tEXPAT_LIBEXPAT = -lexpat\n \t\tendif\n@@ -1644,7 +1644,7 @@ IMAP_SEND_LDFLAGS += $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)\n \n ifdef ZLIB_PATH\n \tBASIC_CFLAGS += -I$(ZLIB_PATH)/include\n-\tEXTLIBS += -L$(ZLIB_PATH)/$(lib) $(CC_LD_DYNPATH)$(ZLIB_PATH)/$(lib)\n+\tEXTLIBS += $(call libpath_template,$(ZLIB_PATH)/$(lib))\n endif\n EXTLIBS += -lz\n \n@@ -1652,7 +1652,7 @@ ifndef NO_OPENSSL\n \tOPENSSL_LIBSSL = -lssl\n \tifdef OPENSSLDIR\n \t\tBASIC_CFLAGS += -I$(OPENSSLDIR)/include\n-\t\tOPENSSL_LINK = -L$(OPENSSLDIR)/$(lib) $(CC_LD_DYNPATH)$(OPENSSLDIR)/$(lib)\n+\t\tOPENSSL_LINK = $(call libpath_template,$(OPENSSLDIR)/$(lib))\n \telse\n \t\tOPENSSL_LINK =\n \tendif\n@@ -1679,7 +1679,7 @@ ifndef NO_ICONV\n \tifdef NEEDS_LIBICONV\n \t\tifdef ICONVDIR\n \t\t\tBASIC_CFLAGS += -I$(ICONVDIR)/include\n-\t\t\tICONV_LINK = -L$(ICONVDIR)/$(lib) $(CC_LD_DYNPATH)$(ICONVDIR)/$(lib)\n+\t\t\tICONV_LINK = $(call libpath_template,$(ICONVDIR)/$(lib))\n \t\telse\n \t\t\tICONV_LINK =\n \t\tendif\ndiff --git a/shared.mak b/shared.mak\nindex aeb80fc4d5..f33cab8a4e 100644\n--- a/shared.mak\n+++ b/shared.mak\n@@ -108,3 +108,9 @@ endif\n define mkdir_p_parent_template\n $(if $(wildcard $(@D)),,$(QUIET_MKDIR_P_PARENT)$(shell mkdir -p $(@D)))\n endef\n+\n+## Getting sick of writing -L$(SOMELIBDIR) $(CC_LD_DYNPATH)$(SOMELIBDIR)?\n+## Write $(call libpath_template,$(SOMELIBDIR)) instead, perhaps?\n+define libpath_template\n+-L$(1) $(CC_LD_DYNPATH)$(1)\n+endef\n-- \n2.43.0-493-gbc7ee2e5e1\n\n"},{"id":"487688","messageId":"xmqqr0hx2joj.fsf@gitster.g","threadId":"60824","inReplyTo":"20240131174220.4160560-3-gitster@pobox.com","subject":"Re: [PATCH 2/2] Makefile: simplify output of the libpath_template","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-01-31T22:59:40Z","receivedAt":"2024-01-31T22:59:51Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Junio C Hamano <gitster@pobox.com> writes:\n\n> by a directory name.  This way,\n>\n>     $(call libpath_tempate,$(SOMELIBDIR))\n\n\"libpath_template\" obviously.\n"}]}