1# We define, separately, PTHREAD_CFLAGS, _LDFLAGS and _LIBS
2# even though currently we don't set them very separately.
3# This means that the makefiles will not need to change in
4# the future if we make the test more sophisticated.
5
6AC_DEFUN([AX_PTHREAD_CV2VARS],[
7    PTHREAD_CFLAGS="$ax_cv_pthread_flags"
8    PTHREAD_LDFLAGS="$ax_cv_pthread_flags"
9    PTHREAD_LIBS=""
10])
11
12# We invoke AX_PTHREAD_VARS with the name of another macro
13# which is then expanded once for each variable.
14AC_DEFUN([AX_PTHREAD_VARS],[$1(CFLAGS) $1(LDFLAGS) $1(LIBS)])
15
16AC_DEFUN([AX_PTHREAD_VAR_APPLY],[
17    $1="$$1 $PTHREAD_$1"
18])
19AC_DEFUN([AX_PTHREAD_VAR_SUBST],[AC_SUBST(PTHREAD_$1)])
20
21AC_DEFUN([AX_CHECK_PTHREAD],[
22    AC_CACHE_CHECK([for pthread flag], [ax_cv_pthread_flags], [
23        ax_cv_pthread_flags=-pthread
24        AX_PTHREAD_CV2VARS
25        AX_PTHREAD_VARS([AX_SAVEVAR_SAVE])
26        AX_PTHREAD_VARS([AX_PTHREAD_VAR_APPLY])
27        AC_LINK_IFELSE([AC_LANG_SOURCE([
28#include <pthread.h>
29int main(void) {
30  pthread_atfork(0,0,0);
31  pthread_create(0,0,0,0);
32}
33])],[],[ax_cv_pthread_flags=failed])
34        AX_PTHREAD_VARS([AX_SAVEVAR_RESTORE])
35    ])
36    if test "x$ax_cv_pthread_flags" = xfailed; then
37        AC_MSG_ERROR([-pthread does not work])
38    fi
39    AX_PTHREAD_CV2VARS
40    AX_PTHREAD_VARS([AX_PTHREAD_VAR_SUBST])
41])
42