gl_CHECK_NEXT_HEADERS implies AC_CHECK_HEADERS_ONCE
[gnulib.git] / m4 / pthread.m4
1 # pthread.m4
2 dnl Copyright (C) 2009-2011 Free Software Foundation, Inc.
3 dnl This file is free software; the Free Software Foundation
4 dnl gives unlimited permission to copy and/or distribute it,
5 dnl with or without modifications, as long as this notice is preserved.
6
7 AC_DEFUN([gl_PTHREAD_CHECK],
8 [
9    AC_REQUIRE([gl_PTHREAD_DEFAULTS])
10    gl_CHECK_NEXT_HEADERS([pthread.h])
11    if test $ac_cv_header_pthread_h = yes; then
12      HAVE_PTHREAD_H=1
13    else
14      HAVE_PTHREAD_H=0
15    fi
16
17    AC_CHECK_TYPES([pthread_t, pthread_spinlock_t], [], [],
18      [AC_INCLUDES_DEFAULT[
19       #if HAVE_PTHREAD_H
20        #include <pthread.h>
21       #endif]])
22    if test $ac_cv_type_pthread_t != yes; then
23      HAVE_PTHREAD_T=0
24    fi
25    if test $ac_cv_type_pthread_spinlock_t != yes; then
26      HAVE_PTHREAD_SPINLOCK_T=0
27    fi
28
29    if test $ac_cv_header_pthread_h != yes ||
30       test $ac_cv_type_pthread_t != yes ||
31       test $ac_cv_type_pthread_spinlock_t != yes; then
32      PTHREAD_H='pthread.h'
33    fi
34
35    LIB_PTHREAD=
36    if test $ac_cv_header_pthread_h = yes; then
37      gl_saved_libs=$LIBS
38      AC_SEARCH_LIBS([pthread_create], [pthread],
39        [if test "$ac_cv_search_pthread_create" != "none required"; then
40           LIB_PTHREAD="$ac_cv_search_pthread_create"
41         fi])
42      LIBS="$gl_saved_libs"
43    fi
44    AC_SUBST([LIB_PTHREAD])
45
46    AC_REQUIRE([AC_C_INLINE])
47    AC_REQUIRE([AC_C_RESTRICT])
48 ])
49
50 AC_DEFUN([gl_PTHREAD_DEFAULTS],
51 [
52   dnl Assume proper GNU behavior unless another module says otherwise.
53   HAVE_PTHREAD_H=1;              AC_SUBST([HAVE_PTHREAD_H])
54   HAVE_PTHREAD_T=1;              AC_SUBST([HAVE_PTHREAD_T])
55   HAVE_PTHREAD_SPINLOCK_T=1;     AC_SUBST([HAVE_PTHREAD_SPINLOCK_T])
56   PTHREAD_H='';                  AC_SUBST([PTHREAD_H])
57 ])