Blame m4/ax_pthread.m4

Packit Service e08953
# ===========================================================================
Packit Service e08953
#        https://www.gnu.org/software/autoconf-archive/ax_pthread.html
Packit Service e08953
# ===========================================================================
Packit Service e08953
#
Packit Service e08953
# SYNOPSIS
Packit Service e08953
#
Packit Service e08953
#   AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
Packit Service e08953
#
Packit Service e08953
# DESCRIPTION
Packit Service e08953
#
Packit Service e08953
#   This macro figures out how to build C programs using POSIX threads. It
Packit Service e08953
#   sets the PTHREAD_LIBS output variable to the threads library and linker
Packit Service e08953
#   flags, and the PTHREAD_CFLAGS output variable to any special C compiler
Packit Service e08953
#   flags that are needed. (The user can also force certain compiler
Packit Service e08953
#   flags/libs to be tested by setting these environment variables.)
Packit Service e08953
#
Packit Service e08953
#   Also sets PTHREAD_CC to any special C compiler that is needed for
Packit Service e08953
#   multi-threaded programs (defaults to the value of CC otherwise). (This
Packit Service e08953
#   is necessary on AIX to use the special cc_r compiler alias.)
Packit Service e08953
#
Packit Service e08953
#   NOTE: You are assumed to not only compile your program with these flags,
Packit Service e08953
#   but also to link with them as well. For example, you might link with
Packit Service e08953
#   $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
Packit Service e08953
#
Packit Service e08953
#   If you are only building threaded programs, you may wish to use these
Packit Service e08953
#   variables in your default LIBS, CFLAGS, and CC:
Packit Service e08953
#
Packit Service e08953
#     LIBS="$PTHREAD_LIBS $LIBS"
Packit Service e08953
#     CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Packit Service e08953
#     CC="$PTHREAD_CC"
Packit Service e08953
#
Packit Service e08953
#   In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant
Packit Service e08953
#   has a nonstandard name, this macro defines PTHREAD_CREATE_JOINABLE to
Packit Service e08953
#   that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
Packit Service e08953
#
Packit Service e08953
#   Also HAVE_PTHREAD_PRIO_INHERIT is defined if pthread is found and the
Packit Service e08953
#   PTHREAD_PRIO_INHERIT symbol is defined when compiling with
Packit Service e08953
#   PTHREAD_CFLAGS.
Packit Service e08953
#
Packit Service e08953
#   ACTION-IF-FOUND is a list of shell commands to run if a threads library
Packit Service e08953
#   is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it
Packit Service e08953
#   is not found. If ACTION-IF-FOUND is not specified, the default action
Packit Service e08953
#   will define HAVE_PTHREAD.
Packit Service e08953
#
Packit Service e08953
#   Please let the authors know if this macro fails on any platform, or if
Packit Service e08953
#   you have any other suggestions or comments. This macro was based on work
Packit Service e08953
#   by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help
Packit Service e08953
#   from M. Frigo), as well as ac_pthread and hb_pthread macros posted by
Packit Service e08953
#   Alejandro Forero Cuervo to the autoconf macro repository. We are also
Packit Service e08953
#   grateful for the helpful feedback of numerous users.
Packit Service e08953
#
Packit Service e08953
#   Updated for Autoconf 2.68 by Daniel Richard G.
Packit Service e08953
#
Packit Service e08953
# LICENSE
Packit Service e08953
#
Packit Service e08953
#   Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu>
Packit Service e08953
#   Copyright (c) 2011 Daniel Richard G. <skunk@iSKUNK.ORG>
Packit Service e08953
#
Packit Service e08953
#   This program is free software: you can redistribute it and/or modify it
Packit Service e08953
#   under the terms of the GNU General Public License as published by the
Packit Service e08953
#   Free Software Foundation, either version 3 of the License, or (at your
Packit Service e08953
#   option) any later version.
Packit Service e08953
#
Packit Service e08953
#   This program is distributed in the hope that it will be useful, but
Packit Service e08953
#   WITHOUT ANY WARRANTY; without even the implied warranty of
Packit Service e08953
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
Packit Service e08953
#   Public License for more details.
Packit Service e08953
#
Packit Service e08953
#   You should have received a copy of the GNU General Public License along
Packit Service e08953
#   with this program. If not, see <https://www.gnu.org/licenses/>.
Packit Service e08953
#
Packit Service e08953
#   As a special exception, the respective Autoconf Macro's copyright owner
Packit Service e08953
#   gives unlimited permission to copy, distribute and modify the configure
Packit Service e08953
#   scripts that are the output of Autoconf when processing the Macro. You
Packit Service e08953
#   need not follow the terms of the GNU General Public License when using
Packit Service e08953
#   or distributing such scripts, even though portions of the text of the
Packit Service e08953
#   Macro appear in them. The GNU General Public License (GPL) does govern
Packit Service e08953
#   all other use of the material that constitutes the Autoconf Macro.
Packit Service e08953
#
Packit Service e08953
#   This special exception to the GPL applies to versions of the Autoconf
Packit Service e08953
#   Macro released by the Autoconf Archive. When you make and distribute a
Packit Service e08953
#   modified version of the Autoconf Macro, you may extend this special
Packit Service e08953
#   exception to the GPL to apply to your modified version as well.
Packit Service e08953
Packit Service e08953
#serial 24
Packit Service e08953
Packit Service e08953
AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD])
Packit Service e08953
AC_DEFUN([AX_PTHREAD], [
Packit Service e08953
AC_REQUIRE([AC_CANONICAL_HOST])
Packit Service e08953
AC_REQUIRE([AC_PROG_CC])
Packit Service e08953
AC_REQUIRE([AC_PROG_SED])
Packit Service e08953
AC_LANG_PUSH([C])
Packit Service e08953
ax_pthread_ok=no
Packit Service e08953
Packit Service e08953
# We used to check for pthread.h first, but this fails if pthread.h
Packit Service e08953
# requires special compiler flags (e.g. on Tru64 or Sequent).
Packit Service e08953
# It gets checked for in the link test anyway.
Packit Service e08953
Packit Service e08953
# First of all, check if the user has set any of the PTHREAD_LIBS,
Packit Service e08953
# etcetera environment variables, and if threads linking works using
Packit Service e08953
# them:
Packit Service e08953
if test "x$PTHREAD_CFLAGS$PTHREAD_LIBS" != "x"; then
Packit Service e08953
        ax_pthread_save_CC="$CC"
Packit Service e08953
        ax_pthread_save_CFLAGS="$CFLAGS"
Packit Service e08953
        ax_pthread_save_LIBS="$LIBS"
Packit Service e08953
        AS_IF([test "x$PTHREAD_CC" != "x"], [CC="$PTHREAD_CC"])
Packit Service e08953
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Packit Service e08953
        LIBS="$PTHREAD_LIBS $LIBS"
Packit Service e08953
        AC_MSG_CHECKING([for pthread_join using $CC $PTHREAD_CFLAGS $PTHREAD_LIBS])
Packit Service e08953
        AC_LINK_IFELSE([AC_LANG_CALL([], [pthread_join])], [ax_pthread_ok=yes])
Packit Service e08953
        AC_MSG_RESULT([$ax_pthread_ok])
Packit Service e08953
        if test "x$ax_pthread_ok" = "xno"; then
Packit Service e08953
                PTHREAD_LIBS=""
Packit Service e08953
                PTHREAD_CFLAGS=""
Packit Service e08953
        fi
Packit Service e08953
        CC="$ax_pthread_save_CC"
Packit Service e08953
        CFLAGS="$ax_pthread_save_CFLAGS"
Packit Service e08953
        LIBS="$ax_pthread_save_LIBS"
Packit Service e08953
fi
Packit Service e08953
Packit Service e08953
# We must check for the threads library under a number of different
Packit Service e08953
# names; the ordering is very important because some systems
Packit Service e08953
# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
Packit Service e08953
# libraries is broken (non-POSIX).
Packit Service e08953
Packit Service e08953
# Create a list of thread flags to try.  Items starting with a "-" are
Packit Service e08953
# C compiler flags, and other items are library names, except for "none"
Packit Service e08953
# which indicates that we try without any flags at all, and "pthread-config"
Packit Service e08953
# which is a program returning the flags for the Pth emulation library.
Packit Service e08953
Packit Service e08953
ax_pthread_flags="pthreads none -Kthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
Packit Service e08953
Packit Service e08953
# The ordering *is* (sometimes) important.  Some notes on the
Packit Service e08953
# individual items follow:
Packit Service e08953
Packit Service e08953
# pthreads: AIX (must check this before -lpthread)
Packit Service e08953
# none: in case threads are in libc; should be tried before -Kthread and
Packit Service e08953
#       other compiler flags to prevent continual compiler warnings
Packit Service e08953
# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
Packit Service e08953
# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads), Tru64
Packit Service e08953
#           (Note: HP C rejects this with "bad form for `-t' option")
Packit Service e08953
# -pthreads: Solaris/gcc (Note: HP C also rejects)
Packit Service e08953
# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
Packit Service e08953
#      doesn't hurt to check since this sometimes defines pthreads and
Packit Service e08953
#      -D_REENTRANT too), HP C (must be checked before -lpthread, which
Packit Service e08953
#      is present but should not be used directly; and before -mthreads,
Packit Service e08953
#      because the compiler interprets this as "-mt" + "-hreads")
Packit Service e08953
# -mthreads: Mingw32/gcc, Lynx/gcc
Packit Service e08953
# pthread: Linux, etcetera
Packit Service e08953
# --thread-safe: KAI C++
Packit Service e08953
# pthread-config: use pthread-config program (for GNU Pth library)
Packit Service e08953
Packit Service e08953
case $host_os in
Packit Service e08953
Packit Service e08953
        freebsd*)
Packit Service e08953
Packit Service e08953
        # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
Packit Service e08953
        # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
Packit Service e08953
Packit Service e08953
        ax_pthread_flags="-kthread lthread $ax_pthread_flags"
Packit Service e08953
        ;;
Packit Service e08953
Packit Service e08953
        hpux*)
Packit Service e08953
Packit Service e08953
        # From the cc(1) man page: "[-mt] Sets various -D flags to enable
Packit Service e08953
        # multi-threading and also sets -lpthread."
Packit Service e08953
Packit Service e08953
        ax_pthread_flags="-mt -pthread pthread $ax_pthread_flags"
Packit Service e08953
        ;;
Packit Service e08953
Packit Service e08953
        openedition*)
Packit Service e08953
Packit Service e08953
        # IBM z/OS requires a feature-test macro to be defined in order to
Packit Service e08953
        # enable POSIX threads at all, so give the user a hint if this is
Packit Service e08953
        # not set. (We don't define these ourselves, as they can affect
Packit Service e08953
        # other portions of the system API in unpredictable ways.)
Packit Service e08953
Packit Service e08953
        AC_EGREP_CPP([AX_PTHREAD_ZOS_MISSING],
Packit Service e08953
            [
Packit Service e08953
#            if !defined(_OPEN_THREADS) && !defined(_UNIX03_THREADS)
Packit Service e08953
             AX_PTHREAD_ZOS_MISSING
Packit Service e08953
#            endif
Packit Service e08953
            ],
Packit Service e08953
            [AC_MSG_WARN([IBM z/OS requires -D_OPEN_THREADS or -D_UNIX03_THREADS to enable pthreads support.])])
Packit Service e08953
        ;;
Packit Service e08953
Packit Service e08953
        solaris*)
Packit Service e08953
Packit Service e08953
        # On Solaris (at least, for some versions), libc contains stubbed
Packit Service e08953
        # (non-functional) versions of the pthreads routines, so link-based
Packit Service e08953
        # tests will erroneously succeed. (N.B.: The stubs are missing
Packit Service e08953
        # pthread_cleanup_push, or rather a function called by this macro,
Packit Service e08953
        # so we could check for that, but who knows whether they'll stub
Packit Service e08953
        # that too in a future libc.)  So we'll check first for the
Packit Service e08953
        # standard Solaris way of linking pthreads (-mt -lpthread).
Packit Service e08953
Packit Service e08953
        ax_pthread_flags="-mt,pthread pthread $ax_pthread_flags"
Packit Service e08953
        ;;
Packit Service e08953
esac
Packit Service e08953
Packit Service e08953
# GCC generally uses -pthread, or -pthreads on some platforms (e.g. SPARC)
Packit Service e08953
Packit Service e08953
AS_IF([test "x$GCC" = "xyes"],
Packit Service e08953
      [ax_pthread_flags="-pthread -pthreads $ax_pthread_flags"])
Packit Service e08953
Packit Service e08953
# The presence of a feature test macro requesting re-entrant function
Packit Service e08953
# definitions is, on some systems, a strong hint that pthreads support is
Packit Service e08953
# correctly enabled
Packit Service e08953
Packit Service e08953
case $host_os in
Packit Service e08953
        darwin* | hpux* | linux* | osf* | solaris*)
Packit Service e08953
        ax_pthread_check_macro="_REENTRANT"
Packit Service e08953
        ;;
Packit Service e08953
Packit Service e08953
        aix*)
Packit Service e08953
        ax_pthread_check_macro="_THREAD_SAFE"
Packit Service e08953
        ;;
Packit Service e08953
Packit Service e08953
        *)
Packit Service e08953
        ax_pthread_check_macro="--"
Packit Service e08953
        ;;
Packit Service e08953
esac
Packit Service e08953
AS_IF([test "x$ax_pthread_check_macro" = "x--"],
Packit Service e08953
      [ax_pthread_check_cond=0],
Packit Service e08953
      [ax_pthread_check_cond="!defined($ax_pthread_check_macro)"])
Packit Service e08953
Packit Service e08953
# Are we compiling with Clang?
Packit Service e08953
Packit Service e08953
AC_CACHE_CHECK([whether $CC is Clang],
Packit Service e08953
    [ax_cv_PTHREAD_CLANG],
Packit Service e08953
    [ax_cv_PTHREAD_CLANG=no
Packit Service e08953
     # Note that Autoconf sets GCC=yes for Clang as well as GCC
Packit Service e08953
     if test "x$GCC" = "xyes"; then
Packit Service e08953
        AC_EGREP_CPP([AX_PTHREAD_CC_IS_CLANG],
Packit Service e08953
            [/* Note: Clang 2.7 lacks __clang_[a-z]+__ */
Packit Service e08953
#            if defined(__clang__) && defined(__llvm__)
Packit Service e08953
             AX_PTHREAD_CC_IS_CLANG
Packit Service e08953
#            endif
Packit Service e08953
            ],
Packit Service e08953
            [ax_cv_PTHREAD_CLANG=yes])
Packit Service e08953
     fi
Packit Service e08953
    ])
Packit Service e08953
ax_pthread_clang="$ax_cv_PTHREAD_CLANG"
Packit Service e08953
Packit Service e08953
ax_pthread_clang_warning=no
Packit Service e08953
Packit Service e08953
# Clang needs special handling, because older versions handle the -pthread
Packit Service e08953
# option in a rather... idiosyncratic way
Packit Service e08953
Packit Service e08953
if test "x$ax_pthread_clang" = "xyes"; then
Packit Service e08953
Packit Service e08953
        # Clang takes -pthread; it has never supported any other flag
Packit Service e08953
Packit Service e08953
        # (Note 1: This will need to be revisited if a system that Clang
Packit Service e08953
        # supports has POSIX threads in a separate library.  This tends not
Packit Service e08953
        # to be the way of modern systems, but it's conceivable.)
Packit Service e08953
Packit Service e08953
        # (Note 2: On some systems, notably Darwin, -pthread is not needed
Packit Service e08953
        # to get POSIX threads support; the API is always present and
Packit Service e08953
        # active.  We could reasonably leave PTHREAD_CFLAGS empty.  But
Packit Service e08953
        # -pthread does define _REENTRANT, and while the Darwin headers
Packit Service e08953
        # ignore this macro, third-party headers might not.)
Packit Service e08953
Packit Service e08953
        PTHREAD_CFLAGS="-pthread"
Packit Service e08953
        PTHREAD_LIBS=
Packit Service e08953
Packit Service e08953
        ax_pthread_ok=yes
Packit Service e08953
Packit Service e08953
        # However, older versions of Clang make a point of warning the user
Packit Service e08953
        # that, in an invocation where only linking and no compilation is
Packit Service e08953
        # taking place, the -pthread option has no effect ("argument unused
Packit Service e08953
        # during compilation").  They expect -pthread to be passed in only
Packit Service e08953
        # when source code is being compiled.
Packit Service e08953
        #
Packit Service e08953
        # Problem is, this is at odds with the way Automake and most other
Packit Service e08953
        # C build frameworks function, which is that the same flags used in
Packit Service e08953
        # compilation (CFLAGS) are also used in linking.  Many systems
Packit Service e08953
        # supported by AX_PTHREAD require exactly this for POSIX threads
Packit Service e08953
        # support, and in fact it is often not straightforward to specify a
Packit Service e08953
        # flag that is used only in the compilation phase and not in
Packit Service e08953
        # linking.  Such a scenario is extremely rare in practice.
Packit Service e08953
        #
Packit Service e08953
        # Even though use of the -pthread flag in linking would only print
Packit Service e08953
        # a warning, this can be a nuisance for well-run software projects
Packit Service e08953
        # that build with -Werror.  So if the active version of Clang has
Packit Service e08953
        # this misfeature, we search for an option to squash it.
Packit Service e08953
Packit Service e08953
        AC_CACHE_CHECK([whether Clang needs flag to prevent "argument unused" warning when linking with -pthread],
Packit Service e08953
            [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG],
Packit Service e08953
            [ax_cv_PTHREAD_CLANG_NO_WARN_FLAG=unknown
Packit Service e08953
             # Create an alternate version of $ac_link that compiles and
Packit Service e08953
             # links in two steps (.c -> .o, .o -> exe) instead of one
Packit Service e08953
             # (.c -> exe), because the warning occurs only in the second
Packit Service e08953
             # step
Packit Service e08953
             ax_pthread_save_ac_link="$ac_link"
Packit Service e08953
             ax_pthread_sed='s/conftest\.\$ac_ext/conftest.$ac_objext/g'
Packit Service e08953
             ax_pthread_link_step=`$as_echo "$ac_link" | sed "$ax_pthread_sed"`
Packit Service e08953
             ax_pthread_2step_ac_link="($ac_compile) && (echo ==== >&5) && ($ax_pthread_link_step)"
Packit Service e08953
             ax_pthread_save_CFLAGS="$CFLAGS"
Packit Service e08953
             for ax_pthread_try in '' -Qunused-arguments -Wno-unused-command-line-argument unknown; do
Packit Service e08953
                AS_IF([test "x$ax_pthread_try" = "xunknown"], [break])
Packit Service e08953
                CFLAGS="-Werror -Wunknown-warning-option $ax_pthread_try -pthread $ax_pthread_save_CFLAGS"
Packit Service e08953
                ac_link="$ax_pthread_save_ac_link"
Packit Service e08953
                AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
Packit Service e08953
                    [ac_link="$ax_pthread_2step_ac_link"
Packit Service e08953
                     AC_LINK_IFELSE([AC_LANG_SOURCE([[int main(void){return 0;}]])],
Packit Service e08953
                         [break])
Packit Service e08953
                    ])
Packit Service e08953
             done
Packit Service e08953
             ac_link="$ax_pthread_save_ac_link"
Packit Service e08953
             CFLAGS="$ax_pthread_save_CFLAGS"
Packit Service e08953
             AS_IF([test "x$ax_pthread_try" = "x"], [ax_pthread_try=no])
Packit Service e08953
             ax_cv_PTHREAD_CLANG_NO_WARN_FLAG="$ax_pthread_try"
Packit Service e08953
            ])
Packit Service e08953
Packit Service e08953
        case "$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG" in
Packit Service e08953
                no | unknown) ;;
Packit Service e08953
                *) PTHREAD_CFLAGS="$ax_cv_PTHREAD_CLANG_NO_WARN_FLAG $PTHREAD_CFLAGS" ;;
Packit Service e08953
        esac
Packit Service e08953
Packit Service e08953
fi # $ax_pthread_clang = yes
Packit Service e08953
Packit Service e08953
if test "x$ax_pthread_ok" = "xno"; then
Packit Service e08953
for ax_pthread_try_flag in $ax_pthread_flags; do
Packit Service e08953
Packit Service e08953
        case $ax_pthread_try_flag in
Packit Service e08953
                none)
Packit Service e08953
                AC_MSG_CHECKING([whether pthreads work without any flags])
Packit Service e08953
                ;;
Packit Service e08953
Packit Service e08953
                -mt,pthread)
Packit Service e08953
                AC_MSG_CHECKING([whether pthreads work with -mt -lpthread])
Packit Service e08953
                PTHREAD_CFLAGS="-mt"
Packit Service e08953
                PTHREAD_LIBS="-lpthread"
Packit Service e08953
                ;;
Packit Service e08953
Packit Service e08953
                -*)
Packit Service e08953
                AC_MSG_CHECKING([whether pthreads work with $ax_pthread_try_flag])
Packit Service e08953
                PTHREAD_CFLAGS="$ax_pthread_try_flag"
Packit Service e08953
                ;;
Packit Service e08953
Packit Service e08953
                pthread-config)
Packit Service e08953
                AC_CHECK_PROG([ax_pthread_config], [pthread-config], [yes], [no])
Packit Service e08953
                AS_IF([test "x$ax_pthread_config" = "xno"], [continue])
Packit Service e08953
                PTHREAD_CFLAGS="`pthread-config --cflags`"
Packit Service e08953
                PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
Packit Service e08953
                ;;
Packit Service e08953
Packit Service e08953
                *)
Packit Service e08953
                AC_MSG_CHECKING([for the pthreads library -l$ax_pthread_try_flag])
Packit Service e08953
                PTHREAD_LIBS="-l$ax_pthread_try_flag"
Packit Service e08953
                ;;
Packit Service e08953
        esac
Packit Service e08953
Packit Service e08953
        ax_pthread_save_CFLAGS="$CFLAGS"
Packit Service e08953
        ax_pthread_save_LIBS="$LIBS"
Packit Service e08953
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Packit Service e08953
        LIBS="$PTHREAD_LIBS $LIBS"
Packit Service e08953
Packit Service e08953
        # Check for various functions.  We must include pthread.h,
Packit Service e08953
        # since some functions may be macros.  (On the Sequent, we
Packit Service e08953
        # need a special flag -Kthread to make this header compile.)
Packit Service e08953
        # We check for pthread_join because it is in -lpthread on IRIX
Packit Service e08953
        # while pthread_create is in libc.  We check for pthread_attr_init
Packit Service e08953
        # due to DEC craziness with -lpthreads.  We check for
Packit Service e08953
        # pthread_cleanup_push because it is one of the few pthread
Packit Service e08953
        # functions on Solaris that doesn't have a non-functional libc stub.
Packit Service e08953
        # We try pthread_create on general principles.
Packit Service e08953
Packit Service e08953
        AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>
Packit Service e08953
#                       if $ax_pthread_check_cond
Packit Service e08953
#                        error "$ax_pthread_check_macro must be defined"
Packit Service e08953
#                       endif
Packit Service e08953
                        static void routine(void *a) { a = 0; }
Packit Service e08953
                        static void *start_routine(void *a) { return a; }],
Packit Service e08953
                       [pthread_t th; pthread_attr_t attr;
Packit Service e08953
                        pthread_create(&th, 0, start_routine, 0);
Packit Service e08953
                        pthread_join(th, 0);
Packit Service e08953
                        pthread_attr_init(&attr);
Packit Service e08953
                        pthread_cleanup_push(routine, 0);
Packit Service e08953
                        pthread_cleanup_pop(0) /* ; */])],
Packit Service e08953
            [ax_pthread_ok=yes],
Packit Service e08953
            [])
Packit Service e08953
Packit Service e08953
        CFLAGS="$ax_pthread_save_CFLAGS"
Packit Service e08953
        LIBS="$ax_pthread_save_LIBS"
Packit Service e08953
Packit Service e08953
        AC_MSG_RESULT([$ax_pthread_ok])
Packit Service e08953
        AS_IF([test "x$ax_pthread_ok" = "xyes"], [break])
Packit Service e08953
Packit Service e08953
        PTHREAD_LIBS=""
Packit Service e08953
        PTHREAD_CFLAGS=""
Packit Service e08953
done
Packit Service e08953
fi
Packit Service e08953
Packit Service e08953
# Various other checks:
Packit Service e08953
if test "x$ax_pthread_ok" = "xyes"; then
Packit Service e08953
        ax_pthread_save_CFLAGS="$CFLAGS"
Packit Service e08953
        ax_pthread_save_LIBS="$LIBS"
Packit Service e08953
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Packit Service e08953
        LIBS="$PTHREAD_LIBS $LIBS"
Packit Service e08953
Packit Service e08953
        # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
Packit Service e08953
        AC_CACHE_CHECK([for joinable pthread attribute],
Packit Service e08953
            [ax_cv_PTHREAD_JOINABLE_ATTR],
Packit Service e08953
            [ax_cv_PTHREAD_JOINABLE_ATTR=unknown
Packit Service e08953
             for ax_pthread_attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
Packit Service e08953
                 AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <pthread.h>],
Packit Service e08953
                                                 [int attr = $ax_pthread_attr; return attr /* ; */])],
Packit Service e08953
                                [ax_cv_PTHREAD_JOINABLE_ATTR=$ax_pthread_attr; break],
Packit Service e08953
                                [])
Packit Service e08953
             done
Packit Service e08953
            ])
Packit Service e08953
        AS_IF([test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xunknown" && \
Packit Service e08953
               test "x$ax_cv_PTHREAD_JOINABLE_ATTR" != "xPTHREAD_CREATE_JOINABLE" && \
Packit Service e08953
               test "x$ax_pthread_joinable_attr_defined" != "xyes"],
Packit Service e08953
              [AC_DEFINE_UNQUOTED([PTHREAD_CREATE_JOINABLE],
Packit Service e08953
                                  [$ax_cv_PTHREAD_JOINABLE_ATTR],
Packit Service e08953
                                  [Define to necessary symbol if this constant
Packit Service e08953
                                   uses a non-standard name on your system.])
Packit Service e08953
               ax_pthread_joinable_attr_defined=yes
Packit Service e08953
              ])
Packit Service e08953
Packit Service e08953
        AC_CACHE_CHECK([whether more special flags are required for pthreads],
Packit Service e08953
            [ax_cv_PTHREAD_SPECIAL_FLAGS],
Packit Service e08953
            [ax_cv_PTHREAD_SPECIAL_FLAGS=no
Packit Service e08953
             case $host_os in
Packit Service e08953
             solaris*)
Packit Service e08953
             ax_cv_PTHREAD_SPECIAL_FLAGS="-D_POSIX_PTHREAD_SEMANTICS"
Packit Service e08953
             ;;
Packit Service e08953
             esac
Packit Service e08953
            ])
Packit Service e08953
        AS_IF([test "x$ax_cv_PTHREAD_SPECIAL_FLAGS" != "xno" && \
Packit Service e08953
               test "x$ax_pthread_special_flags_added" != "xyes"],
Packit Service e08953
              [PTHREAD_CFLAGS="$ax_cv_PTHREAD_SPECIAL_FLAGS $PTHREAD_CFLAGS"
Packit Service e08953
               ax_pthread_special_flags_added=yes])
Packit Service e08953
Packit Service e08953
        AC_CACHE_CHECK([for PTHREAD_PRIO_INHERIT],
Packit Service e08953
            [ax_cv_PTHREAD_PRIO_INHERIT],
Packit Service e08953
            [AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <pthread.h>]],
Packit Service e08953
                                             [[int i = PTHREAD_PRIO_INHERIT;]])],
Packit Service e08953
                            [ax_cv_PTHREAD_PRIO_INHERIT=yes],
Packit Service e08953
                            [ax_cv_PTHREAD_PRIO_INHERIT=no])
Packit Service e08953
            ])
Packit Service e08953
        AS_IF([test "x$ax_cv_PTHREAD_PRIO_INHERIT" = "xyes" && \
Packit Service e08953
               test "x$ax_pthread_prio_inherit_defined" != "xyes"],
Packit Service e08953
              [AC_DEFINE([HAVE_PTHREAD_PRIO_INHERIT], [1], [Have PTHREAD_PRIO_INHERIT.])
Packit Service e08953
               ax_pthread_prio_inherit_defined=yes
Packit Service e08953
              ])
Packit Service e08953
Packit Service e08953
        CFLAGS="$ax_pthread_save_CFLAGS"
Packit Service e08953
        LIBS="$ax_pthread_save_LIBS"
Packit Service e08953
Packit Service e08953
        # More AIX lossage: compile with *_r variant
Packit Service e08953
        if test "x$GCC" != "xyes"; then
Packit Service e08953
            case $host_os in
Packit Service e08953
                aix*)
Packit Service e08953
                AS_CASE(["x/$CC"],
Packit Service e08953
                    [x*/c89|x*/c89_128|x*/c99|x*/c99_128|x*/cc|x*/cc128|x*/xlc|x*/xlc_v6|x*/xlc128|x*/xlc128_v6],
Packit Service e08953
                    [#handle absolute path differently from PATH based program lookup
Packit Service e08953
                     AS_CASE(["x$CC"],
Packit Service e08953
                         [x/*],
Packit Service e08953
                         [AS_IF([AS_EXECUTABLE_P([${CC}_r])],[PTHREAD_CC="${CC}_r"])],
Packit Service e08953
                         [AC_CHECK_PROGS([PTHREAD_CC],[${CC}_r],[$CC])])])
Packit Service e08953
                ;;
Packit Service e08953
            esac
Packit Service e08953
        fi
Packit Service e08953
fi
Packit Service e08953
Packit Service e08953
test -n "$PTHREAD_CC" || PTHREAD_CC="$CC"
Packit Service e08953
Packit Service e08953
AC_SUBST([PTHREAD_LIBS])
Packit Service e08953
AC_SUBST([PTHREAD_CFLAGS])
Packit Service e08953
AC_SUBST([PTHREAD_CC])
Packit Service e08953
Packit Service e08953
# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
Packit Service e08953
if test "x$ax_pthread_ok" = "xyes"; then
Packit Service e08953
        ifelse([$1],,[AC_DEFINE([HAVE_PTHREAD],[1],[Define if you have POSIX threads libraries and header files.])],[$1])
Packit Service e08953
        :
Packit Service e08953
else
Packit Service e08953
        ax_pthread_ok=no
Packit Service e08953
        $2
Packit Service e08953
fi
Packit Service e08953
AC_LANG_POP
Packit Service e08953
])dnl AX_PTHREAD