annotate src/fftw-3.3.5/m4/acx_pthread.m4 @ 58:eab3b14ddc95

Further win32 build updates
author Chris Cannam
date Mon, 09 Jan 2017 13:51:38 +0000
parents 2cd0e3b3e1fd
children
rev   line source
Chris@42 1 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
Chris@42 2 dnl @summary figure out how to build C programs using POSIX threads
Chris@42 3 dnl @category InstalledPackages
Chris@42 4 dnl
Chris@42 5 dnl This macro figures out how to build C programs using POSIX
Chris@42 6 dnl threads. It sets the PTHREAD_LIBS output variable to the threads
Chris@42 7 dnl library and linker flags, and the PTHREAD_CFLAGS output variable
Chris@42 8 dnl to any special C compiler flags that are needed. (The user can also
Chris@42 9 dnl force certain compiler flags/libs to be tested by setting these
Chris@42 10 dnl environment variables.)
Chris@42 11 dnl
Chris@42 12 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
Chris@42 13 dnl multi-threaded programs (defaults to the value of CC otherwise).
Chris@42 14 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
Chris@42 15 dnl
Chris@42 16 dnl NOTE: You are assumed to not only compile your program with these
Chris@42 17 dnl flags, but also link it with them as well. e.g. you should link
Chris@42 18 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS
Chris@42 19 dnl
Chris@42 20 dnl If you are only building threads programs, you may wish to
Chris@42 21 dnl use these variables in your default LIBS, CFLAGS, and CC:
Chris@42 22 dnl
Chris@42 23 dnl LIBS="$PTHREAD_LIBS $LIBS"
Chris@42 24 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Chris@42 25 dnl CC="$PTHREAD_CC"
Chris@42 26 dnl
Chris@42 27 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
Chris@42 28 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE
Chris@42 29 dnl to that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
Chris@42 30 dnl
Chris@42 31 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
Chris@42 32 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands
Chris@42 33 dnl to run it if it is not found. If ACTION-IF-FOUND is not specified,
Chris@42 34 dnl the default action will define HAVE_PTHREAD.
Chris@42 35 dnl
Chris@42 36 dnl Please let the authors know if this macro fails on any platform,
Chris@42 37 dnl or if you have any other suggestions or comments. This macro was
Chris@42 38 dnl based on work by SGJ on autoconf scripts for FFTW (www.fftw.org)
Chris@42 39 dnl (with help from M. Frigo), as well as ac_pthread and hb_pthread
Chris@42 40 dnl macros posted by Alejandro Forero Cuervo to the autoconf macro
Chris@42 41 dnl repository. We are also grateful for the helpful feedback of
Chris@42 42 dnl numerous users.
Chris@42 43 dnl
Chris@42 44 dnl @version 2006-09-15
Chris@42 45 dnl @license GPLWithACException
Chris@42 46 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
Chris@42 47
Chris@42 48 AC_DEFUN([ACX_PTHREAD], [
Chris@42 49 AC_REQUIRE([AC_CANONICAL_HOST])
Chris@42 50 AC_LANG_SAVE
Chris@42 51 AC_LANG_C
Chris@42 52 acx_pthread_ok=no
Chris@42 53
Chris@42 54 # We used to check for pthread.h first, but this fails if pthread.h
Chris@42 55 # requires special compiler flags (e.g. on True64 or Sequent).
Chris@42 56 # It gets checked for in the link test anyway.
Chris@42 57
Chris@42 58 # First of all, check if the user has set any of the PTHREAD_LIBS,
Chris@42 59 # etcetera environment variables, and if threads linking works using
Chris@42 60 # them:
Chris@42 61 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
Chris@42 62 save_CFLAGS="$CFLAGS"
Chris@42 63 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Chris@42 64 save_LIBS="$LIBS"
Chris@42 65 LIBS="$PTHREAD_LIBS $LIBS"
Chris@42 66 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
Chris@42 67 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
Chris@42 68 AC_MSG_RESULT($acx_pthread_ok)
Chris@42 69 if test x"$acx_pthread_ok" = xno; then
Chris@42 70 PTHREAD_LIBS=""
Chris@42 71 PTHREAD_CFLAGS=""
Chris@42 72 fi
Chris@42 73 LIBS="$save_LIBS"
Chris@42 74 CFLAGS="$save_CFLAGS"
Chris@42 75 fi
Chris@42 76
Chris@42 77 # We must check for the threads library under a number of different
Chris@42 78 # names; the ordering is very important because some systems
Chris@42 79 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
Chris@42 80 # libraries is broken (non-POSIX).
Chris@42 81
Chris@42 82 # Create a list of thread flags to try. Items starting with a "-" are
Chris@42 83 # C compiler flags, and other items are library names, except for "none"
Chris@42 84 # which indicates that we try without any flags at all, and "pthread-config"
Chris@42 85 # which is a program returning the flags for the Pth emulation library.
Chris@42 86
Chris@42 87 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mt -mthreads pthread --thread-safe pthread-config"
Chris@42 88
Chris@42 89 # The ordering *is* (sometimes) important. Some notes on the
Chris@42 90 # individual items follow:
Chris@42 91
Chris@42 92 # pthreads: AIX (must check this before -lpthread)
Chris@42 93 # none: in case threads are in libc; should be tried before -Kthread and
Chris@42 94 # other compiler flags to prevent continual compiler warnings
Chris@42 95 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
Chris@42 96 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
Chris@42 97 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
Chris@42 98 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
Chris@42 99 # -pthreads: Solaris/gcc
Chris@42 100 # -mthreads: Mingw32/gcc, Lynx/gcc
Chris@42 101 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
Chris@42 102 # doesn't hurt to check since this sometimes defines pthreads too;
Chris@42 103 # also defines -D_REENTRANT)
Chris@42 104 # ... -mt is also the pthreads flag for HP/aCC
Chris@42 105 # (where it should come before -mthreads to avoid spurious warnings)
Chris@42 106 # pthread: Linux, etcetera
Chris@42 107 # --thread-safe: KAI C++
Chris@42 108 # pthread-config: use pthread-config program (for GNU Pth library)
Chris@42 109
Chris@42 110 case "${host_cpu}-${host_os}" in
Chris@42 111 *solaris*)
Chris@42 112
Chris@42 113 # On Solaris (at least, for some versions), libc contains stubbed
Chris@42 114 # (non-functional) versions of the pthreads routines, so link-based
Chris@42 115 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
Chris@42 116 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
Chris@42 117 # a function called by this macro, so we could check for that, but
Chris@42 118 # who knows whether they'll stub that too in a future libc.) So,
Chris@42 119 # we'll just look for -pthreads and -lpthread first:
Chris@42 120
Chris@42 121 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
Chris@42 122 ;;
Chris@42 123 esac
Chris@42 124
Chris@42 125 if test x"$acx_pthread_ok" = xno; then
Chris@42 126 for flag in $acx_pthread_flags; do
Chris@42 127
Chris@42 128 case $flag in
Chris@42 129 none)
Chris@42 130 AC_MSG_CHECKING([whether pthreads work without any flags])
Chris@42 131 ;;
Chris@42 132
Chris@42 133 -*)
Chris@42 134 AC_MSG_CHECKING([whether pthreads work with $flag])
Chris@42 135 PTHREAD_CFLAGS="$flag"
Chris@42 136 ;;
Chris@42 137
Chris@42 138 pthread-config)
Chris@42 139 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
Chris@42 140 if test x"$acx_pthread_config" = xno; then continue; fi
Chris@42 141 PTHREAD_CFLAGS="`pthread-config --cflags`"
Chris@42 142 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
Chris@42 143 ;;
Chris@42 144
Chris@42 145 *)
Chris@42 146 AC_MSG_CHECKING([for the pthreads library -l$flag])
Chris@42 147 PTHREAD_LIBS="-l$flag"
Chris@42 148 ;;
Chris@42 149 esac
Chris@42 150
Chris@42 151 save_LIBS="$LIBS"
Chris@42 152 save_CFLAGS="$CFLAGS"
Chris@42 153 LIBS="$PTHREAD_LIBS $LIBS"
Chris@42 154 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Chris@42 155
Chris@42 156 # Check for various functions. We must include pthread.h,
Chris@42 157 # since some functions may be macros. (On the Sequent, we
Chris@42 158 # need a special flag -Kthread to make this header compile.)
Chris@42 159 # We check for pthread_join because it is in -lpthread on IRIX
Chris@42 160 # while pthread_create is in libc. We check for pthread_attr_init
Chris@42 161 # due to DEC craziness with -lpthreads. We check for
Chris@42 162 # pthread_cleanup_push because it is one of the few pthread
Chris@42 163 # functions on Solaris that doesn't have a non-functional libc stub.
Chris@42 164 # We try pthread_create on general principles.
Chris@42 165 AC_TRY_LINK([#include <pthread.h>],
Chris@42 166 [pthread_t th; pthread_join(th, (void**) 0);
Chris@42 167 pthread_attr_init((pthread_attr_t*) 0);
Chris@42 168 pthread_cleanup_push((void(*)(void *)) 0, (void*) 0);
Chris@42 169 pthread_create((pthread_t*) 0, (pthread_attr_t*) 0,
Chris@42 170 (void*(*)(void *)) 0, (void*) 0);
Chris@42 171 pthread_cleanup_pop(0); ],
Chris@42 172 [acx_pthread_ok=yes])
Chris@42 173
Chris@42 174 LIBS="$save_LIBS"
Chris@42 175 CFLAGS="$save_CFLAGS"
Chris@42 176
Chris@42 177 AC_MSG_RESULT($acx_pthread_ok)
Chris@42 178 if test "x$acx_pthread_ok" = xyes; then
Chris@42 179 break;
Chris@42 180 fi
Chris@42 181
Chris@42 182 PTHREAD_LIBS=""
Chris@42 183 PTHREAD_CFLAGS=""
Chris@42 184 done
Chris@42 185 fi
Chris@42 186
Chris@42 187 # Various other checks:
Chris@42 188 if test "x$acx_pthread_ok" = xyes; then
Chris@42 189 save_LIBS="$LIBS"
Chris@42 190 LIBS="$PTHREAD_LIBS $LIBS"
Chris@42 191 save_CFLAGS="$CFLAGS"
Chris@42 192 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
Chris@42 193
Chris@42 194 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
Chris@42 195 AC_MSG_CHECKING([for joinable pthread attribute])
Chris@42 196 attr_name=unknown
Chris@42 197 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
Chris@42 198 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
Chris@42 199 [attr_name=$attr; break])
Chris@42 200 done
Chris@42 201 AC_MSG_RESULT($attr_name)
Chris@42 202 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
Chris@42 203 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
Chris@42 204 [Define to necessary symbol if this constant
Chris@42 205 uses a non-standard name on your system.])
Chris@42 206 fi
Chris@42 207
Chris@42 208 AC_MSG_CHECKING([if more special flags are required for pthreads])
Chris@42 209 flag=no
Chris@42 210 case "${host_cpu}-${host_os}" in
Chris@42 211 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
Chris@42 212 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
Chris@42 213 esac
Chris@42 214 AC_MSG_RESULT(${flag})
Chris@42 215 if test "x$flag" != xno; then
Chris@42 216 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
Chris@42 217 fi
Chris@42 218
Chris@42 219 LIBS="$save_LIBS"
Chris@42 220 CFLAGS="$save_CFLAGS"
Chris@42 221
Chris@42 222 # More AIX lossage: must compile with xlc_r or cc_r
Chris@42 223 if test x"$GCC" != xyes; then
Chris@42 224 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
Chris@42 225 else
Chris@42 226 PTHREAD_CC=$CC
Chris@42 227 fi
Chris@42 228 else
Chris@42 229 PTHREAD_CC="$CC"
Chris@42 230 fi
Chris@42 231
Chris@42 232 AC_SUBST(PTHREAD_LIBS)
Chris@42 233 AC_SUBST(PTHREAD_CFLAGS)
Chris@42 234 AC_SUBST(PTHREAD_CC)
Chris@42 235
Chris@42 236 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
Chris@42 237 if test x"$acx_pthread_ok" = xyes; then
Chris@42 238 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
Chris@42 239 :
Chris@42 240 else
Chris@42 241 acx_pthread_ok=no
Chris@42 242 $2
Chris@42 243 fi
Chris@42 244 AC_LANG_RESTORE
Chris@42 245 ])dnl ACX_PTHREAD