1dnl Copyright (c) 1999, 2000 Sascha Schumann. All rights reserved. 2dnl 3dnl Redistribution and use in source and binary forms, with or without 4dnl modification, are permitted provided that the following conditions 5dnl are met: 6dnl 7dnl 1. Redistributions of source code must retain the above copyright 8dnl notice, this list of conditions and the following disclaimer. 9dnl 10dnl 2. Redistributions in binary form must reproduce the above copyright 11dnl notice, this list of conditions and the following disclaimer in 12dnl the documentation and/or other materials provided with the 13dnl distribution. 14dnl 15dnl THIS SOFTWARE IS PROVIDED BY SASCHA SCHUMANN ``AS IS'' AND ANY 16dnl EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17dnl IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 18dnl PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SASCHA SCHUMANN OR 19dnl HIS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20dnl SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21dnl NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 22dnl LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23dnl HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 24dnl STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25dnl ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 26dnl OF THE POSSIBILITY OF SUCH DAMAGE. 27 28dnl 29dnl PTHREADS_FLAGS 30dnl 31dnl Set some magic defines to achieve POSIX threads conformance. 32dnl 33AC_DEFUN([PTHREADS_FLAGS],[ 34 if test -z "$host_alias" && test -n "$host"; then 35 host_alias=$host 36 fi 37 if test -z "$host_alias"; then 38 AC_MSG_ERROR(host_alias is not set. Make sure to run config.guess) 39 fi 40 case $host_alias in 41 *solaris*) 42 PTHREAD_FLAGS="-D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT";; 43 *freebsd*) 44 PTHREAD_FLAGS="-D_REENTRANT -D_THREAD_SAFE";; 45 *linux*) 46 PTHREAD_FLAGS=-D_REENTRANT;; 47 *aix*) 48 PTHREAD_FLAGS=-D_THREAD_SAFE;; 49 *irix*) 50 PTHREAD_FLAGS=-D_POSIX_THREAD_SAFE_FUNCTIONS;; 51 *hpux*) 52 PTHREAD_FLAGS=-D_REENTRANT;; 53 *sco*) 54 PTHREAD_FLAGS=-D_REENTRANT;; 55 esac 56 57 if test -n "$PTHREAD_FLAGS"; then 58 CPPFLAGS="$CPPFLAGS $PTHREAD_FLAGS" 59 fi 60]) 61 62dnl 63dnl PTHREADS_CHECK_COMPILE 64dnl 65dnl Check whether the current setup can use POSIX threads calls. 66dnl 67AC_DEFUN([PTHREADS_CHECK_COMPILE], [ 68AC_LINK_IFELSE([ AC_LANG_SOURCE([ 69#include <pthread.h> 70#include <stddef.h> 71 72void *thread_routine(void *data) { 73 return data; 74} 75 76int main() { 77 pthread_t thd; 78 pthread_mutexattr_t mattr; 79 int data = 1; 80 pthread_mutexattr_init(&mattr); 81 return pthread_create(&thd, NULL, thread_routine, &data); 82} ]) ], [ 83 pthreads_checked=yes 84 ], [ 85 pthreads_checked=no 86 ] 87) ] ) 88 89dnl 90dnl PTHREADS_CHECK 91dnl 92dnl Try to find a way to enable POSIX threads. 93dnl 94dnl Magic flags 95dnl -kthread gcc (FreeBSD) 96dnl -Kthread UDK cc (UnixWare) 97dnl -mt WorkShop cc (Solaris) 98dnl -mthreads gcc (AIX) 99dnl -pthread gcc (Linux, FreeBSD, NetBSD, OpenBSD) 100dnl -pthreads gcc (Solaris) 101dnl -qthreaded AIX cc V5 102dnl -threads gcc (HP-UX) 103dnl 104AC_DEFUN([PTHREADS_CHECK],[ 105AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[ 106ac_cv_pthreads_cflags= 107if test "$pthreads_working" != "yes"; then 108 for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do 109 ac_save=$CFLAGS 110 CFLAGS="$CFLAGS $flag" 111 PTHREADS_CHECK_COMPILE 112 CFLAGS=$ac_save 113 if test "$pthreads_checked" = "yes"; then 114 ac_cv_pthreads_cflags=$flag 115 break 116 fi 117 done 118fi 119]) 120 121AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[ 122ac_cv_pthreads_lib= 123if test "$pthreads_working" != "yes"; then 124 for lib in pthread pthreads c_r; do 125 ac_save=$LIBS 126 LIBS="$LIBS -l$lib" 127 PTHREADS_CHECK_COMPILE 128 LIBS=$ac_save 129 if test "$pthreads_checked" = "yes"; then 130 ac_cv_pthreads_lib=$lib 131 break 132 fi 133 done 134fi 135]) 136 137if test "x$ac_cv_pthreads_cflags" != "x" -o "x$ac_cv_pthreads_lib" != "x"; then 138 pthreads_working="yes" 139fi 140]) 141