git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCH 0/2] CC_LD_DYNPATH improvements
@ 2024-01-31 17:42 Junio C Hamano
  2024-01-31 17:42 ` [PATCH 1/2] Makefile: reduce repetitive library paths Junio C Hamano
  2024-01-31 17:42 ` [PATCH 2/2] Makefile: simplify output of the libpath_template Junio C Hamano
  0 siblings, 2 replies; 4+ messages in thread
From: Junio C Hamano @ 2024-01-31 17:42 UTC (permalink / raw
  To: git; +Cc: Haritha D

We seem to repeat ourselves many times in Makefile with lines like
this:

  EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)

but we should be able to express ourselves without repeating the
same long string twice, perhaps like so:

  EXTLIBS += $(call libpath_template,$(LIBPCREDIR)/$(lib))

I originally wrote this as a practice to use the $(call template)
pattern in Makefile, but it may make porting to a platform without
dynamic library path support simpler.


Junio C Hamano (2):
  Makefile: reduce repetitive library paths
  Makefile: simplify output of the libpath_template

 Makefile   | 12 ++++++------
 shared.mak |  6 ++++++
 2 files changed, 12 insertions(+), 6 deletions(-)

-- 
2.43.0-493-gbc7ee2e5e1



^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 1/2] Makefile: reduce repetitive library paths
  2024-01-31 17:42 [PATCH 0/2] CC_LD_DYNPATH improvements Junio C Hamano
@ 2024-01-31 17:42 ` Junio C Hamano
  2024-01-31 17:42 ` [PATCH 2/2] Makefile: simplify output of the libpath_template Junio C Hamano
  1 sibling, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2024-01-31 17:42 UTC (permalink / raw
  To: git

When we take a library package we depend on (e.g., LIBPCRE) from a
directory other than the default location of the system, we add the
same directory twice on the linker command like, like so:

  EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)

Introduce a template "libpath_template" that takes the path to the
directory, which can be used like so:

  EXTLIBS += $(call libpath_template,$(LIBPCREDIR)/$(lib))

and expand it into the "-L$(DIR) $(CC_LD_DYNPATH)$(DIR)" form.
Hopefully we can reduce the chance of typoes this way.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 Makefile   | 12 ++++++------
 shared.mak |  6 ++++++
 2 files changed, 12 insertions(+), 6 deletions(-)

diff --git a/Makefile b/Makefile
index 03adcb5a48..13f256ca13 100644
--- a/Makefile
+++ b/Makefile
@@ -1575,7 +1575,7 @@ endif
 
 ifdef LIBPCREDIR
 	BASIC_CFLAGS += -I$(LIBPCREDIR)/include
-	EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)
+	EXTLIBS += $(call libpath_template,$(LIBPCREDIR)/$(lib))
 endif
 
 ifdef HAVE_ALLOCA_H
@@ -1595,7 +1595,7 @@ else
 	ifdef CURLDIR
 		# Try "-Wl,-rpath=$(CURLDIR)/$(lib)" in such a case.
 		CURL_CFLAGS = -I$(CURLDIR)/include
-		CURL_LIBCURL = -L$(CURLDIR)/$(lib) $(CC_LD_DYNPATH)$(CURLDIR)/$(lib)
+		CURL_LIBCURL = $(call libpath_template,$(CURLDIR)/$(lib))
 	else
 		CURL_CFLAGS =
 		CURL_LIBCURL =
@@ -1631,7 +1631,7 @@ else
 	ifndef NO_EXPAT
 		ifdef EXPATDIR
 			BASIC_CFLAGS += -I$(EXPATDIR)/include
-			EXPAT_LIBEXPAT = -L$(EXPATDIR)/$(lib) $(CC_LD_DYNPATH)$(EXPATDIR)/$(lib) -lexpat
+			EXPAT_LIBEXPAT = $(call libpath_template,$(EXPATDIR)/$(lib)) -lexpat
 		else
 			EXPAT_LIBEXPAT = -lexpat
 		endif
@@ -1644,7 +1644,7 @@ IMAP_SEND_LDFLAGS += $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
 
 ifdef ZLIB_PATH
 	BASIC_CFLAGS += -I$(ZLIB_PATH)/include
-	EXTLIBS += -L$(ZLIB_PATH)/$(lib) $(CC_LD_DYNPATH)$(ZLIB_PATH)/$(lib)
+	EXTLIBS += $(call libpath_template,$(ZLIB_PATH)/$(lib))
 endif
 EXTLIBS += -lz
 
@@ -1652,7 +1652,7 @@ ifndef NO_OPENSSL
 	OPENSSL_LIBSSL = -lssl
 	ifdef OPENSSLDIR
 		BASIC_CFLAGS += -I$(OPENSSLDIR)/include
-		OPENSSL_LINK = -L$(OPENSSLDIR)/$(lib) $(CC_LD_DYNPATH)$(OPENSSLDIR)/$(lib)
+		OPENSSL_LINK = $(call libpath_template,$(OPENSSLDIR)/$(lib))
 	else
 		OPENSSL_LINK =
 	endif
@@ -1679,7 +1679,7 @@ ifndef NO_ICONV
 	ifdef NEEDS_LIBICONV
 		ifdef ICONVDIR
 			BASIC_CFLAGS += -I$(ICONVDIR)/include
-			ICONV_LINK = -L$(ICONVDIR)/$(lib) $(CC_LD_DYNPATH)$(ICONVDIR)/$(lib)
+			ICONV_LINK = $(call libpath_template,$(ICONVDIR)/$(lib))
 		else
 			ICONV_LINK =
 		endif
diff --git a/shared.mak b/shared.mak
index aeb80fc4d5..f33cab8a4e 100644
--- a/shared.mak
+++ b/shared.mak
@@ -108,3 +108,9 @@ endif
 define mkdir_p_parent_template
 $(if $(wildcard $(@D)),,$(QUIET_MKDIR_P_PARENT)$(shell mkdir -p $(@D)))
 endef
+
+## Getting sick of writing -L$(SOMELIBDIR) $(CC_LD_DYNPATH)$(SOMELIBDIR)?
+## Write $(call libpath_template,$(SOMELIBDIR)) instead, perhaps?
+define libpath_template
+-L$(1) $(CC_LD_DYNPATH)$(1)
+endef
-- 
2.43.0-493-gbc7ee2e5e1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 2/2] Makefile: simplify output of the libpath_template
  2024-01-31 17:42 [PATCH 0/2] CC_LD_DYNPATH improvements Junio C Hamano
  2024-01-31 17:42 ` [PATCH 1/2] Makefile: reduce repetitive library paths Junio C Hamano
@ 2024-01-31 17:42 ` Junio C Hamano
  2024-01-31 22:59   ` Junio C Hamano
  1 sibling, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2024-01-31 17:42 UTC (permalink / raw
  To: git

If a platform lacks the support to specify the dynamic library path,
there is no suitable value to give to the CC_LD_DYNPATH variable.
Allow them to be set to an empty string to signal that they do not
need to add the usual -Wl,-rpath, or -R or whatever option followed
by a directory name.  This way,

    $(call libpath_tempate,$(SOMELIBDIR))

would expand to just a single mention of that directory, i.e.

    -L$(SOMELIBDIR)

when CC_LD_DYNPATH is set to an empty string (or a "-L", which
would have repeated the same "-L$(SOMELIBDIR)" twice without any
ill effect).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
---
 * This obviously makes it impossible to set CC_LD_DYNPATH to an
   empty string to say "-L /usr/local/lib /usr/local/lib" on the
   linker's command line.  I do not think it would serve any useful
   purpose to be able to have just a directory name on the command
   line of the linker there, so it would not regress anything on
   exotic platforms, I hope ;-).

 shared.mak | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/shared.mak b/shared.mak
index f33cab8a4e..c59cea75a1 100644
--- a/shared.mak
+++ b/shared.mak
@@ -112,5 +112,5 @@ endef
 ## Getting sick of writing -L$(SOMELIBDIR) $(CC_LD_DYNPATH)$(SOMELIBDIR)?
 ## Write $(call libpath_template,$(SOMELIBDIR)) instead, perhaps?
 define libpath_template
--L$(1) $(CC_LD_DYNPATH)$(1)
+-L$(1) $(if $(filter-out -L,$(CC_LD_DYNPATH)),$(CC_LD_DYNPATH)$(1))
 endef
-- 
2.43.0-493-gbc7ee2e5e1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 2/2] Makefile: simplify output of the libpath_template
  2024-01-31 17:42 ` [PATCH 2/2] Makefile: simplify output of the libpath_template Junio C Hamano
@ 2024-01-31 22:59   ` Junio C Hamano
  0 siblings, 0 replies; 4+ messages in thread
From: Junio C Hamano @ 2024-01-31 22:59 UTC (permalink / raw
  To: git

Junio C Hamano <gitster@pobox.com> writes:

> by a directory name.  This way,
>
>     $(call libpath_tempate,$(SOMELIBDIR))

"libpath_template" obviously.


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-01-31 23:00 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-31 17:42 [PATCH 0/2] CC_LD_DYNPATH improvements Junio C Hamano
2024-01-31 17:42 ` [PATCH 1/2] Makefile: reduce repetitive library paths Junio C Hamano
2024-01-31 17:42 ` [PATCH 2/2] Makefile: simplify output of the libpath_template Junio C Hamano
2024-01-31 22:59   ` Junio C Hamano

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).