Home | History | Annotate | Line # | Download | only in m4
      1  1.1  christos #serial 13
      2  1.1  christos 
      3  1.1  christos dnl From Jim Meyering.
      4  1.1  christos dnl Check for the nanosleep function.
      5  1.1  christos dnl If not found, use the supplied replacement.
      6  1.1  christos dnl
      7  1.1  christos 
      8  1.1  christos # Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005 Free Software Foundation, Inc.
      9  1.1  christos # This file is free software; the Free Software Foundation
     10  1.1  christos # gives unlimited permission to copy and/or distribute it,
     11  1.1  christos # with or without modifications, as long as this notice is preserved.
     12  1.1  christos 
     13  1.1  christos AC_DEFUN([gl_FUNC_NANOSLEEP],
     14  1.1  christos [
     15  1.1  christos  AC_LIBSOURCES([nanosleep.c])
     16  1.1  christos 
     17  1.1  christos  nanosleep_save_libs=$LIBS
     18  1.1  christos 
     19  1.1  christos  # Solaris 2.5.1 needs -lposix4 to get the nanosleep function.
     20  1.1  christos  # Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4.
     21  1.1  christos  AC_SEARCH_LIBS([nanosleep], [rt posix4],
     22  1.1  christos                 [test "$ac_cv_search_nanosleep" = "none required" ||
     23  1.1  christos 	         LIB_NANOSLEEP=$ac_cv_search_nanosleep])
     24  1.1  christos  AC_SUBST([LIB_NANOSLEEP])
     25  1.1  christos 
     26  1.1  christos  AC_CACHE_CHECK([whether nanosleep works],
     27  1.1  christos   jm_cv_func_nanosleep_works,
     28  1.1  christos   [
     29  1.1  christos    AC_REQUIRE([AC_HEADER_TIME])
     30  1.1  christos    AC_CHECK_HEADERS_ONCE(sys/time.h)
     31  1.1  christos    AC_TRY_RUN([
     32  1.1  christos #   if TIME_WITH_SYS_TIME
     33  1.1  christos #    include <sys/time.h>
     34  1.1  christos #    include <time.h>
     35  1.1  christos #   else
     36  1.1  christos #    if HAVE_SYS_TIME_H
     37  1.1  christos #     include <sys/time.h>
     38  1.1  christos #    else
     39  1.1  christos #     include <time.h>
     40  1.1  christos #    endif
     41  1.1  christos #   endif
     42  1.1  christos 
     43  1.1  christos     int
     44  1.1  christos     main ()
     45  1.1  christos     {
     46  1.1  christos       struct timespec ts_sleep, ts_remaining;
     47  1.1  christos       ts_sleep.tv_sec = 0;
     48  1.1  christos       ts_sleep.tv_nsec = 1;
     49  1.1  christos       exit (nanosleep (&ts_sleep, &ts_remaining) == 0 ? 0 : 1);
     50  1.1  christos     }
     51  1.1  christos 	  ],
     52  1.1  christos 	 jm_cv_func_nanosleep_works=yes,
     53  1.1  christos 	 jm_cv_func_nanosleep_works=no,
     54  1.1  christos 	 dnl When crosscompiling, assume the worst.
     55  1.1  christos 	 jm_cv_func_nanosleep_works=no)
     56  1.1  christos   ])
     57  1.1  christos   if test $jm_cv_func_nanosleep_works = no; then
     58  1.1  christos     AC_LIBOBJ(nanosleep)
     59  1.1  christos     AC_DEFINE(nanosleep, rpl_nanosleep,
     60  1.1  christos       [Define to rpl_nanosleep if the replacement function should be used.])
     61  1.1  christos     gl_PREREQ_NANOSLEEP
     62  1.1  christos   fi
     63  1.1  christos 
     64  1.1  christos  LIBS=$nanosleep_save_libs
     65  1.1  christos ])
     66  1.1  christos 
     67  1.1  christos # Prerequisites of lib/nanosleep.c.
     68  1.1  christos AC_DEFUN([gl_PREREQ_NANOSLEEP],
     69  1.1  christos [
     70  1.1  christos   AC_CHECK_HEADERS_ONCE(unistd.h)
     71  1.1  christos   AC_CHECK_FUNCS_ONCE(siginterrupt)
     72  1.1  christos ])
     73