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