Skip to content

Commit 354dbf7

Browse files
committed
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 <[email protected]>
1 parent 564d025 commit 354dbf7

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

Makefile

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1575,7 +1575,7 @@ endif
15751575

15761576
ifdef LIBPCREDIR
15771577
BASIC_CFLAGS += -I$(LIBPCREDIR)/include
1578-
EXTLIBS += -L$(LIBPCREDIR)/$(lib) $(CC_LD_DYNPATH)$(LIBPCREDIR)/$(lib)
1578+
EXTLIBS += $(call libpath_template,$(LIBPCREDIR)/$(lib))
15791579
endif
15801580

15811581
ifdef HAVE_ALLOCA_H
@@ -1595,7 +1595,7 @@ else
15951595
ifdef CURLDIR
15961596
# Try "-Wl,-rpath=$(CURLDIR)/$(lib)" in such a case.
15971597
CURL_CFLAGS = -I$(CURLDIR)/include
1598-
CURL_LIBCURL = -L$(CURLDIR)/$(lib) $(CC_LD_DYNPATH)$(CURLDIR)/$(lib)
1598+
CURL_LIBCURL = $(call libpath_template,$(CURLDIR)/$(lib))
15991599
else
16001600
CURL_CFLAGS =
16011601
CURL_LIBCURL =
@@ -1631,7 +1631,7 @@ else
16311631
ifndef NO_EXPAT
16321632
ifdef EXPATDIR
16331633
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
16351635
else
16361636
EXPAT_LIBEXPAT = -lexpat
16371637
endif
@@ -1644,15 +1644,15 @@ IMAP_SEND_LDFLAGS += $(OPENSSL_LINK) $(OPENSSL_LIBSSL) $(LIB_4_CRYPTO)
16441644

16451645
ifdef ZLIB_PATH
16461646
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))
16481648
endif
16491649
EXTLIBS += -lz
16501650

16511651
ifndef NO_OPENSSL
16521652
OPENSSL_LIBSSL = -lssl
16531653
ifdef OPENSSLDIR
16541654
BASIC_CFLAGS += -I$(OPENSSLDIR)/include
1655-
OPENSSL_LINK = -L$(OPENSSLDIR)/$(lib) $(CC_LD_DYNPATH)$(OPENSSLDIR)/$(lib)
1655+
OPENSSL_LINK = $(call libpath_template,$(OPENSSLDIR)/$(lib))
16561656
else
16571657
OPENSSL_LINK =
16581658
endif
@@ -1679,7 +1679,7 @@ ifndef NO_ICONV
16791679
ifdef NEEDS_LIBICONV
16801680
ifdef ICONVDIR
16811681
BASIC_CFLAGS += -I$(ICONVDIR)/include
1682-
ICONV_LINK = -L$(ICONVDIR)/$(lib) $(CC_LD_DYNPATH)$(ICONVDIR)/$(lib)
1682+
ICONV_LINK = $(call libpath_template,$(ICONVDIR)/$(lib))
16831683
else
16841684
ICONV_LINK =
16851685
endif

shared.mak

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,3 +108,9 @@ endif
108108
define mkdir_p_parent_template
109109
$(if $(wildcard $(@D)),,$(QUIET_MKDIR_P_PARENT)$(shell mkdir -p $(@D)))
110110
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

0 commit comments

Comments
 (0)