Change jm_ to gl_ in AC_DEFINE'd names. Update all uses.
[gnulib.git] / m4 / nanosleep.m4
1 #serial 10
2
3 dnl From Jim Meyering.
4 dnl Check for the nanosleep function.
5 dnl If not found, use the supplied replacement.
6 dnl
7
8 AC_DEFUN([gl_FUNC_NANOSLEEP],
9 [
10  nanosleep_save_libs=$LIBS
11
12  # Solaris 2.5.1 needs -lposix4 to get the nanosleep function.
13  # Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4.
14  AC_SEARCH_LIBS([nanosleep], [rt posix4],
15                 [test "$ac_cv_search_nanosleep" = "none required" ||
16                  LIB_NANOSLEEP=$ac_cv_search_nanosleep])
17  AC_SUBST([LIB_NANOSLEEP])
18
19  AC_CACHE_CHECK([whether nanosleep works],
20   jm_cv_func_nanosleep_works,
21   [
22    AC_REQUIRE([AC_HEADER_TIME])
23    AC_CHECK_HEADERS_ONCE(sys/time.h)
24    AC_TRY_RUN([
25 #   if TIME_WITH_SYS_TIME
26 #    include <sys/time.h>
27 #    include <time.h>
28 #   else
29 #    if HAVE_SYS_TIME_H
30 #     include <sys/time.h>
31 #    else
32 #     include <time.h>
33 #    endif
34 #   endif
35
36     int
37     main ()
38     {
39       struct timespec ts_sleep, ts_remaining;
40       ts_sleep.tv_sec = 0;
41       ts_sleep.tv_nsec = 1;
42       exit (nanosleep (&ts_sleep, &ts_remaining) == 0 ? 0 : 1);
43     }
44           ],
45          jm_cv_func_nanosleep_works=yes,
46          jm_cv_func_nanosleep_works=no,
47          dnl When crosscompiling, assume the worst.
48          jm_cv_func_nanosleep_works=no)
49   ])
50   if test $jm_cv_func_nanosleep_works = no; then
51     AC_LIBOBJ(nanosleep)
52     AC_DEFINE(nanosleep, rpl_nanosleep,
53       [Define to rpl_nanosleep if the replacement function should be used.])
54     gl_PREREQ_NANOSLEEP
55   fi
56
57  LIBS=$nanosleep_save_libs
58 ])
59
60 # Prerequisites of lib/nanosleep.c.
61 AC_DEFUN([gl_PREREQ_NANOSLEEP],
62 [
63   AC_CHECK_HEADERS_ONCE(unistd.h)
64 ])