Use AC_DEFINE rather than AC_DEFINE_UNQUOTED, whenever the right hand side need not...
[gnulib.git] / m4 / nanosleep.m4
1 #serial 8
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([jm_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], [LIB_NANOSLEEP=$ac_cv_search_nanosleep])
15  AC_SUBST(LIB_NANOSLEEP)
16
17  AC_CACHE_CHECK([whether nanosleep works],
18   jm_cv_func_nanosleep_works,
19   [
20    AC_REQUIRE([AC_HEADER_TIME])
21    AC_TRY_RUN([
22 #   if TIME_WITH_SYS_TIME
23 #    include <sys/time.h>
24 #    include <time.h>
25 #   else
26 #    if HAVE_SYS_TIME_H
27 #     include <sys/time.h>
28 #    else
29 #     include <time.h>
30 #    endif
31 #   endif
32
33     int
34     main ()
35     {
36       struct timespec ts_sleep, ts_remaining;
37       ts_sleep.tv_sec = 0;
38       ts_sleep.tv_nsec = 1;
39       exit (nanosleep (&ts_sleep, &ts_remaining) == 0 ? 0 : 1);
40     }
41           ],
42          jm_cv_func_nanosleep_works=yes,
43          jm_cv_func_nanosleep_works=no,
44          dnl When crosscompiling, assume the worst.
45          jm_cv_func_nanosleep_works=no)
46   ])
47   if test $jm_cv_func_nanosleep_works = no; then
48     AC_LIBOBJ(nanosleep)
49     AC_DEFINE(nanosleep, rpl_nanosleep,
50       [Define to rpl_nanosleep if the replacement function should be used.])
51   fi
52
53  LIBS=$nanosleep_save_libs
54 ])