1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/crashreporter/google-breakpad/m4/ax_pthread.m4 Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,283 @@ 1.4 +# =========================================================================== 1.5 +# http://www.nongnu.org/autoconf-archive/ax_pthread.html 1.6 +# =========================================================================== 1.7 +# 1.8 +# SYNOPSIS 1.9 +# 1.10 +# AX_PTHREAD([ACTION-IF-FOUND[, ACTION-IF-NOT-FOUND]]) 1.11 +# 1.12 +# DESCRIPTION 1.13 +# 1.14 +# This macro figures out how to build C programs using POSIX threads. It 1.15 +# sets the PTHREAD_LIBS output variable to the threads library and linker 1.16 +# flags, and the PTHREAD_CFLAGS output variable to any special C compiler 1.17 +# flags that are needed. (The user can also force certain compiler 1.18 +# flags/libs to be tested by setting these environment variables.) 1.19 +# 1.20 +# Also sets PTHREAD_CC to any special C compiler that is needed for 1.21 +# multi-threaded programs (defaults to the value of CC otherwise). (This 1.22 +# is necessary on AIX to use the special cc_r compiler alias.) 1.23 +# 1.24 +# NOTE: You are assumed to not only compile your program with these flags, 1.25 +# but also link it with them as well. e.g. you should link with 1.26 +# $PTHREAD_CC $CFLAGS $PTHREAD_CFLAGS $LDFLAGS ... $PTHREAD_LIBS $LIBS 1.27 +# 1.28 +# If you are only building threads programs, you may wish to use these 1.29 +# variables in your default LIBS, CFLAGS, and CC: 1.30 +# 1.31 +# LIBS="$PTHREAD_LIBS $LIBS" 1.32 +# CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 1.33 +# CC="$PTHREAD_CC" 1.34 +# 1.35 +# In addition, if the PTHREAD_CREATE_JOINABLE thread-attribute constant 1.36 +# has a nonstandard name, defines PTHREAD_CREATE_JOINABLE to that name 1.37 +# (e.g. PTHREAD_CREATE_UNDETACHED on AIX). 1.38 +# 1.39 +# ACTION-IF-FOUND is a list of shell commands to run if a threads library 1.40 +# is found, and ACTION-IF-NOT-FOUND is a list of commands to run it if it 1.41 +# is not found. If ACTION-IF-FOUND is not specified, the default action 1.42 +# will define HAVE_PTHREAD. 1.43 +# 1.44 +# Please let the authors know if this macro fails on any platform, or if 1.45 +# you have any other suggestions or comments. This macro was based on work 1.46 +# by SGJ on autoconf scripts for FFTW (http://www.fftw.org/) (with help 1.47 +# from M. Frigo), as well as ac_pthread and hb_pthread macros posted by 1.48 +# Alejandro Forero Cuervo to the autoconf macro repository. We are also 1.49 +# grateful for the helpful feedback of numerous users. 1.50 +# 1.51 +# LICENSE 1.52 +# 1.53 +# Copyright (c) 2008 Steven G. Johnson <stevenj@alum.mit.edu> 1.54 +# 1.55 +# This program is free software: you can redistribute it and/or modify it 1.56 +# under the terms of the GNU General Public License as published by the 1.57 +# Free Software Foundation, either version 3 of the License, or (at your 1.58 +# option) any later version. 1.59 +# 1.60 +# This program is distributed in the hope that it will be useful, but 1.61 +# WITHOUT ANY WARRANTY; without even the implied warranty of 1.62 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 1.63 +# Public License for more details. 1.64 +# 1.65 +# You should have received a copy of the GNU General Public License along 1.66 +# with this program. If not, see <http://www.gnu.org/licenses/>. 1.67 +# 1.68 +# As a special exception, the respective Autoconf Macro's copyright owner 1.69 +# gives unlimited permission to copy, distribute and modify the configure 1.70 +# scripts that are the output of Autoconf when processing the Macro. You 1.71 +# need not follow the terms of the GNU General Public License when using 1.72 +# or distributing such scripts, even though portions of the text of the 1.73 +# Macro appear in them. The GNU General Public License (GPL) does govern 1.74 +# all other use of the material that constitutes the Autoconf Macro. 1.75 +# 1.76 +# This special exception to the GPL applies to versions of the Autoconf 1.77 +# Macro released by the Autoconf Archive. When you make and distribute a 1.78 +# modified version of the Autoconf Macro, you may extend this special 1.79 +# exception to the GPL to apply to your modified version as well. 1.80 + 1.81 +#serial 6 1.82 + 1.83 +AU_ALIAS([ACX_PTHREAD], [AX_PTHREAD]) 1.84 +AC_DEFUN([AX_PTHREAD], [ 1.85 +AC_REQUIRE([AC_CANONICAL_HOST]) 1.86 +AC_LANG_SAVE 1.87 +AC_LANG_C 1.88 +ax_pthread_ok=no 1.89 + 1.90 +# We used to check for pthread.h first, but this fails if pthread.h 1.91 +# requires special compiler flags (e.g. on True64 or Sequent). 1.92 +# It gets checked for in the link test anyway. 1.93 + 1.94 +# First of all, check if the user has set any of the PTHREAD_LIBS, 1.95 +# etcetera environment variables, and if threads linking works using 1.96 +# them: 1.97 +if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then 1.98 + save_CFLAGS="$CFLAGS" 1.99 + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 1.100 + save_LIBS="$LIBS" 1.101 + LIBS="$PTHREAD_LIBS $LIBS" 1.102 + AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS]) 1.103 + AC_TRY_LINK_FUNC(pthread_join, ax_pthread_ok=yes) 1.104 + AC_MSG_RESULT($ax_pthread_ok) 1.105 + if test x"$ax_pthread_ok" = xno; then 1.106 + PTHREAD_LIBS="" 1.107 + PTHREAD_CFLAGS="" 1.108 + fi 1.109 + LIBS="$save_LIBS" 1.110 + CFLAGS="$save_CFLAGS" 1.111 +fi 1.112 + 1.113 +# We must check for the threads library under a number of different 1.114 +# names; the ordering is very important because some systems 1.115 +# (e.g. DEC) have both -lpthread and -lpthreads, where one of the 1.116 +# libraries is broken (non-POSIX). 1.117 + 1.118 +# Create a list of thread flags to try. Items starting with a "-" are 1.119 +# C compiler flags, and other items are library names, except for "none" 1.120 +# which indicates that we try without any flags at all, and "pthread-config" 1.121 +# which is a program returning the flags for the Pth emulation library. 1.122 + 1.123 +ax_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config" 1.124 + 1.125 +# The ordering *is* (sometimes) important. Some notes on the 1.126 +# individual items follow: 1.127 + 1.128 +# pthreads: AIX (must check this before -lpthread) 1.129 +# none: in case threads are in libc; should be tried before -Kthread and 1.130 +# other compiler flags to prevent continual compiler warnings 1.131 +# -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h) 1.132 +# -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able) 1.133 +# lthread: LinuxThreads port on FreeBSD (also preferred to -pthread) 1.134 +# -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads) 1.135 +# -pthreads: Solaris/gcc 1.136 +# -mthreads: Mingw32/gcc, Lynx/gcc 1.137 +# -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it 1.138 +# doesn't hurt to check since this sometimes defines pthreads too; 1.139 +# also defines -D_REENTRANT) 1.140 +# ... -mt is also the pthreads flag for HP/aCC 1.141 +# pthread: Linux, etcetera 1.142 +# --thread-safe: KAI C++ 1.143 +# pthread-config: use pthread-config program (for GNU Pth library) 1.144 + 1.145 +case "${host_cpu}-${host_os}" in 1.146 + *solaris*) 1.147 + 1.148 + # On Solaris (at least, for some versions), libc contains stubbed 1.149 + # (non-functional) versions of the pthreads routines, so link-based 1.150 + # tests will erroneously succeed. (We need to link with -pthreads/-mt/ 1.151 + # -lpthread.) (The stubs are missing pthread_cleanup_push, or rather 1.152 + # a function called by this macro, so we could check for that, but 1.153 + # who knows whether they'll stub that too in a future libc.) So, 1.154 + # we'll just look for -pthreads and -lpthread first: 1.155 + 1.156 + ax_pthread_flags="-pthreads pthread -mt -pthread $ax_pthread_flags" 1.157 + ;; 1.158 + 1.159 + *-darwin*) 1.160 + acx_pthread_flags="-pthread $acx_pthread_flags" 1.161 + ;; 1.162 +esac 1.163 + 1.164 +if test x"$ax_pthread_ok" = xno; then 1.165 +for flag in $ax_pthread_flags; do 1.166 + 1.167 + case $flag in 1.168 + none) 1.169 + AC_MSG_CHECKING([whether pthreads work without any flags]) 1.170 + ;; 1.171 + 1.172 + -*) 1.173 + AC_MSG_CHECKING([whether pthreads work with $flag]) 1.174 + PTHREAD_CFLAGS="$flag" 1.175 + ;; 1.176 + 1.177 + pthread-config) 1.178 + AC_CHECK_PROG(ax_pthread_config, pthread-config, yes, no) 1.179 + if test x"$ax_pthread_config" = xno; then continue; fi 1.180 + PTHREAD_CFLAGS="`pthread-config --cflags`" 1.181 + PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`" 1.182 + ;; 1.183 + 1.184 + *) 1.185 + AC_MSG_CHECKING([for the pthreads library -l$flag]) 1.186 + PTHREAD_LIBS="-l$flag" 1.187 + ;; 1.188 + esac 1.189 + 1.190 + save_LIBS="$LIBS" 1.191 + save_CFLAGS="$CFLAGS" 1.192 + LIBS="$PTHREAD_LIBS $LIBS" 1.193 + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 1.194 + 1.195 + # Check for various functions. We must include pthread.h, 1.196 + # since some functions may be macros. (On the Sequent, we 1.197 + # need a special flag -Kthread to make this header compile.) 1.198 + # We check for pthread_join because it is in -lpthread on IRIX 1.199 + # while pthread_create is in libc. We check for pthread_attr_init 1.200 + # due to DEC craziness with -lpthreads. We check for 1.201 + # pthread_cleanup_push because it is one of the few pthread 1.202 + # functions on Solaris that doesn't have a non-functional libc stub. 1.203 + # We try pthread_create on general principles. 1.204 + AC_TRY_LINK([#include <pthread.h> 1.205 + static void routine(void* a) {a=0;} 1.206 + static void* start_routine(void* a) {return a;}], 1.207 + [pthread_t th; pthread_attr_t attr; 1.208 + pthread_join(th, 0); 1.209 + pthread_attr_init(&attr); 1.210 + pthread_cleanup_push(routine, 0); 1.211 + pthread_create(&th,0,start_routine,0); 1.212 + pthread_cleanup_pop(0); ], 1.213 + [ax_pthread_ok=yes]) 1.214 + 1.215 + LIBS="$save_LIBS" 1.216 + CFLAGS="$save_CFLAGS" 1.217 + 1.218 + AC_MSG_RESULT($ax_pthread_ok) 1.219 + if test "x$ax_pthread_ok" = xyes; then 1.220 + break; 1.221 + fi 1.222 + 1.223 + PTHREAD_LIBS="" 1.224 + PTHREAD_CFLAGS="" 1.225 +done 1.226 +fi 1.227 + 1.228 +# Various other checks: 1.229 +if test "x$ax_pthread_ok" = xyes; then 1.230 + save_LIBS="$LIBS" 1.231 + LIBS="$PTHREAD_LIBS $LIBS" 1.232 + save_CFLAGS="$CFLAGS" 1.233 + CFLAGS="$CFLAGS $PTHREAD_CFLAGS" 1.234 + 1.235 + # Detect AIX lossage: JOINABLE attribute is called UNDETACHED. 1.236 + AC_MSG_CHECKING([for joinable pthread attribute]) 1.237 + attr_name=unknown 1.238 + for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do 1.239 + AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;], 1.240 + [attr_name=$attr; break]) 1.241 + done 1.242 + AC_MSG_RESULT($attr_name) 1.243 + if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then 1.244 + AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name, 1.245 + [Define to necessary symbol if this constant 1.246 + uses a non-standard name on your system.]) 1.247 + fi 1.248 + 1.249 + AC_MSG_CHECKING([if more special flags are required for pthreads]) 1.250 + flag=no 1.251 + case "${host_cpu}-${host_os}" in 1.252 + *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";; 1.253 + *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";; 1.254 + esac 1.255 + AC_MSG_RESULT(${flag}) 1.256 + if test "x$flag" != xno; then 1.257 + PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS" 1.258 + fi 1.259 + 1.260 + LIBS="$save_LIBS" 1.261 + CFLAGS="$save_CFLAGS" 1.262 + 1.263 + # More AIX lossage: must compile with xlc_r or cc_r 1.264 + if test x"$GCC" != xyes; then 1.265 + AC_CHECK_PROGS(PTHREAD_CC, xlc_r cc_r, ${CC}) 1.266 + else 1.267 + PTHREAD_CC=$CC 1.268 + fi 1.269 +else 1.270 + PTHREAD_CC="$CC" 1.271 +fi 1.272 + 1.273 +AC_SUBST(PTHREAD_LIBS) 1.274 +AC_SUBST(PTHREAD_CFLAGS) 1.275 +AC_SUBST(PTHREAD_CC) 1.276 + 1.277 +# Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND: 1.278 +if test x"$ax_pthread_ok" = xyes; then 1.279 + ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1]) 1.280 + : 1.281 +else 1.282 + ax_pthread_ok=no 1.283 + $2 1.284 +fi 1.285 +AC_LANG_RESTORE 1.286 +])dnl AX_PTHREAD 1.287 \ No newline at end of file