Blame m4/acx_pthread.html

Packit 0b5880
Packit 0b5880
"http://www.w3.org/TR/html4/strict.dtd">
Packit 0b5880
<html lang="en">
Packit 0b5880
 <head>
Packit 0b5880
  <title>
Packit 0b5880
   Autoconf Macro: acx_pthread
Packit 0b5880
  </title>
Packit 0b5880
  <link rel="stylesheet" type="text/css" href="autoconf-archive.css">
Packit 0b5880
 </head>
Packit 0b5880
 <body>
Packit 0b5880
  
Packit 0b5880
   
Packit 0b5880
    
Packit 0b5880
     
Packit 0b5880
      Download M4
Packit 0b5880
      Source
Packit 0b5880
     
Packit 0b5880
     
Packit 0b5880
      
Packit 0b5880
      "http://git.cryp.to/autoconf-archive?a=history;f=acx_pthread.m4">Macro
Packit 0b5880
      History
Packit 0b5880
     
Packit 0b5880
     
Packit 0b5880
      Category Index
Packit 0b5880
     
Packit 0b5880
     
Packit 0b5880
      <form method="get" action="http://www.google.com/search">
Packit 0b5880
       
Packit 0b5880
        
Packit 0b5880
        "hidden">Search: 
Packit 0b5880
        size="10" maxlength="255" type="text">
Packit 0b5880
       
Packit 0b5880
      </form>
Packit 0b5880
     
Packit 0b5880
    
Packit 0b5880
   
Packit 0b5880
  
Packit 0b5880
  
Packit 0b5880
  

Packit 0b5880
   acx_pthread
Packit 0b5880
  
Packit 0b5880
  

Packit 0b5880
   Synopsis
Packit 0b5880
  
Packit 0b5880
  

Packit 0b5880
   ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
Packit 0b5880
  

Packit 0b5880
  

Packit 0b5880
   Description
Packit 0b5880
  
Packit 0b5880
  
Packit 0b5880
   

Packit 0b5880
    This macro figures out how to build C programs using POSIX threads. It sets
Packit 0b5880
    the PTHREAD_LIBS output variable to the threads library and linker flags,
Packit 0b5880
    and the PTHREAD_CFLAGS output variable to any special C compiler flags that
Packit 0b5880
    are needed. (The user can also force certain compiler flags/libs to be
Packit 0b5880
    tested by setting these environment variables.)
Packit 0b5880
   

Packit 0b5880
   

Packit 0b5880
    Also sets PTHREAD_CC to any special C compiler that is needed for
Packit 0b5880
    multi-threaded programs (defaults to the value of CC otherwise). (This is
Packit 0b5880
    necessary on AIX to use the special cc_r compiler alias.)
Packit 0b5880
   

Packit 0b5880
   

Packit 0b5880
    NOTE: You are assumed to not only compile your program with these flags,
Packit 0b5880
    but also link it with them as well. e.g. you should link with $PTHREAD_CC
Packit 0b5880
    $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
Packit 0b5880
   

Packit 0b5880
   

Packit 0b5880
    If you are only building threads programs, you may wish to use these
Packit 0b5880
    variables in your default LIBS, CFLAGS, and CC:
Packit 0b5880
   

Packit 0b5880
   
Packit 0b5880
       LIBS="$PTHREAD_LIBS $LIBS"
Packit 0b5880
       CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Packit 0b5880
       CC="$PTHREAD_CC"
Packit 0b5880
Packit 0b5880
   

Packit 0b5880
    In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant has a
Packit 0b5880
    nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name (e.g.
Packit 0b5880
    PTHREAD_CREATE_UNDETACHED on AIX).
Packit 0b5880
   

Packit 0b5880
   

Packit 0b5880
    ACTION-IF-FOUND is a list of shell commands to run if a threads library is
Packit 0b5880
    found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it is not
Packit 0b5880
    found. If ACTION-IF-FOUND is not specified, the default action will define
Packit 0b5880
    HAVE_PTHREAD.
Packit 0b5880
   

Packit 0b5880
   

Packit 0b5880
    Please let the authors know if this macro fails on any platform, or if you
Packit 0b5880
    have any other suggestions or comments. This macro was based on work by SGJ
Packit 0b5880
    on autoconf scripts for FFTW (
Packit 0b5880
    "http://www.fftw.org/">http://www.fftw.org/) (with help from M. Frigo),
Packit 0b5880
    as well as ac_pthread and hb_pthread macros posted by Alejandro Forero
Packit 0b5880
    Cuervo to the autoconf macro repository. We are also grateful for the
Packit 0b5880
    helpful feedback of numerous users.
Packit 0b5880
   

Packit 0b5880
  
Packit 0b5880
  

Packit 0b5880
   Author
Packit 0b5880
  
Packit 0b5880
  

Packit 0b5880
   Steven G. Johnson <stevenj@alum.mit.edu>
Packit 0b5880
  

Packit 0b5880
  

Packit 0b5880
   Last Modified
Packit 0b5880
  
Packit 0b5880
  

Packit 0b5880
   2008-04-12
Packit 0b5880
  

Packit 0b5880
  

Packit 0b5880
   Cross References
Packit 0b5880
  
Packit 0b5880
  

Packit 0b5880
   
Packit 0b5880
   "#group19"><map id="group19" name="group19">
Packit 0b5880
    
Packit 0b5880
    coords=
Packit 0b5880
    "944,101 940,94 928,87 909,82 886,79 860,77 834,79 811,82 792,87 780,94 776,101 780,109 792,115 811,121 834,124 860,125 886,124 909,121 928,115 940,109">
Packit 0b5880
    
Packit 0b5880
    coords=
Packit 0b5880
    "661,173 656,166 644,159 625,154 601,151 575,149 548,151 524,154 505,159 493,166 489,173 493,181 505,187 524,193 548,196 575,197 601,196 625,193 644,187 656,181">
Packit 0b5880
    
Packit 0b5880
    "ax_lang_compiler_ms" alt="" coords=
Packit 0b5880
    "1000,173 993,166 973,159 942,154 903,151 860,149 817,151 778,154 747,159 727,166 720,173 727,181 747,187 778,193 817,196 860,197 903,196 942,193 973,187 993,181">
Packit 0b5880
    
Packit 0b5880
    coords=
Packit 0b5880
    "429,173 425,166 412,159 391,154 366,151 337,149 309,151 283,154 263,159 250,166 245,173 250,181 263,187 283,193 309,196 337,197 366,196 391,193 412,187 425,181">
Packit 0b5880
    
Packit 0b5880
    coords=
Packit 0b5880
    "197,173 192,166 179,159 158,154 131,151 101,149 72,151 45,154 24,159 10,166 6,173 10,181 24,187 45,193 72,196 101,197 131,196 158,193 179,187 192,181">
Packit 0b5880
    
Packit 0b5880
    coords=
Packit 0b5880
    "668,29 663,22 650,15 629,10 603,7 575,5 546,7 520,10 499,15 486,22 482,29 486,37 499,43 520,49 546,52 575,53 603,52 629,49 650,43 663,37">
Packit 0b5880
    
Packit 0b5880
    coords=
Packit 0b5880
    "671,101 667,94 653,87 631,82 605,79 575,77 545,79 518,82 497,87 483,94 478,101 483,109 497,115 518,121 545,124 575,125 605,124 631,121 653,115 667,109">
Packit 0b5880
   </map>
Packit 0b5880
  

Packit 0b5880
  

Packit 0b5880
   M4 Source Code
Packit 0b5880
  
Packit 0b5880
  
Packit 0b5880
   
Packit 0b5880
AC_DEFUN([ACX_PTHREAD], [
Packit 0b5880
AC_REQUIRE([AC_CANONICAL_HOST])
Packit 0b5880
AC_LANG_SAVE
Packit 0b5880
AC_LANG_C
Packit 0b5880
acx_pthread_ok=no
Packit 0b5880
Packit 0b5880
# We used to check for pthread.h first, but this fails if pthread.h
Packit 0b5880
# requires special compiler flags (e.g. on True64 or Sequent).
Packit 0b5880
# It gets checked for in the link test anyway.
Packit 0b5880
Packit 0b5880
# First of all, check if the user has set any of the PTHREAD_LIBS,
Packit 0b5880
# etcetera environment variables, and if threads linking works using
Packit 0b5880
# them:
Packit 0b5880
if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
Packit 0b5880
        save_CFLAGS="$CFLAGS"
Packit 0b5880
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Packit 0b5880
        save_LIBS="$LIBS"
Packit 0b5880
        LIBS="$PTHREAD_LIBS $LIBS"
Packit 0b5880
        AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
Packit 0b5880
        AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
Packit 0b5880
        AC_MSG_RESULT($acx_pthread_ok)
Packit 0b5880
        if test x"$acx_pthread_ok" = xno; then
Packit 0b5880
                PTHREAD_LIBS=""
Packit 0b5880
                PTHREAD_CFLAGS=""
Packit 0b5880
        fi
Packit 0b5880
        LIBS="$save_LIBS"
Packit 0b5880
        CFLAGS="$save_CFLAGS"
Packit 0b5880
fi
Packit 0b5880
Packit 0b5880
# We must check for the threads library under a number of different
Packit 0b5880
# names; the ordering is very important because some systems
Packit 0b5880
# (e.g. DEC) have both -lpthread and -lpthreads, where one of the
Packit 0b5880
# libraries is broken (non-POSIX).
Packit 0b5880
Packit 0b5880
# Create a list of thread flags to try.  Items starting with a "-" are
Packit 0b5880
# C compiler flags, and other items are library names, except for "none"
Packit 0b5880
# which indicates that we try without any flags at all, and "pthread-config"
Packit 0b5880
# which is a program returning the flags for the Pth emulation library.
Packit 0b5880
Packit 0b5880
acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
Packit 0b5880
Packit 0b5880
# The ordering *is* (sometimes) important.  Some notes on the
Packit 0b5880
# individual items follow:
Packit 0b5880
Packit 0b5880
# pthreads: AIX (must check this before -lpthread)
Packit 0b5880
# none: in case threads are in libc; should be tried before -Kthread and
Packit 0b5880
#       other compiler flags to prevent continual compiler warnings
Packit 0b5880
# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
Packit 0b5880
# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
Packit 0b5880
# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
Packit 0b5880
# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
Packit 0b5880
# -pthreads: Solaris/gcc
Packit 0b5880
# -mthreads: Mingw32/gcc, Lynx/gcc
Packit 0b5880
# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
Packit 0b5880
#      doesn't hurt to check since this sometimes defines pthreads too;
Packit 0b5880
#      also defines -D_REENTRANT)
Packit 0b5880
#      ... -mt is also the pthreads flag for HP/aCC
Packit 0b5880
# pthread: Linux, etcetera
Packit 0b5880
# --thread-safe: KAI C++
Packit 0b5880
# pthread-config: use pthread-config program (for GNU Pth library)
Packit 0b5880
Packit 0b5880
case "${host_cpu}-${host_os}" in
Packit 0b5880
        *solaris*)
Packit 0b5880
Packit 0b5880
        # On Solaris (at least, for some versions), libc contains stubbed
Packit 0b5880
        # (non-functional) versions of the pthreads routines, so link-based
Packit 0b5880
        # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
Packit 0b5880
        # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
Packit 0b5880
        # a function called by this macro, so we could check for that, but
Packit 0b5880
        # who knows whether they'll stub that too in a future libc.)  So,
Packit 0b5880
        # we'll just look for -pthreads and -lpthread first:
Packit 0b5880
Packit 0b5880
        acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
Packit 0b5880
        ;;
Packit 0b5880
esac
Packit 0b5880
Packit 0b5880
if test x"$acx_pthread_ok" = xno; then
Packit 0b5880
for flag in $acx_pthread_flags; do
Packit 0b5880
Packit 0b5880
        case $flag in
Packit 0b5880
                none)
Packit 0b5880
                AC_MSG_CHECKING([whether pthreads work without any flags])
Packit 0b5880
                ;;
Packit 0b5880
Packit 0b5880
                -*)
Packit 0b5880
                AC_MSG_CHECKING([whether pthreads work with $flag])
Packit 0b5880
                PTHREAD_CFLAGS="$flag"
Packit 0b5880
                ;;
Packit 0b5880
Packit 0b5880
                pthread-config)
Packit 0b5880
                AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
Packit 0b5880
                if test x"$acx_pthread_config" = xno; then continue; fi
Packit 0b5880
                PTHREAD_CFLAGS="`pthread-config --cflags`"
Packit 0b5880
                PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
Packit 0b5880
                ;;
Packit 0b5880
Packit 0b5880
                *)
Packit 0b5880
                AC_MSG_CHECKING([for the pthreads library -l$flag])
Packit 0b5880
                PTHREAD_LIBS="-l$flag"
Packit 0b5880
                ;;
Packit 0b5880
        esac
Packit 0b5880
Packit 0b5880
        save_LIBS="$LIBS"
Packit 0b5880
        save_CFLAGS="$CFLAGS"
Packit 0b5880
        LIBS="$PTHREAD_LIBS $LIBS"
Packit 0b5880
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Packit 0b5880
Packit 0b5880
        # Check for various functions.  We must include pthread.h,
Packit 0b5880
        # since some functions may be macros.  (On the Sequent, we
Packit 0b5880
        # need a special flag -Kthread to make this header compile.)
Packit 0b5880
        # We check for pthread_join because it is in -lpthread on IRIX
Packit 0b5880
        # while pthread_create is in libc.  We check for pthread_attr_init
Packit 0b5880
        # due to DEC craziness with -lpthreads.  We check for
Packit 0b5880
        # pthread_cleanup_push because it is one of the few pthread
Packit 0b5880
        # functions on Solaris that doesn't have a non-functional libc stub.
Packit 0b5880
        # We try pthread_create on general principles.
Packit 0b5880
        AC_TRY_LINK([#include <pthread.h>],
Packit 0b5880
                    [pthread_t th; pthread_join(th, 0);
Packit 0b5880
                     pthread_attr_init(0); pthread_cleanup_push(0, 0);
Packit 0b5880
                     pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
Packit 0b5880
                    [acx_pthread_ok=yes])
Packit 0b5880
Packit 0b5880
        LIBS="$save_LIBS"
Packit 0b5880
        CFLAGS="$save_CFLAGS"
Packit 0b5880
Packit 0b5880
        AC_MSG_RESULT($acx_pthread_ok)
Packit 0b5880
        if test "x$acx_pthread_ok" = xyes; then
Packit 0b5880
                break;
Packit 0b5880
        fi
Packit 0b5880
Packit 0b5880
        PTHREAD_LIBS=""
Packit 0b5880
        PTHREAD_CFLAGS=""
Packit 0b5880
done
Packit 0b5880
fi
Packit 0b5880
Packit 0b5880
# Various other checks:
Packit 0b5880
if test "x$acx_pthread_ok" = xyes; then
Packit 0b5880
        save_LIBS="$LIBS"
Packit 0b5880
        LIBS="$PTHREAD_LIBS $LIBS"
Packit 0b5880
        save_CFLAGS="$CFLAGS"
Packit 0b5880
        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Packit 0b5880
Packit 0b5880
        # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
Packit 0b5880
        AC_MSG_CHECKING([for joinable pthread attribute])
Packit 0b5880
        attr_name=unknown
Packit 0b5880
        for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
Packit 0b5880
            AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
Packit 0b5880
                        [attr_name=$attr; break])
Packit 0b5880
        done
Packit 0b5880
        AC_MSG_RESULT($attr_name)
Packit 0b5880
        if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
Packit 0b5880
            AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
Packit 0b5880
                               [Define to necessary symbol if this constant
Packit 0b5880
                                uses a non-standard name on your system.])
Packit 0b5880
        fi
Packit 0b5880
Packit 0b5880
        AC_MSG_CHECKING([if more special flags are required for pthreads])
Packit 0b5880
        flag=no
Packit 0b5880
        case "${host_cpu}-${host_os}" in
Packit 0b5880
            *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
Packit 0b5880
            *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
Packit 0b5880
        esac
Packit 0b5880
        AC_MSG_RESULT(${flag})
Packit 0b5880
        if test "x$flag" != xno; then
Packit 0b5880
            PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
Packit 0b5880
        fi
Packit 0b5880
Packit 0b5880
        LIBS="$save_LIBS"
Packit 0b5880
        CFLAGS="$save_CFLAGS"
Packit 0b5880
Packit 0b5880
        # More AIX lossage: must compile with xlc_r or cc_r
Packit 0b5880
        if test x"$GCC" != xyes; then
Packit 0b5880
          AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
Packit 0b5880
        else
Packit 0b5880
          PTHREAD_CC=$CC
Packit 0b5880
        fi
Packit 0b5880
else
Packit 0b5880
        PTHREAD_CC="$CC"
Packit 0b5880
fi
Packit 0b5880
Packit 0b5880
AC_SUBST(PTHREAD_LIBS)
Packit 0b5880
AC_SUBST(PTHREAD_CFLAGS)
Packit 0b5880
AC_SUBST(PTHREAD_CC)
Packit 0b5880
Packit 0b5880
# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
Packit 0b5880
if test x"$acx_pthread_ok" = xyes; then
Packit 0b5880
        ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
Packit 0b5880
        :
Packit 0b5880
else
Packit 0b5880
        acx_pthread_ok=no
Packit 0b5880
        $2
Packit 0b5880
fi
Packit 0b5880
AC_LANG_RESTORE
Packit 0b5880
])dnl ACX_PTHREAD
Packit 0b5880
Packit 0b5880
  
Packit 0b5880
  

Packit 0b5880
   License
Packit 0b5880
  
Packit 0b5880
  
Packit 0b5880
   Copyright © 2008 Steven G. Johnson
Packit 0b5880
   <stevenj@alum.mit.edu>
Packit 0b5880
   

Packit 0b5880
    This program is free software: you can redistribute it and/or modify it
Packit 0b5880
    under the terms of the GNU General Public License as published by the Free
Packit 0b5880
    Software Foundation, either version 3 of the License, or (at your option)
Packit 0b5880
    any later version.
Packit 0b5880
   

Packit 0b5880
   

Packit 0b5880
    This program is distributed in the hope that it will be useful, but WITHOUT
Packit 0b5880
    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
Packit 0b5880
    FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
Packit 0b5880
    more details.
Packit 0b5880
   

Packit 0b5880
   

Packit 0b5880
    You should have received a copy of the GNU General Public License along
Packit 0b5880
    with this program. If not, see <
Packit 0b5880
    "http://www.gnu.org/licenses/">http://www.gnu.org/licenses/>.
Packit 0b5880
   

Packit 0b5880
   

Packit 0b5880
    As a special exception, the respective Autoconf Macro's copyright owner
Packit 0b5880
    gives unlimited permission to copy, distribute and modify the configure
Packit 0b5880
    scripts that are the output of Autoconf when processing the Macro. You need
Packit 0b5880
    not follow the terms of the GNU General Public License when using or
Packit 0b5880
    distributing such scripts, even though portions of the text of the Macro
Packit 0b5880
    appear in them. The GNU General Public License (GPL) does govern all other
Packit 0b5880
    use of the material that constitutes the Autoconf Macro.
Packit 0b5880
   

Packit 0b5880
   

Packit 0b5880
    This special exception to the GPL applies to versions of the Autoconf Macro
Packit 0b5880
    released by the Autoconf Macro Archive. When you make and distribute a
Packit 0b5880
    modified version of the Autoconf Macro, you may extend this special
Packit 0b5880
    exception to the GPL to apply to your modified version as well.
Packit 0b5880
   

Packit 0b5880
  
Packit 0b5880
 </body>
Packit 0b5880
</html>