increase operation timeout
[pulseaudio.git] / acinclude.m4
blobf3a4ac5207311a3fae782fd9751c95965f4c99df
1 dnl Available from the GNU Autoconf Macro Archive at:
2 dnl http://www.gnu.org/software/ac-archive/htmldoc/acx_pthread.html
3 dnl
4 AC_DEFUN([ACX_PTHREAD], [
5 AC_REQUIRE([AC_CANONICAL_HOST])
6 AC_LANG_SAVE
7 AC_LANG_C
8 acx_pthread_ok=no
10 # We used to check for pthread.h first, but this fails if pthread.h
11 # requires special compiler flags (e.g. on True64 or Sequent).
12 # It gets checked for in the link test anyway.
14 # First of all, check if the user has set any of the PTHREAD_LIBS,
15 # etcetera environment variables, and if threads linking works using
16 # them:
17 if test x"$PTHREAD_LIBS$PTHREAD_CFLAGS" != x; then
18         save_CFLAGS="$CFLAGS"
19         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
20         save_LIBS="$LIBS"
21         LIBS="$PTHREAD_LIBS $LIBS"
22         AC_MSG_CHECKING([for pthread_join in LIBS=$PTHREAD_LIBS with CFLAGS=$PTHREAD_CFLAGS])
23         AC_TRY_LINK_FUNC(pthread_join, acx_pthread_ok=yes)
24         AC_MSG_RESULT($acx_pthread_ok)
25         if test x"$acx_pthread_ok" = xno; then
26                 PTHREAD_LIBS=""
27                 PTHREAD_CFLAGS=""
28         fi
29         LIBS="$save_LIBS"
30         CFLAGS="$save_CFLAGS"
33 # We must check for the threads library under a number of different
34 # names; the ordering is very important because some systems
35 # (e.g. DEC) have both -lpthread and -lpthreads, where one of the
36 # libraries is broken (non-POSIX).
38 # Create a list of thread flags to try.  Items starting with a "-" are
39 # C compiler flags, and other items are library names, except for "none"
40 # which indicates that we try without any flags at all, and "pthread-config"
41 # which is a program returning the flags for the Pth emulation library.
43 acx_pthread_flags="pthreads none -Kthread -kthread lthread -pthread -pthreads -mthreads pthread --thread-safe -mt pthread-config"
45 # The ordering *is* (sometimes) important.  Some notes on the
46 # individual items follow:
48 # pthreads: AIX (must check this before -lpthread)
49 # none: in case threads are in libc; should be tried before -Kthread and
50 #       other compiler flags to prevent continual compiler warnings
51 # -Kthread: Sequent (threads in libc, but -Kthread needed for pthread.h)
52 # -kthread: FreeBSD kernel threads (preferred to -pthread since SMP-able)
53 # lthread: LinuxThreads port on FreeBSD (also preferred to -pthread)
54 # -pthread: Linux/gcc (kernel threads), BSD/gcc (userland threads)
55 # -pthreads: Solaris/gcc
56 # -mthreads: Mingw32/gcc, Lynx/gcc
57 # -mt: Sun Workshop C (may only link SunOS threads [-lthread], but it
58 #      doesn't hurt to check since this sometimes defines pthreads too;
59 #      also defines -D_REENTRANT)
60 # pthread: Linux, etcetera
61 # --thread-safe: KAI C++
62 # pthread-config: use pthread-config program (for GNU Pth library)
64 case "${host_cpu}-${host_os}" in
65         *solaris*)
67         # On Solaris (at least, for some versions), libc contains stubbed
68         # (non-functional) versions of the pthreads routines, so link-based
69         # tests will erroneously succeed.  (We need to link with -pthread or
70         # -lpthread.)  (The stubs are missing pthread_cleanup_push, or rather
71         # a function called by this macro, so we could check for that, but
72         # who knows whether they'll stub that too in a future libc.)  So,
73         # we'll just look for -pthreads and -lpthread first:
75         acx_pthread_flags="-pthread -pthreads pthread -mt $acx_pthread_flags"
76         ;;
77 esac
79 if test x"$acx_pthread_ok" = xno; then
80 for flag in $acx_pthread_flags; do
82         case $flag in
83                 none)
84                 AC_MSG_CHECKING([whether pthreads work without any flags])
85                 ;;
87                 -*)
88                 AC_MSG_CHECKING([whether pthreads work with $flag])
89                 PTHREAD_CFLAGS="$flag"
90                 ;;
92                 pthread-config)
93                 AC_CHECK_PROG(acx_pthread_config, pthread-config, yes, no)
94                 if test x"$acx_pthread_config" = xno; then continue; fi
95                 PTHREAD_CFLAGS="`pthread-config --cflags`"
96                 PTHREAD_LIBS="`pthread-config --ldflags` `pthread-config --libs`"
97                 ;;
99                 *)
100                 AC_MSG_CHECKING([for the pthreads library -l$flag])
101                 PTHREAD_LIBS="-l$flag"
102                 ;;
103         esac
105         save_LIBS="$LIBS"
106         save_CFLAGS="$CFLAGS"
107         LIBS="$PTHREAD_LIBS $LIBS"
108         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
110         # Check for various functions.  We must include pthread.h,
111         # since some functions may be macros.  (On the Sequent, we
112         # need a special flag -Kthread to make this header compile.)
113         # We check for pthread_join because it is in -lpthread on IRIX
114         # while pthread_create is in libc.  We check for pthread_attr_init
115         # due to DEC craziness with -lpthreads.  We check for
116         # pthread_cleanup_push because it is one of the few pthread
117         # functions on Solaris that doesn't have a non-functional libc stub.
118         # We try pthread_create on general principles.
119         AC_TRY_LINK([#include <pthread.h>],
120                     [pthread_t th; pthread_join(th, 0);
121                      pthread_attr_init(0); pthread_cleanup_push(0, 0);
122                      pthread_create(0,0,0,0); pthread_cleanup_pop(0); ],
123                     [acx_pthread_ok=yes])
125         LIBS="$save_LIBS"
126         CFLAGS="$save_CFLAGS"
128         AC_MSG_RESULT($acx_pthread_ok)
129         if test "x$acx_pthread_ok" = xyes; then
130                 break;
131         fi
133         PTHREAD_LIBS=""
134         PTHREAD_CFLAGS=""
135 done
138 # Various other checks:
139 if test "x$acx_pthread_ok" = xyes; then
140         save_LIBS="$LIBS"
141         LIBS="$PTHREAD_LIBS $LIBS"
142         save_CFLAGS="$CFLAGS"
143         CFLAGS="$CFLAGS $PTHREAD_CFLAGS"
145         # Detect AIX lossage: threads are created detached by default
146         # and the JOINABLE attribute has a nonstandard name (UNDETACHED).
147         AC_MSG_CHECKING([for joinable pthread attribute])
148         AC_TRY_LINK([#include <pthread.h>],
149                     [int attr=PTHREAD_CREATE_JOINABLE;],
150                     ok=PTHREAD_CREATE_JOINABLE, ok=unknown)
151         if test x"$ok" = xunknown; then
152                 AC_TRY_LINK([#include <pthread.h>],
153                             [int attr=PTHREAD_CREATE_UNDETACHED;],
154                             ok=PTHREAD_CREATE_UNDETACHED, ok=unknown)
155         fi
156         if test x"$ok" != xPTHREAD_CREATE_JOINABLE; then
157                 AC_DEFINE(PTHREAD_CREATE_JOINABLE, $ok,
158                           [Define to the necessary symbol if this constant
159                            uses a non-standard name on your system.])
160         fi
161         AC_MSG_RESULT(${ok})
162         if test x"$ok" = xunknown; then
163                 AC_MSG_WARN([we do not know how to create joinable pthreads])
164         fi
166         AC_MSG_CHECKING([if more special flags are required for pthreads])
167         flag=no
168         case "${host_cpu}-${host_os}" in
169                 *-aix* | *-freebsd* | *-darwin*) flag="-D_THREAD_SAFE";;
170                 *solaris* | *-osf* | *-hpux*) flag="-D_REENTRANT";;
171         esac
172         AC_MSG_RESULT(${flag})
173         if test "x$flag" != xno; then
174                 PTHREAD_CFLAGS="$flag $PTHREAD_CFLAGS"
175         fi
177         AC_MSG_CHECKING([if pthread_yield is available])
178         flag=no
179         AC_TRY_LINK([#include <pthread.h>],
180                     [pthread_yield();],
181                     [flag=yes])
182         AC_MSG_RESULT(${flag})
183         if test "x$flag" != xno; then
184                 AC_DEFINE(HAVE_PTHREAD_YIELD, 1,
185                           [Define to 1 if you have the 'pthread_yield' function.])
186         fi
188         LIBS="$save_LIBS"
189         CFLAGS="$save_CFLAGS"
191         # More AIX lossage: must compile with cc_r
192         AC_CHECK_PROG(PTHREAD_CC, cc_r, cc_r, ${CC})
193 else
194         PTHREAD_CC="$CC"
197 AC_SUBST(PTHREAD_LIBS)
198 AC_SUBST(PTHREAD_CFLAGS)
199 AC_SUBST(PTHREAD_CC)
201 # Finally, execute ACTION-IF-FOUND/ACTION-IF-NOT-FOUND:
202 if test x"$acx_pthread_ok" = xyes; then
203         ifelse([$1],,AC_DEFINE(HAVE_PTHREAD,1,[Define if you have POSIX threads libraries and header files.]),[$1])
204         :
205 else
206         acx_pthread_ok=no
207         $2
209 AC_LANG_RESTORE
210 ])dnl ACX_PTHREAD
212 AC_DEFUN([AC_CHECK_DEFINE],[
213 AS_VAR_PUSHDEF([ac_var],[ac_cv_defined_$1_$2])dnl
214 AC_CACHE_CHECK([for $1 in $2], ac_var,
215 AC_TRY_COMPILE([#include <$2>],[
216   #ifdef $1
217   int ok;
218   #else
219   choke me
220   #endif
221 ],AS_VAR_SET(ac_var, yes),AS_VAR_SET(ac_var, no)))
222 AS_IF([test AS_VAR_GET(ac_var) != "no"], [$3], [$4])dnl
223 AS_VAR_POPDEF([ac_var])dnl
226 AC_DEFUN([ACX_LIBWRAP], [
227 LIBWRAP_LIBS=
228 saved_LIBS="$LIBS"
229 LIBS="$LIBS -lwrap"
230 AC_MSG_CHECKING([for tcpwrap library and headers])
231 AC_LINK_IFELSE(
232 AC_LANG_PROGRAM(
233 [#include <tcpd.h>
234 #include <syslog.h>
235 int allow_severity = LOG_INFO;
236 int deny_severity = LOG_WARNING;],
237 [struct request_info *req; 
238 return hosts_access (req);]),
239 [AC_DEFINE(HAVE_LIBWRAP, [], [Have tcpwrap?])
240 LIBWRAP_LIBS="-lwrap"
241 AC_MSG_RESULT(yes)],
242 [AC_MSG_RESULT(no)])
243 LIBS="$saved_LIBS"
246 AC_DEFUN([ACX_LIRC], [
247 LIRC_CFLAGS=
248 LIRC_LIBS=
249 AC_CHECK_HEADER(lirc/lirc_client.h,[AC_CHECK_LIB(lirc_client,lirc_init,[HAVE_LIRC=1
250 LIRC_LIBS=-llirc_client],HAVE_LIRC=0)],HAVE_LIRC=0)