Makefile: reduce repetitive library paths

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>

Junio C Hamano committed Jan 31, 2024 at 09:42 UTC 354dbf7d649ef75c2f83d0f1d7cc03d1e84279dc
2 files changed +12 -6
Makefile
+6 -6
@@ -1575,7 +1575,7 @@ endif
1575
1576 ifdef LIBPCREDIR
1577 BASIC_CFLAGS += -I$(LIBPCREDIR)/include
1578 - EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)
1578 + EXTLIBS += $(call libpath_template,$(LIBPCREDIR)/$(lib))
1579 endif
1580
1581 ifdef HAVE_ALLOCA_H
@@ -1595,7 +1595,7 @@ else
1595 ifdef CURLDIR
1596 # Try "-Wl,-rpath=$(CURLDIR)/$(lib)" in such a case.
1597 CURL_CFLAGS = -I$(CURLDIR)/include
1598 - CURL_LIBCURL = -L$(CURLDIR)/$(lib) $(CC_LD_DYNPATH)$(CURLDIR)/$(lib)
1598 + CURL_LIBCURL = $(call libpath_template,$(CURLDIR)/$(lib))
1599 else
1600 CURL_CFLAGS =
1601 CURL_LIBCURL =
@@ -1631,7 +1631,7 @@ else
1631 ifndef NO_EXPAT
1632 ifdef EXPATDIR
1633 BASIC_CFLAGS += -I$(EXPATDIR)/include
1634 - EXPAT_LIBEXPAT = -L$(EXPATDIR)/$(lib) $(CC_LD_DYNPATH)$(EXPATDIR)/$(lib) -lexpat
1634 + EXPAT_LIBEXPAT = $(call libpath_template,$(EXPATDIR)/$(lib)) -lexpat
1635 else
1636 EXPAT_LIBEXPAT = -lexpat
1637 endif
@@ -1644,7 +1644,7 @@ IMAP_SEND_LDFLAGS += $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
1644
1645 ifdef ZLIB_PATH
1646 BASIC_CFLAGS += -I$(ZLIB_PATH)/include
1647 - EXTLIBS += -L$(ZLIB_PATH)/$(lib) $(CC_LD_DYNPATH)$(ZLIB_PATH)/$(lib)
1647 + EXTLIBS += $(call libpath_template,$(ZLIB_PATH)/$(lib))
1648 endif
1649 EXTLIBS += -lz
1650
@@ -1652,7 +1652,7 @@ ifndef NO_OPENSSL
1652 OPENSSL_LIBSSL = -lssl
1653 ifdef OPENSSLDIR
1654 BASIC_CFLAGS += -I$(OPENSSLDIR)/include
1655 - OPENSSL_LINK = -L$(OPENSSLDIR)/$(lib) $(CC_LD_DYNPATH)$(OPENSSLDIR)/$(lib)
1655 + OPENSSL_LINK = $(call libpath_template,$(OPENSSLDIR)/$(lib))
1656 else
1657 OPENSSL_LINK =
1658 endif
@@ -1679,7 +1679,7 @@ ifndef NO_ICONV
1679 ifdef NEEDS_LIBICONV
1680 ifdef ICONVDIR
1681 BASIC_CFLAGS += -I$(ICONVDIR)/include
1682 - ICONV_LINK = -L$(ICONVDIR)/$(lib) $(CC_LD_DYNPATH)$(ICONVDIR)/$(lib)
1682 + ICONV_LINK = $(call libpath_template,$(ICONVDIR)/$(lib))
1683 else
1684 ICONV_LINK =
1685 endif
shared.mak
+6
@@ -108,3 +108,9 @@ endif
108 define mkdir_p_parent_template
109 $(if $(wildcard $(@D)),,$(QUIET_MKDIR_P_PARENT)$(shell mkdir -p $(@D)))
110 endef
111 +
112 +## Getting sick of writing -L$(SOMELIBDIR) $(CC_LD_DYNPATH)$(SOMELIBDIR)?
113 +## Write $(call libpath_template,$(SOMELIBDIR)) instead, perhaps?
114 +define libpath_template
115 +-L$(1) $(CC_LD_DYNPATH)$(1)
116 +endef