annotate src/fftw-3.3.5/m4/acx_pthread.m4 @ 169:223a55898ab9 tip default

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