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