| 1 |
# Check for getloadavg. |
| 2 |
|
| 3 |
# Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2023 Free |
| 4 |
# 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 |
#serial 10 |
| 11 |
|
| 12 |
# Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent. |
| 13 |
# New applications should use gl_GETLOADAVG instead. |
| 14 |
|
| 15 |
# gl_GETLOADAVG |
| 16 |
# ------------- |
| 17 |
AC_DEFUN([gl_GETLOADAVG], |
| 18 |
[AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
| 19 |
|
| 20 |
# Persuade glibc <stdlib.h> to declare getloadavg(). |
| 21 |
AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS]) |
| 22 |
|
| 23 |
gl_save_LIBS=$LIBS |
| 24 |
|
| 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. |
| 27 |
HAVE_GETLOADAVG=1 |
| 28 |
AC_CHECK_FUNC([getloadavg], [], |
| 29 |
[gl_func_getloadavg_done=no |
| 30 |
|
| 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]) |
| 42 |
fi |
| 43 |
|
| 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" |
| 50 |
fi |
| 51 |
AC_CHECK_LIB([getloadavg], [getloadavg], |
| 52 |
[LIBS="-lgetloadavg $LIBS" gl_func_getloadavg_done=yes], |
| 53 |
[LIBS=$gl_getloadavg_LIBS]) |
| 54 |
fi |
| 55 |
|
| 56 |
# Set up the replacement function if necessary. |
| 57 |
if test $gl_func_getloadavg_done = no; then |
| 58 |
HAVE_GETLOADAVG=0 |
| 59 |
|
| 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 |
| 63 |
|
| 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 |
| 68 |
fi |
| 69 |
|
| 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])]) |
| 75 |
fi |
| 76 |
fi]) |
| 77 |
|
| 78 |
if test "x$gl_save_LIBS" = x; then |
| 79 |
GETLOADAVG_LIBS=$LIBS |
| 80 |
else |
| 81 |
GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"` |
| 82 |
fi |
| 83 |
LIBS=$gl_save_LIBS |
| 84 |
|
| 85 |
AC_SUBST([GETLOADAVG_LIBS])dnl |
| 86 |
|
| 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 |
| 91 |
HAVE_SYS_LOADAVG_H=1 |
| 92 |
else |
| 93 |
HAVE_SYS_LOADAVG_H=0 |
| 94 |
fi |
| 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 |
| 98 |
<sys/loadavg.h>. */ |
| 99 |
# include <sys/time.h> |
| 100 |
# include <sys/loadavg.h> |
| 101 |
#endif |
| 102 |
#include <stdlib.h>]]) |
| 103 |
])# gl_GETLOADAVG |
| 104 |
|
| 105 |
|
| 106 |
# gl_PREREQ_GETLOADAVG |
| 107 |
# -------------------- |
| 108 |
# Set up the AC_LIBOBJ replacement of 'getloadavg'. |
| 109 |
AC_DEFUN([gl_PREREQ_GETLOADAVG], |
| 110 |
[ |
| 111 |
# Figure out what our getloadavg.c needs. |
| 112 |
|
| 113 |
AC_CHECK_HEADERS_ONCE([sys/param.h unistd.h]) |
| 114 |
|
| 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]) |
| 118 |
fi |
| 119 |
|
| 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.]) |
| 127 |
fi |
| 128 |
|
| 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>.])]) |
| 136 |
fi |
| 137 |
|
| 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])]) |
| 141 |
fi |
| 142 |
|
| 143 |
if test $gl_func_getloadavg_done = no; then |
| 144 |
AC_CHECK_HEADERS([mach/mach.h]) |
| 145 |
fi |
| 146 |
|
| 147 |
AC_CHECK_HEADERS([nlist.h], |
| 148 |
[AC_CHECK_MEMBERS([struct nlist.n_un.n_name], |
| 149 |
[], [], |
| 150 |
[#include <nlist.h>]) |
| 151 |
AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]], |
| 152 |
[[struct nlist x; |
| 153 |
#ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME |
| 154 |
x.n_un.n_name = ""; |
| 155 |
#else |
| 156 |
x.n_name = ""; |
| 157 |
#endif]])], |
| 158 |
[AC_DEFINE([N_NAME_POINTER], [1], |
| 159 |
[Define to 1 if the nlist n_name member is a pointer])]) |
| 160 |
])dnl |
| 161 |
])# gl_PREREQ_GETLOADAVG |
| 162 |
|
| 163 |
# ---- GNU Make |
| 164 |
# These macros are imported from stdlib which we don't want to include |
| 165 |
# Only the getloadavg content is imported. |
| 166 |
|
| 167 |
AC_DEFUN_ONCE([gl_STDLIB_H], |
| 168 |
[ |
| 169 |
AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
| 170 |
|
| 171 |
dnl Check for declarations of anything we want to poison if the |
| 172 |
dnl corresponding gnulib module is not in use, and which is not |
| 173 |
dnl guaranteed by C89. |
| 174 |
gl_WARN_ON_USE_PREPARE([[#include <stdlib.h> |
| 175 |
#if HAVE_SYS_LOADAVG_H |
| 176 |
/* OpenIndiana has a bug: <sys/time.h> must be included before |
| 177 |
<sys/loadavg.h>. */ |
| 178 |
# include <sys/time.h> |
| 179 |
# include <sys/loadavg.h> |
| 180 |
#endif |
| 181 |
#if HAVE_RANDOM_H |
| 182 |
# include <random.h> |
| 183 |
#endif |
| 184 |
]], [getloadavg]) |
| 185 |
]) |
| 186 |
|
| 187 |
# gl_STDLIB_MODULE_INDICATOR([modulename]) |
| 188 |
# sets the shell variable that indicates the presence of the given module |
| 189 |
# to a C preprocessor expression that will evaluate to 1. |
| 190 |
# This macro invocation must not occur in macros that are AC_REQUIREd. |
| 191 |
AC_DEFUN([gl_STDLIB_MODULE_INDICATOR], |
| 192 |
[ |
| 193 |
dnl Ensure to expand the default settings once only. |
| 194 |
gl_STDLIB_H_REQUIRE_DEFAULTS |
| 195 |
gl_MODULE_INDICATOR_SET_VARIABLE([$1]) |
| 196 |
dnl Define it also as a C macro, for the benefit of the unit tests. |
| 197 |
gl_MODULE_INDICATOR_FOR_TESTS([$1]) |
| 198 |
]) |
| 199 |
|
| 200 |
# Initializes the default values for AC_SUBSTed shell variables. |
| 201 |
# This macro must not be AC_REQUIREd. It must only be invoked, and only |
| 202 |
# outside of macros or in macros that are not AC_REQUIREd. |
| 203 |
AC_DEFUN([gl_STDLIB_H_REQUIRE_DEFAULTS], |
| 204 |
[ |
| 205 |
m4_defun(GL_MODULE_INDICATOR_PREFIX[_STDLIB_H_MODULE_INDICATOR_DEFAULTS], [ |
| 206 |
gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_GETLOADAVG]) |
| 207 |
]) |
| 208 |
m4_require(GL_MODULE_INDICATOR_PREFIX[_STDLIB_H_MODULE_INDICATOR_DEFAULTS]) |
| 209 |
AC_REQUIRE([gl_STDLIB_H_DEFAULTS]) |
| 210 |
]) |
| 211 |
|
| 212 |
AC_DEFUN([gl_STDLIB_H_DEFAULTS], |
| 213 |
[ |
| 214 |
dnl Assume proper GNU behavior unless another module says otherwise. |
| 215 |
HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG]) |
| 216 |
]) |