diff mbox series

[2/2] configure: Allow compilation without libbsd if strlcpy() is available in libc

Message ID 20260507071613.2850492-3-thuth@redhat.com
State Accepted
Headers show
Series Allow compilation without libbsd | expand

Commit Message

Thomas Huth May 7, 2026, 7:16 a.m. UTC
From: Thomas Huth <thuth@redhat.com>

strlcpy() and strlcat() are available in the glibc since version 2.38:

 https://lists.gnu.org/archive/html/info-gnu/2023-07/msg00010.html

Thus add a check to the configure script to test whether we really have
to link against libbsd to get those functions and allow linking without
libbsd in case these functions are already available in the normal libc.

Note: With this change, the configure step now also fails with an approriate
error message if strlcpy() cannot be found in neither the libc nor libbsd.

Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 configure.ac            | 3 +++
 src/Makefile.am         | 6 +++++-
 src/lib/src/Makefile.am | 7 ++++++-
 3 files changed, 14 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/configure.ac b/configure.ac
index fbf487c5..b8835a1b 100644
--- a/configure.ac
+++ b/configure.ac
@@ -85,6 +85,9 @@ 
 	    AC_DEFINE([HAVE_LIBPCI], [1], [Define if we have libpci])])
 	  AM_CONDITIONAL([HAVE_LIBPCI],
 	    [test "x$ac_cv_search_pci_alloc" != "xno"])
+	  AC_SEARCH_LIBS([strlcpy], [bsd],, AC_MSG_ERROR([strlcpy is not available]))
+	  AM_CONDITIONAL([HAVE_LIBBSD],
+	    [test "x$ac_cv_search_strlcpy" = "x-lbsd"])
 	  AC_FUNC_MALLOC
 	  AC_FUNC_FORK
 	  AC_FUNC_LSTAT_FOLLOWS_SLASHED_SYMLINK
diff --git a/src/Makefile.am b/src/Makefile.am
index a98a75a1..8c50c0ef 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -230,8 +230,12 @@  fwts_SOURCES = main.c 				\
 
 fwts_LDFLAGS = -no-undefined
 
+if HAVE_LIBBSD
+fwts_LDADD_BSD = -lbsd
+endif
+
 fwts_LDADD = \
-	-lbsd \
+	$(fwts_LDADD_BSD) \
 	$(top_builddir)/src/lib/src/libfwts.la \
 	$(top_builddir)/src/libfwtsiasl/libfwtsiasl.la \
 	$(top_builddir)/src/libfwtsacpica/libfwtsacpica.la
diff --git a/src/lib/src/Makefile.am b/src/lib/src/Makefile.am
index 6534f38f..56482084 100644
--- a/src/lib/src/Makefile.am
+++ b/src/lib/src/Makefile.am
@@ -30,8 +30,13 @@  pkglib_LTLIBRARIES = libfwts.la
 
 libfwts_la_LDFLAGS = -version-info 1:0:0
 
+if HAVE_LIBBSD
+libfwts_LDADD_BSD = -lbsd
+endif
+
 libfwts_la_LIBADD = 				\
-	-lm -lpthread -lbsd				\
+	-lm -lpthread					\
+	$(libfwts_LDADD_BSD)				\
 	@GIO_LIBS@					\
 	@GLIB_LIBS@