cannam@133
|
1 # This file was copied to Cap'n Proto from the Protocol Buffers distribution,
|
cannam@133
|
2 # version 2.3.0.
|
cannam@133
|
3
|
cannam@133
|
4 # This was retrieved from
|
cannam@133
|
5 # http://svn.0pointer.de/viewvc/trunk/common/acx_pthread.m4?revision=1277&root=avahi
|
cannam@133
|
6 # See also (perhaps for new versions?)
|
cannam@133
|
7 # http://svn.0pointer.de/viewvc/trunk/common/acx_pthread.m4?root=avahi
|
cannam@133
|
8 #
|
cannam@133
|
9 # We've rewritten the inconsistency check code (from avahi), to work
|
cannam@133
|
10 # more broadly. In particular, it no longer assumes ld accepts -zdefs.
|
cannam@133
|
11 # This caused a restructing of the code, but the functionality has only
|
cannam@133
|
12 # changed a little.
|
cannam@133
|
13
|
cannam@133
|
14 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
|
cannam@133
|
15 dnl
|
cannam@133
|
16 dnl @summary figure out how to build C programs using POSIX threads
|
cannam@133
|
17 dnl
|
cannam@133
|
18 dnl This macro figures out how to build C programs using POSIX threads.
|
cannam@133
|
19 dnl It sets the PTHREAD_LIBS output variable to the threads library and
|
cannam@133
|
20 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
|
cannam@133
|
21 dnl C compiler flags that are needed. (The user can also force certain
|
cannam@133
|
22 dnl compiler flags/libs to be tested by setting these environment
|
cannam@133
|
23 dnl variables.)
|
cannam@133
|
24 dnl
|
cannam@133
|
25 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
|
cannam@133
|
26 dnl multi-threaded programs (defaults to the value of CC otherwise).
|
cannam@133
|
27 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
|
cannam@133
|
28 dnl
|
cannam@133
|
29 dnl NOTE: You are assumed to not only compile your program with these
|
cannam@133
|
30 dnl flags, but also link it with them as well. e.g. you should link
|
cannam@133
|
31 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
|
cannam@133
|
32 dnl $LIBS
|
cannam@133
|
33 dnl
|
cannam@133
|
34 dnl If you are only building threads programs, you may wish to use
|
cannam@133
|
35 dnl these variables in your default LIBS, CFLAGS, and CC:
|
cannam@133
|
36 dnl
|
cannam@133
|
37 dnl LIBS="$PTHREAD_LIBS $LIBS"
|
cannam@133
|
38 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
cannam@133
|
39 dnl CC="$PTHREAD_CC"
|
cannam@133
|
40 dnl
|
cannam@133
|
41 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
|
cannam@133
|
42 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
|
cannam@133
|
43 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
|
cannam@133
|
44 dnl
|
cannam@133
|
45 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
|
cannam@133
|
46 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
|
cannam@133
|
47 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
|
cannam@133
|
48 dnl default action will define HAVE_PTHREAD.
|
cannam@133
|
49 dnl
|
cannam@133
|
50 dnl Please let the authors know if this macro fails on any platform, or
|
cannam@133
|
51 dnl if you have any other suggestions or comments. This macro was based
|
cannam@133
|
52 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
|
cannam@133
|
53 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
|
cannam@133
|
54 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
|
cannam@133
|
55 dnl We are also grateful for the helpful feedback of numerous users.
|
cannam@133
|
56 dnl
|
cannam@133
|
57 dnl @category InstalledPackages
|
cannam@133
|
58 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
|
cannam@133
|
59 dnl @version 2006-05-29
|
cannam@133
|
60 dnl @license GPLWithACException
|
cannam@133
|
61 dnl
|
cannam@133
|
62 dnl Checks for GCC shared/pthread inconsistency based on work by
|
cannam@133
|
63 dnl Marcin Owsiany <marcin@owsiany.pl>
|
cannam@133
|
64
|
cannam@133
|
65
|
cannam@133
|
66 AC_DEFUN([ACX_PTHREAD], [
|
cannam@133
|
67 AC_REQUIRE([AC_CANONICAL_HOST])
|
cannam@133
|
68 AC_LANG_SAVE
|
cannam@133
|
69 AC_LANG_C
|
cannam@133
|
70 acx_pthread_ok=no
|
cannam@133
|
71
|
cannam@133
|
72 # We used to check for pthread.h first, but this fails if pthread.h
|
cannam@133
|
73 # requires special compiler flags (e.g. on True64 or Sequent).
|
cannam@133
|
74 # It gets checked for in the link test anyway.
|
cannam@133
|
75
|
cannam@133
|
76 # First of all, check if the user has set any of the PTHREAD_LIBS,
|
cannam@133
|
77 # etcetera environment variables, and if threads linking works using
|
cannam@133
|
78 # them:
|
cannam@133
|
79 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
|
cannam@133
|
80 save_CFLAGS="$CFLAGS"
|
cannam@133
|
81 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
cannam@133
|
82 save_LIBS="$LIBS"
|
cannam@133
|
83 LIBS="$PTHREAD_LIBS $LIBS"
|
cannam@133
|
84 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
|
cannam@133
|
85 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
|
cannam@133
|
86 AC_MSG_RESULT($acx_pthread_ok)
|
cannam@133
|
87 if test x"$acx_pthread_ok" = xno; then
|
cannam@133
|
88 PTHREAD_LIBS=""
|
cannam@133
|
89 PTHREAD_CFLAGS=""
|
cannam@133
|
90 fi
|
cannam@133
|
91 LIBS="$save_LIBS"
|
cannam@133
|
92 CFLAGS="$save_CFLAGS"
|
cannam@133
|
93 fi
|
cannam@133
|
94
|
cannam@133
|
95 # We must check for the threads library under a number of different
|
cannam@133
|
96 # names; the ordering is very important because some systems
|
cannam@133
|
97 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
|
cannam@133
|
98 # libraries is broken (non-POSIX).
|
cannam@133
|
99
|
cannam@133
|
100 # Create a list of thread flags to try. Items starting with a "-" are
|
cannam@133
|
101 # C compiler flags, and other items are library names, except for "none"
|
cannam@133
|
102 # which indicates that we try without any flags at all, and "pthread-config"
|
cannam@133
|
103 # which is a program returning the flags for the Pth emulation library.
|
cannam@133
|
104
|
cannam@133
|
105 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
|
cannam@133
|
106
|
cannam@133
|
107 # The ordering *is* (sometimes) important. Some notes on the
|
cannam@133
|
108 # individual items follow:
|
cannam@133
|
109
|
cannam@133
|
110 # pthreads: AIX (must check this before -lpthread)
|
cannam@133
|
111 # none: in case threads are in libc; should be tried before -Kthread and
|
cannam@133
|
112 # other compiler flags to prevent continual compiler warnings
|
cannam@133
|
113 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
|
cannam@133
|
114 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
|
cannam@133
|
115 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
|
cannam@133
|
116 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
|
cannam@133
|
117 # -pthreads: Solaris/gcc
|
cannam@133
|
118 # -mthreads: Mingw32/gcc, Lynx/gcc
|
cannam@133
|
119 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
|
cannam@133
|
120 # doesn't hurt to check since this sometimes defines pthreads too;
|
cannam@133
|
121 # also defines -D_REENTRANT)
|
cannam@133
|
122 # ... -mt is also the pthreads flag for HP/aCC
|
cannam@133
|
123 # pthread: Linux, etcetera
|
cannam@133
|
124 # --thread-safe: KAI C++
|
cannam@133
|
125 # pthread-config: use pthread-config program (for GNU Pth library)
|
cannam@133
|
126
|
cannam@133
|
127 case "${host_cpu}-${host_os}" in
|
cannam@133
|
128 *solaris*)
|
cannam@133
|
129
|
cannam@133
|
130 # On Solaris (at least, for some versions), libc contains stubbed
|
cannam@133
|
131 # (non-functional) versions of the pthreads routines, so link-based
|
cannam@133
|
132 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
|
cannam@133
|
133 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
|
cannam@133
|
134 # a function called by this macro, so we could check for that, but
|
cannam@133
|
135 # who knows whether they'll stub that too in a future libc.) So,
|
cannam@133
|
136 # we'll just look for -pthreads and -lpthread first:
|
cannam@133
|
137
|
cannam@133
|
138 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
|
cannam@133
|
139 ;;
|
cannam@133
|
140 esac
|
cannam@133
|
141
|
cannam@133
|
142 if test x"$acx_pthread_ok" = xno; then
|
cannam@133
|
143 for flag in $acx_pthread_flags; do
|
cannam@133
|
144
|
cannam@133
|
145 case $flag in
|
cannam@133
|
146 none)
|
cannam@133
|
147 AC_MSG_CHECKING([whether pthreads work without any flags])
|
cannam@133
|
148 ;;
|
cannam@133
|
149
|
cannam@133
|
150 -*)
|
cannam@133
|
151 AC_MSG_CHECKING([whether pthreads work with $flag])
|
cannam@133
|
152 PTHREAD_CFLAGS="$flag"
|
cannam@133
|
153 ;;
|
cannam@133
|
154
|
cannam@133
|
155 pthread-config)
|
cannam@133
|
156 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
|
cannam@133
|
157 if test x"$acx_pthread_config" = xno; then continue; fi
|
cannam@133
|
158 PTHREAD_CFLAGS="`pthread-config --cflags`"
|
cannam@133
|
159 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
|
cannam@133
|
160 ;;
|
cannam@133
|
161
|
cannam@133
|
162 *)
|
cannam@133
|
163 AC_MSG_CHECKING([for the pthreads library -l$flag])
|
cannam@133
|
164 PTHREAD_LIBS="-l$flag"
|
cannam@133
|
165 ;;
|
cannam@133
|
166 esac
|
cannam@133
|
167
|
cannam@133
|
168 save_LIBS="$LIBS"
|
cannam@133
|
169 save_CFLAGS="$CFLAGS"
|
cannam@133
|
170 LIBS="$PTHREAD_LIBS $LIBS"
|
cannam@133
|
171 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
cannam@133
|
172
|
cannam@133
|
173 # Check for various functions. We must include pthread.h,
|
cannam@133
|
174 # since some functions may be macros. (On the Sequent, we
|
cannam@133
|
175 # need a special flag -Kthread to make this header compile.)
|
cannam@133
|
176 # We check for pthread_join because it is in -lpthread on IRIX
|
cannam@133
|
177 # while pthread_create is in libc. We check for pthread_attr_init
|
cannam@133
|
178 # due to DEC craziness with -lpthreads. We check for
|
cannam@133
|
179 # pthread_cleanup_push because it is one of the few pthread
|
cannam@133
|
180 # functions on Solaris that doesn't have a non-functional libc stub.
|
cannam@133
|
181 # We try pthread_create on general principles.
|
cannam@133
|
182 AC_TRY_LINK([#include <pthread.h>],
|
cannam@133
|
183 [pthread_t th; pthread_join(th, 0);
|
cannam@133
|
184 pthread_attr_init(0); pthread_cleanup_push(0, 0);
|
cannam@133
|
185 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
|
cannam@133
|
186 [acx_pthread_ok=yes])
|
cannam@133
|
187
|
cannam@133
|
188 LIBS="$save_LIBS"
|
cannam@133
|
189 CFLAGS="$save_CFLAGS"
|
cannam@133
|
190
|
cannam@133
|
191 AC_MSG_RESULT($acx_pthread_ok)
|
cannam@133
|
192 if test "x$acx_pthread_ok" = xyes; then
|
cannam@133
|
193 break;
|
cannam@133
|
194 fi
|
cannam@133
|
195
|
cannam@133
|
196 PTHREAD_LIBS=""
|
cannam@133
|
197 PTHREAD_CFLAGS=""
|
cannam@133
|
198 done
|
cannam@133
|
199 fi
|
cannam@133
|
200
|
cannam@133
|
201 # Various other checks:
|
cannam@133
|
202 if test "x$acx_pthread_ok" = xyes; then
|
cannam@133
|
203 save_LIBS="$LIBS"
|
cannam@133
|
204 LIBS="$PTHREAD_LIBS $LIBS"
|
cannam@133
|
205 save_CFLAGS="$CFLAGS"
|
cannam@133
|
206 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
cannam@133
|
207
|
cannam@133
|
208 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
|
cannam@133
|
209 AC_MSG_CHECKING([for joinable pthread attribute])
|
cannam@133
|
210 attr_name=unknown
|
cannam@133
|
211 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
|
cannam@133
|
212 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
|
cannam@133
|
213 [attr_name=$attr; break])
|
cannam@133
|
214 done
|
cannam@133
|
215 AC_MSG_RESULT($attr_name)
|
cannam@133
|
216 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
|
cannam@133
|
217 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
|
cannam@133
|
218 [Define to necessary symbol if this constant
|
cannam@133
|
219 uses a non-standard name on your system.])
|
cannam@133
|
220 fi
|
cannam@133
|
221
|
cannam@133
|
222 AC_MSG_CHECKING([if more special flags are required for pthreads])
|
cannam@133
|
223 flag=no
|
cannam@133
|
224 case "${host_cpu}-${host_os}" in
|
cannam@133
|
225 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
|
cannam@133
|
226 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
|
cannam@133
|
227 esac
|
cannam@133
|
228 AC_MSG_RESULT(${flag})
|
cannam@133
|
229 if test "x$flag" != xno; then
|
cannam@133
|
230 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
|
cannam@133
|
231 fi
|
cannam@133
|
232
|
cannam@133
|
233 LIBS="$save_LIBS"
|
cannam@133
|
234 CFLAGS="$save_CFLAGS"
|
cannam@133
|
235 # More AIX lossage: must compile with xlc_r or cc_r
|
cannam@133
|
236 if test x"$GCC" != xyes; then
|
cannam@133
|
237 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
|
cannam@133
|
238 else
|
cannam@133
|
239 PTHREAD_CC=$CC
|
cannam@133
|
240 fi
|
cannam@133
|
241
|
cannam@133
|
242 # The next part tries to detect GCC inconsistency with -shared on some
|
cannam@133
|
243 # architectures and systems. The problem is that in certain
|
cannam@133
|
244 # configurations, when -shared is specified, GCC "forgets" to
|
cannam@133
|
245 # internally use various flags which are still necessary.
|
cannam@133
|
246
|
cannam@133
|
247 #
|
cannam@133
|
248 # Prepare the flags
|
cannam@133
|
249 #
|
cannam@133
|
250 save_CFLAGS="$CFLAGS"
|
cannam@133
|
251 save_LIBS="$LIBS"
|
cannam@133
|
252 save_CC="$CC"
|
cannam@133
|
253
|
cannam@133
|
254 # Try with the flags determined by the earlier checks.
|
cannam@133
|
255 #
|
cannam@133
|
256 # -Wl,-z,defs forces link-time symbol resolution, so that the
|
cannam@133
|
257 # linking checks with -shared actually have any value
|
cannam@133
|
258 #
|
cannam@133
|
259 # FIXME: -fPIC is required for -shared on many architectures,
|
cannam@133
|
260 # so we specify it here, but the right way would probably be to
|
cannam@133
|
261 # properly detect whether it is actually required.
|
cannam@133
|
262 CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS"
|
cannam@133
|
263 LIBS="$PTHREAD_LIBS $LIBS"
|
cannam@133
|
264 CC="$PTHREAD_CC"
|
cannam@133
|
265
|
cannam@133
|
266 # In order not to create several levels of indentation, we test
|
cannam@133
|
267 # the value of "$done" until we find the cure or run out of ideas.
|
cannam@133
|
268 done="no"
|
cannam@133
|
269
|
cannam@133
|
270 # First, make sure the CFLAGS we added are actually accepted by our
|
cannam@133
|
271 # compiler. If not (and OS X's ld, for instance, does not accept -z),
|
cannam@133
|
272 # then we can't do this test.
|
cannam@133
|
273 if test x"$done" = xno; then
|
cannam@133
|
274 AC_MSG_CHECKING([whether to check for GCC pthread/shared inconsistencies])
|
cannam@133
|
275 AC_TRY_LINK(,, , [done=yes])
|
cannam@133
|
276
|
cannam@133
|
277 if test "x$done" = xyes ; then
|
cannam@133
|
278 AC_MSG_RESULT([no])
|
cannam@133
|
279 else
|
cannam@133
|
280 AC_MSG_RESULT([yes])
|
cannam@133
|
281 fi
|
cannam@133
|
282 fi
|
cannam@133
|
283
|
cannam@133
|
284 if test x"$done" = xno; then
|
cannam@133
|
285 AC_MSG_CHECKING([whether -pthread is sufficient with -shared])
|
cannam@133
|
286 AC_TRY_LINK([#include <pthread.h>],
|
cannam@133
|
287 [pthread_t th; pthread_join(th, 0);
|
cannam@133
|
288 pthread_attr_init(0); pthread_cleanup_push(0, 0);
|
cannam@133
|
289 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
|
cannam@133
|
290 [done=yes])
|
cannam@133
|
291
|
cannam@133
|
292 if test "x$done" = xyes; then
|
cannam@133
|
293 AC_MSG_RESULT([yes])
|
cannam@133
|
294 else
|
cannam@133
|
295 AC_MSG_RESULT([no])
|
cannam@133
|
296 fi
|
cannam@133
|
297 fi
|
cannam@133
|
298
|
cannam@133
|
299 #
|
cannam@133
|
300 # Linux gcc on some architectures such as mips/mipsel forgets
|
cannam@133
|
301 # about -lpthread
|
cannam@133
|
302 #
|
cannam@133
|
303 if test x"$done" = xno; then
|
cannam@133
|
304 AC_MSG_CHECKING([whether -lpthread fixes that])
|
cannam@133
|
305 LIBS="-lpthread $PTHREAD_LIBS $save_LIBS"
|
cannam@133
|
306 AC_TRY_LINK([#include <pthread.h>],
|
cannam@133
|
307 [pthread_t th; pthread_join(th, 0);
|
cannam@133
|
308 pthread_attr_init(0); pthread_cleanup_push(0, 0);
|
cannam@133
|
309 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
|
cannam@133
|
310 [done=yes])
|
cannam@133
|
311
|
cannam@133
|
312 if test "x$done" = xyes; then
|
cannam@133
|
313 AC_MSG_RESULT([yes])
|
cannam@133
|
314 PTHREAD_LIBS="-lpthread $PTHREAD_LIBS"
|
cannam@133
|
315 else
|
cannam@133
|
316 AC_MSG_RESULT([no])
|
cannam@133
|
317 fi
|
cannam@133
|
318 fi
|
cannam@133
|
319 #
|
cannam@133
|
320 # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc
|
cannam@133
|
321 #
|
cannam@133
|
322 if test x"$done" = xno; then
|
cannam@133
|
323 AC_MSG_CHECKING([whether -lc_r fixes that])
|
cannam@133
|
324 LIBS="-lc_r $PTHREAD_LIBS $save_LIBS"
|
cannam@133
|
325 AC_TRY_LINK([#include <pthread.h>],
|
cannam@133
|
326 [pthread_t th; pthread_join(th, 0);
|
cannam@133
|
327 pthread_attr_init(0); pthread_cleanup_push(0, 0);
|
cannam@133
|
328 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
|
cannam@133
|
329 [done=yes])
|
cannam@133
|
330
|
cannam@133
|
331 if test "x$done" = xyes; then
|
cannam@133
|
332 AC_MSG_RESULT([yes])
|
cannam@133
|
333 PTHREAD_LIBS="-lc_r $PTHREAD_LIBS"
|
cannam@133
|
334 else
|
cannam@133
|
335 AC_MSG_RESULT([no])
|
cannam@133
|
336 fi
|
cannam@133
|
337 fi
|
cannam@133
|
338 if test x"$done" = xno; then
|
cannam@133
|
339 # OK, we have run out of ideas
|
cannam@133
|
340 AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries])
|
cannam@133
|
341
|
cannam@133
|
342 # so it's not safe to assume that we may use pthreads
|
cannam@133
|
343 acx_pthread_ok=no
|
cannam@133
|
344 fi
|
cannam@133
|
345
|
cannam@133
|
346 CFLAGS="$save_CFLAGS"
|
cannam@133
|
347 LIBS="$save_LIBS"
|
cannam@133
|
348 CC="$save_CC"
|
cannam@133
|
349 else
|
cannam@133
|
350 PTHREAD_CC="$CC"
|
cannam@133
|
351 fi
|
cannam@133
|
352
|
cannam@133
|
353 if test "x$acx_pthread_ok" = xyes; then
|
cannam@133
|
354 # One more check: If we chose to use a compiler flag like -pthread but it is combined with
|
cannam@133
|
355 # -nostdlib then the compiler won't implicitly link against libpthread. This can happen
|
cannam@133
|
356 # in particular when using some versions of libtool on some distros. See:
|
cannam@133
|
357 # https://bugzilla.redhat.com/show_bug.cgi?id=661333
|
cannam@133
|
358
|
cannam@133
|
359 save_CFLAGS="$CFLAGS"
|
cannam@133
|
360 save_LIBS="$LIBS"
|
cannam@133
|
361 save_CC="$CC"
|
cannam@133
|
362 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
|
cannam@133
|
363 LIBS="-nostdlib $PTHREAD_LIBS $LIBS -lc"
|
cannam@133
|
364 CC="$PTHREAD_CC"
|
cannam@133
|
365
|
cannam@133
|
366 AC_MSG_CHECKING([whether pthread flag is sufficient with -nostdlib])
|
cannam@133
|
367 AC_TRY_LINK([#include <pthread.h>],
|
cannam@133
|
368 [pthread_t th; pthread_join(th, 0);
|
cannam@133
|
369 pthread_attr_init(0); pthread_cleanup_push(0, 0);
|
cannam@133
|
370 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
|
cannam@133
|
371 [AC_MSG_RESULT([yes])], [
|
cannam@133
|
372 AC_MSG_RESULT([no])
|
cannam@133
|
373
|
cannam@133
|
374 AC_MSG_CHECKING([whether adding -lpthread fixes that])
|
cannam@133
|
375
|
cannam@133
|
376 LIBS="-nostdlib $PTHREAD_LIBS -lpthread $save_LIBS -lc"
|
cannam@133
|
377 AC_TRY_LINK([#include <pthread.h>],
|
cannam@133
|
378 [pthread_t th; pthread_join(th, 0);
|
cannam@133
|
379 pthread_attr_init(0); pthread_cleanup_push(0, 0);
|
cannam@133
|
380 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
|
cannam@133
|
381 [
|
cannam@133
|
382 AC_MSG_RESULT([yes])
|
cannam@133
|
383 PTHREAD_LIBS="$PTHREAD_LIBS -lpthread"
|
cannam@133
|
384 ], [AC_MSG_RESULT([no])])
|
cannam@133
|
385 ])
|
cannam@133
|
386
|
cannam@133
|
387 CFLAGS="$save_CFLAGS"
|
cannam@133
|
388 LIBS="$save_LIBS"
|
cannam@133
|
389 CC="$save_CC"
|
cannam@133
|
390 fi
|
cannam@133
|
391
|
cannam@133
|
392 AC_SUBST(PTHREAD_LIBS)
|
cannam@133
|
393 AC_SUBST(PTHREAD_CFLAGS)
|
cannam@133
|
394 AC_SUBST(PTHREAD_CC)
|
cannam@133
|
395
|
cannam@133
|
396 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
|
cannam@133
|
397 if test x"$acx_pthread_ok" = xyes; then
|
cannam@133
|
398 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
|
cannam@133
|
399 :
|
cannam@133
|
400 else
|
cannam@133
|
401 acx_pthread_ok=no
|
cannam@133
|
402 $2
|
cannam@133
|
403 fi
|
cannam@133
|
404 AC_LANG_RESTORE
|
cannam@133
|
405 ])dnl ACX_PTHREAD
|