maint: update copyright
[gnulib.git] / m4 / getloadavg.m4
index 9488c9a..d744804 100644 (file)
-#serial 6
-
-AC_DEFUN(AM_FUNC_GETLOADAVG,
-[ac_have_func=no # yes means we've found a way to get the load average.
+# Check for getloadavg.
 
-am_cv_saved_LIBS="$LIBS"
+# Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2014 Free Software
+# Foundation, Inc.
 
-# On HPUX9, an unprivileged user can get load averages through this function.
-AC_CHECK_FUNCS(pstat_getdynamic)
+# This file is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
 
-# Solaris has libkstat which does not require root.
-AC_CHECK_LIB(kstat, kstat_open)
-if test $ac_cv_lib_kstat_kstat_open = yes ; then ac_have_func=yes ; fi
+#serial 6
 
-# 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.
-# For kstat on solaris, we need libelf to force the definition of SVR4 below.
-AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS")
-if test $ac_have_func = no; then
-  AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS")
-  # Check for the 4.4BSD definition of getloadavg.
-  AC_CHECK_LIB(util, getloadavg,
-    [LIBS="-lutil $LIBS" ac_have_func=yes ac_cv_func_getloadavg_setgid=yes])
+# Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
+# New applications should use gl_GETLOADAVG instead.
+
+# gl_GETLOADAVG
+# -------------
+AC_DEFUN([gl_GETLOADAVG],
+[AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+
+# Persuade glibc <stdlib.h> to declare getloadavg().
+AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+gl_save_LIBS=$LIBS
+
+# getloadvg is present in libc on glibc >= 2.2, Mac OS X, FreeBSD >= 2.0,
+# NetBSD >= 0.9, OpenBSD >= 2.0, Solaris >= 7.
+HAVE_GETLOADAVG=1
+AC_CHECK_FUNC([getloadavg], [],
+  [gl_func_getloadavg_done=no
+
+   # 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.
+   # For kstat on solaris, we need to test for libelf and libkvm to force the
+   # definition of SVR4 below.
+   if test $gl_func_getloadavg_done = no; then
+     AC_CHECK_LIB([elf], [elf_begin], [LIBS="-lelf $LIBS"])
+     AC_CHECK_LIB([kvm], [kvm_open], [LIBS="-lkvm $LIBS"])
+     # Check for the 4.4BSD definition of getloadavg.
+     AC_CHECK_LIB([util], [getloadavg],
+       [LIBS="-lutil $LIBS" gl_func_getloadavg_done=yes])
+   fi
+
+   if test $gl_func_getloadavg_done = no; then
+     # There is a commonly available library for RS/6000 AIX.
+     # Since it is not a standard part of AIX, it might be installed locally.
+     gl_getloadavg_LIBS=$LIBS
+     LIBS="-L/usr/local/lib $LIBS"
+     AC_CHECK_LIB([getloadavg], [getloadavg],
+                  [LIBS="-lgetloadavg $LIBS" gl_func_getloadavg_done=yes],
+                  [LIBS=$gl_getloadavg_LIBS])
+   fi
+
+   # Set up the replacement function if necessary.
+   if test $gl_func_getloadavg_done = no; then
+     HAVE_GETLOADAVG=0
+
+     # Solaris has libkstat which does not require root.
+     AC_CHECK_LIB([kstat], [kstat_open])
+     test $ac_cv_lib_kstat_kstat_open = yes && gl_func_getloadavg_done=yes
+
+     # AIX has libperfstat which does not require root
+     if test $gl_func_getloadavg_done = no; then
+       AC_CHECK_LIB([perfstat], [perfstat_cpu_total])
+       test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_func_getloadavg_done=yes
+     fi
+
+     if test $gl_func_getloadavg_done = no; then
+       AC_CHECK_HEADER([sys/dg_sys_info.h],
+         [gl_func_getloadavg_done=yes
+          AC_DEFINE([DGUX], [1], [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
+          AC_CHECK_LIB([dgc], [dg_sys_info])])
+     fi
+   fi])
+
+if test "x$gl_save_LIBS" = x; then
+  GETLOADAVG_LIBS=$LIBS
+else
+  GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"`
 fi
+LIBS=$gl_save_LIBS
 
-if test $ac_have_func = no; then
-  # There is a commonly available library for RS/6000 AIX.
-  # Since it is not a standard part of AIX, it might be installed locally.
-  ac_save_LIBS="$LIBS"
-  LIBS="-L/usr/local/lib $LIBS"
-  AC_CHECK_LIB(getloadavg, getloadavg,
-    LIBS="-lgetloadavg $LIBS", LIBS="$ac_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
+
+
+# gl_PREREQ_GETLOADAVG
+# --------------------
+# Set up the AC_LIBOBJ replacement of 'getloadavg'.
+AC_DEFUN([gl_PREREQ_GETLOADAVG],
+[
+# Figure out what our getloadavg.c needs.
+
+AC_CHECK_HEADERS_ONCE([sys/param.h])
+
+# On HPUX9, an unprivileged user can get load averages this way.
+if test $gl_func_getloadavg_done = no; then
+  AC_CHECK_FUNCS([pstat_getdynamic], [gl_func_getloadavg_done=yes])
 fi
 
-# Make sure it is really in the library, if we think we found it.
-AC_REPLACE_FUNCS(getloadavg)
+# We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
+# uses stabs), but it is still SVR4.  We cannot check for <elf.h> because
+# Irix 4.0.5F has the header but not the library.
+if test $gl_func_getloadavg_done = no && test "$ac_cv_lib_elf_elf_begin" = yes \
+    && test "$ac_cv_lib_kvm_kvm_open" = yes; then
+  gl_func_getloadavg_done=yes
+  AC_DEFINE([SVR4], [1], [Define to 1 on System V Release 4.])
+fi
 
-if test $ac_cv_func_getloadavg = yes; then
-  AC_DEFINE(HAVE_GETLOADAVG, 1, [FIXME])
-  ac_have_func=yes
-else
-  AC_DEFINE(C_GETLOADAVG, 1, [Define if using getloadavg.c.])
-  # Figure out what our getloadavg.c needs.
-  ac_have_func=no
-  AC_CHECK_HEADER(sys/dg_sys_info.h,
-  [ac_have_func=yes; AC_DEFINE(DGUX, 1, [FIXME])
-  AC_CHECK_LIB(dgc, dg_sys_info)])
-
-  AC_CHECK_HEADERS(locale.h)
-  AC_CHECK_FUNCS(setlocale)
-
-  # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
-  # uses stabs), but it is still SVR4.  We cannot check for <elf.h> because
-  # Irix 4.0.5F has the header but not the library.
-  if test $ac_have_func = no && test $ac_cv_lib_elf_elf_begin = yes; then
-    ac_have_func=yes; AC_DEFINE(SVR4, 1, [FIXME])
-  fi
-
-  if test $ac_have_func = no; then
-    AC_CHECK_HEADER(inq_stats/cpustats.h,
-    [ac_have_func=yes; AC_DEFINE(UMAX, 1, [FIXME])
-    AC_DEFINE(UMAX4_3, 1, [FIXME])])
-  fi
-
-  if test $ac_have_func = no; then
-    AC_CHECK_HEADER(sys/cpustats.h,
-    [ac_have_func=yes; AC_DEFINE(UMAX, 1, [FIXME])])
-  fi
-
-  if test $ac_have_func = no; then
-    AC_CHECK_HEADERS(mach/mach.h)
-  fi
-
-  AC_CHECK_HEADER(nlist.h,
-  [AC_DEFINE(NLIST_STRUCT, 1, [FIXME])
-  AC_CACHE_CHECK([for n_un in struct nlist], ac_cv_struct_nlist_n_un,
-  [AC_TRY_COMPILE([#include <nlist.h>],
-  [struct nlist n; n.n_un.n_name = 0;],
-  ac_cv_struct_nlist_n_un=yes, ac_cv_struct_nlist_n_un=no)])
-  if test $ac_cv_struct_nlist_n_un = yes; then
-    AC_DEFINE(NLIST_NAME_UNION, 1, [FIXME])
-  fi
-  ])dnl
-fi # Do not have getloadavg in system libraries.
-
-# Some definitions of getloadavg require that the program be installed setgid.
-dnl FIXME Don't hardwire the path of getloadavg.c in the top-level directory.
-AC_CACHE_CHECK(whether getloadavg requires setgid,
-  ac_cv_func_getloadavg_setgid,
-[AC_EGREP_CPP([Yowza Am I SETGID yet],
-[#include "$srcdir/lib/getloadavg.c"
-#ifdef LDAV_PRIVILEGED
-Yowza Am I SETGID yet
-#endif],
-  ac_cv_func_getloadavg_setgid=yes, ac_cv_func_getloadavg_setgid=no)])
-if test $ac_cv_func_getloadavg_setgid = yes; then
-  NEED_SETGID=true; AC_DEFINE(GETLOADAVG_PRIVILEGED, 1, [FIXME])
-else
-  NEED_SETGID=false
+if test $gl_func_getloadavg_done = no; then
+  AC_CHECK_HEADER([inq_stats/cpustats.h],
+  [gl_func_getloadavg_done=yes
+   AC_DEFINE([UMAX], [1], [Define to 1 for Encore UMAX.])
+   AC_DEFINE([UMAX4_3], [1],
+             [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
+              instead of <sys/cpustats.h>.])])
 fi
-AC_SUBST(NEED_SETGID)dnl
-
-if test $ac_cv_func_getloadavg_setgid = yes; then
-  AC_CACHE_CHECK(group of /dev/kmem, ac_cv_group_kmem,
-[  # On Solaris, /dev/kmem is a symlink.  Get info on the real file.
-  ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null`
-  # If we got an error (system does not support symlinks), try without -L.
-  test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem`
-  ac_cv_group_kmem=`echo $ac_ls_output \
-    | sed -ne 's/[     ][      ]*/ /g;
-              s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\)  *.*/\1/;
-              / /s/.* //;p;'`
-]
-)
-  KMEM_GROUP=$ac_cv_group_kmem
+
+if test $gl_func_getloadavg_done = no; then
+  AC_CHECK_HEADER([sys/cpustats.h],
+  [gl_func_getloadavg_done=yes; AC_DEFINE([UMAX])])
 fi
-AC_SUBST(KMEM_GROUP)dnl
 
-if test x = "x$am_cv_saved_LIBS"; then
-  GETLOADAVG_LIBS="$LIBS"
-else
-  GETLOADAVG_LIBS=`echo "$LIBS"|sed "s!$am_cv_saved_LIBS!!"`
+if test $gl_func_getloadavg_done = no; then
+  AC_CHECK_HEADERS([mach/mach.h])
 fi
-AC_SUBST(GETLOADAVG_LIBS)dnl
-LIBS="$am_cv_saved_LIBS"
-])
+
+AC_CHECK_HEADERS([nlist.h],
+[AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
+                  [], [],
+                  [@%:@include <nlist.h>])
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]],
+                   [[struct nlist x;
+                    #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
+                    x.n_un.n_name = "";
+                    #else
+                    x.n_name = "";
+                    #endif]])],
+                [AC_DEFINE([N_NAME_POINTER], [1],
+                           [Define to 1 if the nlist n_name member is a pointer])])
+])dnl
+])# gl_PREREQ_GETLOADAVG