xref: /freebsd/sys/contrib/openzfs/config/user-libatomic.m4 (revision 2e3f49888ec8851bafb22011533217487764fdb0)
1dnl #
2dnl # If -latomic exists and atomic.c doesn't link without it,
3dnl # it's needed for __atomic intrinsics.
4dnl #
5AC_DEFUN([ZFS_AC_CONFIG_USER_LIBATOMIC], [
6	AC_MSG_CHECKING([whether -latomic is required])
7
8	saved_libs="$LIBS"
9	LIBS="$LIBS -latomic"
10	LIBATOMIC_LIBS=""
11
12	AC_LINK_IFELSE([AC_LANG_PROGRAM([], [])], [
13		LIBS="$saved_libs"
14		saved_cflags="$CFLAGS"
15		CFLAGS="$CFLAGS -isystem lib/libspl/include"
16		AC_LINK_IFELSE([AC_LANG_PROGRAM([#include "lib/libspl/atomic.c"], [])], [], [LIBATOMIC_LIBS="-latomic"])
17		CFLAGS="$saved_cflags"
18	])
19
20	if test -n "$LIBATOMIC_LIBS"; then
21		AC_MSG_RESULT([yes])
22	else
23		AC_MSG_RESULT([no])
24	fi
25
26	LIBS="$saved_libs"
27	AC_SUBST([LIBATOMIC_LIBS])
28])
29