1*4559860eSchristos# =========================================================================== 2*4559860eSchristos# https://www.gnu.org/software/autoconf-archive/ax_pthread.html 3*4559860eSchristos# =========================================================================== 4*4559860eSchristos# 5*4559860eSchristos# SYNOPSIS 6*4559860eSchristos# 7*4559860eSchristos# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) 8*4559860eSchristos# 9*4559860eSchristos# DESCRIPTION 10*4559860eSchristos# 11*4559860eSchristos# This macro figures out how to build C programs using POSIX threads. It 12*4559860eSchristos# sets the PTHREAD_LIBS output variable to the threads library and linker 13*4559860eSchristos# flags, and the PTHREAD_CFLAGS output variable to any special C compiler 14*4559860eSchristos# flags that are needed. (The user can also force certain compiler 15*4559860eSchristos# flags/libs to be tested by setting these environment variables.) 16*4559860eSchristos# 17*4559860eSchristos# Also sets PTHREAD_CC to any special C compiler that is needed for 18*4559860eSchristos# multi-threaded programs (defaults to the value of CC otherwise). (This 19*4559860eSchristos# is necessary on AIX to use the special cc_r compiler alias.) 20*4559860eSchristos# 21*4559860eSchristos# NOTE: You are assumed to not only compile your program with these flags, 22*4559860eSchristos# but also to link with them as well. For example, you might link with 23*4559860eSchristos# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS 24*4559860eSchristos# 25*4559860eSchristos# If you are only building threaded programs, you may wish to use these 26*4559860eSchristos# variables in your default LIBS, CFLAGS, and CC: 27*4559860eSchristos# 28*4559860eSchristos# LIBS="$PTHREAD_LIBS $LIBS" 29*4559860eSchristos# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 30*4559860eSchristos# CC="$PTHREAD_CC" 31*4559860eSchristos# 32*4559860eSchristos# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant 33*4559860eSchristos# has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to 34*4559860eSchristos# that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX). 35*4559860eSchristos# 36*4559860eSchristos# Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the 37*4559860eSchristos# PTHREAD_PRIO_INHERIT symbol is defined when compiling with 38*4559860eSchristos# PTHREAD_CFLAGS. 39*4559860eSchristos# 40*4559860eSchristos# ACTION-IF-FOUND is a list of shell commands to run if a threads library 41*4559860eSchristos# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it 42*4559860eSchristos# is not found. If ACTION-IF-FOUND is not specified, the default action 43*4559860eSchristos# will define HAVE_PTHREAD. 44*4559860eSchristos# 45*4559860eSchristos# Please let the authors know if this macro fails on any platform, or if 46*4559860eSchristos# you have any other suggestions or comments. This macro was based on work 47*4559860eSchristos# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help 48*4559860eSchristos# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by 49*4559860eSchristos# Alejandro Forero Cuervo to the autoconf macro repository. We are also 50*4559860eSchristos# grateful for the helpful feedback of numerous users. 51*4559860eSchristos# 52*4559860eSchristos# Updated for Autoconf 2.68 by Daniel Richard G. 53*4559860eSchristos# 54*4559860eSchristos# LICENSE 55*4559860eSchristos# 56*4559860eSchristos# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu> 57*4559860eSchristos# Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG> 58*4559860eSchristos# 59*4559860eSchristos# This program is free software: you can redistribute it and/or modify it 60*4559860eSchristos# under the terms of the GNU General Public License as published by the 61*4559860eSchristos# Free Software Foundation, either version 3 of the License, or (at your 62*4559860eSchristos# option) any later version. 63*4559860eSchristos# 64*4559860eSchristos# This program is distributed in the hope that it will be useful, but 65*4559860eSchristos# WITHOUT ANY WARRANTY; without even the implied warranty of 66*4559860eSchristos# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 67*4559860eSchristos# Public License for more details. 68*4559860eSchristos# 69*4559860eSchristos# You should have received a copy of the GNU General Public License along 70*4559860eSchristos# with this program. If not, see <https://www.gnu.org/licenses/>. 71*4559860eSchristos# 72*4559860eSchristos# As a special exception, the respective Autoconf Macro's copyright owner 73*4559860eSchristos# gives unlimited permission to copy, distribute and modify the configure 74*4559860eSchristos# scripts that are the output of Autoconf when processing the Macro. You 75*4559860eSchristos# need not follow the terms of the GNU General Public License when using 76*4559860eSchristos# or distributing such scripts, even though portions of the text of the 77*4559860eSchristos# Macro appear in them. The GNU General Public License (GPL) does govern 78*4559860eSchristos# all other use of the material that constitutes the Autoconf Macro. 79*4559860eSchristos# 80*4559860eSchristos# This special exception to the GPL applies to versions of the Autoconf 81*4559860eSchristos# Macro released by the Autoconf Archive. When you make and distribute a 82*4559860eSchristos# modified version of the Autoconf Macro, you may extend this special 83*4559860eSchristos# exception to the GPL to apply to your modified version as well. 84*4559860eSchristos 85*4559860eSchristos#serial 24 86*4559860eSchristos 87*4559860eSchristosAU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) 88*4559860eSchristosAC_DEFUN([AX_PTHREAD], [ 89*4559860eSchristosAC_REQUIRE([AC_CANONICAL_HOST]) 90*4559860eSchristosAC_REQUIRE([AC_PROG_CC]) 91*4559860eSchristosAC_REQUIRE([AC_PROG_SED]) 92*4559860eSchristosAC_LANG_PUSH([C]) 93*4559860eSchristosax_pthread_ok=no 94*4559860eSchristos 95*4559860eSchristos# We used to check for pthread.h first, but this fails if pthread.h 96*4559860eSchristos# requires special compiler flags (e.g. on Tru64 or Sequent). 97*4559860eSchristos# It gets checked for in the link test anyway. 98*4559860eSchristos 99*4559860eSchristos# First of all, check if the user has set any of the PTHREAD_LIBS, 100*4559860eSchristos# etcetera environment variables, and if threads linking works using 101*4559860eSchristos# them: 102*4559860eSchristosif test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then 103*4559860eSchristos ax_pthread_save_CC="$CC" 104*4559860eSchristos ax_pthread_save_CFLAGS="$CFLAGS" 105*4559860eSchristos ax_pthread_save_LIBS="$LIBS" 106*4559860eSchristos AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"]) 107*4559860eSchristos CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 108*4559860eSchristos LIBS="$PTHREAD_LIBS $LIBS" 109*4559860eSchristos AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS]) 110*4559860eSchristos AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes]) 111*4559860eSchristos AC_MSG_RESULT([$ax_pthread_ok]) 112*4559860eSchristos if test "x$ax_pthread_ok" = "xno"; then 113*4559860eSchristos PTHREAD_LIBS="" 114*4559860eSchristos PTHREAD_CFLAGS="" 115*4559860eSchristos fi 116*4559860eSchristos CC="$ax_pthread_save_CC" 117*4559860eSchristos CFLAGS="$ax_pthread_save_CFLAGS" 118*4559860eSchristos LIBS="$ax_pthread_save_LIBS" 119*4559860eSchristosfi 120*4559860eSchristos 121*4559860eSchristos# We must check for the threads library under a number of different 122*4559860eSchristos# names; the ordering is very important because some systems 123*4559860eSchristos# (e.g. DEC) have both -lpthread and -lpthreads, where one of the 124*4559860eSchristos# libraries is broken (non-POSIX). 125*4559860eSchristos 126*4559860eSchristos# Create a list of thread flags to try. Items starting with a "-" are 127*4559860eSchristos# C compiler flags, and other items are library names, except for "none" 128*4559860eSchristos# which indicates that we try without any flags at all, and "pthread-config" 129*4559860eSchristos# which is a program returning the flags for the Pth emulation library. 130*4559860eSchristos 131*4559860eSchristosax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" 132*4559860eSchristos 133*4559860eSchristos# The ordering *is* (sometimes) important. Some notes on the 134*4559860eSchristos# individual items follow: 135*4559860eSchristos 136*4559860eSchristos# pthreads: AIX (must check this before -lpthread) 137*4559860eSchristos# none: in case threads are in libc; should be tried before -Kthread and 138*4559860eSchristos# other compiler flags to prevent continual compiler warnings 139*4559860eSchristos# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) 140*4559860eSchristos# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64 141*4559860eSchristos# (Note: HP C rejects this with "bad form for `-t' option") 142*4559860eSchristos# -pthreads: Solaris/gcc (Note: HP C also rejects) 143*4559860eSchristos# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it 144*4559860eSchristos# doesn't hurt to check since this sometimes defines pthreads and 145*4559860eSchristos# -D_REENTRANT too), HP C (must be checked before -lpthread, which 146*4559860eSchristos# is present but should not be used directly; and before -mthreads, 147*4559860eSchristos# because the compiler interprets this as "-mt" + "-hreads") 148*4559860eSchristos# -mthreads: Mingw32/gcc, Lynx/gcc 149*4559860eSchristos# pthread: Linux, etcetera 150*4559860eSchristos# --thread-safe: KAI C++ 151*4559860eSchristos# pthread-config: use pthread-config program (for GNU Pth library) 152*4559860eSchristos 153*4559860eSchristoscase $host_os in 154*4559860eSchristos 155*4559860eSchristos freebsd*) 156*4559860eSchristos 157*4559860eSchristos # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) 158*4559860eSchristos # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) 159*4559860eSchristos 160*4559860eSchristos ax_pthread_flags="-kthread lthread $ax_pthread_flags" 161*4559860eSchristos ;; 162*4559860eSchristos 163*4559860eSchristos hpux*) 164*4559860eSchristos 165*4559860eSchristos # From the cc(1) man page: "[-mt] Sets various -D flags to enable 166*4559860eSchristos # multi-threading and also sets -lpthread." 167*4559860eSchristos 168*4559860eSchristos ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags" 169*4559860eSchristos ;; 170*4559860eSchristos 171*4559860eSchristos openedition*) 172*4559860eSchristos 173*4559860eSchristos # IBM z/OS requires a feature-test macro to be defined in order to 174*4559860eSchristos # enable POSIX threads at all, so give the user a hint if this is 175*4559860eSchristos # not set. (We don't define these ourselves, as they can affect 176*4559860eSchristos # other portions of the system API in unpredictable ways.) 177*4559860eSchristos 178*4559860eSchristos AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING], 179*4559860eSchristos [ 180*4559860eSchristos# if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS) 181*4559860eSchristos AX_PTHREAD_ZOS_MISSING 182*4559860eSchristos# endif 183*4559860eSchristos ], 184*4559860eSchristos [AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])]) 185*4559860eSchristos ;; 186*4559860eSchristos 187*4559860eSchristos solaris*) 188*4559860eSchristos 189*4559860eSchristos # On Solaris (at least, for some versions), libc contains stubbed 190*4559860eSchristos # (non-functional) versions of the pthreads routines, so link-based 191*4559860eSchristos # tests will erroneously succeed. (N.B.: The stubs are missing 192*4559860eSchristos # pthread_cleanup_push, or rather a function called by this macro, 193*4559860eSchristos # so we could check for that, but who knows whether they'll stub 194*4559860eSchristos # that too in a future libc.) So we'll check first for the 195*4559860eSchristos # standard Solaris way of linking pthreads (-mt -lpthread). 196*4559860eSchristos 197*4559860eSchristos ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags" 198*4559860eSchristos ;; 199*4559860eSchristosesac 200*4559860eSchristos 201*4559860eSchristos# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC) 202*4559860eSchristos 203*4559860eSchristosAS_IF([test "x$GCC" = "xyes"], 204*4559860eSchristos [ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"]) 205*4559860eSchristos 206*4559860eSchristos# The presence of a feature test macro requesting re-entrant function 207*4559860eSchristos# definitions is, on some systems, a strong hint that pthreads support is 208*4559860eSchristos# correctly enabled 209*4559860eSchristos 210*4559860eSchristoscase $host_os in 211*4559860eSchristos darwin* | hpux* | linux* | osf* | solaris*) 212*4559860eSchristos ax_pthread_check_macro="_REENTRANT" 213*4559860eSchristos ;; 214*4559860eSchristos 215*4559860eSchristos aix*) 216*4559860eSchristos ax_pthread_check_macro="_THREAD_SAFE" 217*4559860eSchristos ;; 218*4559860eSchristos 219*4559860eSchristos *) 220*4559860eSchristos ax_pthread_check_macro="--" 221*4559860eSchristos ;; 222*4559860eSchristosesac 223*4559860eSchristosAS_IF([test "x$ax_pthread_check_macro" = "x--"], 224*4559860eSchristos [ax_pthread_check_cond=0], 225*4559860eSchristos [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"]) 226*4559860eSchristos 227*4559860eSchristos# Are we compiling with Clang? 228*4559860eSchristos 229*4559860eSchristosAC_CACHE_CHECK([whether $CC is Clang], 230*4559860eSchristos [ax_cv_PTHREAD_CLANG], 231*4559860eSchristos [ax_cv_PTHREAD_CLANG=no 232*4559860eSchristos # Note that Autoconf sets GCC=yes for Clang as well as GCC 233*4559860eSchristos if test "x$GCC" = "xyes"; then 234*4559860eSchristos AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG], 235*4559860eSchristos [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */ 236*4559860eSchristos# if defined(__clang__) && defined(__llvm__) 237*4559860eSchristos AX_PTHREAD_CC_IS_CLANG 238*4559860eSchristos# endif 239*4559860eSchristos ], 240*4559860eSchristos [ax_cv_PTHREAD_CLANG=yes]) 241*4559860eSchristos fi 242*4559860eSchristos ]) 243*4559860eSchristosax_pthread_clang="$ax_cv_PTHREAD_CLANG" 244*4559860eSchristos 245*4559860eSchristosax_pthread_clang_warning=no 246*4559860eSchristos 247*4559860eSchristos# Clang needs special handling, because older versions handle the -pthread 248*4559860eSchristos# option in a rather... idiosyncratic way 249*4559860eSchristos 250*4559860eSchristosif test "x$ax_pthread_clang" = "xyes"; then 251*4559860eSchristos 252*4559860eSchristos # Clang takes -pthread; it has never supported any other flag 253*4559860eSchristos 254*4559860eSchristos # (Note 1: This will need to be revisited if a system that Clang 255*4559860eSchristos # supports has POSIX threads in a separate library. This tends not 256*4559860eSchristos # to be the way of modern systems, but it's conceivable.) 257*4559860eSchristos 258*4559860eSchristos # (Note 2: On some systems, notably Darwin, -pthread is not needed 259*4559860eSchristos # to get POSIX threads support; the API is always present and 260*4559860eSchristos # active. We could reasonably leave PTHREAD_CFLAGS empty. But 261*4559860eSchristos # -pthread does define _REENTRANT, and while the Darwin headers 262*4559860eSchristos # ignore this macro, third-party headers might not.) 263*4559860eSchristos 264*4559860eSchristos PTHREAD_CFLAGS="-pthread" 265*4559860eSchristos PTHREAD_LIBS= 266*4559860eSchristos 267*4559860eSchristos ax_pthread_ok=yes 268*4559860eSchristos 269*4559860eSchristos # However, older versions of Clang make a point of warning the user 270*4559860eSchristos # that, in an invocation where only linking and no compilation is 271*4559860eSchristos # taking place, the -pthread option has no effect ("argument unused 272*4559860eSchristos # during compilation"). They expect -pthread to be passed in only 273*4559860eSchristos # when source code is being compiled. 274*4559860eSchristos # 275*4559860eSchristos # Problem is, this is at odds with the way Automake and most other 276*4559860eSchristos # C build frameworks function, which is that the same flags used in 277*4559860eSchristos # compilation (CFLAGS) are also used in linking. Many systems 278*4559860eSchristos # supported by AX_PTHREAD require exactly this for POSIX threads 279*4559860eSchristos # support, and in fact it is often not straightforward to specify a 280*4559860eSchristos # flag that is used only in the compilation phase and not in 281*4559860eSchristos # linking. Such a scenario is extremely rare in practice. 282*4559860eSchristos # 283*4559860eSchristos # Even though use of the -pthread flag in linking would only print 284*4559860eSchristos # a warning, this can be a nuisance for well-run software projects 285*4559860eSchristos # that build with -Werror. So if the active version of Clang has 286*4559860eSchristos # this misfeature, we search for an option to squash it. 287*4559860eSchristos 288*4559860eSchristos AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread], 289*4559860eSchristos [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG], 290*4559860eSchristos [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown 291*4559860eSchristos # Create an alternate version of $ac_link that compiles and 292*4559860eSchristos # links in two steps (.c -> .o, .o -> exe) instead of one 293*4559860eSchristos # (.c -> exe), because the warning occurs only in the second 294*4559860eSchristos # step 295*4559860eSchristos ax_pthread_save_ac_link="$ac_link" 296*4559860eSchristos ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g' 297*4559860eSchristos ax_pthread_link_step=`$as_echo "$ac_link" | sed "$ax_pthread_sed"` 298*4559860eSchristos ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)" 299*4559860eSchristos ax_pthread_save_CFLAGS="$CFLAGS" 300*4559860eSchristos for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do 301*4559860eSchristos AS_IF([test "x$ax_pthread_try" = "xunknown"], [break]) 302*4559860eSchristos CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS" 303*4559860eSchristos ac_link="$ax_pthread_save_ac_link" 304*4559860eSchristos AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], 305*4559860eSchristos [ac_link="$ax_pthread_2step_ac_link" 306*4559860eSchristos AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])], 307*4559860eSchristos [break]) 308*4559860eSchristos ]) 309*4559860eSchristos done 310*4559860eSchristos ac_link="$ax_pthread_save_ac_link" 311*4559860eSchristos CFLAGS="$ax_pthread_save_CFLAGS" 312*4559860eSchristos AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no]) 313*4559860eSchristos ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try" 314*4559860eSchristos ]) 315*4559860eSchristos 316*4559860eSchristos case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in 317*4559860eSchristos no | unknown) ;; 318*4559860eSchristos *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;; 319*4559860eSchristos esac 320*4559860eSchristos 321*4559860eSchristosfi # $ax_pthread_clang = yes 322*4559860eSchristos 323*4559860eSchristosif test "x$ax_pthread_ok" = "xno"; then 324*4559860eSchristosfor ax_pthread_try_flag in $ax_pthread_flags; do 325*4559860eSchristos 326*4559860eSchristos case $ax_pthread_try_flag in 327*4559860eSchristos none) 328*4559860eSchristos AC_MSG_CHECKING([whether pthreads work without any flags]) 329*4559860eSchristos ;; 330*4559860eSchristos 331*4559860eSchristos -mt,pthread) 332*4559860eSchristos AC_MSG_CHECKING([whether pthreads work with -mt -lpthread]) 333*4559860eSchristos PTHREAD_CFLAGS="-mt" 334*4559860eSchristos PTHREAD_LIBS="-lpthread" 335*4559860eSchristos ;; 336*4559860eSchristos 337*4559860eSchristos -*) 338*4559860eSchristos AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag]) 339*4559860eSchristos PTHREAD_CFLAGS="$ax_pthread_try_flag" 340*4559860eSchristos ;; 341*4559860eSchristos 342*4559860eSchristos pthread-config) 343*4559860eSchristos AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no]) 344*4559860eSchristos AS_IF([test "x$ax_pthread_config" = "xno"], [continue]) 345*4559860eSchristos PTHREAD_CFLAGS="`pthread-config --cflags`" 346*4559860eSchristos PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" 347*4559860eSchristos ;; 348*4559860eSchristos 349*4559860eSchristos *) 350*4559860eSchristos AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag]) 351*4559860eSchristos PTHREAD_LIBS="-l$ax_pthread_try_flag" 352*4559860eSchristos ;; 353*4559860eSchristos esac 354*4559860eSchristos 355*4559860eSchristos ax_pthread_save_CFLAGS="$CFLAGS" 356*4559860eSchristos ax_pthread_save_LIBS="$LIBS" 357*4559860eSchristos CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 358*4559860eSchristos LIBS="$PTHREAD_LIBS $LIBS" 359*4559860eSchristos 360*4559860eSchristos # Check for various functions. We must include pthread.h, 361*4559860eSchristos # since some functions may be macros. (On the Sequent, we 362*4559860eSchristos # need a special flag -Kthread to make this header compile.) 363*4559860eSchristos # We check for pthread_join because it is in -lpthread on IRIX 364*4559860eSchristos # while pthread_create is in libc. We check for pthread_attr_init 365*4559860eSchristos # due to DEC craziness with -lpthreads. We check for 366*4559860eSchristos # pthread_cleanup_push because it is one of the few pthread 367*4559860eSchristos # functions on Solaris that doesn't have a non-functional libc stub. 368*4559860eSchristos # We try pthread_create on general principles. 369*4559860eSchristos 370*4559860eSchristos AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h> 371*4559860eSchristos# if $ax_pthread_check_cond 372*4559860eSchristos# error "$ax_pthread_check_macro must be defined" 373*4559860eSchristos# endif 374*4559860eSchristos static void routine(void *a) { a = 0; } 375*4559860eSchristos static void *start_routine(void *a) { return a; }], 376*4559860eSchristos [pthread_t th; pthread_attr_t attr; 377*4559860eSchristos pthread_create(&th, 0, start_routine, 0); 378*4559860eSchristos pthread_join(th, 0); 379*4559860eSchristos pthread_attr_init(&attr); 380*4559860eSchristos pthread_cleanup_push(routine, 0); 381*4559860eSchristos pthread_cleanup_pop(0) /* ; */])], 382*4559860eSchristos [ax_pthread_ok=yes], 383*4559860eSchristos []) 384*4559860eSchristos 385*4559860eSchristos CFLAGS="$ax_pthread_save_CFLAGS" 386*4559860eSchristos LIBS="$ax_pthread_save_LIBS" 387*4559860eSchristos 388*4559860eSchristos AC_MSG_RESULT([$ax_pthread_ok]) 389*4559860eSchristos AS_IF([test "x$ax_pthread_ok" = "xyes"], [break]) 390*4559860eSchristos 391*4559860eSchristos PTHREAD_LIBS="" 392*4559860eSchristos PTHREAD_CFLAGS="" 393*4559860eSchristosdone 394*4559860eSchristosfi 395*4559860eSchristos 396*4559860eSchristos# Various other checks: 397*4559860eSchristosif test "x$ax_pthread_ok" = "xyes"; then 398*4559860eSchristos ax_pthread_save_CFLAGS="$CFLAGS" 399*4559860eSchristos ax_pthread_save_LIBS="$LIBS" 400*4559860eSchristos CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 401*4559860eSchristos LIBS="$PTHREAD_LIBS $LIBS" 402*4559860eSchristos 403*4559860eSchristos # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. 404*4559860eSchristos AC_CACHE_CHECK([for joinable pthread attribute], 405*4559860eSchristos [ax_cv_PTHREAD_JOINABLE_ATTR], 406*4559860eSchristos [ax_cv_PTHREAD_JOINABLE_ATTR=unknown 407*4559860eSchristos for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do 408*4559860eSchristos AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>], 409*4559860eSchristos [int attr = $ax_pthread_attr; return attr /* ; */])], 410*4559860eSchristos [ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break], 411*4559860eSchristos []) 412*4559860eSchristos done 413*4559860eSchristos ]) 414*4559860eSchristos AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \ 415*4559860eSchristos test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \ 416*4559860eSchristos test "x$ax_pthread_joinable_attr_defined" != "xyes"], 417*4559860eSchristos [AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE], 418*4559860eSchristos [$ax_cv_PTHREAD_JOINABLE_ATTR], 419*4559860eSchristos [Define to necessary symbol if this constant 420*4559860eSchristos uses a non-standard name on your system.]) 421*4559860eSchristos ax_pthread_joinable_attr_defined=yes 422*4559860eSchristos ]) 423*4559860eSchristos 424*4559860eSchristos AC_CACHE_CHECK([whether more special flags are required for pthreads], 425*4559860eSchristos [ax_cv_PTHREAD_SPECIAL_FLAGS], 426*4559860eSchristos [ax_cv_PTHREAD_SPECIAL_FLAGS=no 427*4559860eSchristos case $host_os in 428*4559860eSchristos solaris*) 429*4559860eSchristos ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS" 430*4559860eSchristos ;; 431*4559860eSchristos esac 432*4559860eSchristos ]) 433*4559860eSchristos AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \ 434*4559860eSchristos test "x$ax_pthread_special_flags_added" != "xyes"], 435*4559860eSchristos [PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS" 436*4559860eSchristos ax_pthread_special_flags_added=yes]) 437*4559860eSchristos 438*4559860eSchristos AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT], 439*4559860eSchristos [ax_cv_PTHREAD_PRIO_INHERIT], 440*4559860eSchristos [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]], 441*4559860eSchristos [[int i = PTHREAD_PRIO_INHERIT;]])], 442*4559860eSchristos [ax_cv_PTHREAD_PRIO_INHERIT=yes], 443*4559860eSchristos [ax_cv_PTHREAD_PRIO_INHERIT=no]) 444*4559860eSchristos ]) 445*4559860eSchristos AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \ 446*4559860eSchristos test "x$ax_pthread_prio_inherit_defined" != "xyes"], 447*4559860eSchristos [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.]) 448*4559860eSchristos ax_pthread_prio_inherit_defined=yes 449*4559860eSchristos ]) 450*4559860eSchristos 451*4559860eSchristos CFLAGS="$ax_pthread_save_CFLAGS" 452*4559860eSchristos LIBS="$ax_pthread_save_LIBS" 453*4559860eSchristos 454*4559860eSchristos # More AIX lossage: compile with *_r variant 455*4559860eSchristos if test "x$GCC" != "xyes"; then 456*4559860eSchristos case $host_os in 457*4559860eSchristos aix*) 458*4559860eSchristos AS_CASE(["x/$CC"], 459*4559860eSchristos [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6], 460*4559860eSchristos [#handle absolute path differently from PATH based program lookup 461*4559860eSchristos AS_CASE(["x$CC"], 462*4559860eSchristos [x/*], 463*4559860eSchristos [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])], 464*4559860eSchristos [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])]) 465*4559860eSchristos ;; 466*4559860eSchristos esac 467*4559860eSchristos fi 468*4559860eSchristosfi 469*4559860eSchristos 470*4559860eSchristostest -n "$PTHREAD_CC" || PTHREAD_CC="$CC" 471*4559860eSchristos 472*4559860eSchristosAC_SUBST([PTHREAD_LIBS]) 473*4559860eSchristosAC_SUBST([PTHREAD_CFLAGS]) 474*4559860eSchristosAC_SUBST([PTHREAD_CC]) 475*4559860eSchristos 476*4559860eSchristos# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: 477*4559860eSchristosif test "x$ax_pthread_ok" = "xyes"; then 478*4559860eSchristos ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1]) 479*4559860eSchristos : 480*4559860eSchristoselse 481*4559860eSchristos ax_pthread_ok=no 482*4559860eSchristos $2 483*4559860eSchristosfi 484*4559860eSchristosAC_LANG_POP 485*4559860eSchristos])dnl AX_PTHREAD 486