summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlan Coopersmith <alan.coopersmith@oracle.com>2022-11-05 10:37:33 -0700
committerAlan Coopersmith <alan.coopersmith@oracle.com>2022-11-05 11:52:48 -0700
commit968b9c0b390f15f44ab4f3ee5fce23a9cec60720 (patch)
tree25d82a87866a8fa71a09821a8bfb9ed5ac1fdcde
parent8a10c98d29d0ff2028f109b5671dfae2910df051 (diff)
Only link with libbsd if needed for arc4random() or setproctitle()
Avoid unnecessary library dependency when using a libc with these functions included. Also only links to the binary that needs them (xdm, not chooser or greeter) Signed-off-by: Alan Coopersmith <alan.coopersmith@oracle.com>
-rw-r--r--configure.ac37
1 files changed, 26 insertions, 11 deletions
diff --git a/configure.ac b/configure.ac
index 4f91f01..e5df403 100644
--- a/configure.ac
+++ b/configure.ac
@@ -59,10 +59,26 @@ AM_CONDITIONAL(HAVE_MKTEMP_COMMAND, test x$MKTEMP_COMMAND != x)
#
#------------------------------------------------------------------------------
-PKG_CHECK_MODULES([LIBBSD], [libbsd-overlay], [
- CFLAGS="$CFLAGS $LIBBSD_CFLAGS"
- LIBS="$LIBS $LIBBSD_LIBS"
-], [:])
+PKG_CHECK_MODULES([XDM], [xmu x11 xau xproto >= 7.0.17])
+PKG_CHECK_MODULES([LIBBSD], [libbsd-overlay], [:], [:])
+
+dnl Check in libbsd for functions that might be there if not already found
+dnl XDM_SEARCH_LIBBSD(FUNCTION, PROGRAM, [ACTION-IF-FOUND], [ACTION-IF-NOT-FOUND])
+AC_DEFUN([XDM_SEARCH_LIBBSD],[
+if test "x$ac_cv_search_$1" = "xno"; then
+ if test "x$LIBBSD_LIBS" != "x"; then
+ AC_MSG_CHECKING([for $1 in libbsd])
+ xdm_save_LIBS="$LIBS"
+ LIBS="$LIBS $[$2]_LIBS $LIBBSD_LIBS"
+ AC_LINK_IFELSE([AC_LANG_CALL([], [$1])], [xdm_res="yes"], [xdm_res="no"])
+ LIBS="$xdm_save_LIBS"
+ AS_IF([test "x$xdm_res" = "xyes"], [
+ $2_CFLAGS="$[$2]_CFLAGS $LIBBSD_CFLAGS"
+ $2_LIBS="$[$2]_LIBS $LIBBSD_LIBS"
+ [$3]], [$4])
+ AC_MSG_RESULT([$xdm_res])
+ fi
+fi])
# Function getifaddrs() comes from the C library, Solaris 11 -lsocket, or
# the -lnsl name service library
@@ -74,12 +90,14 @@ AC_SEARCH_LIBS([getspnam], [sec gen shadow])
# Function setproctitle() is in BSD -lutil or GNU systems -lbsd but N/A on Solaris
AC_SEARCH_LIBS([setproctitle], [util])
+XDM_SEARCH_LIBBSD([setproctitle], [XDM])
# Function setusercontext() is in BSD -lutil but N/A on Solaris or GNU systems
AC_SEARCH_LIBS([setusercontext], [util])
-# Function arc4random() is in BSD standard C or GNU systems -lbsd
+# Function arc4random() is in BSD standard C, glibc 2.36+, or GNU systems -lbsd
AC_SEARCH_LIBS([arc4random], [], [HAVE_ARC4RANDOM="yes"])
+XDM_SEARCH_LIBBSD([arc4random], [XDM], [HAVE_ARC4RANDOM="yes"])
AC_SUBST(HAVE_ARC4RANDOM)
AM_CONDITIONAL(HAVE_ARC4RANDOM, test x$HAVE_ARC4RANDOM = xyes)
@@ -103,12 +121,11 @@ AC_CHECK_DECL(key_setnet,
# Check for system library functions
# Required system libraries have been searched for and are listed in $LIBS
AC_FUNC_FORK
+xdm_save_LIBS="$LIBS"
+LIBS="$LIBS $XDM_LIBS"
AC_CHECK_FUNCS([daemon sigaction openlog asprintf setproctitle setusercontext \
mkstemp getifaddrs getspnam arc4random])
-
-XDM_CFLAGS="$XDM_CFLAGS"
-GREETER_CFLAGS="$GREETER_CFLAGS"
-CHOOSER_CFLAGS="$CHOOSER_CFLAGS"
+LIBS="$xdm_save_LIBS"
# Find needed libraries for TCP sockets (pre-pended in $LIBS)
XTRANS_CONNECTION_FLAGS
@@ -334,8 +351,6 @@ AC_SUBST(SHELL_CMD)
# Checks for pkg-config packages
-PKG_CHECK_MODULES(XDM, [xmu x11 xau xproto >= 7.0.17])
-
AC_ARG_WITH(xinerama,
AS_HELP_STRING([--with-xinerama],
[Use Xinerama (default is YES if installed)]),