1From bbf710e77e4a0438a2d995fd69b472e5ff054c69 Mon Sep 17 00:00:00 2001
2From: Jan Palus <jpalus@fastmail.com>
3Date: Sun, 3 Dec 2023 12:14:05 +0100
4Subject: [PATCH] Check and link libatomic if needed
5
6Some architectures without native support for 64-bit atomics need
7linking with libatomic.
8
9Signed-off-by: Julien Olivain <ju.o@free.fr>
10Upstream: https://github.com/esnet/iperf/commit/1511e9f85b548891ea53d4e378903344df1fd31e
11---
12 configure.ac | 14 +++++++++++++-
13 1 file changed, 13 insertions(+), 1 deletion(-)
14
15diff --git a/configure.ac b/configure.ac
16index 2594b39..ad7eaf1 100644
17--- a/configure.ac
18+++ b/configure.ac
19@@ -92,7 +92,19 @@ CXX="$PTHREAD_CXX"
20 ])
21
22 # Atomics
23-AC_CHECK_HEADERS([stdatomic.h])
24+AC_CHECK_HEADERS([stdatomic.h],
25+    [AC_MSG_CHECKING([whether libatomic is required])
26+    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdatomic.h>]], [[atomic_uint_fast64_t i; i++;]])],
27+        [AC_MSG_RESULT([no])],
28+        [save_LIBS="$LIBS"
29+        LIBS="$LIBS -latomic"
30+        AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <stdatomic.h>]], [[atomic_uint_fast64_t i; i++;]])],
31+            [AC_MSG_RESULT([yes])],
32+            [AC_MSG_ERROR([failed to find working configuration with atomics])]
33+        )]
34+    )],
35+    []
36+)
37
38 # Check for poll.h (it's in POSIX so everyone should have it?)
39 AC_CHECK_HEADERS([poll.h])
40--
412.44.0
42
43