toolkit/crashreporter/google-breakpad/m4/ax_pthread.m4

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial