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