Home My Page Projects Code Snippets Project Openings diderot
Summary Activity Tracker Tasks SCM

SCM Repository

[diderot] Diff of /branches/opencl/config/acx_pthread.m4
ViewVC logotype

Diff of /branches/opencl/config/acx_pthread.m4

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1112, Thu May 5 01:30:20 2011 UTC revision 1113, Thu May 5 04:11:52 2011 UTC
# Line 1  Line 1 
1    dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
2  dnl  dnl
3  dnl  ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])  dnl @summary figure out how to build C programs using POSIX threads
4  dnl  dnl
5  dnl Description  dnl This macro figures out how to build C programs using POSIX threads.
6  dnl  dnl It sets the PTHREAD_LIBS output variable to the threads library and
7  dnl This macro figures out how to build C programs using POSIX threads. It  dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
8  dnl sets the PTHREAD_LIBS output variable to the threads library and linker  dnl C compiler flags that are needed. (The user can also force certain
9  dnl flags, and the PTHREAD_CFLAGS output variable to any special C compiler  dnl compiler flags/libs to be tested by setting these environment
10  dnl flags that are needed. (The user can also force certain compiler  dnl variables.)
 dnl flags/libs to be tested by setting these environment variables.)  
11  dnl  dnl
12  dnl Also sets PTHREAD_CC to any special C compiler that is needed for  dnl Also sets PTHREAD_CC to any special C compiler that is needed for
13  dnl multi-threaded programs (defaults to the value of CC otherwise). (This is  dnl multi-threaded programs (defaults to the value of CC otherwise).
14  dnl necessary on AIX to use the special cc_r compiler alias.)  dnl (This is necessary on AIX to use the special cc_r compiler alias.)
15  dnl  dnl
16  dnl NOTE: You are assumed to not only compile your program with these flags,  dnl NOTE: You are assumed to not only compile your program with these
17  dnl but also link it with them as well. e.g. you should link with $PTHREAD_CC  dnl flags, but also link it with them as well. e.g. you should link
18  dnl $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS  dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
19    dnl $LIBS
20  dnl  dnl
21  dnl If you are only building threads programs, you may wish to use these  dnl If you are only building threads programs, you may wish to use
22  dnl variables in your default LIBS, CFLAGS, and CC:  dnl these variables in your default LIBS, CFLAGS, and CC:
23  dnl  dnl
24  dnl        LIBS="$PTHREAD_LIBS $LIBS"  dnl        LIBS="$PTHREAD_LIBS $LIBS"
25  dnl        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"  dnl        CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
26  dnl        CC="$PTHREAD_CC"  dnl        CC="$PTHREAD_CC"
27  dnl  dnl
28  dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant  dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
29  dnl has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name  dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
30  dnl (e.g. PTHREAD_CREATE_UNDETACHED on AIX).  dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
31  dnl  dnl
32  dnl ACTION-IF-FOUND is a list of shell commands to run if a threads library  dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
33  dnl is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it  dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
34  dnl is not found. If ACTION-IF-FOUND is not specified, the default action  dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
35  dnl will define HAVE_PTHREAD.  dnl default action will define HAVE_PTHREAD.
36  dnl  dnl
37  dnl Please let the authors know if this macro fails on any platform, or if  dnl Please let the authors know if this macro fails on any platform, or
38  dnl you have any other suggestions or comments. This macro was based on work  dnl if you have any other suggestions or comments. This macro was based
39  dnl by SGJ on autoconf scripts for FFTW (www.fftw.org) (with help from M.  dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
40  dnl Frigo), as well as ac_pthread and hb_pthread macros posted by AFC to the  dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
41  dnl autoconf macro repository. We are also grateful for the helpful feedback  dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
42  dnl of numerous users.  dnl We are also grateful for the helpful feedback of numerous users.
43  dnl  dnl
44  dnl Version: 1.8 (last modified: 2003-05-21)  dnl @category InstalledPackages
45  dnl Author: Steven G. Johnson <stevenj@alum.mit.edu> and  dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
46  dnl         Alejandro Forero Cuervo <bachue@bachue.com>  dnl @version 2006-05-29
47  dnl  dnl @license GPLWithACException
 dnl from http://www.gnu.org/software/ac-archive/htmldoc/index.html  
 dnl  
 dnl License:  
 dnl GNU General Public License  
 dnl [http://www.gnu.org/software/ac-archive/htmldoc/COPYING.html]  
 dnl with this special exception  
 dnl [http://www.gnu.org/software/ac-archive/htmldoc/COPYING-Exception.html].  
 dnl  
48    
49  AC_DEFUN([ACX_PTHREAD], [  AC_DEFUN([ACX_PTHREAD], [
50  AC_REQUIRE([AC_CANONICAL_HOST])  AC_REQUIRE([AC_CANONICAL_HOST])
# Line 89  Line 82 
82    
83  # Create a list of thread flags to try.  Items starting with a "-" are  # Create a list of thread flags to try.  Items starting with a "-" are
84  # C compiler flags, and other items are library names, except for "none"  # C compiler flags, and other items are library names, except for "none"
85  # which indicates that we try without any flags at all.  # which indicates that we try without any flags at all, and "pthread-config"
86    # which is a program returning the flags for the Pth emulation library.
87    
88  acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt"  acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
89    
90  # The ordering *is* (sometimes) important.  Some notes on the  # The ordering *is* (sometimes) important.  Some notes on the
91  # individual items follow:  # individual items follow:
# Line 108  Line 102 
102  # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it  # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
103  #      doesn't hurt to check since this sometimes defines pthreads too;  #      doesn't hurt to check since this sometimes defines pthreads too;
104  #      also defines -D_REENTRANT)  #      also defines -D_REENTRANT)
105    #      ... -mt is also the pthreads flag for HP/aCC
106  # pthread: Linux, etcetera  # pthread: Linux, etcetera
107  # --thread-safe: KAI C++  # --thread-safe: KAI C++
108    # pthread-config: use pthread-config program (for GNU Pth library)
109    
110  case "${host_cpu}-${host_os}" in  case "${host_cpu}-${host_os}" in
111          *solaris*)          *solaris*)
112    
113          # On Solaris (at least, for some versions), libc contains stubbed          # On Solaris (at least, for some versions), libc contains stubbed
114          # (non-functional) versions of the pthreads routines, so link-based          # (non-functional) versions of the pthreads routines, so link-based
115          # tests will erroneously succeed.  (We need to link with -pthread or          # tests will erroneously succeed.  (We need to link with -pthreads/-mt/
116          # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather          # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
117          # a function called by this macro, so we could check for that, but          # a function called by this macro, so we could check for that, but
118          # who knows whether they'll stub that too in a future libc.)  So,          # who knows whether they'll stub that too in a future libc.)  So,
119          # we'll just look for -pthreads and -lpthread first:          # we'll just look for -pthreads and -lpthread first:
120    
121          acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"          acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
122          ;;          ;;
123  esac  esac
124    
# Line 139  Line 135 
135                  PTHREAD_CFLAGS="$flag"                  PTHREAD_CFLAGS="$flag"
136                  ;;                  ;;
137    
138                    pthread-config)
139                    AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
140                    if test x"$acx_pthread_config" = xno; then continue; fi
141                    PTHREAD_CFLAGS="`pthread-config --cflags`"
142                    PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
143                    ;;
144    
145                  *)                  *)
146                  AC_MSG_CHECKING([for the pthreads library -l$flag])                  AC_MSG_CHECKING([for the pthreads library -l$flag])
147                  PTHREAD_LIBS="-l$flag"                  PTHREAD_LIBS="-l$flag"
# Line 185  Line 188 
188          save_CFLAGS="$CFLAGS"          save_CFLAGS="$CFLAGS"
189          CFLAGS="$CFLAGS $PTHREAD_CFLAGS"          CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
190    
191          # Detect AIX lossage: threads are created detached by default          # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
         # and the JOINABLE attribute has a nonstandard name (UNDETACHED).  
192          AC_MSG_CHECKING([for joinable pthread attribute])          AC_MSG_CHECKING([for joinable pthread attribute])
193          AC_TRY_LINK([#include <pthread.h>],          attr_name=unknown
194                      [int attr=PTHREAD_CREATE_JOINABLE;],          for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
195                      ok=PTHREAD_CREATE_JOINABLE, ok=unknown)              AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
196          if test x"$ok" = xunknown; then                          [attr_name=$attr; break])
197                  AC_TRY_LINK([#include <pthread.h>],          done
198                              [int attr=PTHREAD_CREATE_UNDETACHED;],          AC_MSG_RESULT($attr_name)
199                              ok=PTHREAD_CREATE_UNDETACHED, ok=unknown)          if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
200          fi              AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
201          if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then                                 [Define to necessary symbol if this constant
                 AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok,  
                           [Define to the necessary symbol if this constant  
202                             uses a non-standard name on your system.])                             uses a non-standard name on your system.])
203          fi          fi
         AC_MSG_RESULT(${ok})  
         if test x"$ok" = xunknown; then  
                 AC_MSG_WARN([we do not know how to create joinable pthreads])  
         fi  
204    
205          AC_MSG_CHECKING([if more special flags are required for pthreads])          AC_MSG_CHECKING([if more special flags are required for pthreads])
206          flag=no          flag=no
207          case "${host_cpu}-${host_os}" in          case "${host_cpu}-${host_os}" in
208                  *-aix* | *-freebsd*)     flag="-D_THREAD_SAFE";;              *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
209                  *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;                  *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
210          esac          esac
211          AC_MSG_RESULT(${flag})          AC_MSG_RESULT(${flag})
# Line 220  Line 216 
216          LIBS="$save_LIBS"          LIBS="$save_LIBS"
217          CFLAGS="$save_CFLAGS"          CFLAGS="$save_CFLAGS"
218    
219          # More AIX lossage: must compile with cc_r          # More AIX lossage: must compile with xlc_r or cc_r
220          AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})          if test x"$GCC" != xyes; then
221              AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
222            else
223              PTHREAD_CC=$CC
224            fi
225  else  else
226          PTHREAD_CC="$CC"          PTHREAD_CC="$CC"
227  fi  fi

Legend:
Removed from v.1112  
changed lines
  Added in v.1113

root@smlnj-gforge.cs.uchicago.edu
ViewVC Help
Powered by ViewVC 1.0.0