annotate src/capnproto-git-20161025/c++/m4/acx_pthread.m4 @ 55:284acf908dcd

Add source for PortAudio stable v190600_20161030
author Chris Cannam
date Tue, 03 Jan 2017 13:44:07 +0000
parents 9530b331f8c1
children
rev   line source
cannam@48 1 # This file was copied to Cap'n Proto from the Protocol Buffers distribution,
cannam@48 2 # version 2.3.0.
cannam@48 3
cannam@48 4 # This was retrieved from
cannam@48 5 # http://svn.0pointer.de/viewvc/trunk/common/acx_pthread.m4?revision=1277&root=avahi
cannam@48 6 # See also (perhaps for new versions?)
cannam@48 7 # http://svn.0pointer.de/viewvc/trunk/common/acx_pthread.m4?root=avahi
cannam@48 8 #
cannam@48 9 # We've rewritten the inconsistency check code (from avahi), to work
cannam@48 10 # more broadly. In particular, it no longer assumes ld accepts -zdefs.
cannam@48 11 # This caused a restructing of the code, but the functionality has only
cannam@48 12 # changed a little.
cannam@48 13
cannam@48 14 dnl @synopsis ACX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]])
cannam@48 15 dnl
cannam@48 16 dnl @summary figure out how to build C programs using POSIX threads
cannam@48 17 dnl
cannam@48 18 dnl This macro figures out how to build C programs using POSIX threads.
cannam@48 19 dnl It sets the PTHREAD_LIBS output variable to the threads library and
cannam@48 20 dnl linker flags, and the PTHREAD_CFLAGS output variable to any special
cannam@48 21 dnl C compiler flags that are needed. (The user can also force certain
cannam@48 22 dnl compiler flags/libs to be tested by setting these environment
cannam@48 23 dnl variables.)
cannam@48 24 dnl
cannam@48 25 dnl Also sets PTHREAD_CC to any special C compiler that is needed for
cannam@48 26 dnl multi-threaded programs (defaults to the value of CC otherwise).
cannam@48 27 dnl (This is necessary on AIX to use the special cc_r compiler alias.)
cannam@48 28 dnl
cannam@48 29 dnl NOTE: You are assumed to not only compile your program with these
cannam@48 30 dnl flags, but also link it with them as well. e.g. you should link
cannam@48 31 dnl with $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS
cannam@48 32 dnl $LIBS
cannam@48 33 dnl
cannam@48 34 dnl If you are only building threads programs, you may wish to use
cannam@48 35 dnl these variables in your default LIBS, CFLAGS, and CC:
cannam@48 36 dnl
cannam@48 37 dnl LIBS="$PTHREAD_LIBS $LIBS"
cannam@48 38 dnl CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
cannam@48 39 dnl CC="$PTHREAD_CC"
cannam@48 40 dnl
cannam@48 41 dnl In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute
cannam@48 42 dnl constant has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to
cannam@48 43 dnl that name (e.g. PTHREAD_CREATE_UNDETACHED on AIX).
cannam@48 44 dnl
cannam@48 45 dnl ACTION-IF-FOUND is a list of shell commands to run if a threads
cannam@48 46 dnl library is found, and ACTION-IF-NOT-FOUND is a list of commands to
cannam@48 47 dnl run it if it is not found. If ACTION-IF-FOUND is not specified, the
cannam@48 48 dnl default action will define HAVE_PTHREAD.
cannam@48 49 dnl
cannam@48 50 dnl Please let the authors know if this macro fails on any platform, or
cannam@48 51 dnl if you have any other suggestions or comments. This macro was based
cannam@48 52 dnl on work by SGJ on autoconf scripts for FFTW (www.fftw.org) (with
cannam@48 53 dnl help from M. Frigo), as well as ac_pthread and hb_pthread macros
cannam@48 54 dnl posted by Alejandro Forero Cuervo to the autoconf macro repository.
cannam@48 55 dnl We are also grateful for the helpful feedback of numerous users.
cannam@48 56 dnl
cannam@48 57 dnl @category InstalledPackages
cannam@48 58 dnl @author Steven G. Johnson <stevenj@alum.mit.edu>
cannam@48 59 dnl @version 2006-05-29
cannam@48 60 dnl @license GPLWithACException
cannam@48 61 dnl
cannam@48 62 dnl Checks for GCC shared/pthread inconsistency based on work by
cannam@48 63 dnl Marcin Owsiany <marcin@owsiany.pl>
cannam@48 64
cannam@48 65
cannam@48 66 AC_DEFUN([ACX_PTHREAD], [
cannam@48 67 AC_REQUIRE([AC_CANONICAL_HOST])
cannam@48 68 AC_LANG_SAVE
cannam@48 69 AC_LANG_C
cannam@48 70 acx_pthread_ok=no
cannam@48 71
cannam@48 72 # We used to check for pthread.h first, but this fails if pthread.h
cannam@48 73 # requires special compiler flags (e.g. on True64 or Sequent).
cannam@48 74 # It gets checked for in the link test anyway.
cannam@48 75
cannam@48 76 # First of all, check if the user has set any of the PTHREAD_LIBS,
cannam@48 77 # etcetera environment variables, and if threads linking works using
cannam@48 78 # them:
cannam@48 79 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
cannam@48 80 save_CFLAGS="$CFLAGS"
cannam@48 81 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
cannam@48 82 save_LIBS="$LIBS"
cannam@48 83 LIBS="$PTHREAD_LIBS $LIBS"
cannam@48 84 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
cannam@48 85 AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
cannam@48 86 AC_MSG_RESULT($acx_pthread_ok)
cannam@48 87 if test x"$acx_pthread_ok" = xno; then
cannam@48 88 PTHREAD_LIBS=""
cannam@48 89 PTHREAD_CFLAGS=""
cannam@48 90 fi
cannam@48 91 LIBS="$save_LIBS"
cannam@48 92 CFLAGS="$save_CFLAGS"
cannam@48 93 fi
cannam@48 94
cannam@48 95 # We must check for the threads library under a number of different
cannam@48 96 # names; the ordering is very important because some systems
cannam@48 97 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
cannam@48 98 # libraries is broken (non-POSIX).
cannam@48 99
cannam@48 100 # Create a list of thread flags to try. Items starting with a "-" are
cannam@48 101 # C compiler flags, and other items are library names, except for "none"
cannam@48 102 # which indicates that we try without any flags at all, and "pthread-config"
cannam@48 103 # which is a program returning the flags for the Pth emulation library.
cannam@48 104
cannam@48 105 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
cannam@48 106
cannam@48 107 # The ordering *is* (sometimes) important. Some notes on the
cannam@48 108 # individual items follow:
cannam@48 109
cannam@48 110 # pthreads: AIX (must check this before -lpthread)
cannam@48 111 # none: in case threads are in libc; should be tried before -Kthread and
cannam@48 112 # other compiler flags to prevent continual compiler warnings
cannam@48 113 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
cannam@48 114 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
cannam@48 115 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
cannam@48 116 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
cannam@48 117 # -pthreads: Solaris/gcc
cannam@48 118 # -mthreads: Mingw32/gcc, Lynx/gcc
cannam@48 119 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
cannam@48 120 # doesn't hurt to check since this sometimes defines pthreads too;
cannam@48 121 # also defines -D_REENTRANT)
cannam@48 122 # ... -mt is also the pthreads flag for HP/aCC
cannam@48 123 # pthread: Linux, etcetera
cannam@48 124 # --thread-safe: KAI C++
cannam@48 125 # pthread-config: use pthread-config program (for GNU Pth library)
cannam@48 126
cannam@48 127 case "${host_cpu}-${host_os}" in
cannam@48 128 *solaris*)
cannam@48 129
cannam@48 130 # On Solaris (at least, for some versions), libc contains stubbed
cannam@48 131 # (non-functional) versions of the pthreads routines, so link-based
cannam@48 132 # tests will erroneously succeed. (We need to link with -pthreads/-mt/
cannam@48 133 # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
cannam@48 134 # a function called by this macro, so we could check for that, but
cannam@48 135 # who knows whether they'll stub that too in a future libc.) So,
cannam@48 136 # we'll just look for -pthreads and -lpthread first:
cannam@48 137
cannam@48 138 acx_pthread_flags="-pthreads pthread -mt -pthread $acx_pthread_flags"
cannam@48 139 ;;
cannam@48 140 esac
cannam@48 141
cannam@48 142 if test x"$acx_pthread_ok" = xno; then
cannam@48 143 for flag in $acx_pthread_flags; do
cannam@48 144
cannam@48 145 case $flag in
cannam@48 146 none)
cannam@48 147 AC_MSG_CHECKING([whether pthreads work without any flags])
cannam@48 148 ;;
cannam@48 149
cannam@48 150 -*)
cannam@48 151 AC_MSG_CHECKING([whether pthreads work with $flag])
cannam@48 152 PTHREAD_CFLAGS="$flag"
cannam@48 153 ;;
cannam@48 154
cannam@48 155 pthread-config)
cannam@48 156 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
cannam@48 157 if test x"$acx_pthread_config" = xno; then continue; fi
cannam@48 158 PTHREAD_CFLAGS="`pthread-config --cflags`"
cannam@48 159 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
cannam@48 160 ;;
cannam@48 161
cannam@48 162 *)
cannam@48 163 AC_MSG_CHECKING([for the pthreads library -l$flag])
cannam@48 164 PTHREAD_LIBS="-l$flag"
cannam@48 165 ;;
cannam@48 166 esac
cannam@48 167
cannam@48 168 save_LIBS="$LIBS"
cannam@48 169 save_CFLAGS="$CFLAGS"
cannam@48 170 LIBS="$PTHREAD_LIBS $LIBS"
cannam@48 171 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
cannam@48 172
cannam@48 173 # Check for various functions. We must include pthread.h,
cannam@48 174 # since some functions may be macros. (On the Sequent, we
cannam@48 175 # need a special flag -Kthread to make this header compile.)
cannam@48 176 # We check for pthread_join because it is in -lpthread on IRIX
cannam@48 177 # while pthread_create is in libc. We check for pthread_attr_init
cannam@48 178 # due to DEC craziness with -lpthreads. We check for
cannam@48 179 # pthread_cleanup_push because it is one of the few pthread
cannam@48 180 # functions on Solaris that doesn't have a non-functional libc stub.
cannam@48 181 # We try pthread_create on general principles.
cannam@48 182 AC_TRY_LINK([#include <pthread.h>],
cannam@48 183 [pthread_t th; pthread_join(th, 0);
cannam@48 184 pthread_attr_init(0); pthread_cleanup_push(0, 0);
cannam@48 185 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
cannam@48 186 [acx_pthread_ok=yes])
cannam@48 187
cannam@48 188 LIBS="$save_LIBS"
cannam@48 189 CFLAGS="$save_CFLAGS"
cannam@48 190
cannam@48 191 AC_MSG_RESULT($acx_pthread_ok)
cannam@48 192 if test "x$acx_pthread_ok" = xyes; then
cannam@48 193 break;
cannam@48 194 fi
cannam@48 195
cannam@48 196 PTHREAD_LIBS=""
cannam@48 197 PTHREAD_CFLAGS=""
cannam@48 198 done
cannam@48 199 fi
cannam@48 200
cannam@48 201 # Various other checks:
cannam@48 202 if test "x$acx_pthread_ok" = xyes; then
cannam@48 203 save_LIBS="$LIBS"
cannam@48 204 LIBS="$PTHREAD_LIBS $LIBS"
cannam@48 205 save_CFLAGS="$CFLAGS"
cannam@48 206 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
cannam@48 207
cannam@48 208 # Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
cannam@48 209 AC_MSG_CHECKING([for joinable pthread attribute])
cannam@48 210 attr_name=unknown
cannam@48 211 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
cannam@48 212 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
cannam@48 213 [attr_name=$attr; break])
cannam@48 214 done
cannam@48 215 AC_MSG_RESULT($attr_name)
cannam@48 216 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
cannam@48 217 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
cannam@48 218 [Define to necessary symbol if this constant
cannam@48 219 uses a non-standard name on your system.])
cannam@48 220 fi
cannam@48 221
cannam@48 222 AC_MSG_CHECKING([if more special flags are required for pthreads])
cannam@48 223 flag=no
cannam@48 224 case "${host_cpu}-${host_os}" in
cannam@48 225 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
cannam@48 226 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
cannam@48 227 esac
cannam@48 228 AC_MSG_RESULT(${flag})
cannam@48 229 if test "x$flag" != xno; then
cannam@48 230 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
cannam@48 231 fi
cannam@48 232
cannam@48 233 LIBS="$save_LIBS"
cannam@48 234 CFLAGS="$save_CFLAGS"
cannam@48 235 # More AIX lossage: must compile with xlc_r or cc_r
cannam@48 236 if test x"$GCC" != xyes; then
cannam@48 237 AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC})
cannam@48 238 else
cannam@48 239 PTHREAD_CC=$CC
cannam@48 240 fi
cannam@48 241
cannam@48 242 # The next part tries to detect GCC inconsistency with -shared on some
cannam@48 243 # architectures and systems. The problem is that in certain
cannam@48 244 # configurations, when -shared is specified, GCC "forgets" to
cannam@48 245 # internally use various flags which are still necessary.
cannam@48 246
cannam@48 247 #
cannam@48 248 # Prepare the flags
cannam@48 249 #
cannam@48 250 save_CFLAGS="$CFLAGS"
cannam@48 251 save_LIBS="$LIBS"
cannam@48 252 save_CC="$CC"
cannam@48 253
cannam@48 254 # Try with the flags determined by the earlier checks.
cannam@48 255 #
cannam@48 256 # -Wl,-z,defs forces link-time symbol resolution, so that the
cannam@48 257 # linking checks with -shared actually have any value
cannam@48 258 #
cannam@48 259 # FIXME: -fPIC is required for -shared on many architectures,
cannam@48 260 # so we specify it here, but the right way would probably be to
cannam@48 261 # properly detect whether it is actually required.
cannam@48 262 CFLAGS="-shared -fPIC -Wl,-z,defs $CFLAGS $PTHREAD_CFLAGS"
cannam@48 263 LIBS="$PTHREAD_LIBS $LIBS"
cannam@48 264 CC="$PTHREAD_CC"
cannam@48 265
cannam@48 266 # In order not to create several levels of indentation, we test
cannam@48 267 # the value of "$done" until we find the cure or run out of ideas.
cannam@48 268 done="no"
cannam@48 269
cannam@48 270 # First, make sure the CFLAGS we added are actually accepted by our
cannam@48 271 # compiler. If not (and OS X's ld, for instance, does not accept -z),
cannam@48 272 # then we can't do this test.
cannam@48 273 if test x"$done" = xno; then
cannam@48 274 AC_MSG_CHECKING([whether to check for GCC pthread/shared inconsistencies])
cannam@48 275 AC_TRY_LINK(,, , [done=yes])
cannam@48 276
cannam@48 277 if test "x$done" = xyes ; then
cannam@48 278 AC_MSG_RESULT([no])
cannam@48 279 else
cannam@48 280 AC_MSG_RESULT([yes])
cannam@48 281 fi
cannam@48 282 fi
cannam@48 283
cannam@48 284 if test x"$done" = xno; then
cannam@48 285 AC_MSG_CHECKING([whether -pthread is sufficient with -shared])
cannam@48 286 AC_TRY_LINK([#include <pthread.h>],
cannam@48 287 [pthread_t th; pthread_join(th, 0);
cannam@48 288 pthread_attr_init(0); pthread_cleanup_push(0, 0);
cannam@48 289 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
cannam@48 290 [done=yes])
cannam@48 291
cannam@48 292 if test "x$done" = xyes; then
cannam@48 293 AC_MSG_RESULT([yes])
cannam@48 294 else
cannam@48 295 AC_MSG_RESULT([no])
cannam@48 296 fi
cannam@48 297 fi
cannam@48 298
cannam@48 299 #
cannam@48 300 # Linux gcc on some architectures such as mips/mipsel forgets
cannam@48 301 # about -lpthread
cannam@48 302 #
cannam@48 303 if test x"$done" = xno; then
cannam@48 304 AC_MSG_CHECKING([whether -lpthread fixes that])
cannam@48 305 LIBS="-lpthread $PTHREAD_LIBS $save_LIBS"
cannam@48 306 AC_TRY_LINK([#include <pthread.h>],
cannam@48 307 [pthread_t th; pthread_join(th, 0);
cannam@48 308 pthread_attr_init(0); pthread_cleanup_push(0, 0);
cannam@48 309 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
cannam@48 310 [done=yes])
cannam@48 311
cannam@48 312 if test "x$done" = xyes; then
cannam@48 313 AC_MSG_RESULT([yes])
cannam@48 314 PTHREAD_LIBS="-lpthread $PTHREAD_LIBS"
cannam@48 315 else
cannam@48 316 AC_MSG_RESULT([no])
cannam@48 317 fi
cannam@48 318 fi
cannam@48 319 #
cannam@48 320 # FreeBSD 4.10 gcc forgets to use -lc_r instead of -lc
cannam@48 321 #
cannam@48 322 if test x"$done" = xno; then
cannam@48 323 AC_MSG_CHECKING([whether -lc_r fixes that])
cannam@48 324 LIBS="-lc_r $PTHREAD_LIBS $save_LIBS"
cannam@48 325 AC_TRY_LINK([#include <pthread.h>],
cannam@48 326 [pthread_t th; pthread_join(th, 0);
cannam@48 327 pthread_attr_init(0); pthread_cleanup_push(0, 0);
cannam@48 328 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
cannam@48 329 [done=yes])
cannam@48 330
cannam@48 331 if test "x$done" = xyes; then
cannam@48 332 AC_MSG_RESULT([yes])
cannam@48 333 PTHREAD_LIBS="-lc_r $PTHREAD_LIBS"
cannam@48 334 else
cannam@48 335 AC_MSG_RESULT([no])
cannam@48 336 fi
cannam@48 337 fi
cannam@48 338 if test x"$done" = xno; then
cannam@48 339 # OK, we have run out of ideas
cannam@48 340 AC_MSG_WARN([Impossible to determine how to use pthreads with shared libraries])
cannam@48 341
cannam@48 342 # so it's not safe to assume that we may use pthreads
cannam@48 343 acx_pthread_ok=no
cannam@48 344 fi
cannam@48 345
cannam@48 346 CFLAGS="$save_CFLAGS"
cannam@48 347 LIBS="$save_LIBS"
cannam@48 348 CC="$save_CC"
cannam@48 349 else
cannam@48 350 PTHREAD_CC="$CC"
cannam@48 351 fi
cannam@48 352
cannam@48 353 if test "x$acx_pthread_ok" = xyes; then
cannam@48 354 # One more check: If we chose to use a compiler flag like -pthread but it is combined with
cannam@48 355 # -nostdlib then the compiler won't implicitly link against libpthread. This can happen
cannam@48 356 # in particular when using some versions of libtool on some distros. See:
cannam@48 357 # https://bugzilla.redhat.com/show_bug.cgi?id=661333
cannam@48 358
cannam@48 359 save_CFLAGS="$CFLAGS"
cannam@48 360 save_LIBS="$LIBS"
cannam@48 361 save_CC="$CC"
cannam@48 362 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
cannam@48 363 LIBS="-nostdlib $PTHREAD_LIBS $LIBS -lc"
cannam@48 364 CC="$PTHREAD_CC"
cannam@48 365
cannam@48 366 AC_MSG_CHECKING([whether pthread flag is sufficient with -nostdlib])
cannam@48 367 AC_TRY_LINK([#include <pthread.h>],
cannam@48 368 [pthread_t th; pthread_join(th, 0);
cannam@48 369 pthread_attr_init(0); pthread_cleanup_push(0, 0);
cannam@48 370 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
cannam@48 371 [AC_MSG_RESULT([yes])], [
cannam@48 372 AC_MSG_RESULT([no])
cannam@48 373
cannam@48 374 AC_MSG_CHECKING([whether adding -lpthread fixes that])
cannam@48 375
cannam@48 376 LIBS="-nostdlib $PTHREAD_LIBS -lpthread $save_LIBS -lc"
cannam@48 377 AC_TRY_LINK([#include <pthread.h>],
cannam@48 378 [pthread_t th; pthread_join(th, 0);
cannam@48 379 pthread_attr_init(0); pthread_cleanup_push(0, 0);
cannam@48 380 pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
cannam@48 381 [
cannam@48 382 AC_MSG_RESULT([yes])
cannam@48 383 PTHREAD_LIBS="$PTHREAD_LIBS -lpthread"
cannam@48 384 ], [AC_MSG_RESULT([no])])
cannam@48 385 ])
cannam@48 386
cannam@48 387 CFLAGS="$save_CFLAGS"
cannam@48 388 LIBS="$save_LIBS"
cannam@48 389 CC="$save_CC"
cannam@48 390 fi
cannam@48 391
cannam@48 392 AC_SUBST(PTHREAD_LIBS)
cannam@48 393 AC_SUBST(PTHREAD_CFLAGS)
cannam@48 394 AC_SUBST(PTHREAD_CC)
cannam@48 395
cannam@48 396 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
cannam@48 397 if test x"$acx_pthread_ok" = xyes; then
cannam@48 398 ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
cannam@48 399 :
cannam@48 400 else
cannam@48 401 acx_pthread_ok=no
cannam@48 402 $2
cannam@48 403 fi
cannam@48 404 AC_LANG_RESTORE
cannam@48 405 ])dnl ACX_PTHREAD