(jm_FUNC_NANOSLEEP): Search for nanosleep in -lrt
[gnulib.git] / m4 / nanosleep.m4
1 #serial 2
2
3 dnl From Jim Meyering.
4 dnl Check for the nanosleep function
5 dnl
6
7 AC_DEFUN(jm_FUNC_NANOSLEEP,
8 [
9  # Solaris 2.5.1 needs -lposix4 to get the nanosleep function.
10  # Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4.
11  AC_SEARCH_LIBS(nanosleep, [rt posix4])
12
13  AC_CACHE_CHECK([whether nanosleep works],
14   jm_cv_func_nanosleep_works,
15   [AC_TRY_RUN([
16 #   include <time.h>
17
18     int
19     main ()
20     {
21       struct timespec ts_sleep, ts_remaining;
22       ts_sleep.tv_sec = 0;
23       ts_sleep.tv_nsec = 1;
24       exit (nanosleep (&ts_sleep, &ts_remaining) == 0 ? 0 : 1);
25     }
26           ],
27          jm_cv_func_nanosleep_works=yes,
28          jm_cv_func_nanosleep_works=no,
29          dnl When crosscompiling, assume the worst.
30          jm_cv_func_nanosleep_works=yes)
31   ])
32   if test $jm_cv_func_nanosleep_works = no; then
33     AC_SUBST(LIBOBJS)
34     LIBOBJS="$LIBOBJS nanosleep.$ac_objext"
35     AC_DEFINE_UNQUOTED(nanosleep, gnu_nanosleep,
36       [Define to gnu_nanosleep if the replacement function should be used.])
37   fi
38 ])