An independent .m4 file for each module.
[gnulib.git] / m4 / getloadavg.m4
1 #serial 10
2
3 # A replacement for autoconf's macro by the same name.  This version
4 # accepts an optional argument specifying the name of the $srcdir-relative
5 # directory in which the file getloadavg.c may be found.  It is unusual
6 # (but justified, imho) that this file is required at ./configure time.
7
8 undefine([AC_FUNC_GETLOADAVG])
9
10 # AC_FUNC_GETLOADAVG
11 # ------------------
12 AC_DEFUN([AC_FUNC_GETLOADAVG],
13 [ac_have_func=no # yes means we've found a way to get the load average.
14
15 AC_CHECK_HEADERS_ONCE(fcntl.h locale.h unistd.h)
16 AC_CHECK_HEADERS(mach/mach.h)
17 AC_CHECK_FUNCS(setlocale)
18
19 # By default, expect to find getloadavg.c in $srcdir/.
20 ac_lib_dir_getloadavg=$srcdir
21 # But if there's an argument, DIR, expect to find getloadavg.c in $srcdir/DIR.
22 m4_ifval([$1], [ac_lib_dir_getloadavg=$srcdir/$1])
23 # Make sure getloadavg.c is where it belongs, at ./configure-time.
24 test -f $ac_lib_dir_getloadavg/getloadavg.c \
25   || AC_MSG_ERROR([getloadavg.c is not in $ac_lib_dir_getloadavg])
26 # FIXME: Add an autoconf-time test, too?
27
28 ac_save_LIBS=$LIBS
29
30 # Check for getloadavg, but be sure not to touch the cache variable.
31 (AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && ac_have_func=yes
32
33 # On HPUX9, an unprivileged user can get load averages through this function.
34 AC_CHECK_FUNCS(pstat_getdynamic)
35
36 # Solaris has libkstat which does not require root.
37 AC_CHECK_LIB(kstat, kstat_open)
38 test $ac_cv_lib_kstat_kstat_open = yes && ac_have_func=yes
39
40 # Some systems with -lutil have (and need) -lkvm as well, some do not.
41 # On Solaris, -lkvm requires nlist from -lelf, so check that first
42 # to get the right answer into the cache.
43 # For kstat on solaris, we need libelf to force the definition of SVR4 below.
44 if test $ac_have_func = no; then
45   AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
46 fi
47 if test $ac_have_func = no; then
48   AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
49   # Check for the 4.4BSD definition of getloadavg.
50   AC_CHECK_LIB(util, getloadavg,
51     [LIBS="-lutil $LIBS" ac_have_func=yes ac_cv_func_getloadavg_setgid=yes])
52 fi
53
54 if test $ac_have_func = no; then
55   # There is a commonly available library for RS/6000 AIX.
56   # Since it is not a standard part of AIX, it might be installed locally.
57   ac_getloadavg_LIBS=$LIBS
58   LIBS="-L/usr/local/lib $LIBS"
59   AC_CHECK_LIB(getloadavg, getloadavg,
60                [LIBS="-lgetloadavg $LIBS"], [LIBS=$ac_getloadavg_LIBS])
61 fi
62
63 # Make sure it is really in the library, if we think we found it,
64 # otherwise set up the replacement function.
65 AC_CHECK_FUNCS(getloadavg, [],
66                [_AC_LIBOBJ_GETLOADAVG])
67
68 # Some definitions of getloadavg require that the program be installed setgid.
69 AC_CACHE_CHECK(whether getloadavg requires setgid,
70                ac_cv_func_getloadavg_setgid,
71 [AC_EGREP_CPP([Yowza Am I SETGID yet],
72 [#include "$ac_lib_dir_getloadavg/getloadavg.c"
73 #ifdef LDAV_PRIVILEGED
74 Yowza Am I SETGID yet
75 @%:@endif],
76               ac_cv_func_getloadavg_setgid=yes,
77               ac_cv_func_getloadavg_setgid=no)])
78 if test $ac_cv_func_getloadavg_setgid = yes; then
79   NEED_SETGID=true
80   AC_DEFINE(GETLOADAVG_PRIVILEGED, 1,
81             [Define if the `getloadavg' function needs to be run setuid
82              or setgid.])
83 else
84   NEED_SETGID=false
85 fi
86 AC_SUBST(NEED_SETGID)dnl
87
88 if test $ac_cv_func_getloadavg_setgid = yes; then
89   AC_CACHE_CHECK(group of /dev/kmem, ac_cv_group_kmem,
90 [ # On Solaris, /dev/kmem is a symlink.  Get info on the real file.
91   ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
92   # If we got an error (system does not support symlinks), try without -L.
93   test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
94   ac_cv_group_kmem=`echo $ac_ls_output \
95     | sed -ne ['s/[     ][      ]*/ /g;
96                s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\)  *.*/\1/;
97                / /s/.* //;p;']`
98 ])
99   AC_SUBST(KMEM_GROUP, $ac_cv_group_kmem)dnl
100 fi
101 if test "x$ac_save_LIBS" = x; then
102   GETLOADAVG_LIBS=$LIBS
103 else
104   GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$ac_save_LIBS!!"`
105 fi
106 LIBS=$ac_save_LIBS
107
108 AC_SUBST(GETLOADAVG_LIBS)dnl
109 ])# AC_FUNC_GETLOADAVG
110
111
112 AC_DEFUN([gl_FUNC_GETLOADAVG],
113 [
114   AC_FUNC_GETLOADAVG([lib])
115   dnl Note AC_FUNC_GETLOADAVG does AC_LIBOBJ(getloadavg).
116   if test $ac_cv_func_getloadavg = no; then
117     gl_PREREQ_GETLOADAVG
118   fi
119 ])
120
121 # Prerequisites of lib/getloadavg.c not done by autoconf's AC_FUNC_GETLOADAVG.
122 AC_DEFUN([gl_PREREQ_GETLOADAVG],
123 [
124   AC_CHECK_HEADERS_ONCE(fcntl.h unistd.h)
125 ])