src/xdisp.c (single_display_spec_string): Correct a FIXME comment.
[emacs.git] / m4 / getloadavg.m4
blobe58d29b238f76c0b69db2d37509e63eca1c06ef5
1 # Check for getloadavg.
3 # Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2011 Free Software
4 # Foundation, Inc.
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.
10 #serial 2
12 # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
13 # New applications should use gl_GETLOADAVG instead.
15 # gl_GETLOADAVG(LIBOBJDIR)
16 # ------------------------
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])
23 # Make sure getloadavg.c is where it belongs, at configure-time.
24 test -f "$srcdir/$1/getloadavg.c" ||
25   AC_MSG_ERROR([$srcdir/$1/getloadavg.c is missing])
27 gl_save_LIBS=$LIBS
29 # getloadvg is present in libc on glibc >= 2.2, MacOS X, FreeBSD >= 2.0,
30 # NetBSD >= 0.9, OpenBSD >= 2.0, Solaris >= 7.
31 AC_CHECK_FUNC([getloadavg], [],
32   [gl_have_func=no
34    # Some systems with -lutil have (and need) -lkvm as well, some do not.
35    # On Solaris, -lkvm requires nlist from -lelf, so check that first
36    # to get the right answer into the cache.
37    # For kstat on solaris, we need to test for libelf and libkvm to force the
38    # definition of SVR4 below.
39    if test $gl_have_func = no; then
40      AC_CHECK_LIB([elf], [elf_begin], [LIBS="-lelf $LIBS"])
41      AC_CHECK_LIB([kvm], [kvm_open], [LIBS="-lkvm $LIBS"])
42      # Check for the 4.4BSD definition of getloadavg.
43      AC_CHECK_LIB([util], [getloadavg],
44        [LIBS="-lutil $LIBS" gl_have_func=yes])
45    fi
47    if test $gl_have_func = no; then
48      # There is a commonly available library for RS/6000 AIX.
49      # Since it is not a standard part of AIX, it might be installed locally.
50      gl_getloadavg_LIBS=$LIBS
51      LIBS="-L/usr/local/lib $LIBS"
52      AC_CHECK_LIB([getloadavg], [getloadavg],
53                   [LIBS="-lgetloadavg $LIBS" gl_have_func=yes],
54                   [LIBS=$gl_getloadavg_LIBS])
55    fi
57    # Set up the replacement function if necessary.
58    if test $gl_have_func = no; then
59      AC_LIBOBJ([getloadavg])
60      gl_PREREQ_GETLOADAVG
61    fi])
63 if test "x$gl_save_LIBS" = x; then
64   GETLOADAVG_LIBS=$LIBS
65 else
66   GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"`
68 LIBS=$gl_save_LIBS
70 AC_SUBST([GETLOADAVG_LIBS])dnl
72 # Test whether the system declares getloadavg. Solaris has the function
73 # but declares it in <sys/loadavg.h>, not <stdlib.h>.
74 AC_CHECK_HEADERS([sys/loadavg.h])
75 if test $ac_cv_header_sys_loadavg_h = yes; then
76   HAVE_SYS_LOADAVG_H=1
77 else
78   HAVE_SYS_LOADAVG_H=0
80 AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0],
81   [#if HAVE_SYS_LOADAVG_H
82    # include <sys/loadavg.h>
83    #endif
84    #include <stdlib.h>])
85 ])# gl_GETLOADAVG
88 # gl_PREREQ_GETLOADAVG
89 # --------------------
90 # Set up the AC_LIBOBJ replacement of `getloadavg'.
91 AC_DEFUN([gl_PREREQ_GETLOADAVG],
93 # Figure out what our getloadavg.c needs.
95 # Solaris has libkstat which does not require root.
96 AC_CHECK_LIB([kstat], [kstat_open])
97 test $ac_cv_lib_kstat_kstat_open = yes && gl_have_func=yes
99 # On HPUX9, an unprivileged user can get load averages this way.
100 if test $gl_have_func = no; then
101   AC_CHECK_FUNCS([pstat_getdynamic], [gl_have_func=yes])
104 # AIX has libperfstat which does not require root
105 if test $gl_have_func = no; then
106   AC_CHECK_LIB([perfstat], [perfstat_cpu_total])
107   test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_have_func=yes
110 if test $gl_have_func = no; then
111   AC_CHECK_HEADER([sys/dg_sys_info.h],
112     [gl_have_func=yes
113      AC_DEFINE([DGUX], [1], [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
114      AC_CHECK_LIB([dgc], [dg_sys_info])])
117 # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
118 # uses stabs), but it is still SVR4.  We cannot check for <elf.h> because
119 # Irix 4.0.5F has the header but not the library.
120 if test $gl_have_func = no && test "$ac_cv_lib_elf_elf_begin" = yes \
121     && test "$ac_cv_lib_kvm_kvm_open" = yes; then
122   gl_have_func=yes
123   AC_DEFINE([SVR4], [1], [Define to 1 on System V Release 4.])
126 if test $gl_have_func = no; then
127   AC_CHECK_HEADER([inq_stats/cpustats.h],
128   [gl_have_func=yes
129    AC_DEFINE([UMAX], [1], [Define to 1 for Encore UMAX.])
130    AC_DEFINE([UMAX4_3], [1],
131              [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
132               instead of <sys/cpustats.h>.])])
135 if test $gl_have_func = no; then
136   AC_CHECK_HEADER([sys/cpustats.h],
137   [gl_have_func=yes; AC_DEFINE([UMAX])])
140 if test $gl_have_func = no; then
141   AC_CHECK_HEADERS([mach/mach.h])
144 AC_CHECK_HEADERS([nlist.h],
145 [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
146                   [], [],
147                   [@%:@include <nlist.h>])
148  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]],
149                    [[struct nlist x;
150                     #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
151                     x.n_un.n_name = "";
152                     #else
153                     x.n_name = "";
154                     #endif]])],
155                 [AC_DEFINE([N_NAME_POINTER], [1],
156                            [Define to 1 if the nlist n_name member is a pointer])])
157 ])dnl
158 ])# gl_PREREQ_GETLOADAVG