33ec478b24d8a52dbdc400a17d3219af01207635
[pspp] / m4 / getloadavg.m4
1 # Check for getloadavg.
2
3 # Copyright (C) 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2002, 2003,
4 # 2006 Free Software Foundation, Inc.
5
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.
9
10 # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
11 # New applications should use gl_GETLOADAVG instead.
12
13 # gl_PREREQ_GETLOADAVG
14 # --------------------
15 # Set up the AC_LIBOBJ replacement of `getloadavg'.
16 m4_define([gl_PREREQ_GETLOADAVG],
17 [AC_LIBOBJ(getloadavg)
18 AC_DEFINE(C_GETLOADAVG, 1, [Define to 1 if using `getloadavg.c'.])
19 # Figure out what our getloadavg.c needs.
20 gl_have_func=no
21 AC_CHECK_HEADER(sys/dg_sys_info.h,
22 [gl_have_func=yes
23  AC_DEFINE(DGUX, 1, [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
24  AC_CHECK_LIB(dgc, dg_sys_info)])
25
26 # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
27 # uses stabs), but it is still SVR4.  We cannot check for <elf.h> because
28 # Irix 4.0.5F has the header but not the library.
29 if test $gl_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes; then
30   gl_have_func=yes
31   AC_DEFINE(SVR4, 1, [Define to 1 on System V Release 4.])
32 fi
33
34 if test $gl_have_func = no; then
35   AC_CHECK_HEADER(inq_stats/cpustats.h,
36   [gl_have_func=yes
37    AC_DEFINE(UMAX, 1, [Define to 1 for Encore UMAX.])
38    AC_DEFINE(UMAX4_3, 1,
39              [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
40               instead of <sys/cpustats.h>.])])
41 fi
42
43 if test $gl_have_func = no; then
44   AC_CHECK_HEADER(sys/cpustats.h,
45   [gl_have_func=yes; AC_DEFINE(UMAX)])
46 fi
47
48 if test $gl_have_func = no; then
49   AC_CHECK_HEADERS(mach/mach.h)
50 fi
51
52 AC_CHECK_HEADERS(nlist.h,
53 [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
54                   [AC_DEFINE(NLIST_NAME_UNION, 1,
55                              [Define to 1 if your `struct nlist' has an
56                               `n_un' member.  Obsolete, depend on
57                               `HAVE_STRUCT_NLIST_N_UN_N_NAME])], [],
58                   [@%:@include <nlist.h>])
59 ])dnl
60 ])# gl_PREREQ_GETLOADAVG
61
62
63 # gl_GETLOADAVG
64 # -------------
65 AN_FUNCTION([getloadavg], [gl_GETLOADAVG])
66 AC_DEFUN([gl_GETLOADAVG],
67 [gl_have_func=no # yes means we've found a way to get the load average.
68
69 # Make sure getloadavg.c is where it belongs, at configure-time.
70 test -f "$srcdir/$ac_config_libobj_dir/getloadavg.c" ||
71   AC_MSG_ERROR([$srcdir/$ac_config_libobj_dir/getloadavg.c is missing])
72
73 gl_save_LIBS=$LIBS
74
75 # Check for getloadavg, but be sure not to touch the cache variable.
76 (AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && gl_have_func=yes
77
78 # On HPUX9, an unprivileged user can get load averages through this function.
79 AC_CHECK_FUNCS(pstat_getdynamic)
80
81 # Solaris has libkstat which does not require root.
82 AC_CHECK_LIB(kstat, kstat_open)
83 test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes
84
85 # Some systems with -lutil have (and need) -lkvm as well, some do not.
86 # On Solaris, -lkvm requires nlist from -lelf, so check that first
87 # to get the right answer into the cache.
88 # For kstat on solaris, we need libelf to force the definition of SVR4 below.
89 if test $gl_have_func = no; then
90   AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
91 fi
92 if test $gl_have_func = no; then
93   AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
94   # Check for the 4.4BSD definition of getloadavg.
95   AC_CHECK_LIB(util, getloadavg,
96     [LIBS="-lutil $LIBS" gl_have_func=yes gl_cv_func_getloadavg_setgid=yes])
97 fi
98
99 if test $gl_have_func = no; then
100   # There is a commonly available library for RS/6000 AIX.
101   # Since it is not a standard part of AIX, it might be installed locally.
102   gl_getloadavg_LIBS=$LIBS
103   LIBS="-L/usr/local/lib $LIBS"
104   AC_CHECK_LIB(getloadavg, getloadavg,
105                [LIBS="-lgetloadavg $LIBS"], [LIBS=$gl_getloadavg_LIBS])
106 fi
107
108 # Make sure it is really in the library, if we think we found it,
109 # otherwise set up the replacement function.
110 AC_CHECK_FUNCS(getloadavg, [],
111                [gl_PREREQ_GETLOADAVG])
112
113 # Some definitions of getloadavg require that the program be installed setgid.
114 AC_CACHE_CHECK(whether getloadavg requires setgid,
115                gl_cv_func_getloadavg_setgid,
116 [AC_EGREP_CPP([Yowza Am I SETGID yet],
117 [#define gl_GETLOADAVG
118 #include "$srcdir/$ac_config_libobj_dir/getloadavg.c"
119 #ifdef LDAV_PRIVILEGED
120 Yowza Am I SETGID yet
121 #endif
122 ],
123               gl_cv_func_getloadavg_setgid=yes,
124               gl_cv_func_getloadavg_setgid=no)])
125 if test $gl_cv_func_getloadavg_setgid = yes; then
126   NEED_SETGID=true
127   AC_DEFINE(GETLOADAVG_PRIVILEGED, 1,
128             [Define to 1 if the `getloadavg' function needs to be run setuid
129              or setgid.])
130 else
131   NEED_SETGID=false
132 fi
133 AC_SUBST(NEED_SETGID)dnl
134
135 if test $gl_cv_func_getloadavg_setgid = yes; then
136   AC_CACHE_CHECK(group of /dev/kmem, gl_cv_group_kmem,
137 [ # On Solaris, /dev/kmem is a symlink.  Get info on the real file.
138   ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
139   # If we got an error (system does not support symlinks), try without -L.
140   test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
141   gl_cv_group_kmem=`echo $ac_ls_output \
142     | sed -ne ['s/[      ][      ]*/ /g;
143                s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\)  *.*/\1/;
144                / /s/.* //;p;']`
145 ])
146   AC_SUBST(KMEM_GROUP, $gl_cv_group_kmem)dnl
147 fi
148 if test "x$gl_save_LIBS" = x; then
149   GETLOADAVG_LIBS=$LIBS
150 else
151   GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"`
152 fi
153 LIBS=$gl_save_LIBS
154
155 AC_SUBST(GETLOADAVG_LIBS)dnl
156 ])# gl_GETLOADAVG