Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
PATCH 1/3: add --disable-link-all-libs configure option
- X-seq: zsh-workers 54669
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: PATCH 1/3: add --disable-link-all-libs configure option
- Date: Thu, 4 Jun 2026 07:31:10 +0200
- Archived-at: <https://zsh.org/workers/54669>
- List-id: <zsh-workers.zsh.org>
When this is used, libraries only needed by specific modules will only
be linked to those modules (currently libgdbm and libpcre2). When
--enable-cap is used, the main shell also uses libcap functions so we
want to link that either way.
Speaking of the cap module, it did some weird thing where it always
compiles but creates useless builtins that only error, which means you
can't rely on zmodload to check if they'll work. I'm sure someone will
complain about me changing this but I'm going to at least try it and see
if someone has a good reason for it.
The gdbm module also has a big ifdef for the whole module, but instead
of dummy builtins it just does #error, so remove that. We won't try to
compile it if the user didn't ask for it, and if the user asked for it
and it wouldn't compile, configure won't create a Makefile. Using the
ac_cv_ cache variables in db_gdbm.mdd also doesn't actually work
properly, those will remain set and enable the module to be linked after
you pass --disable-gdbm and you will get the aforementioned #error. Use
the enable_gdbm variable instead, like pcre.mdd does (and also cap.mdd
now that I evilly made it conditional on --enable-cap).
---
Src/Modules/cap.c | 10 ----------
Src/Modules/cap.mdd | 2 +-
Src/Modules/db_gdbm.c | 10 ----------
Src/Modules/db_gdbm.mdd | 4 +++-
Src/Modules/pcre.mdd | 2 ++
Src/mkmakemod.sh | 5 +++--
configure.ac | 43 ++++++++++++++++++++++++++++++++++-------
7 files changed, 45 insertions(+), 31 deletions(-)
diff --git a/Src/Modules/cap.c b/Src/Modules/cap.c
index 6db7cbc2a1..a99e15c885 100644
--- a/Src/Modules/cap.c
+++ b/Src/Modules/cap.c
@@ -30,8 +30,6 @@
#include "cap.mdh"
#include "cap.pro"
-#ifdef HAVE_CAP_GET_PROC
-
static int
bin_cap(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
{
@@ -116,14 +114,6 @@ bin_setcap(char *nam, char **argv, UNUSED(Options ops), UNUSED(int func))
return ret;
}
-#else /* !HAVE_CAP_GET_PROC */
-
-# define bin_cap bin_notavail
-# define bin_getcap bin_notavail
-# define bin_setcap bin_notavail
-
-#endif /* !HAVE_CAP_GET_PROC */
-
/* module paraphernalia */
static struct builtin bintab[] = {
diff --git a/Src/Modules/cap.mdd b/Src/Modules/cap.mdd
index 905f7ca472..543cf0139d 100644
--- a/Src/Modules/cap.mdd
+++ b/Src/Modules/cap.mdd
@@ -1,5 +1,5 @@
name=zsh/cap
-link=dynamic
+link=`if test "x$enable_cap" = xyes; then echo dynamic; else echo no; fi`
load=no
autofeatures="b:cap b:getcap b:setcap"
diff --git a/Src/Modules/db_gdbm.c b/Src/Modules/db_gdbm.c
index 34f577e30f..604788ae8e 100644
--- a/Src/Modules/db_gdbm.c
+++ b/Src/Modules/db_gdbm.c
@@ -46,12 +46,6 @@ static void myfreeparamnode(HashNode hn);
static int no_database_action = 0;
-/*
- * Make sure we have all the bits I'm using for memory mapping, otherwise
- * I don't know what I'm doing.
- */
-#if defined(HAVE_GDBM_H) && defined(HAVE_GDBM_OPEN)
-
#include <gdbm.h>
static char *backtype = "db/gdbm";
@@ -817,7 +811,3 @@ myfreeparamnode(HashNode hn)
}
zfree(pm, sizeof(struct param));
}
-
-#else
-# error no gdbm
-#endif /* have gdbm */
diff --git a/Src/Modules/db_gdbm.mdd b/Src/Modules/db_gdbm.mdd
index 210c221775..122ba8a364 100644
--- a/Src/Modules/db_gdbm.mdd
+++ b/Src/Modules/db_gdbm.mdd
@@ -1,5 +1,5 @@
name=zsh/db/gdbm
-link='if test "x$ac_cv_lib_gdbm_gdbm_open" = xyes && test "x$ac_cv_header_gdbm_h" = xyes; then
+link='if test "x$enable_gdbm" = xyes; then
echo dynamic
else
echo no
@@ -10,3 +10,5 @@ load=no
autofeatures="b:ztie b:zuntie b:zgdbmpath p:zgdbm_tied"
objects="db_gdbm.o"
+
+libs="@GDBM_LIBS@"
diff --git a/Src/Modules/pcre.mdd b/Src/Modules/pcre.mdd
index 3e15791179..dac271b48c 100644
--- a/Src/Modules/pcre.mdd
+++ b/Src/Modules/pcre.mdd
@@ -5,3 +5,5 @@ load=no
autofeatures="b:pcre_compile b:pcre_study b:pcre_match"
objects="pcre.o"
+
+libs="@PCRE_LIBS@"
diff --git a/Src/mkmakemod.sh b/Src/mkmakemod.sh
index 3ccf9c5e59..5e5adc070e 100644
--- a/Src/mkmakemod.sh
+++ b/Src/mkmakemod.sh
@@ -28,6 +28,7 @@
# headers extra headers for this module (default none)
# hdrdeps extra headers on which the .mdh depends (default none)
# otherincs extra headers that are included indirectly (default none)
+# libs extra libraries to link this module against (default none)
#
# The .mdd file may also include a Makefile.in fragment between lines
# `:<<\Make' and `Make' -- this will be copied into Makemod.in.
@@ -186,7 +187,7 @@ if $first_stage; then
unset name moddeps nozshdep alwayslink hasexport
unset autofeatures autofeatures_emu
- unset objects proto headers hdrdeps otherincs
+ unset objects proto headers hdrdeps otherincs libs
. $top_srcdir/$the_subdir/${mddname}.mdd
q_name=`echo $name | sed 's,Q,Qq,g;s,_,Qu,g;s,/,Qs,g'`
test -n "${moddeps+set}" || moddeps=
@@ -324,7 +325,7 @@ if $first_stage; then
echo
echo "${mddname}.\$(DL_EXT): \$(MODDOBJS_${mddname}) ${mddname}.export $exportdeps \$(@LINKMODS@_${mddname})"
echo ' rm -f $@'
- echo " \$(DLLINK) \$(@E@XPIMP_$mddname) \$(@E@NTRYOPT) \$(MODDOBJS_${mddname}) \$(@LINKMODS@_${mddname}) \$(LIBS) "
+ echo " \$(DLLINK) \$(@E@XPIMP_$mddname) \$(@E@NTRYOPT) \$(MODDOBJS_${mddname}) \$(@LINKMODS@_${mddname}) \$(LIBS) ${libs} "
echo
fi
echo "${mddname}.mdhi: ${mddname}.mdhs \$(INCS_${mddname})"
diff --git a/configure.ac b/configure.ac
index e152588eb0..4d348134e2 100644
--- a/configure.ac
+++ b/configure.ac
@@ -438,8 +438,15 @@ AS_HELP_STRING([--enable-cap],[enable the search for POSIX capabilities (may req
# Default off for licensing reasons
AC_ARG_ENABLE(gdbm,
-AS_HELP_STRING([--enable-gdbm],[enable the search for the GDBM library (see the zsh/db/gdbm module)]),
-[gdbm="$enableval"], [gdbm=no])
+AS_HELP_STRING([--enable-gdbm],[enable the search for the GDBM library (see the zsh/db/gdbm module)]))
+
+dnl
+dnl link all libraries in main shell
+dnl
+AC_ARG_ENABLE(link-all-libs,
+AS_HELP_STRING([--disable-link-all-libs],
+ [do not link module-only libraries into the main binary]),
+[enable_link_all_libs=$enableval], [enable_link_all_libs=yes])
dnl ------------------
dnl CHECK THE COMPILER
@@ -719,7 +726,6 @@ AC_ARG_WITH(term-lib,
AS_HELP_STRING([--with-term-lib=LIBS],[search space-separated LIBS for terminal handling]),
[if test "x$withval" != xno && test "x$withval" != x ; then
termcap_curses_order="$withval"
- AC_SEARCH_LIBS(tigetstr, [$termcap_curses_order])
else
termcap_curses_order="$ncursesw_test $ncurses_test tinfow tinfo termcap curses"
fi],
@@ -931,9 +937,18 @@ elif test x$zsh_cv_decl_ospeed_must_define = xyes; then
AC_DEFINE(MUST_DEFINE_OSPEED)
fi
-if test x$gdbm != xno; then
+if test x$enable_gdbm = xyes; then
AC_CHECK_HEADERS(gdbm.h)
+ save_LIBS=$LIBS
+ LIBS=
AC_CHECK_LIB(gdbm, gdbm_open)
+ GDBM_LIBS=$LIBS
+ LIBS=$save_LIBS
+ if test x$enable_link_all_libs = xyes; then
+ LIBS="$GDBM_LIBS $LIBS"
+ GDBM_LIBS=
+ fi
+ AC_SUBST(GDBM_LIBS)
fi
AC_CHECK_HEADERS(sys/xattr.h)
@@ -1268,7 +1283,7 @@ AC_CHECK_FUNCS(strftime strptime mktime timelocal \
grantpt unlockpt ptsname \
htons ntohs \
regcomp regexec regerror regfree \
- gdbm_open getxattr \
+ getxattr \
realpath canonicalize_file_name \
symlink getcwd \
cygwin_conv_path \
@@ -1320,8 +1335,16 @@ if test x$zsh_cv_func_realpath_accepts_null = xyes; then
fi
if test x$enable_pcre = xyes; then
- LIBS="`$PCRE_CONFIG --libs8` $LIBS"
+ save_LIBS=$LIBS
+ PCRE_LIBS="`$PCRE_CONFIG --libs8`"
+ LIBS="$PCRE_LIBS $LIBS"
AC_CHECK_FUNCS(pcre2_compile_8)
+ LIBS=$save_LIBS
+ if test x$enable_link_all_libs = xyes; then
+ LIBS="$PCRE_LIBS $LIBS"
+ PCRE_LIBS=
+ fi
+ AC_SUBST(PCRE_LIBS)
fi
if test x$enable_cap = xyes; then
@@ -3051,7 +3074,13 @@ if test "x$dynamic" = xyes; then
module linker flags : ${LDFLAGS} ${LIBLDFLAGS} ${DLLDFLAGS}"
fi
echo "\
-library flags : ${LIBS}
+library flags : ${LIBS}"
+if test x$enable_link_all_libs != xyes; then
+echo "\
+gdbm module library flags : ${GDBM_LIBS}
+pcre module library flags : ${PCRE_LIBS}"
+fi
+echo "\
installation basename : ${tzsh_name}
binary install path : ${zshbin2}
man page install path : ${zshman2}
--
2.38.1
Messages sorted by:
Reverse Date,
Date,
Thread,
Author