1 dnl -*- mode: m4; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2 dnl vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4 dnl pandora-build: A pedantic build system
5 dnl Copyright (C) 2009 Sun Microsystems, Inc.
6 dnl This file is free software; Sun Microsystems
7 dnl gives unlimited permission to copy and/or distribute it,
8 dnl with or without modifications, as long as this notice is preserved.
13 dnl --------------------------------------------------------------------
14 dnl Check for libpthread
15 dnl --------------------------------------------------------------------
17 AC_DEFUN([PANDORA_PTHREAD_YIELD],[
18 AC_REQUIRE([ACX_PTHREAD])
20 save_CFLAGS="${CFLAGS}"
21 save_CXXFLAGS="${CXXFLAGS}"
22 CFLAGS="${PTHREAD_CFLAGS} ${CFLAGS}"
23 CXXFLAGS="${PTHREAD_CFLAGS} ${CXXFLAGS}"
24 dnl Some OSes like Mac OS X have that as a replacement for pthread_yield()
25 AC_CHECK_FUNCS(pthread_yield_np)
26 AC_CACHE_CHECK([if pthread_yield takes zero arguments],
27 [pandora_cv_pthread_yield_zero_arg],
34 [pandora_cv_pthread_yield_zero_arg=yes],
35 [pandora_cv_pthread_yield_zero_arg=no])])
36 AS_IF([test "$pandora_cv_pthread_yield_zero_arg" = "yes"],[
37 AC_DEFINE([HAVE_PTHREAD_YIELD_ZERO_ARG], [1],
38 [pthread_yield that doesn't take any arguments])
41 AC_CACHE_CHECK([if pthread_yield takes one argument],
42 [pandora_cv_pthread_yield_one_arg],
49 [pandora_cv_pthread_yield_one_arg=yes],
50 [pandora_cv_pthread_yield_one_arg=no])])
51 AS_IF([test "$pandora_cv_pthread_yield_one_arg" = "yes"],[
52 AC_DEFINE([HAVE_PTHREAD_YIELD_ONE_ARG], [1],
53 [pthread_yield function with one argument])
56 AC_CHECK_FUNCS(pthread_attr_getstacksize pthread_attr_setprio \
57 pthread_attr_setschedparam \
58 pthread_attr_setstacksize pthread_condattr_create pthread_getsequence_np \
59 pthread_key_delete pthread_rwlock_rdlock pthread_setprio \
60 pthread_setprio_np pthread_setschedparam pthread_sigmask \
61 pthread_attr_create rwlock_init
66 # Check definition of pthread_getspecific
67 AC_CACHE_CHECK([args to pthread_getspecific], [pandora_cv_getspecific_args],
68 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
69 #if !defined(_REENTRANT)
72 #ifndef _POSIX_PTHREAD_SEMANTICS
73 #define _POSIX_PTHREAD_SEMANTICS
77 void *pthread_getspecific(pthread_key_t key);
78 pthread_getspecific((pthread_key_t) NULL);
80 [pandora_cv_getspecific_args=POSIX],
81 [pandora_cv_getspecific_args=other])])
82 if test "$pandora_cv_getspecific_args" = "other"
84 AC_DEFINE([HAVE_NONPOSIX_PTHREAD_GETSPECIFIC], [1],
85 [For some non posix threads])
88 # Check definition of pthread_mutex_init
89 AC_CACHE_CHECK([args to pthread_mutex_init], [pandora_cv_mutex_init_args],
90 [AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
94 #ifndef _POSIX_PTHREAD_SEMANTICS
95 #define _POSIX_PTHREAD_SEMANTICS
97 #include <pthread.h> ]], [[
98 pthread_mutexattr_t attr;
100 pthread_mutex_init(&mp,&attr); ]])],
101 [pandora_cv_mutex_init_args=POSIX],
102 [pandora_cv_mutex_init_args=other])])
103 if test "$pandora_cv_mutex_init_args" = "other"
105 AC_DEFINE([HAVE_NONPOSIX_PTHREAD_MUTEX_INIT], [1],
106 [For some non posix threads])
110 #---START: Used in for client configure
111 # Check definition of readdir_r
112 AC_CACHE_CHECK([args to readdir_r], [pandora_cv_readdir_r],
113 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
117 #ifndef _POSIX_PTHREAD_SEMANTICS
118 #define _POSIX_PTHREAD_SEMANTICS
121 #include <dirent.h>]], [[ int readdir_r(DIR *dirp, struct dirent *entry, struct dirent **result);
122 readdir_r((DIR *) NULL, (struct dirent *) NULL, (struct dirent **) NULL); ]])],
123 [pandora_cv_readdir_r=POSIX],
124 [pandora_cv_readdir_r=other])])
125 if test "$pandora_cv_readdir_r" = "POSIX"
127 AC_DEFINE([HAVE_READDIR_R], [1], [POSIX readdir_r])
130 # Check definition of posix sigwait()
131 AC_CACHE_CHECK([style of sigwait], [pandora_cv_sigwait],
132 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
136 #ifndef _POSIX_PTHREAD_SEMANTICS
137 #define _POSIX_PTHREAD_SEMANTICS
148 [pandora_cv_sigwait=POSIX],
149 [pandora_cv_sigwait=other])])
150 if test "$pandora_cv_sigwait" = "POSIX"
152 AC_DEFINE([HAVE_SIGWAIT], [1], [POSIX sigwait])
155 if test "$pandora_cv_sigwait" != "POSIX"
157 unset pandora_cv_sigwait
158 # Check definition of posix sigwait()
159 AC_CACHE_CHECK([style of sigwait], [pandora_cv_sigwait],
160 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
164 #ifndef _POSIX_PTHREAD_SEMANTICS
165 #define _POSIX_PTHREAD_SEMANTICS
174 [pandora_cv_sigwait=NONPOSIX],
175 [pandora_cv_sigwait=other])])
176 if test "$pandora_cv_sigwait" = "NONPOSIX"
178 AC_DEFINE([HAVE_NONPOSIX_SIGWAIT], [1], [sigwait with one argument])
183 # Check if pthread_attr_setscope() exists
184 AC_CACHE_CHECK([for pthread_attr_setscope], [pandora_cv_pthread_attr_setscope],
185 [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
189 #ifndef _POSIX_PTHREAD_SEMANTICS
190 #define _POSIX_PTHREAD_SEMANTICS
194 pthread_attr_t thr_attr;
195 pthread_attr_setscope(&thr_attr,0);
197 [pandora_cv_pthread_attr_setscope=yes],
198 [pandora_cv_pthread_attr_setscope=no])])
199 if test "$pandora_cv_pthread_attr_setscope" = "yes"
201 AC_DEFINE([HAVE_PTHREAD_ATTR_SETSCOPE], [1], [pthread_attr_setscope])
205 AC_CACHE_CHECK([if pthread_yield takes zero arguments], ac_cv_pthread_yield_zero_arg,
206 [AC_TRY_LINK([#define _GNU_SOURCE
214 ], ac_cv_pthread_yield_zero_arg=yes, ac_cv_pthread_yield_zero_arg=yeso)])
215 if test "$ac_cv_pthread_yield_zero_arg" = "yes"
217 AC_DEFINE([HAVE_PTHREAD_YIELD_ZERO_ARG], [1],
218 [pthread_yield that doesn't take any arguments])
220 AC_CACHE_CHECK([if pthread_yield takes 1 argument], ac_cv_pthread_yield_one_arg,
221 [AC_TRY_LINK([#define _GNU_SOURCE
229 ], ac_cv_pthread_yield_one_arg=yes, ac_cv_pthread_yield_one_arg=no)])
230 if test "$ac_cv_pthread_yield_one_arg" = "yes"
232 AC_DEFINE([HAVE_PTHREAD_YIELD_ONE_ARG], [1],
233 [pthread_yield function with one argument])
236 CFLAGS="${save_CFLAGS}"
237 CXXFLAGS="${save_CXXFLAGS}"
241 AC_DEFUN([_PANDORA_SEARCH_PTHREAD],[
242 AC_REQUIRE([ACX_PTHREAD])
243 LIBS="${PTHREAD_LIBS} ${LIBS}"
244 AM_CFLAGS="${PTHREAD_CFLAGS} ${AM_CFLAGS}"
245 AM_CXXFLAGS="${PTHREAD_CFLAGS} ${AM_CXXFLAGS}"
246 PANDORA_PTHREAD_YIELD
250 AC_DEFUN([PANDORA_HAVE_PTHREAD],[
251 AC_REQUIRE([_PANDORA_SEARCH_PTHREAD])
254 AC_DEFUN([PANDORA_REQUIRE_PTHREAD],[
255 AC_REQUIRE([PANDORA_HAVE_PTHREAD])
256 AS_IF([test "x$acx_pthread_ok" != "xyes"],[
257 AC_MSG_ERROR(could not find libpthread)])