e2fsprogs
e2fsprogs copied to clipboard
Having autoconf script check for libexecinfo when looking for backtrace
Currently the autoconf script checks for the execinfo.h header and backtrace function in libc (.e.g. glibc). But FreeBSD / NetBSD / OpenBSD and DragonFlyBSD as well as musl-based Linux OS's use libexecinfo for the backtrace functionality. Please have the script also check for libexecinfo if the function does not exist in libc.
To check for the presence of libexecinfo
on BSD-based systems and musl-based Linux OS's in addition to the execinfo.h
header and the backtrace
function from libc, you can modify your autoconf script as follows:
AC_CHECK_HEADERS([execinfo.h])
AC_CHECK_FUNCS([backtrace])
# Check for libexecinfo
AC_ARG_WITH([libexecinfo],
AS_HELP_STRING([--with-libexecinfo], [Use libexecinfo for backtrace]),
[use_libexecinfo="$withval"],
[use_libexecinfo="no"])
if test "x$use_libexecinfo" = "xyes"; then
AC_CHECK_LIB([execinfo], [backtrace], [LIBEXECINFO_LIBS="-lexecinfo"])
fi
# Check if backtrace is found
if test -z "$LIBEXECINFO_LIBS"; then
AC_MSG_ERROR([Cannot find backtrace function or libexecinfo])
fi
AC_SUBST([LIBEXECINFO_LIBS])
In this updated script:
-
We use
AC_ARG_WITH
to introduce an optional--with-libexecinfo
flag, which allows the user to explicitly specify whether to uselibexecinfo
or not. -
If the user specifies
--with-libexecinfo=yes
, we check for the presence oflibexecinfo
usingAC_CHECK_LIB
. -
We then ensure that either the
backtrace
function from libc orlibexecinfo
is found. If neither is found, we display an error message.