Add automated test on delayed return value handling in ExternalInterface.call().
[gnash.git] / macros / pthreads.m4
blob28d4c6e1b23eba0b2b783fee7d20ac46c0c7476d
1 dnl 
2 dnl  Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 dnl  2011 Free Software Foundation, Inc.
4 dnl  
5 dnl  This program is free software; you can redistribute it and/or modify
6 dnl  it under the terms of the GNU General Public License as published by
7 dnl  the Free Software Foundation; either version 3 of the License, or
8 dnl  (at your option) any later version.
9 dnl  
10 dnl  This program is distributed in the hope that it will be useful,
11 dnl  but WITHOUT ANY WARRANTY; without even the implied warranty of
12 dnl  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 dnl  GNU General Public License for more details.
14 dnl  You should have received a copy of the GNU General Public License
15 dnl  along with this program; if not, write to the Free Software
16 dnl  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18 dnl Copyright (C) 2006 Steven G. Johnson <stevenj@alum.mit.edu>.
20 AC_DEFUN([GNASH_PATH_PTHREADS],
22 AC_REQUIRE([AC_CANONICAL_HOST])
23 AC_LANG_SAVE
24 AC_LANG_C
25 PTHREAD_LIBS=""
26 PTHREAD_CFLAGS=""
28 dnl We used to check for pthread.h first, but this fails if pthread.h
29 dnl requires special compiler flags (e.g. on True64 or Sequent).
30 dnl It gets checked for in the link test anyway.
32 dnl First of all, check if the user has set any of the PTHREAD_LIBS,
33 dnl etcetera environment variables, and if threads linking works using
34 dnl them:
35 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
36   save_CFLAGS="$CFLAGS"
37   CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
38   save_LIBS="$LIBS"
39   LIBS="$PTHREAD_LIBS $LIBS"
40   AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
41   AC_TRY_LINK_FUNC(pthread_join, pthreads=yes)
42   AC_MSG_RESULT($pthreads)
43   if test x"$pthreads" = xno; then
44     PTHREAD_LIBS=""
45     PTHREAD_CFLAGS=""
46   fi
47   LIBS="$save_LIBS"
48   CFLAGS="$save_CFLAGS"
51 dnl We must check for the threads library under a number of different
52 dnl names; the ordering is very important because some systems
53 dnl (e.g. DEC) have both -lpthread and -lpthreads, where one of the
54 dnl libraries is broken (non-POSIX).
56 dnl Create a list of thread flags to try.  Items starting with a "-" are
57 dnl C compiler flags, and other items are library names, except for "none"
58 dnl which indicates that we try without any flags at all, and "pthread-config"
59 dnl which is a program returning the flags for the Pth emulation library.
61 pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config pth-config"
63 dnl When cross configuring, we're always using GCC, and we always have a platform
64 dnl with pthreads in that case, but it's often sonewhere non-standard, so
65 dnl unless this is a problem, assume we don't need any special flags.
66 if test x$cross_compiling = xyes; then
67     pthread_flags="none"
70 dnl The ordering *is* (sometimes) important.  Some notes on the
71 dnl individual items follow:
73 dnl pthreads:   AIX (must check this before -lpthread)
74 dnl none:       in case threads are in libc; should be tried before -Kthread and
75 dnl             other compiler flags to prevent continual compiler warnings
76 dnl -Kthread:   Sequent (threads in libc, but -Kthread needed for pthread.h)
77 dnl -kthread:   FreeBSD kernel threads (preferred to -pthread since SMP-able)
78 dnl lthread:    LinuxThreads port on FreeBSD (also preferred to -pthread)
79 dnl -pthread:   Linux/gcc (kernel threads), BSD/gcc (userland threads)
80 dnl -pthreads:  Solaris/gcc
81 dnl -mthreads:  Mingw32/gcc, Lynx/gcc
82 dnl -mt:                Sun Workshop C (may only link SunOS threads [-lthread], but it
83 dnl             doesn't hurt to check since this sometimes defines pthreads too;
84 dnl             also defines -D_REENTRANT)
85 dnl             ... -mt is also the pthreads flag for HP/aCC
86 dnl pthread:    Linux, etcetera
87 dnl --thread-safe: KAI C++
88 dnl pth(read)-config: use pthread-config program (for GNU Pth library)
90 case "${host_os}" in
91   *linux* | *bsd*)
92     pthread_flags="-pthread"
93     ;;
94   *darwin*)
95     pthread_flags="none"
96     ;;
97   *mingw* | *cygwin*)
98     pthread_flags="-mthreads"
99     ;;
100   *solaris*)
102   dnl On Solaris (at least, for some versions), libc contains stubbed
103   dnl (non-functional) versions of the pthreads routines, so link-based
104   dnl tests will erroneously succeed.  (We need to link with -pthreads/-mt/
105   dnl -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
106   dnl a function called by this macro, so we could check for that, but
107   dnl who knows whether they'll stub that too in a future libc.)  So,
108   dnl we'll just look for -pthreads and -lpthread first:
110     pthread_flags="-pthreads pthread -mt -pthread $pthread_flags"
111     ;;
112 esac
114 for flag in $pthread_flags; do\
115     case $flag in
116       none)
117         AC_MSG_CHECKING([whether pthreads work without any flags])
118         PTHREAD_CFLAGS=""
119         PTHREAD_LIBS=""
120         ;;
121       -*)
122         AC_MSG_CHECKING([whether pthreads work with $flag])
123         PTHREAD_CFLAGS="$flag"
124               PTHREAD_LIBS=""
125         ;;
127       pth-config)
128        AC_CHECK_PROG(pth_config, pth-config, yes, no)
129        if test x"$pth_config" = xno; then
130          continue;
131        fi
132        PTHREAD_CFLAGS="`pth-config --cflags`"
133        PTHREAD_LIBS="`pth-config --ldflags` `pth-config --libs`"
134        ;;
136       pthread-config)
137        AC_CHECK_PROG(pthread_config, pthread-config, yes, no)
138        if test x"$pthread_config" = xno; then
139          continue;
140        fi
141        PTHREAD_CFLAGS="`pthread-config --cflags`"
142        PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
143        ;;
145       *)
146         AC_MSG_CHECKING([for the pthreads library -l$flag])
147         PTHREAD_LIBS="-l$flag"
148               PTHREAD_CFLAGS=""
149         ;;
150     esac
152     save_LIBS="$LIBS"
153     save_CFLAGS="$CFLAGS"
154     save_CXXFLAGS="$CXXFLAGS"
155     LIBS="$PTHREAD_LIBS $LIBS"
156     CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
157     CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
159     dnl Check for various functions.  We must include pthread.h,
160     dnl since some functions may be macros.  (On the Sequent, we
161     dnl need a special flag -Kthread to make this header compile.)
162     dnl We check for pthread_join because it is in -lpthread on IRIX
163     dnl while pthread_create is in libc.  We check for pthread_attr_init
164     dnl due to DEC craziness with -lpthreads.  We check for
165     dnl pthread_cleanup_push because it is one of the few pthread
166     dnl functions on Solaris that doesn't have a non-functional libc stub.
167     dnl We try pthread_create on general principles.
168     AC_TRY_LINK([#include <pthread.h>],
169       [pthread_t th; pthread_join(th, 0);
170       pthread_attr_init(0); pthread_cleanup_push(0, 0);
171       pthread_create(0,0,0,0); pthread_cleanup_pop(0);],
172       [pthreads=yes])
174     LIBS="$save_LIBS"
175     CFLAGS="$save_CFLAGS"
176     CXXFLAGS="$save_CXXFLAGS"
178     AC_MSG_RESULT($pthreads)
179     if test "x${pthreads}" = xyes; then
180        break;
181     fi
182 done
184 dnl Try a manual search, useful for cross-compiling
185 if test "x${pthreads}" = xyes; then
186   AC_MSG_CHECKING([searching for pthread library])
187   for i in $libslist; do
188     if test -f $i/libpthread.a -o -f $i/libpthread.${shlibext} -o -f $i/libpthread.dylib; then
189       pthreads=yes
190       if test ! x"$i" = x"/usr/lib" -a ! x"$i" = x"/usr/lib64"; then
191         PTHREAD_LIBS="-L$i -lpthread"
192         AC_MSG_RESULT([using $PTHREAD_LIBS])
193         break
194       else
195         dnl If using Mingw, we have to use the pthreadGCE2 library,as it has
196         dnl has exception handling support for C++.
197         if test x"${host_os}" = x"mingw32"; then
198           PTHREAD_LIBS="-lpthreadGCE2"
199         else
200           PTHREAD_LIBS="-lpthread"
201         fi
202         AC_MSG_RESULT([using $PTHREAD_LIBS])
203         break
204       fi
205     fi
206   done
207   if test x"${PTHREAD_LIBS}" = "x"; then
208     AC_MSG_RESULT(not found)
209     pthreads=no
210   fi
213 dnl Various other checks:
214 if test "x$pthreads" = xyes; then
215   save_LIBS="$LIBS"
216   LIBS="$PTHREAD_LIBS $LIBS"
217   save_CFLAGS="$CFLAGS"
218   CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
220   dnl Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
221   AC_MSG_CHECKING([for joinable pthread attribute])
222   attr_name=unknown
223   for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
224     AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
225       [attr_name=$attr; break])
226   done
227   AC_MSG_RESULT($attr_name)
228   if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
229     AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
230       [Define to necessary symbol if this constant
231       uses a non-standard name on your system.])
232   fi
234   AC_MSG_CHECKING([if more special flags are required for pthreads])
235   flag=no
236   case "${host_cpu}-${host_os}" in
237     *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
238     *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
239     *irix*) flag="-D_SGI_MP_SOURCE";;
240   esac
241   AC_MSG_RESULT(${flag})
242   if test "x$flag" != xno; then
243     PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
244   fi
246   LIBS="$save_LIBS"
247   CFLAGS="$save_CFLAGS"
249   dnl More AIX lossage: must compile with cc_r (or xlc_r)
250   case "${host_os}" in
251     aix* )
252       case "$CC" in
253     *xlc )
254       AC_CHECK_PROG(PTHREAD_CC, xlc_r, xlc_r, ${CC}) ;;
255     *cc )
256       AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC}) ;;
257   esac
258   case "$CXX" in
259     *xlC )
260       AC_CHECK_PROG(PTHREAD_CXX, xlC_r, xlC_r, ${CXX}) ;;
261   esac
262      ;;
263   esac
266 if test "${PTHREAD_CC}x" = "x"; then
267   PTHREAD_CC="$CC"
269 if test "${PTHREAD_CXX}x" = "x"; then
270   PTHREAD_CXX="$CXX"
273 AC_SUBST(PTHREAD_LIBS)
274 AC_SUBST(PTHREAD_CFLAGS)
275 AC_SUBST(PTHREAD_CC)
276 AC_SUBST(PTHREAD_CXX)
278 dnl Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
279 if test x"$pthreads" = xyes; then
280   ifelse([$1],,AC_DEFINE(HAVE_PTHREADS,1,[Define if you have POSIX threads libraries and header files.]),[$1])
281         :
282 else
283   pthreads=no
284   $2
286   AC_LANG_RESTORE
289 # Local Variables:
290 # c-basic-offset: 2
291 # tab-width: 2
292 # indent-tabs-mode: nil
293 # End: