gen-ci: Properly encapsulate GitLab predicates
[ghc.git] / m4 / fp_check_pthreads.m4
blob55657f60b5508522d9815a40914dee0dd4c880a6
1 # FP_CHECK_PTHREAD_LIB
2 # ----------------------------------
3 # Check whether -lpthread is needed for pthread.
5 # Sets variables:
6 #   - UseLibpthread: [YES|NO]
7 AC_DEFUN([FP_CHECK_PTHREAD_LIB],
9   dnl Some platforms (e.g. Android's Bionic) have pthreads support available
10   dnl without linking against libpthread. Check whether -lpthread is necessary
11   dnl to use pthreads.
12   dnl
13   dnl Note that it is important that this happens before we AC_CHECK_LIB(thread)
14   AC_MSG_CHECKING(whether -lpthread is needed for pthreads)
15   AC_CHECK_FUNC(pthread_create,
16       [
17           AC_MSG_RESULT(no)
18           UseLibpthread=NO
19       ],
20       [
21           AC_CHECK_LIB(pthread, pthread_create,
22               [
23                   AC_MSG_RESULT(yes)
24                   UseLibpthread=YES
25               ],
26               [
27                   AC_MSG_RESULT([no pthreads support found.])
28                   UseLibpthread=NO
29               ])
30       ])
33 # FP_CHECK_PTHREAD_FUNCS
34 # ----------------------------------
35 # Check various aspects of the platform's pthreads support
37 # `AC_DEFINE`s various C `HAVE_*` macros.
38 AC_DEFUN([FP_CHECK_PTHREAD_FUNCS],
40   dnl Setting thread names
41   dnl ~~~~~~~~~~~~~~~~~~~~
42   dnl The portability situation here is complicated:
43   dnl
44   dnl * FreeBSD supports pthread_set_name_np in <pthread_np.h>
45   dnl   and (if not _POSIX_SOURCE) pthread_setname_np() in <pthread.h>
46   dnl   because of the conditional visibility, we prefer the former.
47   dnl * glibc supports pthread_setname_np
48   dnl * Darwin supports pthread_setname_np but does not take a
49   dnl   pthread_t argument.
50   dnl
51   AC_CHECK_HEADERS([pthread_np.h])
53   dnl ** pthread_setname_np is a recent addition to glibc, and OS X has
54   dnl    a different single-argument version.
55   AC_CHECK_LIB(pthread, pthread_setname_np)
57   AC_MSG_CHECKING([for pthread_setname_np (Darwin)])
58   AC_LINK_IFELSE([
59     AC_LANG_PROGRAM(
60       [[
61       #include <pthread.h>
62       ]],
63       [[pthread_setname_np("name");]]
64     )],
65     [
66       AC_MSG_RESULT(yes)
67       AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_DARWIN], [1],
68         [Define to 1 if you have the Darwin version of pthread_setname_np])
69     ],
70     AC_MSG_RESULT(no)
71   )
73   dnl glibc
74   AC_MSG_CHECKING([for pthread_setname_np (glibc)])
75   AC_LINK_IFELSE([
76     AC_LANG_PROGRAM(
77       [[
78       #define _GNU_SOURCE
79       #include <pthread.h>
80       ]],
81       [[pthread_setname_np(pthread_self(), "name");]]
82     )],
83     [
84       AC_MSG_RESULT(yes)
85       AC_DEFINE([HAVE_PTHREAD_SETNAME_NP], [1],
86         [Define to 1 if you have the glibc version of pthread_setname_np])
87     ],
88     AC_MSG_RESULT(no)
89   )
91   dnl NetBSD
92   AC_MSG_CHECKING([for pthread_setname_np (NetBSD)])
93   AC_LINK_IFELSE([
94     AC_LANG_PROGRAM(
95       [[
96       #include <pthread.h>
97       ]],
98       [[pthread_setname_np(pthread_self(), "%s", "name");]]
99     )],
100     [
101       AC_MSG_RESULT([yes])
102       AC_DEFINE([HAVE_PTHREAD_SETNAME_NP_NETBSD], [1],
103         [Define to 1 if you have the NetBSD version of pthread_setname_np])
104     ],
105     AC_MSG_RESULT([no])
106   )
108   dnl FreeBSD
109   AC_MSG_CHECKING([for pthread_set_name_np])
110   AC_LINK_IFELSE([
111     AC_LANG_PROGRAM(
112       [[
113       #include <pthread_np.h>
114       ]],
115       [[pthread_set_name_np(pthread_self(), "name");]]
116     )],
117     [
118       AC_MSG_RESULT(yes)
119       AC_DEFINE([HAVE_PTHREAD_SET_NAME_NP], [1],
120         [Define to 1 if you have pthread_set_name_np])
121     ],
122     AC_MSG_RESULT(no)
123   )
125   AC_CHECK_FUNCS_ONCE([pthread_condattr_setclock])