aboutsummaryrefslogtreecommitdiffstats
path: root/community/cmus/c11-atomics-check.patch
blob: b5c22e9be8e8aaceb9bc6de4262a91ffd61d005a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
--- a/Makefile
+++ b/Makefile
@@ -21,7 +21,7 @@
 FFMPEG_CFLAGS += $(shell pkg-config --cflags libswresample)
 FFMPEG_LIBS += $(shell pkg-config --libs libswresample)
 
-CMUS_LIBS = $(PTHREAD_LIBS) $(NCURSES_LIBS) $(ICONV_LIBS) $(DL_LIBS) $(DISCID_LIBS) \
+CMUS_LIBS = $(ATOMIC_LIBS) $(PTHREAD_LIBS) $(NCURSES_LIBS) $(ICONV_LIBS) $(DL_LIBS) $(DISCID_LIBS) \
 			-lm $(COMPAT_LIBS) $(LIBSYSTEMD_LIBS)
 
 input.o main.o ui_curses.o op/pulse.lo: .version
--- a/configure
+++ b/configure
@@ -39,7 +39,35 @@
 	return 1
 }
 
+readonly atomic_code="
+#include <stdatomic.h>
 
+int main(int argc, char *argv[])
+{
+	static atomic_llong x = ATOMIC_VAR_INIT(1);
+	return atomic_fetch_add_explicit(&x, argc, memory_order_relaxed) == 2;
+}
+"
+
+check_atomic()
+{
+	msg_checking "if -latomic is needed for C11 atomics"
+	if try_compile_link "$atomic_code"
+	then
+		msg_result "no"
+		ATOMIC_LIBS=
+	elif try_compile_link "$atomic_code" -latomic
+	then
+		msg_result "yes"
+		ATOMIC_LIBS=-latomic
+	else
+		msg_result "no C11 atomics?!"
+		return 1
+	fi
+	makefile_vars ATOMIC_LIBS
+	return 0
+}
+
 check_compat()
 {
 	COMPAT_LIBS=
@@ -517,6 +545,7 @@
 check check_cflags
 check check_cc_depgen
 check check_endianness
+check check_atomic
 check check_compat
 check check_dl
 check check_pthread