2 dnl Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010,
3 dnl 2011 Free Software Foundation, Inc.
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.
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])
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
35 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
37 CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
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
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
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)
92 pthread_flags="-pthread"
98 pthread_flags="-mthreads"
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"
114 for flag in $pthread_flags; do\
117 AC_MSG_CHECKING([whether pthreads work without any flags])
122 AC_MSG_CHECKING([whether pthreads work with $flag])
123 PTHREAD_CFLAGS="$flag"
128 AC_CHECK_PROG(pth_config, pth-config, yes, no)
129 if test x"$pth_config" = xno; then
132 PTHREAD_CFLAGS="`pth-config --cflags`"
133 PTHREAD_LIBS="`pth-config --ldflags` `pth-config --libs`"
137 AC_CHECK_PROG(pthread_config, pthread-config, yes, no)
138 if test x"$pthread_config" = xno; then
141 PTHREAD_CFLAGS="`pthread-config --cflags`"
142 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
146 AC_MSG_CHECKING([for the pthreads library -l$flag])
147 PTHREAD_LIBS="-l$flag"
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);],
175 CFLAGS="$save_CFLAGS"
176 CXXFLAGS="$save_CXXFLAGS"
178 AC_MSG_RESULT($pthreads)
179 if test "x${pthreads}" = xyes; then
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
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])
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"
200 PTHREAD_LIBS="-lpthread"
202 AC_MSG_RESULT([using $PTHREAD_LIBS])
207 if test x"${PTHREAD_LIBS}" = "x"; then
208 AC_MSG_RESULT(not found)
213 dnl Various other checks:
214 if test "x$pthreads" = xyes; then
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])
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])
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.])
234 AC_MSG_CHECKING([if more special flags are required for pthreads])
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";;
241 AC_MSG_RESULT(${flag})
242 if test "x$flag" != xno; then
243 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
247 CFLAGS="$save_CFLAGS"
249 dnl More AIX lossage: must compile with cc_r (or xlc_r)
254 AC_CHECK_PROG(PTHREAD_CC, xlc_r, xlc_r, ${CC}) ;;
256 AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC}) ;;
260 AC_CHECK_PROG(PTHREAD_CXX, xlC_r, xlC_r, ${CXX}) ;;
266 if test "${PTHREAD_CC}x" = "x"; then
269 if test "${PTHREAD_CXX}x" = "x"; then
273 AC_SUBST(PTHREAD_LIBS)
274 AC_SUBST(PTHREAD_CFLAGS)
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])
292 # indent-tabs-mode: nil