annotate src/fftw-3.3.8/m4/acx_pthread.m4 @ 84:08ae793730bd

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