summaryrefslogtreecommitdiff
path: root/m4
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2011-02-15 16:33:44 -0800
committerPaul Eggert <eggert@cs.ucla.edu>2011-02-15 16:33:44 -0800
commit1f5d53eb532df40b6c41d25a8b1eaf4ccf69d518 (patch)
tree344ee816d4cbc354fb53a4d4a31bfad28f2e1bff /m4
parent7127b760aed65cd08fbba67b8ad14f1840532b45 (diff)
downloademacs-1f5d53eb532df40b6c41d25a8b1eaf4ccf69d518.tar.gz
Import getloadavg module from gnulib.
Diffstat (limited to 'm4')
-rw-r--r--m4/getloadavg.m4156
-rw-r--r--m4/gl-comp.m411
-rw-r--r--m4/stdlib_h.m4101
3 files changed, 268 insertions, 0 deletions
diff --git a/m4/getloadavg.m4 b/m4/getloadavg.m4
new file mode 100644
index 00000000000..4aae158e963
--- /dev/null
+++ b/m4/getloadavg.m4
@@ -0,0 +1,156 @@
+# Check for getloadavg.
+
+# Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2011 Free Software
+# Foundation, Inc.
+
+# 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.
+
+#serial 2
+
+# Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
+# New applications should use gl_GETLOADAVG instead.
+
+# gl_GETLOADAVG(LIBOBJDIR)
+# ------------------------
+AC_DEFUN([gl_GETLOADAVG],
+[AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+
+# Persuade glibc <stdlib.h> to declare getloadavg().
+AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
+
+# Make sure getloadavg.c is where it belongs, at configure-time.
+test -f "$srcdir/$1/getloadavg.c" ||
+ AC_MSG_ERROR([$srcdir/$1/getloadavg.c is missing])
+
+gl_save_LIBS=$LIBS
+
+AC_CHECK_FUNC([getloadavg], [],
+ [gl_have_func=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_have_func = 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_have_func=yes])
+ fi
+
+ if test $gl_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.
+ gl_getloadavg_LIBS=$LIBS
+ LIBS="-L/usr/local/lib $LIBS"
+ AC_CHECK_LIB([getloadavg], [getloadavg],
+ [LIBS="-lgetloadavg $LIBS" gl_have_func=yes],
+ [LIBS=$gl_getloadavg_LIBS])
+ fi
+
+ # Set up the replacement function if necessary.
+ if test $gl_have_func = no; then
+ AC_LIBOBJ([getloadavg])
+ gl_PREREQ_GETLOADAVG
+ 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
+
+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.
+
+# Solaris has libkstat which does not require root.
+AC_CHECK_LIB([kstat], [kstat_open])
+test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes
+
+# On HPUX9, an unprivileged user can get load averages this way.
+if test $gl_have_func = no; then
+ AC_CHECK_FUNCS([pstat_getdynamic], [gl_have_func=yes])
+fi
+
+# AIX has libperfstat which does not require root
+if test $gl_have_func = no; then
+ AC_CHECK_LIB([perfstat], [perfstat_cpu_total])
+ test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_have_func=yes
+fi
+
+if test $gl_have_func = no; then
+ AC_CHECK_HEADER([sys/dg_sys_info.h],
+ [gl_have_func=yes
+ AC_DEFINE([DGUX], [1], [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
+ AC_CHECK_LIB([dgc], [dg_sys_info])])
+fi
+
+# 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_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes \
+ && test "$ac_cv_lib_kvm_kvm_open" = yes; then
+ gl_have_func=yes
+ AC_DEFINE([SVR4], [1], [Define to 1 on System V Release 4.])
+fi
+
+if test $gl_have_func = no; then
+ AC_CHECK_HEADER([inq_stats/cpustats.h],
+ [gl_have_func=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
+
+if test $gl_have_func = no; then
+ AC_CHECK_HEADER([sys/cpustats.h],
+ [gl_have_func=yes; AC_DEFINE([UMAX])])
+fi
+
+if test $gl_have_func = no; then
+ AC_CHECK_HEADERS([mach/mach.h])
+fi
+
+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
diff --git a/m4/gl-comp.m4 b/m4/gl-comp.m4
index 4bd213cdbd5..036b67452c8 100644
--- a/m4/gl-comp.m4
+++ b/m4/gl-comp.m4
@@ -31,6 +31,7 @@ AC_DEFUN([gl_EARLY],
# Code from module dtoastr:
# Code from module extensions:
AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
+ # Code from module getloadavg:
# Code from module getopt-gnu:
# Code from module getopt-posix:
# Code from module gettext-h:
@@ -41,6 +42,7 @@ AC_DEFUN([gl_EARLY],
# Code from module multiarch:
# Code from module stdbool:
# Code from module stddef:
+ # Code from module stdlib:
# Code from module strftime:
# Code from module time:
# Code from module time_r:
@@ -69,6 +71,9 @@ AC_DEFUN([gl_INIT],
# Code from module dtoastr:
AC_REQUIRE([gl_C99_STRTOLD])
# Code from module extensions:
+ # Code from module getloadavg:
+ gl_GETLOADAVG([$gl_source_base])
+ gl_STDLIB_MODULE_INDICATOR([getloadavg])
# Code from module getopt-gnu:
gl_FUNC_GETOPT_GNU
gl_MODULE_INDICATOR_FOR_TESTS([getopt-gnu])
@@ -90,6 +95,8 @@ AC_DEFUN([gl_INIT],
AM_STDBOOL_H
# Code from module stddef:
gl_STDDEF_H
+ # Code from module stdlib:
+ gl_STDLIB_H
# Code from module strftime:
gl_FUNC_GNU_STRFTIME
# Code from module time:
@@ -246,6 +253,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/dtoastr.c
lib/ftoastr.c
lib/ftoastr.h
+ lib/getloadavg.c
lib/getopt.c
lib/getopt.in.h
lib/getopt1.c
@@ -257,6 +265,7 @@ AC_DEFUN([gl_FILE_LIST], [
lib/mktime.c
lib/stdbool.in.h
lib/stddef.in.h
+ lib/stdlib.in.h
lib/strftime.c
lib/strftime.h
lib/time.in.h
@@ -265,6 +274,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/00gnulib.m4
m4/c-strtod.m4
m4/extensions.m4
+ m4/getloadavg.m4
m4/getopt.m4
m4/gnulib-common.m4
m4/include_next.m4
@@ -272,6 +282,7 @@ AC_DEFUN([gl_FILE_LIST], [
m4/multiarch.m4
m4/stdbool.m4
m4/stddef_h.m4
+ m4/stdlib_h.m4
m4/strftime.m4
m4/time_h.m4
m4/time_r.m4
diff --git a/m4/stdlib_h.m4 b/m4/stdlib_h.m4
new file mode 100644
index 00000000000..d28b552e905
--- /dev/null
+++ b/m4/stdlib_h.m4
@@ -0,0 +1,101 @@
+# stdlib_h.m4 serial 36
+dnl Copyright (C) 2007-2011 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+AC_DEFUN([gl_STDLIB_H],
+[
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+ gl_NEXT_HEADERS([stdlib.h])
+
+ dnl Check for declarations of anything we want to poison if the
+ dnl corresponding gnulib module is not in use, and which is not
+ dnl guaranteed by C89.
+ gl_WARN_ON_USE_PREPARE([[#include <stdlib.h>
+#if HAVE_SYS_LOADAVG_H
+# include <sys/loadavg.h>
+#endif
+#if HAVE_RANDOM_H
+# include <random.h>
+#endif
+ ]], [_Exit atoll canonicalize_file_name getloadavg getsubopt grantpt mkdtemp
+ mkostemp mkostemps mkstemp mkstemps ptsname random_r initstat_r srandom_r
+ setstate_r realpath rpmatch setenv strtod strtoll strtoull unlockpt
+ unsetenv])
+])
+
+AC_DEFUN([gl_STDLIB_MODULE_INDICATOR],
+[
+ dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+ AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
+ gl_MODULE_INDICATOR_SET_VARIABLE([$1])
+ dnl Define it also as a C macro, for the benefit of the unit tests.
+ gl_MODULE_INDICATOR_FOR_TESTS([$1])
+])
+
+AC_DEFUN([gl_STDLIB_H_DEFAULTS],
+[
+ GNULIB__EXIT=0; AC_SUBST([GNULIB__EXIT])
+ GNULIB_ATOLL=0; AC_SUBST([GNULIB_ATOLL])
+ GNULIB_CALLOC_POSIX=0; AC_SUBST([GNULIB_CALLOC_POSIX])
+ GNULIB_CANONICALIZE_FILE_NAME=0; AC_SUBST([GNULIB_CANONICALIZE_FILE_NAME])
+ GNULIB_GETLOADAVG=0; AC_SUBST([GNULIB_GETLOADAVG])
+ GNULIB_GETSUBOPT=0; AC_SUBST([GNULIB_GETSUBOPT])
+ GNULIB_GRANTPT=0; AC_SUBST([GNULIB_GRANTPT])
+ GNULIB_MALLOC_POSIX=0; AC_SUBST([GNULIB_MALLOC_POSIX])
+ GNULIB_MKDTEMP=0; AC_SUBST([GNULIB_MKDTEMP])
+ GNULIB_MKOSTEMP=0; AC_SUBST([GNULIB_MKOSTEMP])
+ GNULIB_MKOSTEMPS=0; AC_SUBST([GNULIB_MKOSTEMPS])
+ GNULIB_MKSTEMP=0; AC_SUBST([GNULIB_MKSTEMP])
+ GNULIB_MKSTEMPS=0; AC_SUBST([GNULIB_MKSTEMPS])
+ GNULIB_PTSNAME=0; AC_SUBST([GNULIB_PTSNAME])
+ GNULIB_PUTENV=0; AC_SUBST([GNULIB_PUTENV])
+ GNULIB_RANDOM_R=0; AC_SUBST([GNULIB_RANDOM_R])
+ GNULIB_REALLOC_POSIX=0; AC_SUBST([GNULIB_REALLOC_POSIX])
+ GNULIB_REALPATH=0; AC_SUBST([GNULIB_REALPATH])
+ GNULIB_RPMATCH=0; AC_SUBST([GNULIB_RPMATCH])
+ GNULIB_SETENV=0; AC_SUBST([GNULIB_SETENV])
+ GNULIB_STRTOD=0; AC_SUBST([GNULIB_STRTOD])
+ GNULIB_STRTOLL=0; AC_SUBST([GNULIB_STRTOLL])
+ GNULIB_STRTOULL=0; AC_SUBST([GNULIB_STRTOULL])
+ GNULIB_SYSTEM_POSIX=0; AC_SUBST([GNULIB_SYSTEM_POSIX])
+ GNULIB_UNLOCKPT=0; AC_SUBST([GNULIB_UNLOCKPT])
+ GNULIB_UNSETENV=0; AC_SUBST([GNULIB_UNSETENV])
+ dnl Assume proper GNU behavior unless another module says otherwise.
+ HAVE__EXIT=1; AC_SUBST([HAVE__EXIT])
+ HAVE_ATOLL=1; AC_SUBST([HAVE_ATOLL])
+ HAVE_CANONICALIZE_FILE_NAME=1; AC_SUBST([HAVE_CANONICALIZE_FILE_NAME])
+ HAVE_DECL_GETLOADAVG=1; AC_SUBST([HAVE_DECL_GETLOADAVG])
+ HAVE_GETSUBOPT=1; AC_SUBST([HAVE_GETSUBOPT])
+ HAVE_GRANTPT=1; AC_SUBST([HAVE_GRANTPT])
+ HAVE_MKDTEMP=1; AC_SUBST([HAVE_MKDTEMP])
+ HAVE_MKOSTEMP=1; AC_SUBST([HAVE_MKOSTEMP])
+ HAVE_MKOSTEMPS=1; AC_SUBST([HAVE_MKOSTEMPS])
+ HAVE_MKSTEMP=1; AC_SUBST([HAVE_MKSTEMP])
+ HAVE_MKSTEMPS=1; AC_SUBST([HAVE_MKSTEMPS])
+ HAVE_PTSNAME=1; AC_SUBST([HAVE_PTSNAME])
+ HAVE_RANDOM_H=1; AC_SUBST([HAVE_RANDOM_H])
+ HAVE_RANDOM_R=1; AC_SUBST([HAVE_RANDOM_R])
+ HAVE_REALPATH=1; AC_SUBST([HAVE_REALPATH])
+ HAVE_RPMATCH=1; AC_SUBST([HAVE_RPMATCH])
+ HAVE_SETENV=1; AC_SUBST([HAVE_SETENV])
+ HAVE_DECL_SETENV=1; AC_SUBST([HAVE_DECL_SETENV])
+ HAVE_STRTOD=1; AC_SUBST([HAVE_STRTOD])
+ HAVE_STRTOLL=1; AC_SUBST([HAVE_STRTOLL])
+ HAVE_STRTOULL=1; AC_SUBST([HAVE_STRTOULL])
+ HAVE_STRUCT_RANDOM_DATA=1; AC_SUBST([HAVE_STRUCT_RANDOM_DATA])
+ HAVE_SYS_LOADAVG_H=0; AC_SUBST([HAVE_SYS_LOADAVG_H])
+ HAVE_UNLOCKPT=1; AC_SUBST([HAVE_UNLOCKPT])
+ HAVE_DECL_UNSETENV=1; AC_SUBST([HAVE_DECL_UNSETENV])
+ REPLACE_CALLOC=0; AC_SUBST([REPLACE_CALLOC])
+ REPLACE_CANONICALIZE_FILE_NAME=0; AC_SUBST([REPLACE_CANONICALIZE_FILE_NAME])
+ REPLACE_MALLOC=0; AC_SUBST([REPLACE_MALLOC])
+ REPLACE_MKSTEMP=0; AC_SUBST([REPLACE_MKSTEMP])
+ REPLACE_PUTENV=0; AC_SUBST([REPLACE_PUTENV])
+ REPLACE_REALLOC=0; AC_SUBST([REPLACE_REALLOC])
+ REPLACE_REALPATH=0; AC_SUBST([REPLACE_REALPATH])
+ REPLACE_SETENV=0; AC_SUBST([REPLACE_SETENV])
+ REPLACE_STRTOD=0; AC_SUBST([REPLACE_STRTOD])
+ REPLACE_UNSETENV=0; AC_SUBST([REPLACE_UNSETENV])
+])