Check for locale.h and the function, setlocale.
[gnulib.git] / m4 / getloadavg.m4
1 #serial 4
2
3 AC_DEFUN(AM_FUNC_GETLOADAVG,
4 [ac_have_func=no # yes means we've found a way to get the load average.
5
6 am_cv_saved_LIBS="$LIBS"
7
8 # On HPUX9, an unprivileged user can get load averages through this function.
9 AC_CHECK_FUNCS(pstat_getdynamic)
10
11 # Solaris has libkstat which does not require root.
12 AC_CHECK_LIB(kstat, kstat_open)
13 if test $ac_cv_lib_kstat_kstat_open = yes ; then ac_have_func=yes ; fi
14
15 # Some systems with -lutil have (and need) -lkvm as well, some do not.
16 # On Solaris, -lkvm requires nlist from -lelf, so check that first
17 # to get the right answer into the cache.
18 # For kstat on solaris, we need libelf to force the definition of SVR4 below.
19 AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
20 if test $ac_have_func = no; then
21   AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
22   # Check for the 4.4BSD definition of getloadavg.
23   AC_CHECK_LIB(util, getloadavg,
24     [LIBS="-lutil $LIBS" ac_have_func=yes ac_cv_func_getloadavg_setgid=yes])
25 fi
26
27 if test $ac_have_func = no; then
28   # There is a commonly available library for RS/6000 AIX.
29   # Since it is not a standard part of AIX, it might be installed locally.
30   ac_save_LIBS="$LIBS"
31   LIBS="-L/usr/local/lib $LIBS"
32   AC_CHECK_LIB(getloadavg, getloadavg,
33     LIBS="-lgetloadavg $LIBS", LIBS="$ac_save_LIBS")
34 fi
35
36 # Make sure it is really in the library, if we think we found it.
37 AC_REPLACE_FUNCS(getloadavg)
38
39 if test $ac_cv_func_getloadavg = yes; then
40   AC_DEFINE(HAVE_GETLOADAVG)
41   ac_have_func=yes
42 else
43   AC_DEFINE(C_GETLOADAVG, 1, [Define if using getloadavg.c.])
44   # Figure out what our getloadavg.c needs.
45   ac_have_func=no
46   AC_CHECK_HEADER(sys/dg_sys_info.h,
47   [ac_have_func=yes; AC_DEFINE(DGUX)
48   AC_CHECK_LIB(dgc, dg_sys_info)])
49
50   AC_CHECK_HEADER(locale.h)
51   AC_CHECK_FUNCS(setlocale)
52
53   # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
54   # uses stabs), but it is still SVR4.  We cannot check for <elf.h> because
55   # Irix 4.0.5F has the header but not the library.
56   if test $ac_have_func = no && test $ac_cv_lib_elf_elf_begin = yes; then
57     ac_have_func=yes; AC_DEFINE(SVR4)
58   fi
59
60   if test $ac_have_func = no; then
61     AC_CHECK_HEADER(inq_stats/cpustats.h,
62     [ac_have_func=yes; AC_DEFINE(UMAX)
63     AC_DEFINE(UMAX4_3)])
64   fi
65
66   if test $ac_have_func = no; then
67     AC_CHECK_HEADER(sys/cpustats.h,
68     [ac_have_func=yes; AC_DEFINE(UMAX)])
69   fi
70
71   if test $ac_have_func = no; then
72     AC_CHECK_HEADERS(mach/mach.h)
73   fi
74
75   AC_CHECK_HEADER(nlist.h,
76   [AC_DEFINE(NLIST_STRUCT)
77   AC_CACHE_CHECK([for n_un in struct nlist], ac_cv_struct_nlist_n_un,
78   [AC_TRY_COMPILE([#include <nlist.h>],
79   [struct nlist n; n.n_un.n_name = 0;],
80   ac_cv_struct_nlist_n_un=yes, ac_cv_struct_nlist_n_un=no)])
81   if test $ac_cv_struct_nlist_n_un = yes; then
82     AC_DEFINE(NLIST_NAME_UNION)
83   fi
84   ])dnl
85 fi # Do not have getloadavg in system libraries.
86
87 # Some definitions of getloadavg require that the program be installed setgid.
88 dnl FIXME Don't hardwire the path of getloadavg.c in the top-level directory.
89 AC_CACHE_CHECK(whether getloadavg requires setgid,
90   ac_cv_func_getloadavg_setgid,
91 [AC_EGREP_CPP([Yowza Am I SETGID yet],
92 [#include "$srcdir/lib/getloadavg.c"
93 #ifdef LDAV_PRIVILEGED
94 Yowza Am I SETGID yet
95 #endif],
96   ac_cv_func_getloadavg_setgid=yes, ac_cv_func_getloadavg_setgid=no)])
97 if test $ac_cv_func_getloadavg_setgid = yes; then
98   NEED_SETGID=true; AC_DEFINE(GETLOADAVG_PRIVILEGED)
99 else
100   NEED_SETGID=false
101 fi
102 AC_SUBST(NEED_SETGID)dnl
103
104 if test $ac_cv_func_getloadavg_setgid = yes; then
105   AC_CACHE_CHECK(group of /dev/kmem, ac_cv_group_kmem,
106 changequote(<<, >>)dnl
107 <<
108   # On Solaris, /dev/kmem is a symlink.  Get info on the real file.
109   ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
110   # If we got an error (system does not support symlinks), try without -L.
111   test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
112   ac_cv_group_kmem=`echo $ac_ls_output \
113     | sed -ne 's/[      ][      ]*/ /g;
114                s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\)  *.*/\1/;
115                / /s/.* //;p;'`
116 >>
117 changequote([, ])dnl
118 )
119   KMEM_GROUP=$ac_cv_group_kmem
120 fi
121 AC_SUBST(KMEM_GROUP)dnl
122
123 if test x = "x$am_cv_saved_LIBS"; then
124   GETLOADAVG_LIBS="$LIBS"
125 else
126   GETLOADAVG_LIBS=`echo "$LIBS"|sed "s!$am_cv_saved_LIBS!!"`
127 fi
128 AC_SUBST(GETLOADAVG_LIBS)dnl
129 LIBS="$am_cv_saved_LIBS"
130 ])