Avoid the need for AC_LIBSOURCES in m4 macros.
[pspp] / m4 / nanosleep.m4
1 #serial 18
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 # Copyright (C) 1999, 2000, 2001, 2003, 2004, 2005, 2006 Free Software
9 # Foundation, Inc.
10
11 # This file is free software; the Free Software Foundation
12 # gives unlimited permission to copy and/or distribute it,
13 # with or without modifications, as long as this notice is preserved.
14
15 AC_DEFUN([gl_FUNC_NANOSLEEP],
16 [
17  dnl Persuade glibc and Solaris <time.h> to declare nanosleep.
18  AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
19
20  AC_REQUIRE([AC_HEADER_TIME])
21  AC_CHECK_HEADERS_ONCE(sys/time.h)
22
23  nanosleep_save_libs=$LIBS
24
25  # Solaris 2.5.1 needs -lposix4 to get the nanosleep function.
26  # Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4.
27  AC_SEARCH_LIBS([nanosleep], [rt posix4],
28                 [test "$ac_cv_search_nanosleep" = "none required" ||
29                  LIB_NANOSLEEP=$ac_cv_search_nanosleep])
30  AC_SUBST([LIB_NANOSLEEP])
31
32  AC_CACHE_CHECK([for nanosleep],
33   [gl_cv_func_nanosleep],
34   [
35    AC_LINK_IFELSE([AC_LANG_SOURCE([[
36 #   if TIME_WITH_SYS_TIME
37 #    include <sys/time.h>
38 #    include <time.h>
39 #   else
40 #    if HAVE_SYS_TIME_H
41 #     include <sys/time.h>
42 #    else
43 #     include <time.h>
44 #    endif
45 #   endif
46
47     int
48     main ()
49     {
50       struct timespec ts_sleep, ts_remaining;
51       ts_sleep.tv_sec = 0;
52       ts_sleep.tv_nsec = 1;
53       return nanosleep (&ts_sleep, &ts_remaining) < 0;
54     }
55       ]])],
56      [gl_cv_func_nanosleep=yes],
57      [gl_cv_func_nanosleep=no])
58   ])
59   if test $gl_cv_func_nanosleep = no; then
60     AC_LIBOBJ(nanosleep)
61     AC_DEFINE(nanosleep, rpl_nanosleep,
62       [Define to rpl_nanosleep if the replacement function should be used.])
63     gl_PREREQ_NANOSLEEP
64   fi
65
66  LIBS=$nanosleep_save_libs
67 ])
68
69 # Prerequisites of lib/nanosleep.c.
70 AC_DEFUN([gl_PREREQ_NANOSLEEP],
71 [
72   AC_CHECK_FUNCS_ONCE(siginterrupt)
73   AC_CHECK_HEADERS_ONCE(sys/select.h)
74 ])