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