From 644bea5c481365343e709d0f2ddbc553a6d8fc30 Mon Sep 17 00:00:00 2001 From: Alan Coopersmith Date: Sat, 5 Nov 2022 09:16:14 -0700 Subject: Only link with libbsd if needed for reallocarray() or strlcat() Avoid unnecessary library dependency when using a libc with these functions included Signed-off-by: Alan Coopersmith --- configure.ac | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/configure.ac b/configure.ac index 701f9fd..fe2f987 100644 --- a/configure.ac +++ b/configure.ac @@ -50,12 +50,18 @@ XORG_CHECK_SGML_DOCTOOLS(1.7) # Checks for header files. AC_CHECK_HEADERS([endian.h poll.h sys/poll.h]) -# Checks for library functions. -PKG_CHECK_MODULES([LIBBSD], [libbsd-overlay], [ +# Checks for non-standard functions and fallback to libbsd if we can +AC_LINK_IFELSE([AC_LANG_CALL([], [reallocarray])], + [TRY_LIBBSD="no"], [TRY_LIBBSD="yes"]) +AC_LINK_IFELSE([AC_LANG_CALL([], [strlcat])], + [TRY_LIBBSD="no"], [TRY_LIBBSD="yes"]) +AS_IF([test "x$TRY_LIBBSD" = "xyes"], + [PKG_CHECK_MODULES([LIBBSD], [libbsd-overlay], [ CFLAGS="$CFLAGS $LIBBSD_CFLAGS" LIBS="$LIBS $LIBBSD_LIBS" -], [:]) +], [:])]) +# Checks for library functions. AC_CHECK_FUNCS([poll readlink strlcat]) AC_CONFIG_LIBOBJ_DIR([src/util]) AC_REPLACE_FUNCS([reallocarray realpath strlcat strlcpy]) -- cgit v1.2.3