Debian Codegraph @

m4/libcthreads.m4

raw
1 dnl Checks for libcthreads required headers and functions
2 dnl
3 dnl Version: 20240513
4
5 dnl Function to detect if libcthreads is available
6 dnl ac_libcthreads_dummy is used to prevent AC_CHECK_LIB adding unnecessary -l<library> arguments
7 AC_DEFUN([AX_LIBCTHREADS_CHECK_LIB],
8 [AS_IF(
9 [test "x$ac_cv_enable_shared_libs" = xno || test "x$ac_cv_with_libcthreads" = xno],
10 [ac_cv_libcthreads=no],
11 [ac_cv_libcthreads=check
12 dnl Check if the directory provided as parameter exists
13 dnl For both --with-libcthreads which returns "yes" and --with-libcthreads= which returns ""
14 dnl treat them as auto-detection.
15 AS_IF(
16 [test "x$ac_cv_with_libcthreads" != x && test "x$ac_cv_with_libcthreads" != xauto-detect && test "x$ac_cv_with_libcthreads" != xyes],
17 [AX_CHECK_LIB_DIRECTORY_EXISTS([libcthreads])],
18 [dnl Check for a pkg-config file
19 AS_IF(
20 [test "x$cross_compiling" != "xyes" && test "x$PKGCONFIG" != "x"],
21 [PKG_CHECK_MODULES(
22 [libcthreads],
23 [libcthreads >= 20160404],
24 [ac_cv_libcthreads=yes],
25 [ac_cv_libcthreads=check])
26 ])
27 AS_IF(
28 [test "x$ac_cv_libcthreads" = xyes],
29 [ac_cv_libcthreads_CPPFLAGS="$pkg_cv_libcthreads_CFLAGS"
30 ac_cv_libcthreads_LIBADD="$pkg_cv_libcthreads_LIBS"])
31 ])
32
33 AS_IF(
34 [test "x$ac_cv_libcthreads" = xcheck],
35 [dnl Check for headers
36 AC_CHECK_HEADERS([libcthreads.h])
37
38 AS_IF(
39 [test "x$ac_cv_header_libcthreads_h" = xno],
40 [ac_cv_libcthreads=no],
41 [ac_cv_libcthreads=yes
42
43 AX_CHECK_LIB_FUNCTIONS(
44 [libcthreads],
45 [cthreads],
46 [[libcthreads_get_version],
47 [libcthreads_thread_create],
48 [libcthreads_thread_join],
49 [libcthreads_thread_attributes_initialize],
50 [libcthreads_thread_attributes_free],
51 [libcthreads_condition_initialize],
52 [libcthreads_condition_free],
53 [libcthreads_condition_broadcast],
54 [libcthreads_condition_signal],
55 [libcthreads_condition_wait],
56 [libcthreads_lock_initialize],
57 [libcthreads_lock_free],
58 [libcthreads_lock_grab],
59 [libcthreads_lock_release],
60 [libcthreads_mutex_initialize],
61 [libcthreads_mutex_free],
62 [libcthreads_mutex_grab],
63 [libcthreads_mutex_try_grab],
64 [libcthreads_mutex_release],
65 [libcthreads_read_write_lock_initialize],
66 [libcthreads_read_write_lock_free],
67 [libcthreads_read_write_lock_grab_for_read],
68 [libcthreads_read_write_lock_grab_for_write],
69 [libcthreads_read_write_lock_release_for_read],
70 [libcthreads_read_write_lock_release_for_write],
71 [libcthreads_queue_initialize],
72 [libcthreads_queue_free],
73 [libcthreads_queue_type_pop],
74 [libcthreads_queue_pop],
75 [libcthreads_queue_try_push],
76 [libcthreads_queue_push],
77 [libcthreads_queue_push_sorted],
78 [libcthreads_thread_pool_create],
79 [libcthreads_thread_pool_push],
80 [libcthreads_thread_pool_push_sorted],
81 [libcthreads_thread_pool_join]])
82
83 ac_cv_libcthreads_LIBADD="-lcthreads"])
84 ])
85
86 AX_CHECK_LIB_DIRECTORY_MSG_ON_FAILURE([libcthreads])
87 ])
88
89 AS_IF(
90 [test "x$ac_cv_libcthreads" = xyes],
91 [AC_DEFINE(
92 [HAVE_LIBCTHREADS],
93 [1],
94 [Define to 1 if you have the `cthreads' library (-lcthreads).])
95 ])
96
97 AS_IF(
98 [test "x$ac_cv_libcthreads" = xyes],
99 [ac_cv_libcthreads_multi_threading=libcthreads],
100 [ac_cv_libcthreads_multi_threading=no])
101
102 AS_IF(
103 [test "x$ac_cv_libcthreads" = xyes],
104 [AC_SUBST(
105 [HAVE_LIBCTHREADS],
106 [1]) ],
107 [AC_SUBST(
108 [HAVE_LIBCTHREADS],
109 [0])
110 ])
111 ])
112
113 dnl Function to detect if libcthreads dependencies are available
114 AC_DEFUN([AX_LIBCTHREADS_CHECK_LOCAL],
115 [AS_IF(
116 [test "x$ac_cv_enable_winapi" = xno],
117 [dnl Check for enabling pthread support
118 AX_PTHREAD_CHECK_ENABLE
119 ac_cv_libcthreads_multi_threading=$ac_cv_pthread],
120 [ac_cv_libcthreads_multi_threading="winapi"])
121
122 AS_IF(
123 [test "x$ac_cv_libcthreads_multi_threading" != xno],
124 [ac_cv_libcthreads_CPPFLAGS="-I../libcthreads -I\$(top_srcdir)/libcthreads";
125 ac_cv_libcthreads_LIBADD="../libcthreads/libcthreads.la";
126
127 ac_cv_libcthreads=local],
128 [ac_cv_libcthreads=no])
129 ])
130
131 dnl Function to detect how to enable libcthreads
132 AC_DEFUN([AX_LIBCTHREADS_CHECK_ENABLE],
133 [AX_COMMON_ARG_ENABLE(
134 [multi-threading-support],
135 [multi_threading_support],
136 [enable multi-threading support],
137 [yes])
138 AX_COMMON_ARG_WITH(
139 [libcthreads],
140 [libcthreads],
141 [search for libcthreads in includedir and libdir or in the specified DIR, or no if to use local version],
142 [auto-detect],
143 [DIR])
144
145 AS_IF(
146 [test "x$ac_cv_enable_multi_threading_support" = xno],
147 [ac_cv_libcthreads="no"
148 ac_cv_libcthreads_multi_threading="no"],
149 [dnl Check for a shared library version
150 AX_LIBCTHREADS_CHECK_LIB
151
152 dnl Check if the dependencies for the local library version
153 AS_IF(
154 [test "x$ac_cv_libcthreads" != xyes],
155 [AX_LIBCTHREADS_CHECK_LOCAL
156
157 AC_DEFINE(
158 [HAVE_LOCAL_LIBCTHREADS],
159 [1],
160 [Define to 1 if the local version of libcthreads is used.])
161 AC_SUBST(
162 [HAVE_LOCAL_LIBCTHREADS],
163 [1])
164 ])
165 ])
166
167 AM_CONDITIONAL(
168 [HAVE_LOCAL_LIBCTHREADS],
169 [test "x$ac_cv_libcthreads" = xlocal])
170 AS_IF(
171 [test "x$ac_cv_libcthreads_CPPFLAGS" != "x"],
172 [AC_SUBST(
173 [LIBCTHREADS_CPPFLAGS],
174 [$ac_cv_libcthreads_CPPFLAGS])
175 ])
176 AS_IF(
177 [test "x$ac_cv_libcthreads_LIBADD" != "x"],
178 [AC_SUBST(
179 [LIBCTHREADS_LIBADD],
180 [$ac_cv_libcthreads_LIBADD])
181 ])
182
183 AS_IF(
184 [test "x$ac_cv_libcthreads" != xno],
185 [AC_DEFINE(
186 [HAVE_MULTI_THREAD_SUPPORT],
187 [1],
188 [Define to 1 if multi thread support should be used.])
189 AC_SUBST(
190 [HAVE_MULTI_THREAD_SUPPORT],
191 [1]) ],
192 [AC_SUBST(
193 [HAVE_MULTI_THREAD_SUPPORT],
194 [0])
195 ])
196
197 AS_IF(
198 [test "x$ac_cv_libcthreads" = xyes],
199 [AC_SUBST(
200 [ax_libcthreads_pc_libs_private],
201 [-lcthreads])
202 ])
203
204 AS_IF(
205 [test "x$ac_cv_libcthreads" = xyes],
206 [AC_SUBST(
207 [ax_libcthreads_spec_requires],
208 [libcthreads])
209 AC_SUBST(
210 [ax_libcthreads_spec_build_requires],
211 [libcthreads-devel])
212 ])
213 ])
214