2 dnl Copyright (C) 2005, 2006, 2009, 2010 Free Software Foundation, Inc.
4 dnl This program is free software; you can redistribute it and/or modify
5 dnl it under the terms of the GNU General Public License as published by
6 dnl the Free Software Foundation; either version 3 of the License, or
7 dnl (at your option) any later version.
9 dnl This program is distributed in the hope that it will be useful,
10 dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
11 dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 dnl GNU General Public License for more details.
13 dnl You should have received a copy of the GNU General Public License
14 dnl along with this program; if not, write to the Free Software
15 dnl Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
17 dnl Copyright (C) 2006 Steven G. Johnson <stevenj@alum.mit.edu>.
19 AC_DEFUN([GNASH_PATH_PTHREADS],
21 AC_REQUIRE([AC_CANONICAL_HOST])
27 dnl We used to check for pthread.h first, but this fails if pthread.h
28 dnl requires special compiler flags (e.g. on True64 or Sequent).
29 dnl It gets checked for in the link test anyway.
31 dnl First of all, check if the user has set any of the PTHREAD_LIBS,
32 dnl etcetera environment variables, and if threads linking works using
34 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
36 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
38 LIBS="$PTHREAD_LIBS $LIBS"
39 AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
40 AC_TRY_LINK_FUNC(pthread_join, pthreads=yes)
41 AC_MSG_RESULT($pthreads)
42 if test x"$pthreads" = xno; then
50 dnl We must check for the threads library under a number of different
51 dnl names; the ordering is very important because some systems
52 dnl (e.g. DEC) have both -lpthread and -lpthreads, where one of the
53 dnl libraries is broken (non-POSIX).
55 dnl Create a list of thread flags to try. Items starting with a "-" are
56 dnl C compiler flags, and other items are library names, except for "none"
57 dnl which indicates that we try without any flags at all, and "pthread-config"
58 dnl which is a program returning the flags for the Pth emulation library.
60 pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config pth-config"
62 dnl When cross configuring, we're always using GCC, and we always have a platform
63 dnl with pthreads in that case, but it's often sonewhere non-standard, so
64 dnl unless this is a problem, assume we don't need any special flags.
65 if test x$cross_compiling = xyes; then
69 dnl The ordering *is* (sometimes) important. Some notes on the
70 dnl individual items follow:
72 dnl pthreads: AIX (must check this before -lpthread)
73 dnl none: in case threads are in libc; should be tried before -Kthread and
74 dnl other compiler flags to prevent continual compiler warnings
75 dnl -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
76 dnl -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
77 dnl lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
78 dnl -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
79 dnl -pthreads: Solaris/gcc
80 dnl -mthreads: Mingw32/gcc, Lynx/gcc
81 dnl -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
82 dnl doesn't hurt to check since this sometimes defines pthreads too;
83 dnl also defines -D_REENTRANT)
84 dnl ... -mt is also the pthreads flag for HP/aCC
85 dnl pthread: Linux, etcetera
86 dnl --thread-safe: KAI C++
87 dnl pth(read)-config: use pthread-config program (for GNU Pth library)
91 pthread_flags="-pthread"
97 pthread_flags="-mthreads"
101 dnl On Solaris (at least, for some versions), libc contains stubbed
102 dnl (non-functional) versions of the pthreads routines, so link-based
103 dnl tests will erroneously succeed. (We need to link with -pthreads/-mt/
104 dnl -lpthread.) (The stubs are missing pthread_cleanup_push, or rather
105 dnl a function called by this macro, so we could check for that, but
106 dnl who knows whether they'll stub that too in a future libc.) So,
107 dnl we'll just look for -pthreads and -lpthread first:
109 pthread_flags="-pthreads pthread -mt -pthread $pthread_flags"
113 for flag in $pthread_flags; do\
116 AC_MSG_CHECKING([whether pthreads work without any flags])
121 AC_MSG_CHECKING([whether pthreads work with $flag])
122 PTHREAD_CFLAGS="$flag"
127 AC_CHECK_PROG(pth_config, pth-config, yes, no)
128 if test x"$pth_config" = xno; then
131 PTHREAD_CFLAGS="`pth-config --cflags`"
132 PTHREAD_LIBS="`pth-config --ldflags` `pth-config --libs`"
136 AC_CHECK_PROG(pthread_config, pthread-config, yes, no)
137 if test x"$pthread_config" = xno; then
140 PTHREAD_CFLAGS="`pthread-config --cflags`"
141 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
145 AC_MSG_CHECKING([for the pthreads library -l$flag])
146 PTHREAD_LIBS="-l$flag"
152 save_CFLAGS="$CFLAGS"
153 save_CXXFLAGS="$CXXFLAGS"
154 LIBS="$PTHREAD_LIBS $LIBS"
155 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
156 CXXFLAGS="$CXXFLAGS $PTHREAD_CFLAGS"
158 dnl Check for various functions. We must include pthread.h,
159 dnl since some functions may be macros. (On the Sequent, we
160 dnl need a special flag -Kthread to make this header compile.)
161 dnl We check for pthread_join because it is in -lpthread on IRIX
162 dnl while pthread_create is in libc. We check for pthread_attr_init
163 dnl due to DEC craziness with -lpthreads. We check for
164 dnl pthread_cleanup_push because it is one of the few pthread
165 dnl functions on Solaris that doesn't have a non-functional libc stub.
166 dnl We try pthread_create on general principles.
167 AC_TRY_LINK([#include <pthread.h>],
168 [pthread_t th; pthread_join(th, 0);
169 pthread_attr_init(0); pthread_cleanup_push(0, 0);
170 pthread_create(0,0,0,0); pthread_cleanup_pop(0);],
174 CFLAGS="$save_CFLAGS"
175 CXXFLAGS="$save_CXXFLAGS"
177 AC_MSG_RESULT($pthreads)
178 if test "x${pthreads}" = xyes; then
183 dnl Try a manual search, useful for cross-compiling
184 if test "x${pthreads}" = xyes; then
185 AC_MSG_CHECKING([searching for pthread library])
186 for i in $libslist; do
187 if test -f $i/libpthread.a -o -f $i/libpthread.${shlibext} -o -f $i/libpthread.dylib; then
189 if test ! x"$i" = x"/usr/lib" -a ! x"$i" = x"/usr/lib64"; then
190 PTHREAD_LIBS="-L$i -lpthread"
191 AC_MSG_RESULT([using $PTHREAD_LIBS])
194 dnl If using Mingw, we have to use the pthreadGCE2 library,as it has
195 dnl has exception handling support for C++.
196 if test x"${host_os}" = x"mingw32"; then
197 PTHREAD_LIBS="-lpthreadGCE2"
199 PTHREAD_LIBS="-lpthread"
201 AC_MSG_RESULT([using $PTHREAD_LIBS])
206 if test x"${PTHREAD_LIBS}" = "x"; then
207 AC_MSG_RESULT(not found)
212 dnl Various other checks:
213 if test "x$pthreads" = xyes; then
215 LIBS="$PTHREAD_LIBS $LIBS"
216 save_CFLAGS="$CFLAGS"
217 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
219 dnl Detect AIX lossage: JOINABLE attribute is called UNDETACHED.
220 AC_MSG_CHECKING([for joinable pthread attribute])
222 for attr in PTHREAD_CREATE_JOINABLE PTHREAD_CREATE_UNDETACHED; do
223 AC_TRY_LINK([#include <pthread.h>], [int attr=$attr; return attr;],
224 [attr_name=$attr; break])
226 AC_MSG_RESULT($attr_name)
227 if test "$attr_name" != PTHREAD_CREATE_JOINABLE; then
228 AC_DEFINE_UNQUOTED(PTHREAD_CREATE_JOINABLE, $attr_name,
229 [Define to necessary symbol if this constant
230 uses a non-standard name on your system.])
233 AC_MSG_CHECKING([if more special flags are required for pthreads])
235 case "${host_cpu}-${host_os}" in
236 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
237 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
238 *irix*) flag="-D_SGI_MP_SOURCE";;
240 AC_MSG_RESULT(${flag})
241 if test "x$flag" != xno; then
242 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
246 CFLAGS="$save_CFLAGS"
248 dnl More AIX lossage: must compile with cc_r (or xlc_r)
253 AC_CHECK_PROG(PTHREAD_CC, xlc_r, xlc_r, ${CC}) ;;
255 AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC}) ;;
259 AC_CHECK_PROG(PTHREAD_CXX, xlC_r, xlC_r, ${CXX}) ;;
265 if test "${PTHREAD_CC}x" = "x"; then
268 if test "${PTHREAD_CXX}x" = "x"; then
272 AC_SUBST(PTHREAD_LIBS)
273 AC_SUBST(PTHREAD_CFLAGS)
275 AC_SUBST(PTHREAD_CXX)
277 dnl Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
278 if test x"$pthreads" = xyes; then
279 ifelse([$1],,AC_DEFINE(HAVE_PTHREADS,1,[Define if you have POSIX threads libraries and header files.]),[$1])
291 # indent-tabs-mode: nil