* lisp/dired-aux.el (shell-command-guess-xdg): Check nil xdg-mime (bug#71270).
[emacs.git] / m4 / getloadavg.m4
blob0918bcd21eca25a703918ac6df8d3d517ff99c16
1 # getloadavg.m4
2 # serial 13
3 dnl Copyright (C) 1992-1996, 1999-2000, 2002-2003, 2006, 2008-2024 Free Software
4 dnl Foundation, Inc.
5 dnl This file is free software; the Free Software Foundation
6 dnl gives unlimited permission to copy and/or distribute it,
7 dnl with or without modifications, as long as this notice is preserved.
9 # Check for getloadavg.
11 # Autoconf defines AC_FUNC_GETLOADAVG, but that is obsolescent.
12 # New applications should use gl_GETLOADAVG instead.
14 # gl_GETLOADAVG
15 # -------------
16 AC_DEFUN([gl_GETLOADAVG],
17 [AC_REQUIRE([gl_STDLIB_H_DEFAULTS])
19 # Persuade glibc <stdlib.h> to declare getloadavg().
20 AC_REQUIRE([AC_USE_SYSTEM_EXTENSIONS])
22 gl_saved_LIBS=$LIBS
24 # getloadavg is present in libc on glibc >= 2.2, Mac OS X, FreeBSD >= 2.0,
25 # NetBSD >= 0.9, OpenBSD >= 2.0, Solaris >= 7.
26 HAVE_GETLOADAVG=1
27 gl_CHECK_FUNCS_ANDROID([getloadavg], [[#include <stdlib.h>]])
28 if test $ac_cv_func_getloadavg != yes; then
29    case "$gl_cv_onwards_func_getloadavg" in
30      future*) REPLACE_GETLOADAVG=1 ;;
31    esac
33    gl_func_getloadavg_done=no
35    # Some systems with -lutil have (and need) -lkvm as well, some do not.
36    # On Solaris, -lkvm requires nlist from -lelf, so check that first
37    # to get the right answer into the cache.
38    # For kstat on solaris, we need to test for libelf and libkvm to force the
39    # definition of SVR4 below.
40    if test $gl_func_getloadavg_done = no; then
41      AC_CHECK_LIB([elf], [elf_begin], [LIBS="-lelf $LIBS"])
42      AC_CHECK_LIB([kvm], [kvm_open], [LIBS="-lkvm $LIBS"])
43      # Check for the 4.4BSD definition of getloadavg.
44      AC_CHECK_LIB([util], [getloadavg],
45        [LIBS="-lutil $LIBS" gl_func_getloadavg_done=yes])
46    fi
48    if test $gl_func_getloadavg_done = no; then
49      # There is a commonly available library for RS/6000 AIX.
50      # Since it is not a standard part of AIX, it might be installed locally.
51      gl_getloadavg_LIBS=$LIBS
52      if test $cross_compiling != yes; then
53        LIBS="-L/usr/local/lib $LIBS"
54      fi
55      AC_CHECK_LIB([getloadavg], [getloadavg],
56                   [LIBS="-lgetloadavg $LIBS" gl_func_getloadavg_done=yes],
57                   [LIBS=$gl_getloadavg_LIBS])
58    fi
60    # Set up the replacement function if necessary.
61    if test $gl_func_getloadavg_done = no; then
62      HAVE_GETLOADAVG=0
64      # Solaris has libkstat which does not require root.
65      AC_CHECK_LIB([kstat], [kstat_open])
66      test $ac_cv_lib_kstat_kstat_open = yes && gl_func_getloadavg_done=yes
68      # AIX has libperfstat which does not require root
69      if test $gl_func_getloadavg_done = no; then
70        AC_CHECK_LIB([perfstat], [perfstat_cpu_total])
71        test $ac_cv_lib_perfstat_perfstat_cpu_total = yes && gl_func_getloadavg_done=yes
72      fi
74      if test $gl_func_getloadavg_done = no; then
75        AC_CHECK_HEADER([sys/dg_sys_info.h],
76          [gl_func_getloadavg_done=yes
77           AC_DEFINE([DGUX], [1], [Define to 1 for DGUX with <sys/dg_sys_info.h>.])
78           AC_CHECK_LIB([dgc], [dg_sys_info])])
79      fi
80    fi
83 if test "x$gl_saved_LIBS" = x; then
84   GETLOADAVG_LIBS=$LIBS
85 else
86   GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$gl_saved_LIBS!!"`
88 LIBS=$gl_saved_LIBS
90 AC_SUBST([GETLOADAVG_LIBS])dnl
92 # Test whether the system declares getloadavg. Solaris has the function
93 # but declares it in <sys/loadavg.h>, not <stdlib.h>.
94 AC_CHECK_HEADERS([sys/loadavg.h])
95 if test $ac_cv_header_sys_loadavg_h = yes; then
96   HAVE_SYS_LOADAVG_H=1
97 else
98   HAVE_SYS_LOADAVG_H=0
100 AC_CHECK_DECL([getloadavg], [], [HAVE_DECL_GETLOADAVG=0],
101   [[#if HAVE_SYS_LOADAVG_H
102     /* OpenIndiana has a bug: <sys/time.h> must be included before
103        <sys/loadavg.h>.  */
104     # include <sys/time.h>
105     # include <sys/loadavg.h>
106     #endif
107     #include <stdlib.h>]])
108 ])# gl_GETLOADAVG
111 # gl_PREREQ_GETLOADAVG
112 # --------------------
113 # Set up the AC_LIBOBJ replacement of 'getloadavg'.
114 AC_DEFUN([gl_PREREQ_GETLOADAVG],
116 # Figure out what our getloadavg.c needs.
118 AC_CHECK_HEADERS_ONCE([sys/param.h unistd.h])
120 # On HPUX9, an unprivileged user can get load averages this way.
121 if test $gl_func_getloadavg_done = no; then
122   AC_CHECK_FUNCS([pstat_getdynamic], [gl_func_getloadavg_done=yes])
125 # We cannot check for <dwarf.h>, because Solaris 2 does not use dwarf (it
126 # uses stabs), but it is still SVR4.  We cannot check for <elf.h> because
127 # Irix 4.0.5F has the header but not the library.
128 if test $gl_func_getloadavg_done = no && test "$ac_cv_lib_elf_elf_begin" = yes \
129     && test "$ac_cv_lib_kvm_kvm_open" = yes; then
130   gl_func_getloadavg_done=yes
131   AC_DEFINE([SVR4], [1], [Define to 1 on System V Release 4.])
134 if test $gl_func_getloadavg_done = no; then
135   AC_CHECK_HEADER([inq_stats/cpustats.h],
136   [gl_func_getloadavg_done=yes
137    AC_DEFINE([UMAX], [1], [Define to 1 for Encore UMAX.])
138    AC_DEFINE([UMAX4_3], [1],
139              [Define to 1 for Encore UMAX 4.3 that has <inq_status/cpustats.h>
140               instead of <sys/cpustats.h>.])])
143 if test $gl_func_getloadavg_done = no; then
144   AC_CHECK_HEADER([sys/cpustats.h],
145   [gl_func_getloadavg_done=yes; AC_DEFINE([UMAX])])
148 if test $gl_func_getloadavg_done = no; then
149   AC_CHECK_HEADERS([mach/mach.h])
152 AC_CHECK_HEADERS([nlist.h],
153 [AC_CHECK_MEMBERS([struct nlist.n_un.n_name],
154                   [], [],
155                   [#include <nlist.h>])
156  AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <nlist.h>]],
157                    [[struct nlist x;
158                     #ifdef HAVE_STRUCT_NLIST_N_UN_N_NAME
159                     x.n_un.n_name = "";
160                     #else
161                     x.n_name = "";
162                     #endif]])],
163                 [AC_DEFINE([N_NAME_POINTER], [1],
164                            [Define to 1 if the nlist n_name member is a pointer])])
165 ])dnl
166 ])# gl_PREREQ_GETLOADAVG