annotate fft/fftw/fftw-3.3.4/m4/acx_pthread.m4 @ 40:223f770b5341 kissfft-double tip

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