getloadavg.m4 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  1. # Check for getloadavg.
  2. # Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2011 Free Software
  3. # Foundation, Inc.
  4. # This file is free software; the Free Software Foundation
  5. # gives unlimited permission to copy and/or distribute it,
  6. # with or without modifications, as long as this notice is preserved.
  7. #serial 5
  8. # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
  9. # New applications should use gl_GETLOADAVG instead.
  10. # gl_GETLOADAVG
  11. # -------------
  12. AC_DEFUN([gl_GETLOADAVG],
  13. [AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
  14. # Persuade glibc <stdlib.h> to declare getloadavg().
  15. AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
  16. gl_save_LIBS=$LIBS
  17. # getloadvg is present in libc on glibc >= 2.2, MacOS X, FreeBSD >= 2.0,
  18. # NetBSD >= 0.9, OpenBSD >= 2.0, Solaris >= 7.
  19. HAVE_GETLOADAVG=1
  20. AC_CHECK_FUNC([getloadavg], [],
  21. [gl_func_getloadavg_done=no
  22. # Some systems with -lutil have (and need) -lkvm as well, some do not.
  23. # On Solaris, -lkvm requires nlist from -lelf, so check that first
  24. # to get the right answer into the cache.
  25. # For kstat on solaris, we need to test for libelf and libkvm to force the
  26. # definition of SVR4 below.
  27. if test $gl_func_getloadavg_done = no; then
  28. AC_CHECK_LIB([elf], [elf_begin], [LIBS="-lelf $LIBS"])
  29. AC_CHECK_LIB([kvm], [kvm_open], [LIBS="-lkvm $LIBS"])
  30. # Check for the 4.4BSD definition of getloadavg.
  31. AC_CHECK_LIB([util], [getloadavg],
  32. [LIBS="-lutil $LIBS" gl_func_getloadavg_done=yes])
  33. fi
  34. if test $gl_func_getloadavg_done = no; then
  35. # There is a commonly available library for RS/6000 AIX.
  36. # Since it is not a standard part of AIX, it might be installed locally.
  37. gl_getloadavg_LIBS=$LIBS
  38. LIBS="-L/usr/local/lib $LIBS"
  39. AC_CHECK_LIB([getloadavg], [getloadavg],
  40. [LIBS="-lgetloadavg $LIBS" gl_func_getloadavg_done=yes],
  41. [LIBS=$gl_getloadavg_LIBS])
  42. fi
  43. # Set up the replacement function if necessary.
  44. if test $gl_func_getloadavg_done = no; then
  45. HAVE_GETLOADAVG=0
  46. # Solaris has libkstat which does not require root.
  47. AC_CHECK_LIB([kstat], [kstat_open])
  48. test $ac_cv_lib_kstat_kstat_open = yes && gl_func_getloadavg_done=yes
  49. # AIX has libperfstat which does not require root
  50. if test $gl_func_getloadavg_done = no; then
  51. AC_CHECK_LIB([perfstat], [perfstat_cpu_total])
  52. test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_func_getloadavg_done=yes
  53. fi
  54. if test $gl_func_getloadavg_done = no; then
  55. AC_CHECK_HEADER([sys/dg_sys_info.h],
  56. [gl_func_getloadavg_done=yes
  57. AC_DEFINE([DGUX], [1], [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
  58. AC_CHECK_LIB([dgc], [dg_sys_info])])
  59. fi
  60. fi])
  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. AC_SUBST([GETLOADAVG_LIBS])dnl
  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. # gl_PREREQ_GETLOADAVG
  83. # --------------------
  84. # Set up the AC_LIBOBJ replacement of `getloadavg'.
  85. AC_DEFUN([gl_PREREQ_GETLOADAVG],
  86. [
  87. # Figure out what our getloadavg.c needs.
  88. # On HPUX9, an unprivileged user can get load averages this way.
  89. if test $gl_func_getloadavg_done = no; then
  90. AC_CHECK_FUNCS([pstat_getdynamic], [gl_func_getloadavg_done=yes])
  91. fi
  92. # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
  93. # uses stabs), but it is still SVR4. We cannot check for <elf.h> because
  94. # Irix 4.0.5F has the header but not the library.
  95. if test $gl_func_getloadavg_done = no && test "$ac_cv_lib_elf_elf_begin" = yes \
  96. && test "$ac_cv_lib_kvm_kvm_open" = yes; then
  97. gl_func_getloadavg_done=yes
  98. AC_DEFINE([SVR4], [1], [Define to 1 on System V Release 4.])
  99. fi
  100. if test $gl_func_getloadavg_done = no; then
  101. AC_CHECK_HEADER([inq_stats/cpustats.h],
  102. [gl_func_getloadavg_done=yes
  103. AC_DEFINE([UMAX], [1], [Define to 1 for Encore UMAX.])
  104. AC_DEFINE([UMAX4_3], [1],
  105. [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
  106. instead of <sys/cpustats.h>.])])
  107. fi
  108. if test $gl_func_getloadavg_done = no; then
  109. AC_CHECK_HEADER([sys/cpustats.h],
  110. [gl_func_getloadavg_done=yes; AC_DEFINE([UMAX])])
  111. fi
  112. if test $gl_func_getloadavg_done = no; then
  113. AC_CHECK_HEADERS([mach/mach.h])
  114. fi
  115. AC_CHECK_HEADERS([nlist.h],
  116. [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
  117. [], [],
  118. [@%:@include <nlist.h>])
  119. AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]],
  120. [[struct nlist x;
  121. #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
  122. x.n_un.n_name = "";
  123. #else
  124. x.n_name = "";
  125. #endif]])],
  126. [AC_DEFINE([N_NAME_POINTER], [1],
  127. [Define to 1 if the nlist n_name member is a pointer])])
  128. ])dnl
  129. ])# gl_PREREQ_GETLOADAVG