# Check for getloadavg.
# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1999, 2000, 2002, 2003,
-# 2006 Free Software Foundation, Inc.
+# 2006, 2008 Free Software Foundation, Inc.
# This file is free software; the Free Software Foundation
# gives unlimited permission to copy and/or distribute it,
# gl_GETLOADAVG(LIBOBJDIR)
# ------------------------
AC_DEFUN([gl_GETLOADAVG],
-[gl_have_func=no # yes means we've found a way to get the load average.
+[AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+
+# Persuade glibc <stdlib.h> to declare getloadavg().
+AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+gl_have_func=no # yes means we've found a way to get the load average.
# Make sure getloadavg.c is where it belongs, at configure-time.
test -f "$srcdir/$1/getloadavg.c" ||
AC_CHECK_LIB(kstat, kstat_open)
test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes
+# AIX has libperfstat which does not require root
+AC_CHECK_LIB(perfstat, perfstat_cpu_total)
+test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_have_func=yes
+
# Some systems with -lutil have (and need) -lkvm as well, some do not.
# On Solaris, -lkvm requires nlist from -lelf, so check that first
# to get the right answer into the cache.
LIBS=$gl_save_LIBS
AC_SUBST(GETLOADAVG_LIBS)dnl
+
+# Test whether the system declares getloadavg. Solaris has the function
+# but declares it in <sys/loadavg.h>, not <stdlib.h>.
+AC_CHECK_HEADERS([sys/loadavg.h])
+if test $ac_cv_header_sys_loadavg_h = yes; then
+ HAVE_SYS_LOADAVG_H=1
+else
+ HAVE_SYS_LOADAVG_H=0
+fi
+AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0],
+ [#if HAVE_SYS_LOADAVG_H
+ # include <sys/loadavg.h>
+ #endif
+ #include <stdlib.h>])
])# gl_GETLOADAVG