xref: /freebsd/contrib/unbound/ax_pthread.m4 (revision 17d15b251108ff09e632ed4812f7c66999a6b69b)
1*17d15b25SDag-Erling Smørgrav# ===========================================================================
2*17d15b25SDag-Erling Smørgrav#        http://www.gnu.org/software/autoconf-archive/ax_pthread.html
3*17d15b25SDag-Erling Smørgrav# ===========================================================================
4*17d15b25SDag-Erling Smørgrav#
5*17d15b25SDag-Erling Smørgrav# SYNOPSIS
6*17d15b25SDag-Erling Smørgrav#
7*17d15b25SDag-Erling Smørgrav#   AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
8*17d15b25SDag-Erling Smørgrav#
9*17d15b25SDag-Erling Smørgrav# DESCRIPTION
10*17d15b25SDag-Erling Smørgrav#
11*17d15b25SDag-Erling Smørgrav#   This macro figures out how to build C programs using POSIX threads. It
12*17d15b25SDag-Erling Smørgrav#   sets the PTHREAD_LIBS output variable to the threads library and linker
13*17d15b25SDag-Erling Smørgrav#   flags, and the PTHREAD_CFLAGS output variable to any special C compiler
14*17d15b25SDag-Erling Smørgrav#   flags that are needed. (The user can also force certain compiler
15*17d15b25SDag-Erling Smørgrav#   flags/libs to be tested by setting these environment variables.)
16*17d15b25SDag-Erling Smørgrav#
17*17d15b25SDag-Erling Smørgrav#   Also sets PTHREAD_CC to any special C compiler that is needed for
18*17d15b25SDag-Erling Smørgrav#   multi-threaded programs (defaults to the value of CC otherwise). (This
19*17d15b25SDag-Erling Smørgrav#   is necessary on AIX to use the special cc_r compiler alias.)
20*17d15b25SDag-Erling Smørgrav#
21*17d15b25SDag-Erling Smørgrav#   NOTE: You are assumed to not only compile your program with these flags,
22*17d15b25SDag-Erling Smørgrav#   but also link it with them as well. e.g. you should link with
23*17d15b25SDag-Erling Smørgrav#   $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
24*17d15b25SDag-Erling Smørgrav#
25*17d15b25SDag-Erling Smørgrav#   If you are only building threads programs, you may wish to use these
26*17d15b25SDag-Erling Smørgrav#   variables in your default LIBS, CFLAGS, and CC:
27*17d15b25SDag-Erling Smørgrav#
28*17d15b25SDag-Erling Smørgrav#     LIBS="$PTHREAD_LIBS $LIBS"
29*17d15b25SDag-Erling Smørgrav#     CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
30*17d15b25SDag-Erling Smørgrav#     CC="$PTHREAD_CC"
31*17d15b25SDag-Erling Smørgrav#
32*17d15b25SDag-Erling Smørgrav#   In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
33*17d15b25SDag-Erling Smørgrav#   has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name
34*17d15b25SDag-Erling Smørgrav#   (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
35*17d15b25SDag-Erling Smørgrav#
36*17d15b25SDag-Erling Smørgrav#   Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the
37*17d15b25SDag-Erling Smørgrav#   PTHREAD_PRIO_INHERIT symbol is defined when compiling with
38*17d15b25SDag-Erling Smørgrav#   PTHREAD_CFLAGS.
39*17d15b25SDag-Erling Smørgrav#
40*17d15b25SDag-Erling Smørgrav#   ACTION-IF-FOUND is a list of shell commands to run if a threads library
41*17d15b25SDag-Erling Smørgrav#   is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
42*17d15b25SDag-Erling Smørgrav#   is not found. If ACTION-IF-FOUND is not specified, the default action
43*17d15b25SDag-Erling Smørgrav#   will define HAVE_PTHREAD.
44*17d15b25SDag-Erling Smørgrav#
45*17d15b25SDag-Erling Smørgrav#   Please let the authors know if this macro fails on any platform, or if
46*17d15b25SDag-Erling Smørgrav#   you have any other suggestions or comments. This macro was based on work
47*17d15b25SDag-Erling Smørgrav#   by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
48*17d15b25SDag-Erling Smørgrav#   from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
49*17d15b25SDag-Erling Smørgrav#   Alejandro Forero Cuervo to the autoconf macro repository. We are also
50*17d15b25SDag-Erling Smørgrav#   grateful for the helpful feedback of numerous users.
51*17d15b25SDag-Erling Smørgrav#
52*17d15b25SDag-Erling Smørgrav#   Updated for Autoconf 2.68 by Daniel Richard G.
53*17d15b25SDag-Erling Smørgrav#
54*17d15b25SDag-Erling Smørgrav# LICENSE
55*17d15b25SDag-Erling Smørgrav#
56*17d15b25SDag-Erling Smørgrav#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
57*17d15b25SDag-Erling Smørgrav#   Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG>
58*17d15b25SDag-Erling Smørgrav#
59*17d15b25SDag-Erling Smørgrav#   This program is free software: you can redistribute it and/or modify it
60*17d15b25SDag-Erling Smørgrav#   under the terms of the GNU General Public License as published by the
61*17d15b25SDag-Erling Smørgrav#   Free Software Foundation, either version 3 of the License, or (at your
62*17d15b25SDag-Erling Smørgrav#   option) any later version.
63*17d15b25SDag-Erling Smørgrav#
64*17d15b25SDag-Erling Smørgrav#   This program is distributed in the hope that it will be useful, but
65*17d15b25SDag-Erling Smørgrav#   WITHOUT ANY WARRANTY; without even the implied warranty of
66*17d15b25SDag-Erling Smørgrav#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
67*17d15b25SDag-Erling Smørgrav#   Public License for more details.
68*17d15b25SDag-Erling Smørgrav#
69*17d15b25SDag-Erling Smørgrav#   You should have received a copy of the GNU General Public License along
70*17d15b25SDag-Erling Smørgrav#   with this program. If not, see <http://www.gnu.org/licenses/>.
71*17d15b25SDag-Erling Smørgrav#
72*17d15b25SDag-Erling Smørgrav#   As a special exception, the respective Autoconf Macro's copyright owner
73*17d15b25SDag-Erling Smørgrav#   gives unlimited permission to copy, distribute and modify the configure
74*17d15b25SDag-Erling Smørgrav#   scripts that are the output of Autoconf when processing the Macro. You
75*17d15b25SDag-Erling Smørgrav#   need not follow the terms of the GNU General Public License when using
76*17d15b25SDag-Erling Smørgrav#   or distributing such scripts, even though portions of the text of the
77*17d15b25SDag-Erling Smørgrav#   Macro appear in them. The GNU General Public License (GPL) does govern
78*17d15b25SDag-Erling Smørgrav#   all other use of the material that constitutes the Autoconf Macro.
79*17d15b25SDag-Erling Smørgrav#
80*17d15b25SDag-Erling Smørgrav#   This special exception to the GPL applies to versions of the Autoconf
81*17d15b25SDag-Erling Smørgrav#   Macro released by the Autoconf Archive. When you make and distribute a
82*17d15b25SDag-Erling Smørgrav#   modified version of the Autoconf Macro, you may extend this special
83*17d15b25SDag-Erling Smørgrav#   exception to the GPL to apply to your modified version as well.
84*17d15b25SDag-Erling Smørgrav
85*17d15b25SDag-Erling Smørgrav#serial 20
86*17d15b25SDag-Erling Smørgrav
87*17d15b25SDag-Erling SmørgravAU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
88*17d15b25SDag-Erling SmørgravAC_DEFUN([AX_PTHREAD], [
89*17d15b25SDag-Erling SmørgravAC_REQUIRE([AC_CANONICAL_HOST])
90*17d15b25SDag-Erling SmørgravAC_LANG_PUSH([C])
91*17d15b25SDag-Erling Smørgravax_pthread_ok=no
92*17d15b25SDag-Erling Smørgrav
93*17d15b25SDag-Erling Smørgrav# We used to check for pthread.h first, but this fails if pthread.h
94*17d15b25SDag-Erling Smørgrav# requires special compiler flags (e.g. on True64 or Sequent).
95*17d15b25SDag-Erling Smørgrav# It gets checked for in the link test anyway.
96*17d15b25SDag-Erling Smørgrav
97*17d15b25SDag-Erling Smørgrav# First of all, check if the user has set any of the PTHREAD_LIBS,
98*17d15b25SDag-Erling Smørgrav# etcetera environment variables, and if threads linking works using
99*17d15b25SDag-Erling Smørgrav# them:
100*17d15b25SDag-Erling Smørgravif test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
101*17d15b25SDag-Erling Smørgrav        save_CFLAGS="$CFLAGS"
102*17d15b25SDag-Erling Smørgrav        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
103*17d15b25SDag-Erling Smørgrav        save_LIBS="$LIBS"
104*17d15b25SDag-Erling Smørgrav        LIBS="$PTHREAD_LIBS $LIBS"
105*17d15b25SDag-Erling Smørgrav        AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
106*17d15b25SDag-Erling Smørgrav        AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes)
107*17d15b25SDag-Erling Smørgrav        AC_MSG_RESULT($ax_pthread_ok)
108*17d15b25SDag-Erling Smørgrav        if test x"$ax_pthread_ok" = xno; then
109*17d15b25SDag-Erling Smørgrav                PTHREAD_LIBS=""
110*17d15b25SDag-Erling Smørgrav                PTHREAD_CFLAGS=""
111*17d15b25SDag-Erling Smørgrav        fi
112*17d15b25SDag-Erling Smørgrav        LIBS="$save_LIBS"
113*17d15b25SDag-Erling Smørgrav        CFLAGS="$save_CFLAGS"
114*17d15b25SDag-Erling Smørgravfi
115*17d15b25SDag-Erling Smørgrav
116*17d15b25SDag-Erling Smørgrav# We must check for the threads library under a number of different
117*17d15b25SDag-Erling Smørgrav# names; the ordering is very important because some systems
118*17d15b25SDag-Erling Smørgrav# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
119*17d15b25SDag-Erling Smørgrav# libraries is broken (non-POSIX).
120*17d15b25SDag-Erling Smørgrav
121*17d15b25SDag-Erling Smørgrav# Create a list of thread flags to try.  Items starting with a "-" are
122*17d15b25SDag-Erling Smørgrav# C compiler flags, and other items are library names, except for "none"
123*17d15b25SDag-Erling Smørgrav# which indicates that we try without any flags at all, and "pthread-config"
124*17d15b25SDag-Erling Smørgrav# which is a program returning the flags for the Pth emulation library.
125*17d15b25SDag-Erling Smørgrav
126*17d15b25SDag-Erling Smørgravax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
127*17d15b25SDag-Erling Smørgrav
128*17d15b25SDag-Erling Smørgrav# The ordering *is* (sometimes) important.  Some notes on the
129*17d15b25SDag-Erling Smørgrav# individual items follow:
130*17d15b25SDag-Erling Smørgrav
131*17d15b25SDag-Erling Smørgrav# pthreads: AIX (must check this before -lpthread)
132*17d15b25SDag-Erling Smørgrav# none: in case threads are in libc; should be tried before -Kthread and
133*17d15b25SDag-Erling Smørgrav#       other compiler flags to prevent continual compiler warnings
134*17d15b25SDag-Erling Smørgrav# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
135*17d15b25SDag-Erling Smørgrav# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
136*17d15b25SDag-Erling Smørgrav# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
137*17d15b25SDag-Erling Smørgrav# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
138*17d15b25SDag-Erling Smørgrav# -pthreads: Solaris/gcc
139*17d15b25SDag-Erling Smørgrav# -mthreads: Mingw32/gcc, Lynx/gcc
140*17d15b25SDag-Erling Smørgrav# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
141*17d15b25SDag-Erling Smørgrav#      doesn't hurt to check since this sometimes defines pthreads too;
142*17d15b25SDag-Erling Smørgrav#      also defines -D_REENTRANT)
143*17d15b25SDag-Erling Smørgrav#      ... -mt is also the pthreads flag for HP/aCC
144*17d15b25SDag-Erling Smørgrav# pthread: Linux, etcetera
145*17d15b25SDag-Erling Smørgrav# --thread-safe: KAI C++
146*17d15b25SDag-Erling Smørgrav# pthread-config: use pthread-config program (for GNU Pth library)
147*17d15b25SDag-Erling Smørgrav
148*17d15b25SDag-Erling Smørgravcase ${host_os} in
149*17d15b25SDag-Erling Smørgrav        solaris*)
150*17d15b25SDag-Erling Smørgrav
151*17d15b25SDag-Erling Smørgrav        # On Solaris (at least, for some versions), libc contains stubbed
152*17d15b25SDag-Erling Smørgrav        # (non-functional) versions of the pthreads routines, so link-based
153*17d15b25SDag-Erling Smørgrav        # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
154*17d15b25SDag-Erling Smørgrav        # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
155*17d15b25SDag-Erling Smørgrav        # a function called by this macro, so we could check for that, but
156*17d15b25SDag-Erling Smørgrav        # who knows whether they'll stub that too in a future libc.)  So,
157*17d15b25SDag-Erling Smørgrav        # we'll just look for -pthreads and -lpthread first:
158*17d15b25SDag-Erling Smørgrav
159*17d15b25SDag-Erling Smørgrav        ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags"
160*17d15b25SDag-Erling Smørgrav        ;;
161*17d15b25SDag-Erling Smørgrav
162*17d15b25SDag-Erling Smørgrav        darwin*)
163*17d15b25SDag-Erling Smørgrav        ax_pthread_flags="-pthread $ax_pthread_flags"
164*17d15b25SDag-Erling Smørgrav        ;;
165*17d15b25SDag-Erling Smørgravesac
166*17d15b25SDag-Erling Smørgrav
167*17d15b25SDag-Erling Smørgravif test x"$ax_pthread_ok" = xno; then
168*17d15b25SDag-Erling Smørgravfor flag in $ax_pthread_flags; do
169*17d15b25SDag-Erling Smørgrav
170*17d15b25SDag-Erling Smørgrav        case $flag in
171*17d15b25SDag-Erling Smørgrav                none)
172*17d15b25SDag-Erling Smørgrav                AC_MSG_CHECKING([whether pthreads work without any flags])
173*17d15b25SDag-Erling Smørgrav                ;;
174*17d15b25SDag-Erling Smørgrav
175*17d15b25SDag-Erling Smørgrav                -*)
176*17d15b25SDag-Erling Smørgrav                AC_MSG_CHECKING([whether pthreads work with $flag])
177*17d15b25SDag-Erling Smørgrav                PTHREAD_CFLAGS="$flag"
178*17d15b25SDag-Erling Smørgrav                ;;
179*17d15b25SDag-Erling Smørgrav
180*17d15b25SDag-Erling Smørgrav                pthread-config)
181*17d15b25SDag-Erling Smørgrav                AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no)
182*17d15b25SDag-Erling Smørgrav                if test x"$ax_pthread_config" = xno; then continue; fi
183*17d15b25SDag-Erling Smørgrav                PTHREAD_CFLAGS="`pthread-config --cflags`"
184*17d15b25SDag-Erling Smørgrav                PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
185*17d15b25SDag-Erling Smørgrav                ;;
186*17d15b25SDag-Erling Smørgrav
187*17d15b25SDag-Erling Smørgrav                *)
188*17d15b25SDag-Erling Smørgrav                AC_MSG_CHECKING([for the pthreads library -l$flag])
189*17d15b25SDag-Erling Smørgrav                PTHREAD_LIBS="-l$flag"
190*17d15b25SDag-Erling Smørgrav                ;;
191*17d15b25SDag-Erling Smørgrav        esac
192*17d15b25SDag-Erling Smørgrav
193*17d15b25SDag-Erling Smørgrav        save_LIBS="$LIBS"
194*17d15b25SDag-Erling Smørgrav        save_CFLAGS="$CFLAGS"
195*17d15b25SDag-Erling Smørgrav        LIBS="$PTHREAD_LIBS $LIBS"
196*17d15b25SDag-Erling Smørgrav        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
197*17d15b25SDag-Erling Smørgrav
198*17d15b25SDag-Erling Smørgrav        # Check for various functions.  We must include pthread.h,
199*17d15b25SDag-Erling Smørgrav        # since some functions may be macros.  (On the Sequent, we
200*17d15b25SDag-Erling Smørgrav        # need a special flag -Kthread to make this header compile.)
201*17d15b25SDag-Erling Smørgrav        # We check for pthread_join because it is in -lpthread on IRIX
202*17d15b25SDag-Erling Smørgrav        # while pthread_create is in libc.  We check for pthread_attr_init
203*17d15b25SDag-Erling Smørgrav        # due to DEC craziness with -lpthreads.  We check for
204*17d15b25SDag-Erling Smørgrav        # pthread_cleanup_push because it is one of the few pthread
205*17d15b25SDag-Erling Smørgrav        # functions on Solaris that doesn't have a non-functional libc stub.
206*17d15b25SDag-Erling Smørgrav        # We try pthread_create on general principles.
207*17d15b25SDag-Erling Smørgrav        AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
208*17d15b25SDag-Erling Smørgrav                        static void routine(void *a) { *((int*)a) = 0; }
209*17d15b25SDag-Erling Smørgrav                        static void *start_routine(void *a) { return a; }],
210*17d15b25SDag-Erling Smørgrav                       [pthread_t th; pthread_attr_t attr;
211*17d15b25SDag-Erling Smørgrav                        pthread_create(&th, 0, start_routine, 0);
212*17d15b25SDag-Erling Smørgrav                        pthread_join(th, 0);
213*17d15b25SDag-Erling Smørgrav                        pthread_attr_init(&attr);
214*17d15b25SDag-Erling Smørgrav                        pthread_cleanup_push(routine, 0);
215*17d15b25SDag-Erling Smørgrav                        pthread_cleanup_pop(0) /* ; */])],
216*17d15b25SDag-Erling Smørgrav                [ax_pthread_ok=yes],
217*17d15b25SDag-Erling Smørgrav                [])
218*17d15b25SDag-Erling Smørgrav
219*17d15b25SDag-Erling Smørgrav        LIBS="$save_LIBS"
220*17d15b25SDag-Erling Smørgrav        CFLAGS="$save_CFLAGS"
221*17d15b25SDag-Erling Smørgrav
222*17d15b25SDag-Erling Smørgrav        AC_MSG_RESULT($ax_pthread_ok)
223*17d15b25SDag-Erling Smørgrav        if test "x$ax_pthread_ok" = xyes; then
224*17d15b25SDag-Erling Smørgrav                break;
225*17d15b25SDag-Erling Smørgrav        fi
226*17d15b25SDag-Erling Smørgrav
227*17d15b25SDag-Erling Smørgrav        PTHREAD_LIBS=""
228*17d15b25SDag-Erling Smørgrav        PTHREAD_CFLAGS=""
229*17d15b25SDag-Erling Smørgravdone
230*17d15b25SDag-Erling Smørgravfi
231*17d15b25SDag-Erling Smørgrav
232*17d15b25SDag-Erling Smørgrav# Various other checks:
233*17d15b25SDag-Erling Smørgravif test "x$ax_pthread_ok" = xyes; then
234*17d15b25SDag-Erling Smørgrav        save_LIBS="$LIBS"
235*17d15b25SDag-Erling Smørgrav        LIBS="$PTHREAD_LIBS $LIBS"
236*17d15b25SDag-Erling Smørgrav        save_CFLAGS="$CFLAGS"
237*17d15b25SDag-Erling Smørgrav        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
238*17d15b25SDag-Erling Smørgrav
239*17d15b25SDag-Erling Smørgrav        # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
240*17d15b25SDag-Erling Smørgrav        AC_MSG_CHECKING([for joinable pthread attribute])
241*17d15b25SDag-Erling Smørgrav        attr_name=unknown
242*17d15b25SDag-Erling Smørgrav        for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
243*17d15b25SDag-Erling Smørgrav            AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
244*17d15b25SDag-Erling Smørgrav                           [int attr = $attr; return attr /* ; */])],
245*17d15b25SDag-Erling Smørgrav                [attr_name=$attr; break],
246*17d15b25SDag-Erling Smørgrav                [])
247*17d15b25SDag-Erling Smørgrav        done
248*17d15b25SDag-Erling Smørgrav        AC_MSG_RESULT($attr_name)
249*17d15b25SDag-Erling Smørgrav        if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
250*17d15b25SDag-Erling Smørgrav            AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
251*17d15b25SDag-Erling Smørgrav                               [Define to necessary symbol if this constant
252*17d15b25SDag-Erling Smørgrav                                uses a non-standard name on your system.])
253*17d15b25SDag-Erling Smørgrav        fi
254*17d15b25SDag-Erling Smørgrav
255*17d15b25SDag-Erling Smørgrav        AC_MSG_CHECKING([if more special flags are required for pthreads])
256*17d15b25SDag-Erling Smørgrav        flag=no
257*17d15b25SDag-Erling Smørgrav        case ${host_os} in
258*17d15b25SDag-Erling Smørgrav            aix* | freebsd* | darwin*) flag="-D_THREAD_SAFE";;
259*17d15b25SDag-Erling Smørgrav            osf* | hpux*) flag="-D_REENTRANT";;
260*17d15b25SDag-Erling Smørgrav            solaris*)
261*17d15b25SDag-Erling Smørgrav            if test "$GCC" = "yes"; then
262*17d15b25SDag-Erling Smørgrav                flag="-D_REENTRANT"
263*17d15b25SDag-Erling Smørgrav            else
264*17d15b25SDag-Erling Smørgrav                flag="-mt -D_REENTRANT"
265*17d15b25SDag-Erling Smørgrav            fi
266*17d15b25SDag-Erling Smørgrav            ;;
267*17d15b25SDag-Erling Smørgrav        esac
268*17d15b25SDag-Erling Smørgrav        AC_MSG_RESULT(${flag})
269*17d15b25SDag-Erling Smørgrav        if test "x$flag" != xno; then
270*17d15b25SDag-Erling Smørgrav            PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
271*17d15b25SDag-Erling Smørgrav        fi
272*17d15b25SDag-Erling Smørgrav
273*17d15b25SDag-Erling Smørgrav        AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT],
274*17d15b25SDag-Erling Smørgrav            ax_cv_PTHREAD_PRIO_INHERIT, [
275*17d15b25SDag-Erling Smørgrav                AC_LINK_IFELSE([
276*17d15b25SDag-Erling Smørgrav                    AC_LANG_PROGRAM([[#include <pthread.h>]], [[int i = PTHREAD_PRIO_INHERIT;]])],
277*17d15b25SDag-Erling Smørgrav                    [ax_cv_PTHREAD_PRIO_INHERIT=yes],
278*17d15b25SDag-Erling Smørgrav                    [ax_cv_PTHREAD_PRIO_INHERIT=no])
279*17d15b25SDag-Erling Smørgrav            ])
280*17d15b25SDag-Erling Smørgrav        AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes"],
281*17d15b25SDag-Erling Smørgrav            AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], 1, [Have PTHREAD_PRIO_INHERIT.]))
282*17d15b25SDag-Erling Smørgrav
283*17d15b25SDag-Erling Smørgrav        LIBS="$save_LIBS"
284*17d15b25SDag-Erling Smørgrav        CFLAGS="$save_CFLAGS"
285*17d15b25SDag-Erling Smørgrav
286*17d15b25SDag-Erling Smørgrav        # More AIX lossage: compile with *_r variant
287*17d15b25SDag-Erling Smørgrav        if test "x$GCC" != xyes; then
288*17d15b25SDag-Erling Smørgrav            case $host_os in
289*17d15b25SDag-Erling Smørgrav                aix*)
290*17d15b25SDag-Erling Smørgrav                AS_CASE(["x/$CC"],
291*17d15b25SDag-Erling Smørgrav                  [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6],
292*17d15b25SDag-Erling Smørgrav                  [#handle absolute path differently from PATH based program lookup
293*17d15b25SDag-Erling Smørgrav                   AS_CASE(["x$CC"],
294*17d15b25SDag-Erling Smørgrav                     [x/*],
295*17d15b25SDag-Erling Smørgrav                     [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])],
296*17d15b25SDag-Erling Smørgrav                     [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])])
297*17d15b25SDag-Erling Smørgrav                ;;
298*17d15b25SDag-Erling Smørgrav            esac
299*17d15b25SDag-Erling Smørgrav        fi
300*17d15b25SDag-Erling Smørgravfi
301*17d15b25SDag-Erling Smørgrav
302*17d15b25SDag-Erling Smørgravtest -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
303*17d15b25SDag-Erling Smørgrav
304*17d15b25SDag-Erling SmørgravAC_SUBST(PTHREAD_LIBS)
305*17d15b25SDag-Erling SmørgravAC_SUBST(PTHREAD_CFLAGS)
306*17d15b25SDag-Erling SmørgravAC_SUBST(PTHREAD_CC)
307*17d15b25SDag-Erling Smørgrav
308*17d15b25SDag-Erling Smørgrav# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
309*17d15b25SDag-Erling Smørgravif test x"$ax_pthread_ok" = xyes; then
310*17d15b25SDag-Erling Smørgrav        ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
311*17d15b25SDag-Erling Smørgrav        :
312*17d15b25SDag-Erling Smørgravelse
313*17d15b25SDag-Erling Smørgrav        ax_pthread_ok=no
314*17d15b25SDag-Erling Smørgrav        $2
315*17d15b25SDag-Erling Smørgravfi
316*17d15b25SDag-Erling SmørgravAC_LANG_POP
317*17d15b25SDag-Erling Smørgrav])dnl AX_PTHREAD
318