1 # Check for getloadavg.
3 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2002, 2003,
4 # 2006 Free Software Foundation, Inc.
6 # This file is free software; the Free Software Foundation
7 # gives unlimited permission to copy and/or distribute it,
8 # with or without modifications, as long as this notice is preserved.
10 # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
11 # New applications should use gl_GETLOADAVG instead.
13 # gl_GETLOADAVG(LIBOBJDIR)
14 # ------------------------
15 AC_DEFUN([gl_GETLOADAVG],
16 [gl_have_func=no # yes means we've found a way to get the load average.
18 # Make sure getloadavg.c is where it belongs, at configure-time.
19 test -f "$srcdir/$1/getloadavg.c" ||
20 AC_MSG_ERROR([$srcdir/$1/getloadavg.c is missing])
24 # Check for getloadavg, but be sure not to touch the cache variable.
25 (AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && gl_have_func=yes
27 # On HPUX9, an unprivileged user can get load averages through this function.
28 AC_CHECK_FUNCS(pstat_getdynamic)
30 # Solaris has libkstat which does not require root.
31 AC_CHECK_LIB(kstat, kstat_open)
32 test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes
34 # AIX has libperfstat which does not require root
35 AC_CHECK_LIB(perfstat, perfstat_cpu_total)
36 test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_have_func=yes
38 # Some systems with -lutil have (and need) -lkvm as well, some do not.
39 # On Solaris, -lkvm requires nlist from -lelf, so check that first
40 # to get the right answer into the cache.
41 # For kstat on solaris, we need libelf to force the definition of SVR4 below.
42 if test $gl_have_func = no; then
43 AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
45 if test $gl_have_func = no; then
46 AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
47 # Check for the 4.4BSD definition of getloadavg.
48 AC_CHECK_LIB(util, getloadavg,
49 [LIBS="-lutil $LIBS" gl_have_func=yes gl_cv_func_getloadavg_setgid=yes])
52 if test $gl_have_func = no; then
53 # There is a commonly available library for RS/6000 AIX.
54 # Since it is not a standard part of AIX, it might be installed locally.
55 gl_getloadavg_LIBS=$LIBS
56 LIBS="-L/usr/local/lib $LIBS"
57 AC_CHECK_LIB(getloadavg, getloadavg,
58 [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS])
61 # Make sure it is really in the library, if we think we found it,
62 # otherwise set up the replacement function.
63 AC_CHECK_FUNCS(getloadavg, [],
64 [gl_PREREQ_GETLOADAVG])
66 # Some definitions of getloadavg require that the program be installed setgid.
67 AC_CACHE_CHECK(whether getloadavg requires setgid,
68 gl_cv_func_getloadavg_setgid,
69 [AC_EGREP_CPP([Yowza Am I SETGID yet],
70 [#define CONFIGURING_GETLOADAVG
71 #include "$srcdir/$1/getloadavg.c"
72 #ifdef LDAV_PRIVILEGED
76 gl_cv_func_getloadavg_setgid=yes,
77 gl_cv_func_getloadavg_setgid=no)])
78 if test $gl_cv_func_getloadavg_setgid = yes; then
80 AC_DEFINE(GETLOADAVG_PRIVILEGED, 1,
81 [Define to 1 if the `getloadavg' function needs to be run setuid
86 AC_SUBST(NEED_SETGID)dnl
88 if test $gl_cv_func_getloadavg_setgid = yes; then
89 AC_CACHE_CHECK(group of /dev/kmem, gl_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 gl_cv_group_kmem=`echo $ac_ls_output \
95 | sed -ne ['s/[ ][ ]*/ /g
96 s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/
99 AC_SUBST(KMEM_GROUP, $gl_cv_group_kmem)dnl
101 if test "x$gl_save_LIBS" = x; then
102 GETLOADAVG_LIBS=$LIBS
104 GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"`
108 AC_SUBST(GETLOADAVG_LIBS)dnl
112 # gl_PREREQ_GETLOADAVG
113 # --------------------
114 # Set up the AC_LIBOBJ replacement of `getloadavg'.
115 AC_DEFUN([gl_PREREQ_GETLOADAVG],
116 [AC_LIBOBJ(getloadavg)
117 AC_DEFINE(C_GETLOADAVG, 1, [Define to 1 if using `getloadavg.c'.])
118 # Figure out what our getloadavg.c needs.
120 AC_CHECK_HEADER(sys/dg_sys_info.h,
122 AC_DEFINE(DGUX, 1, [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
123 AC_CHECK_LIB(dgc, dg_sys_info)])
125 # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
126 # uses stabs), but it is still SVR4. We cannot check for <elf.h> because
127 # Irix 4.0.5F has the header but not the library.
128 if test $gl_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes; then
130 AC_DEFINE(SVR4, 1, [Define to 1 on System V Release 4.])
133 if test $gl_have_func = no; then
134 AC_CHECK_HEADER(inq_stats/cpustats.h,
136 AC_DEFINE(UMAX, 1, [Define to 1 for Encore UMAX.])
137 AC_DEFINE(UMAX4_3, 1,
138 [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
139 instead of <sys/cpustats.h>.])])
142 if test $gl_have_func = no; then
143 AC_CHECK_HEADER(sys/cpustats.h,
144 [gl_have_func=yes; AC_DEFINE(UMAX)])
147 if test $gl_have_func = no; then
148 AC_CHECK_HEADERS(mach/mach.h)
151 AC_CHECK_HEADERS(nlist.h,
152 [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
153 [AC_DEFINE(NLIST_NAME_UNION, 1,
154 [Define to 1 if your `struct nlist' has an
155 `n_un' member. Obsolete, depend on
156 `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
157 [@%:@include <nlist.h>])
159 ])# gl_PREREQ_GETLOADAVG