Commit | Line | Data |
---|---|---|
1f5d53eb PE |
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 | ||
316f8af0 | 10 | #serial 5 |
1f5d53eb PE |
11 | |
12 | # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent. | |
13 | # New applications should use gl_GETLOADAVG instead. | |
14 | ||
6a3e57bb PE |
15 | # gl_GETLOADAVG |
16 | # ------------- | |
1f5d53eb PE |
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 | ||
1f5d53eb PE |
23 | gl_save_LIBS=$LIBS |
24 | ||
7d315eb6 PE |
25 | # getloadvg is present in libc on glibc >= 2.2, MacOS X, FreeBSD >= 2.0, |
26 | # NetBSD >= 0.9, OpenBSD >= 2.0, Solaris >= 7. | |
8aeb5be9 | 27 | HAVE_GETLOADAVG=1 |
1f5d53eb | 28 | AC_CHECK_FUNC([getloadavg], [], |
add3f049 | 29 | [gl_func_getloadavg_done=no |
1f5d53eb PE |
30 | |
31 | # Some systems with -lutil have (and need) -lkvm as well, some do not. | |
32 | # On Solaris, -lkvm requires nlist from -lelf, so check that first | |
33 | # to get the right answer into the cache. | |
34 | # For kstat on solaris, we need to test for libelf and libkvm to force the | |
35 | # definition of SVR4 below. | |
add3f049 | 36 | if test $gl_func_getloadavg_done = no; then |
1f5d53eb PE |
37 | AC_CHECK_LIB([elf], [elf_begin], [LIBS="-lelf $LIBS"]) |
38 | AC_CHECK_LIB([kvm], [kvm_open], [LIBS="-lkvm $LIBS"]) | |
39 | # Check for the 4.4BSD definition of getloadavg. | |
40 | AC_CHECK_LIB([util], [getloadavg], | |
add3f049 | 41 | [LIBS="-lutil $LIBS" gl_func_getloadavg_done=yes]) |
1f5d53eb PE |
42 | fi |
43 | ||
add3f049 | 44 | if test $gl_func_getloadavg_done = no; then |
1f5d53eb PE |
45 | # There is a commonly available library for RS/6000 AIX. |
46 | # Since it is not a standard part of AIX, it might be installed locally. | |
47 | gl_getloadavg_LIBS=$LIBS | |
48 | LIBS="-L/usr/local/lib $LIBS" | |
49 | AC_CHECK_LIB([getloadavg], [getloadavg], | |
add3f049 | 50 | [LIBS="-lgetloadavg $LIBS" gl_func_getloadavg_done=yes], |
1f5d53eb PE |
51 | [LIBS=$gl_getloadavg_LIBS]) |
52 | fi | |
53 | ||
54 | # Set up the replacement function if necessary. | |
add3f049 | 55 | if test $gl_func_getloadavg_done = no; then |
8aeb5be9 | 56 | HAVE_GETLOADAVG=0 |
add3f049 PE |
57 | |
58 | # Solaris has libkstat which does not require root. | |
59 | AC_CHECK_LIB([kstat], [kstat_open]) | |
60 | test $ac_cv_lib_kstat_kstat_open = yes && gl_func_getloadavg_done=yes | |
61 | ||
62 | # AIX has libperfstat which does not require root | |
63 | if test $gl_func_getloadavg_done = no; then | |
64 | AC_CHECK_LIB([perfstat], [perfstat_cpu_total]) | |
65 | test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_func_getloadavg_done=yes | |
66 | fi | |
67 | ||
68 | if test $gl_func_getloadavg_done = no; then | |
69 | AC_CHECK_HEADER([sys/dg_sys_info.h], | |
70 | [gl_func_getloadavg_done=yes | |
71 | AC_DEFINE([DGUX], [1], [Define to 1 for DGUX with <sys/dg_sys_info.h>.]) | |
72 | AC_CHECK_LIB([dgc], [dg_sys_info])]) | |
73 | fi | |
1f5d53eb PE |
74 | fi]) |
75 | ||
76 | if test "x$gl_save_LIBS" = x; then | |
77 | GETLOADAVG_LIBS=$LIBS | |
78 | else | |
79 | GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_save_LIBS!!"` | |
80 | fi | |
81 | LIBS=$gl_save_LIBS | |
82 | ||
83 | AC_SUBST([GETLOADAVG_LIBS])dnl | |
84 | ||
85 | # Test whether the system declares getloadavg. Solaris has the function | |
86 | # but declares it in <sys/loadavg.h>, not <stdlib.h>. | |
87 | AC_CHECK_HEADERS([sys/loadavg.h]) | |
88 | if test $ac_cv_header_sys_loadavg_h = yes; then | |
89 | HAVE_SYS_LOADAVG_H=1 | |
90 | else | |
91 | HAVE_SYS_LOADAVG_H=0 | |
92 | fi | |
93 | AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0], | |
316f8af0 PE |
94 | [[#if HAVE_SYS_LOADAVG_H |
95 | # include <sys/loadavg.h> | |
96 | #endif | |
97 | #include <stdlib.h>]]) | |
1f5d53eb PE |
98 | ])# gl_GETLOADAVG |
99 | ||
100 | ||
101 | # gl_PREREQ_GETLOADAVG | |
102 | # -------------------- | |
103 | # Set up the AC_LIBOBJ replacement of `getloadavg'. | |
104 | AC_DEFUN([gl_PREREQ_GETLOADAVG], | |
105 | [ | |
106 | # Figure out what our getloadavg.c needs. | |
107 | ||
1f5d53eb | 108 | # On HPUX9, an unprivileged user can get load averages this way. |
add3f049 PE |
109 | if test $gl_func_getloadavg_done = no; then |
110 | AC_CHECK_FUNCS([pstat_getdynamic], [gl_func_getloadavg_done=yes]) | |
1f5d53eb PE |
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. | |
add3f049 | 116 | if test $gl_func_getloadavg_done = no && test "$ac_cv_lib_elf_elf_begin" = yes \ |
1f5d53eb | 117 | && test "$ac_cv_lib_kvm_kvm_open" = yes; then |
add3f049 | 118 | gl_func_getloadavg_done=yes |
1f5d53eb PE |
119 | AC_DEFINE([SVR4], [1], [Define to 1 on System V Release 4.]) |
120 | fi | |
121 | ||
add3f049 | 122 | if test $gl_func_getloadavg_done = no; then |
1f5d53eb | 123 | AC_CHECK_HEADER([inq_stats/cpustats.h], |
add3f049 | 124 | [gl_func_getloadavg_done=yes |
1f5d53eb PE |
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 | ||
add3f049 | 131 | if test $gl_func_getloadavg_done = no; then |
1f5d53eb | 132 | AC_CHECK_HEADER([sys/cpustats.h], |
add3f049 | 133 | [gl_func_getloadavg_done=yes; AC_DEFINE([UMAX])]) |
1f5d53eb PE |
134 | fi |
135 | ||
add3f049 | 136 | if test $gl_func_getloadavg_done = no; then |
1f5d53eb PE |
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 |