xref: /PHP-5.3/TSRM/threads.m4 (revision 5d4230a7)
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;;
55dnl Solves sigwait() problem, creates problems with u_long etc.
56dnl    PTHREAD_FLAGS="-D_REENTRANT -D_XOPEN_SOURCE=500 -D_POSIX_C_SOURCE=199506 -D_XOPEN_SOURCE_EXTENDED=1";;
57  esac
58
59  if test -n "$PTHREAD_FLAGS"; then
60    CPPFLAGS="$CPPFLAGS $PTHREAD_FLAGS"
61  fi
62])dnl
63dnl
64dnl PTHREADS_CHECK_COMPILE
65dnl
66dnl Check whether the current setup can use POSIX threads calls
67dnl
68AC_DEFUN([PTHREADS_CHECK_COMPILE], [
69AC_TRY_RUN( [
70#include <pthread.h>
71#include <stddef.h>
72
73void *thread_routine(void *data) {
74    return data;
75}
76
77int main() {
78    pthread_t thd;
79    pthread_mutexattr_t mattr;
80    int data = 1;
81    pthread_mutexattr_init(&mattr);
82    return pthread_create(&thd, NULL, thread_routine, &data);
83} ], [
84  pthreads_working=yes
85  ], [
86  pthreads_working=no
87  ], [
88  dnl For cross compiling running this test is of no use. NetWare supports pthreads
89  pthreads_working=no
90  case $host_alias in
91  *netware*)
92    pthreads_working=yes
93  esac
94]
95) ] )dnl
96dnl
97dnl PTHREADS_CHECK()
98dnl
99dnl Try to find a way to enable POSIX threads
100dnl
101dnl  Magic flags
102dnl  -kthread          gcc (FreeBSD)
103dnl  -Kthread          UDK cc (UnixWare)
104dnl  -mt               WorkShop cc (Solaris)
105dnl  -mthreads         gcc (AIX)
106dnl  -pthread          gcc (Linux, FreeBSD, NetBSD, OpenBSD)
107dnl  -pthreads         gcc (Solaris)
108dnl  -qthreaded        AIX cc V5
109dnl  -threads          gcc (HP-UX)
110dnl
111AC_DEFUN([PTHREADS_CHECK],[
112
113if test "$beos_threads" = "1"; then
114  pthreads_working="yes"
115  ac_cv_pthreads_cflags=""
116else
117  save_CFLAGS=$CFLAGS
118  save_LIBS=$LIBS
119  PTHREADS_ASSIGN_VARS
120  PTHREADS_CHECK_COMPILE
121  LIBS=$save_LIBS
122  CFLAGS=$save_CFLAGS
123
124  AC_CACHE_CHECK(for pthreads_cflags,ac_cv_pthreads_cflags,[
125  ac_cv_pthreads_cflags=
126  if test "$pthreads_working" != "yes"; then
127    for flag in -kthread -pthread -pthreads -mthreads -Kthread -threads -mt -qthreaded; do
128      ac_save=$CFLAGS
129      CFLAGS="$CFLAGS $flag"
130      PTHREADS_CHECK_COMPILE
131      CFLAGS=$ac_save
132      if test "$pthreads_working" = "yes"; then
133        ac_cv_pthreads_cflags=$flag
134        break
135      fi
136    done
137  fi
138fi
139])
140
141AC_CACHE_CHECK(for pthreads_lib, ac_cv_pthreads_lib,[
142ac_cv_pthreads_lib=
143if test "$pthreads_working" != "yes"; then
144  for lib in pthread pthreads c_r; do
145    ac_save=$LIBS
146    LIBS="$LIBS -l$lib"
147    PTHREADS_CHECK_COMPILE
148    LIBS=$ac_save
149    if test "$pthreads_working" = "yes"; then
150      ac_cv_pthreads_lib=$lib
151      break
152    fi
153  done
154fi
155])
156
157if test "$pthreads_working" = "yes"; then
158  threads_result="POSIX-Threads found"
159else
160  threads_result="POSIX-Threads not found"
161fi
162])dnl
163dnl
164dnl
165AC_DEFUN([PTHREADS_ASSIGN_VARS],[
166if test -n "$ac_cv_pthreads_lib"; then
167  LIBS="$LIBS -l$ac_cv_pthreads_lib"
168fi
169
170if test -n "$ac_cv_pthreads_cflags"; then
171  CFLAGS="$CFLAGS $ac_cv_pthreads_cflags"
172fi
173])dnl
174