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