1 # Check for getloadavg.
3 # Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2020 Free Software
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.
12 # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
13 # New applications should use gl_GETLOADAVG instead.
17 AC_DEFUN([gl_GETLOADAVG],
18 [AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
20 # Persuade glibc <stdlib.h> to declare getloadavg().
21 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
25 # getloadavg is present in libc on glibc >= 2.2, Mac OS X, FreeBSD >= 2.0,
26 # NetBSD >= 0.9, OpenBSD >= 2.0, Solaris >= 7.
28 AC_CHECK_FUNC([getloadavg], [],
29 [gl_func_getloadavg_done=no
31 # Some systems with -lutil have (and need) -lkvm as well, some do not.
32 # On Solaris, -lkvm requires nlist from -lelf, so check that first
33 # to get the right answer into the cache.
34 # For kstat on solaris, we need to test for libelf and libkvm to force the
35 # definition of SVR4 below.
36 if test $gl_func_getloadavg_done = no; then
37 AC_CHECK_LIB([elf], [elf_begin], [LIBS="-lelf $LIBS"])
38 AC_CHECK_LIB([kvm], [kvm_open], [LIBS="-lkvm $LIBS"])
39 # Check for the 4.4BSD definition of getloadavg.
40 AC_CHECK_LIB([util], [getloadavg],
41 [LIBS="-lutil $LIBS" gl_func_getloadavg_done=yes])
44 if test $gl_func_getloadavg_done = no; then
45 # There is a commonly available library for RS/6000 AIX.
46 # Since it is not a standard part of AIX, it might be installed locally.
47 gl_getloadavg_LIBS=$LIBS
48 if test $cross_compiling != yes; then
49 LIBS="-L/usr/local/lib $LIBS"
51 AC_CHECK_LIB([getloadavg], [getloadavg],
52 [LIBS="-lgetloadavg $LIBS" gl_func_getloadavg_done=yes],
53 [LIBS=$gl_getloadavg_LIBS])
56 # Set up the replacement function if necessary.
57 if test $gl_func_getloadavg_done = no; then
60 # Solaris has libkstat which does not require root.
61 AC_CHECK_LIB([kstat], [kstat_open])
62 test $ac_cv_lib_kstat_kstat_open = yes && gl_func_getloadavg_done=yes
64 # AIX has libperfstat which does not require root
65 if test $gl_func_getloadavg_done = no; then
66 AC_CHECK_LIB([perfstat], [perfstat_cpu_total])
67 test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_func_getloadavg_done=yes
70 if test $gl_func_getloadavg_done = no; then
71 AC_CHECK_HEADER([sys/dg_sys_info.h],
72 [gl_func_getloadavg_done=yes
73 AC_DEFINE([DGUX], [1], [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
74 AC_CHECK_LIB([dgc], [dg_sys_info])])
78 if test "x$gl_save_LIBS" = x; then
81 GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"`
85 AC_SUBST([GETLOADAVG_LIBS])dnl
87 # Test whether the system declares getloadavg. Solaris has the function
88 # but declares it in <sys/loadavg.h>, not <stdlib.h>.
89 AC_CHECK_HEADERS([sys/loadavg.h])
90 if test $ac_cv_header_sys_loadavg_h = yes; then
95 AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0],
96 [[#if HAVE_SYS_LOADAVG_H
97 /* OpenIndiana has a bug: <sys/time.h> must be included before
99 # include <sys/time.h>
100 # include <sys/loadavg.h>
102 #include <stdlib.h>]])
106 # gl_PREREQ_GETLOADAVG
107 # --------------------
108 # Set up the AC_LIBOBJ replacement of 'getloadavg'.
109 AC_DEFUN([gl_PREREQ_GETLOADAVG],
111 # Figure out what our getloadavg.c needs.
113 AC_CHECK_HEADERS_ONCE([sys/param.h unistd.h])
115 # On HPUX9, an unprivileged user can get load averages this way.
116 if test $gl_func_getloadavg_done = no; then
117 AC_CHECK_FUNCS([pstat_getdynamic], [gl_func_getloadavg_done=yes])
120 # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
121 # uses stabs), but it is still SVR4. We cannot check for <elf.h> because
122 # Irix 4.0.5F has the header but not the library.
123 if test $gl_func_getloadavg_done = no && test "$ac_cv_lib_elf_elf_begin" = yes \
124 && test "$ac_cv_lib_kvm_kvm_open" = yes; then
125 gl_func_getloadavg_done=yes
126 AC_DEFINE([SVR4], [1], [Define to 1 on System V Release 4.])
129 if test $gl_func_getloadavg_done = no; then
130 AC_CHECK_HEADER([inq_stats/cpustats.h],
131 [gl_func_getloadavg_done=yes
132 AC_DEFINE([UMAX], [1], [Define to 1 for Encore UMAX.])
133 AC_DEFINE([UMAX4_3], [1],
134 [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
135 instead of <sys/cpustats.h>.])])
138 if test $gl_func_getloadavg_done = no; then
139 AC_CHECK_HEADER([sys/cpustats.h],
140 [gl_func_getloadavg_done=yes; AC_DEFINE([UMAX])])
143 if test $gl_func_getloadavg_done = no; then
144 AC_CHECK_HEADERS([mach/mach.h])
147 AC_CHECK_HEADERS([nlist.h],
148 [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
150 [#include <nlist.h>])
151 AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]],
153 #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
158 [AC_DEFINE([N_NAME_POINTER], [1],
159 [Define to 1 if the nlist n_name member is a pointer])])
161 ])# gl_PREREQ_GETLOADAVG