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