1
1
# ===========================================================================
2
- # http ://www.gnu.org/software/autoconf-archive/ax_pthread.html
2
+ # https ://www.gnu.org/software/autoconf-archive/ax_pthread.html
3
3
# ===========================================================================
4
4
#
5
5
# SYNOPSIS
55
55
#
56
56
# Copyright (c) 2008 Steven G. Johnson <[email protected] >
57
57
# Copyright (c) 2011 Daniel Richard G. <[email protected] >
58
+ # Copyright (c) 2019 Marc Stevens <[email protected] >
58
59
#
59
60
# This program is free software: you can redistribute it and/or modify it
60
61
# under the terms of the GNU General Public License as published by the
67
68
# Public License for more details.
68
69
#
69
70
# You should have received a copy of the GNU General Public License along
70
- # with this program. If not, see <http ://www.gnu.org/licenses/>.
71
+ # with this program. If not, see <https ://www.gnu.org/licenses/>.
71
72
#
72
73
# As a special exception, the respective Autoconf Macro's copyright owner
73
74
# gives unlimited permission to copy, distribute and modify the configure
82
83
# modified version of the Autoconf Macro, you may extend this special
83
84
# exception to the GPL to apply to your modified version as well.
84
85
85
- # serial 23
86
+ # serial 27
86
87
87
88
AU_ALIAS ( [ ACX_PTHREAD] , [ AX_PTHREAD ] )
88
89
AC_DEFUN ( [ AX_PTHREAD ] , [
123
124
# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
124
125
# libraries is broken (non-POSIX).
125
126
126
- # Create a list of thread flags to try. Items starting with a "-" are
127
- # C compiler flags, and other items are library names, except for "none"
128
- # which indicates that we try without any flags at all, and "pthread-config"
129
- # which is a program returning the flags for the Pth emulation library.
127
+ # Create a list of thread flags to try. Items with a "," contain both
128
+ # C compiler flags (before ",") and linker flags (after ","). Other items
129
+ # starting with a "-" are C compiler flags, and remaining items are
130
+ # library names, except for "none" which indicates that we try without
131
+ # any flags at all, and "pthread-config" which is a program returning
132
+ # the flags for the Pth emulation library.
130
133
131
134
ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
132
135
@@ -194,14 +197,47 @@ case $host_os in
194
197
# that too in a future libc.) So we'll check first for the
195
198
# standard Solaris way of linking pthreads (-mt -lpthread).
196
199
197
- ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags"
200
+ ax_pthread_flags="-mt,-lpthread pthread $ax_pthread_flags"
198
201
;;
199
202
esac
200
203
204
+ # Are we compiling with Clang?
205
+
206
+ AC_CACHE_CHECK ( [ whether $CC is Clang] ,
207
+ [ ax_cv_PTHREAD_CLANG] ,
208
+ [ ax_cv_PTHREAD_CLANG=no
209
+ # Note that Autoconf sets GCC=yes for Clang as well as GCC
210
+ if test "x$GCC" = "xyes"; then
211
+ AC_EGREP_CPP ( [ AX_PTHREAD_CC_IS_CLANG] ,
212
+ [ /* Note: Clang 2.7 lacks __clang_[ a-z] +__ */
213
+ # if defined(__clang__) && defined(__llvm__)
214
+ AX_PTHREAD_CC_IS_CLANG
215
+ # endif
216
+ ] ,
217
+ [ ax_cv_PTHREAD_CLANG=yes] )
218
+ fi
219
+ ] )
220
+ ax_pthread_clang="$ax_cv_PTHREAD_CLANG"
221
+
222
+
201
223
# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC)
202
224
225
+ # Note that for GCC and Clang -pthread generally implies -lpthread,
226
+ # except when -nostdlib is passed.
227
+ # This is problematic using libtool to build C++ shared libraries with pthread:
228
+ # [ 1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=25460
229
+ # [ 2] https://bugzilla.redhat.com/show_bug.cgi?id=661333
230
+ # [ 3] https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=468555
231
+ # To solve this, first try -pthread together with -lpthread for GCC
232
+
203
233
AS_IF ( [ test "x$GCC" = "xyes"] ,
204
- [ ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"] )
234
+ [ ax_pthread_flags="-pthread,-lpthread -pthread -pthreads $ax_pthread_flags"] )
235
+
236
+ # Clang takes -pthread (never supported any other flag), but we'll try with -lpthread first
237
+
238
+ AS_IF ( [ test "x$ax_pthread_clang" = "xyes"] ,
239
+ [ ax_pthread_flags="-pthread,-lpthread -pthread"] )
240
+
205
241
206
242
# The presence of a feature test macro requesting re-entrant function
207
243
# definitions is, on some systems, a strong hint that pthreads support is
@@ -224,25 +260,86 @@ AS_IF([test "x$ax_pthread_check_macro" = "x--"],
224
260
[ ax_pthread_check_cond=0] ,
225
261
[ ax_pthread_check_cond="!defined($ax_pthread_check_macro)"] )
226
262
227
- # Are we compiling with Clang?
228
263
229
- AC_CACHE_CHECK ( [ whether $CC is Clang] ,
230
- [ ax_cv_PTHREAD_CLANG] ,
231
- [ ax_cv_PTHREAD_CLANG=no
232
- # Note that Autoconf sets GCC=yes for Clang as well as GCC
233
- if test "x$GCC" = "xyes"; then
234
- AC_EGREP_CPP ( [ AX_PTHREAD_CC_IS_CLANG] ,
235
- [ /* Note: Clang 2.7 lacks __clang_[ a-z] +__ */
236
- # if defined(__clang__) && defined(__llvm__)
237
- AX_PTHREAD_CC_IS_CLANG
238
- # endif
239
- ] ,
240
- [ ax_cv_PTHREAD_CLANG=yes] )
241
- fi
242
- ] )
243
- ax_pthread_clang="$ax_cv_PTHREAD_CLANG"
264
+ if test "x$ax_pthread_ok" = "xno"; then
265
+ for ax_pthread_try_flag in $ax_pthread_flags; do
266
+
267
+ case $ax_pthread_try_flag in
268
+ none)
269
+ AC_MSG_CHECKING ( [ whether pthreads work without any flags] )
270
+ ;;
271
+
272
+ *,*)
273
+ PTHREAD_CFLAGS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\1/"`
274
+ PTHREAD_LIBS=`echo $ax_pthread_try_flag | sed "s/^\(.*\),\(.*\)$/\2/"`
275
+ AC_MSG_CHECKING ( [ whether pthreads work with "$PTHREAD_CFLAGS" and "$PTHREAD_LIBS"] )
276
+ ;;
277
+
278
+ -*)
279
+ AC_MSG_CHECKING ( [ whether pthreads work with $ax_pthread_try_flag] )
280
+ PTHREAD_CFLAGS="$ax_pthread_try_flag"
281
+ ;;
282
+
283
+ pthread-config)
284
+ AC_CHECK_PROG ( [ ax_pthread_config] , [ pthread-config] , [ yes] , [ no] )
285
+ AS_IF ( [ test "x$ax_pthread_config" = "xno"] , [ continue] )
286
+ PTHREAD_CFLAGS="`pthread-config --cflags`"
287
+ PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
288
+ ;;
289
+
290
+ *)
291
+ AC_MSG_CHECKING ( [ for the pthreads library -l$ax_pthread_try_flag] )
292
+ PTHREAD_LIBS="-l$ax_pthread_try_flag"
293
+ ;;
294
+ esac
295
+
296
+ ax_pthread_save_CFLAGS="$CFLAGS"
297
+ ax_pthread_save_LIBS="$LIBS"
298
+ CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
299
+ LIBS="$PTHREAD_LIBS $LIBS"
300
+
301
+ # Check for various functions. We must include pthread.h,
302
+ # since some functions may be macros. (On the Sequent, we
303
+ # need a special flag -Kthread to make this header compile.)
304
+ # We check for pthread_join because it is in -lpthread on IRIX
305
+ # while pthread_create is in libc. We check for pthread_attr_init
306
+ # due to DEC craziness with -lpthreads. We check for
307
+ # pthread_cleanup_push because it is one of the few pthread
308
+ # functions on Solaris that doesn't have a non-functional libc stub.
309
+ # We try pthread_create on general principles.
310
+
311
+ AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ #include <pthread.h>
312
+ # if $ax_pthread_check_cond
313
+ # error "$ax_pthread_check_macro must be defined"
314
+ # endif
315
+ static void *some_global = NULL;
316
+ static void routine(void *a)
317
+ {
318
+ /* To avoid any unused-parameter or
319
+ unused-but-set-parameter warning. */
320
+ some_global = a;
321
+ }
322
+ static void *start_routine(void *a) { return a; }] ,
323
+ [ pthread_t th; pthread_attr_t attr;
324
+ pthread_create(&th, 0, start_routine, 0);
325
+ pthread_join(th, 0);
326
+ pthread_attr_init(&attr);
327
+ pthread_cleanup_push(routine, 0);
328
+ pthread_cleanup_pop(0) /* ; */] ) ] ,
329
+ [ ax_pthread_ok=yes] ,
330
+ [ ] )
331
+
332
+ CFLAGS="$ax_pthread_save_CFLAGS"
333
+ LIBS="$ax_pthread_save_LIBS"
334
+
335
+ AC_MSG_RESULT ( [ $ax_pthread_ok] )
336
+ AS_IF ( [ test "x$ax_pthread_ok" = "xyes"] , [ break] )
337
+
338
+ PTHREAD_LIBS=""
339
+ PTHREAD_CFLAGS=""
340
+ done
341
+ fi
244
342
245
- ax_pthread_clang_warning=no
246
343
247
344
# Clang needs special handling, because older versions handle the -pthread
248
345
# option in a rather... idiosyncratic way
@@ -261,11 +358,6 @@ if test "x$ax_pthread_clang" = "xyes"; then
261
358
# -pthread does define _REENTRANT, and while the Darwin headers
262
359
# ignore this macro, third-party headers might not.)
263
360
264
- PTHREAD_CFLAGS="-pthread"
265
- PTHREAD_LIBS=
266
-
267
- ax_pthread_ok=yes
268
-
269
361
# However, older versions of Clang make a point of warning the user
270
362
# that, in an invocation where only linking and no compilation is
271
363
# taking place, the -pthread option has no effect ("argument unused
@@ -320,78 +412,7 @@ if test "x$ax_pthread_clang" = "xyes"; then
320
412
321
413
fi # $ax_pthread_clang = yes
322
414
323
- if test "x$ax_pthread_ok" = "xno"; then
324
- for ax_pthread_try_flag in $ax_pthread_flags; do
325
-
326
- case $ax_pthread_try_flag in
327
- none)
328
- AC_MSG_CHECKING ( [ whether pthreads work without any flags] )
329
- ;;
330
-
331
- -mt,pthread)
332
- AC_MSG_CHECKING ( [ whether pthreads work with -mt -lpthread] )
333
- PTHREAD_CFLAGS="-mt"
334
- PTHREAD_LIBS="-lpthread"
335
- ;;
336
-
337
- -*)
338
- AC_MSG_CHECKING ( [ whether pthreads work with $ax_pthread_try_flag] )
339
- PTHREAD_CFLAGS="$ax_pthread_try_flag"
340
- ;;
341
-
342
- pthread-config)
343
- AC_CHECK_PROG ( [ ax_pthread_config] , [ pthread-config] , [ yes] , [ no] )
344
- AS_IF ( [ test "x$ax_pthread_config" = "xno"] , [ continue] )
345
- PTHREAD_CFLAGS="`pthread-config --cflags`"
346
- PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
347
- ;;
348
415
349
- *)
350
- AC_MSG_CHECKING ( [ for the pthreads library -l$ax_pthread_try_flag] )
351
- PTHREAD_LIBS="-l$ax_pthread_try_flag"
352
- ;;
353
- esac
354
-
355
- ax_pthread_save_CFLAGS="$CFLAGS"
356
- ax_pthread_save_LIBS="$LIBS"
357
- CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
358
- LIBS="$PTHREAD_LIBS $LIBS"
359
-
360
- # Check for various functions. We must include pthread.h,
361
- # since some functions may be macros. (On the Sequent, we
362
- # need a special flag -Kthread to make this header compile.)
363
- # We check for pthread_join because it is in -lpthread on IRIX
364
- # while pthread_create is in libc. We check for pthread_attr_init
365
- # due to DEC craziness with -lpthreads. We check for
366
- # pthread_cleanup_push because it is one of the few pthread
367
- # functions on Solaris that doesn't have a non-functional libc stub.
368
- # We try pthread_create on general principles.
369
-
370
- AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ #include <pthread.h>
371
- # if $ax_pthread_check_cond
372
- # error "$ax_pthread_check_macro must be defined"
373
- # endif
374
- static void routine(void *a) { a = 0; }
375
- static void *start_routine(void *a) { return a; }] ,
376
- [ pthread_t th; pthread_attr_t attr;
377
- pthread_create(&th, 0, start_routine, 0);
378
- pthread_join(th, 0);
379
- pthread_attr_init(&attr);
380
- pthread_cleanup_push(routine, 0);
381
- pthread_cleanup_pop(0) /* ; */] ) ] ,
382
- [ ax_pthread_ok=yes] ,
383
- [ ] )
384
-
385
- CFLAGS="$ax_pthread_save_CFLAGS"
386
- LIBS="$ax_pthread_save_LIBS"
387
-
388
- AC_MSG_RESULT ( [ $ax_pthread_ok] )
389
- AS_IF ( [ test "x$ax_pthread_ok" = "xyes"] , [ break] )
390
-
391
- PTHREAD_LIBS=""
392
- PTHREAD_CFLAGS=""
393
- done
394
- fi
395
416
396
417
# Various other checks:
397
418
if test "x$ax_pthread_ok" = "xyes"; then
@@ -438,7 +459,8 @@ if test "x$ax_pthread_ok" = "xyes"; then
438
459
AC_CACHE_CHECK ( [ for PTHREAD_PRIO_INHERIT] ,
439
460
[ ax_cv_PTHREAD_PRIO_INHERIT] ,
440
461
[ AC_LINK_IFELSE ( [ AC_LANG_PROGRAM ( [ [ #include <pthread.h>] ] ,
441
- [ [ int i = PTHREAD_PRIO_INHERIT;] ] ) ] ,
462
+ [ [ int i = PTHREAD_PRIO_INHERIT;
463
+ return i;] ] ) ] ,
442
464
[ ax_cv_PTHREAD_PRIO_INHERIT=yes] ,
443
465
[ ax_cv_PTHREAD_PRIO_INHERIT=no] )
444
466
] )
0 commit comments