X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=m4%2Fgetloadavg.m4;h=567245ea8bc495fa47b0eff942f2c1356dcca072;hb=f68c57a7466a299f333352b6d6c958a3a36c0e3c;hp=9680420009ea3191e02eed72bb662ada6b41b960;hpb=d30b38a75f551054922811ead835433176b3fb23;p=gnulib.git diff --git a/m4/getloadavg.m4 b/m4/getloadavg.m4 index 968042000..567245ea8 100644 --- a/m4/getloadavg.m4 +++ b/m4/getloadavg.m4 @@ -1,22 +1,49 @@ -#serial 3 +#serial 11 -AC_DEFUN(AM_FUNC_GETLOADAVG, +# A replacement for autoconf's macro by the same name. This version +# accepts an optional argument specifying the name of the $srcdir-relative +# directory in which the file getloadavg.c may be found. It is unusual +# (but justified, imho) that this file is required at ./configure time. + +undefine([AC_FUNC_GETLOADAVG]) + +# AC_FUNC_GETLOADAVG +# ------------------ +AC_DEFUN([AC_FUNC_GETLOADAVG], [ac_have_func=no # yes means we've found a way to get the load average. -am_cv_saved_LIBS="$LIBS" +AC_CHECK_HEADERS_ONCE(fcntl.h locale.h unistd.h) +AC_CHECK_HEADERS(mach/mach.h) +AC_CHECK_FUNCS(setlocale) + +# By default, expect to find getloadavg.c in $srcdir/. +ac_lib_dir_getloadavg=$srcdir +# But if there's an argument, DIR, expect to find getloadavg.c in $srcdir/DIR. +m4_ifval([$1], [ac_lib_dir_getloadavg=$srcdir/$1]) +# Make sure getloadavg.c is where it belongs, at ./configure-time. +test -f $ac_lib_dir_getloadavg/getloadavg.c \ + || AC_MSG_ERROR([getloadavg.c is not in $ac_lib_dir_getloadavg]) +# FIXME: Add an autoconf-time test, too? + +ac_save_LIBS=$LIBS + +# Check for getloadavg, but be sure not to touch the cache variable. +(AC_CHECK_FUNC(getloadavg, exit 0, exit 1)) && ac_have_func=yes # On HPUX9, an unprivileged user can get load averages through this function. AC_CHECK_FUNCS(pstat_getdynamic) # Solaris has libkstat which does not require root. AC_CHECK_LIB(kstat, kstat_open) -if test $ac_cv_lib_kstat_kstat_open = yes ; then ac_have_func=yes ; fi +test $ac_cv_lib_kstat_kstat_open = yes && ac_have_func=yes # Some systems with -lutil have (and need) -lkvm as well, some do not. # On Solaris, -lkvm requires nlist from -lelf, so check that first # to get the right answer into the cache. # For kstat on solaris, we need libelf to force the definition of SVR4 below. -AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS") +if test $ac_have_func = no; then + AC_CHECK_LIB(elf, elf_begin, LIBS="-lelf $LIBS") +fi if test $ac_have_func = no; then AC_CHECK_LIB(kvm, kvm_open, LIBS="-lkvm $LIBS") # Check for the 4.4BSD definition of getloadavg. @@ -27,72 +54,32 @@ fi if test $ac_have_func = no; then # There is a commonly available library for RS/6000 AIX. # Since it is not a standard part of AIX, it might be installed locally. - ac_save_LIBS="$LIBS" + ac_getloadavg_LIBS=$LIBS LIBS="-L/usr/local/lib $LIBS" AC_CHECK_LIB(getloadavg, getloadavg, - LIBS="-lgetloadavg $LIBS", LIBS="$ac_save_LIBS") + [LIBS="-lgetloadavg $LIBS"], [LIBS=$ac_getloadavg_LIBS]) fi -# Make sure it is really in the library, if we think we found it. -AC_REPLACE_FUNCS(getloadavg) - -if test $ac_cv_func_getloadavg = yes; then - AC_DEFINE(HAVE_GETLOADAVG) - ac_have_func=yes -else - AC_DEFINE(C_GETLOADAVG) - # Figure out what our getloadavg.c needs. - ac_have_func=no - AC_CHECK_HEADER(sys/dg_sys_info.h, - [ac_have_func=yes; AC_DEFINE(DGUX) - AC_CHECK_LIB(dgc, dg_sys_info)]) - - # We cannot check for , because Solaris 2 does not use dwarf (it - # uses stabs), but it is still SVR4. We cannot check for because - # Irix 4.0.5F has the header but not the library. - if test $ac_have_func = no && test $ac_cv_lib_elf_elf_begin = yes; then - ac_have_func=yes; AC_DEFINE(SVR4) - fi - - if test $ac_have_func = no; then - AC_CHECK_HEADER(inq_stats/cpustats.h, - [ac_have_func=yes; AC_DEFINE(UMAX) - AC_DEFINE(UMAX4_3)]) - fi - - if test $ac_have_func = no; then - AC_CHECK_HEADER(sys/cpustats.h, - [ac_have_func=yes; AC_DEFINE(UMAX)]) - fi - - if test $ac_have_func = no; then - AC_CHECK_HEADERS(mach/mach.h) - fi - - AC_CHECK_HEADER(nlist.h, - [AC_DEFINE(NLIST_STRUCT) - AC_CACHE_CHECK([for n_un in struct nlist], ac_cv_struct_nlist_n_un, - [AC_TRY_COMPILE([#include ], - [struct nlist n; n.n_un.n_name = 0;], - ac_cv_struct_nlist_n_un=yes, ac_cv_struct_nlist_n_un=no)]) - if test $ac_cv_struct_nlist_n_un = yes; then - AC_DEFINE(NLIST_NAME_UNION) - fi - ])dnl -fi # Do not have getloadavg in system libraries. +# Make sure it is really in the library, if we think we found it, +# otherwise set up the replacement function. +AC_CHECK_FUNCS(getloadavg, [], + [_AC_LIBOBJ_GETLOADAVG]) # Some definitions of getloadavg require that the program be installed setgid. -dnl FIXME Don't hardwire the path of getloadavg.c in the top-level directory. AC_CACHE_CHECK(whether getloadavg requires setgid, - ac_cv_func_getloadavg_setgid, + ac_cv_func_getloadavg_setgid, [AC_EGREP_CPP([Yowza Am I SETGID yet], -[#include "$srcdir/lib/getloadavg.c" +[#include "$ac_lib_dir_getloadavg/getloadavg.c" #ifdef LDAV_PRIVILEGED Yowza Am I SETGID yet -#endif], - ac_cv_func_getloadavg_setgid=yes, ac_cv_func_getloadavg_setgid=no)]) +@%:@endif], + ac_cv_func_getloadavg_setgid=yes, + ac_cv_func_getloadavg_setgid=no)]) if test $ac_cv_func_getloadavg_setgid = yes; then - NEED_SETGID=true; AC_DEFINE(GETLOADAVG_PRIVILEGED) + NEED_SETGID=true + AC_DEFINE(GETLOADAVG_PRIVILEGED, 1, + [Define if the `getloadavg' function needs to be run setuid + or setgid.]) else NEED_SETGID=false fi @@ -100,28 +87,39 @@ AC_SUBST(NEED_SETGID)dnl if test $ac_cv_func_getloadavg_setgid = yes; then AC_CACHE_CHECK(group of /dev/kmem, ac_cv_group_kmem, -changequote(<<, >>)dnl -<< - # On Solaris, /dev/kmem is a symlink. Get info on the real file. +[ # On Solaris, /dev/kmem is a symlink. Get info on the real file. ac_ls_output=`ls -lgL /dev/kmem 2>/dev/null` # If we got an error (system does not support symlinks), try without -L. test -z "$ac_ls_output" && ac_ls_output=`ls -lg /dev/kmem` ac_cv_group_kmem=`echo $ac_ls_output \ - | sed -ne 's/[ ][ ]*/ /g; + | sed -ne ['s/[ ][ ]*/ /g; s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\) *.*/\1/; - / /s/.* //;p;'` ->> -changequote([, ])dnl -) - KMEM_GROUP=$ac_cv_group_kmem + / /s/.* //;p;']` +]) + AC_SUBST(KMEM_GROUP, $ac_cv_group_kmem)dnl fi -AC_SUBST(KMEM_GROUP)dnl - -if test x = "x$am_cv_saved_LIBS"; then - GETLOADAVG_LIBS="$LIBS" +if test "x$ac_save_LIBS" = x; then + GETLOADAVG_LIBS=$LIBS else - GETLOADAVG_LIBS=`echo "$LIBS"|sed "s!$am_cv_saved_LIBS!!"` + GETLOADAVG_LIBS=`echo "$LIBS" | sed "s!$ac_save_LIBS!!"` fi +LIBS=$ac_save_LIBS + AC_SUBST(GETLOADAVG_LIBS)dnl -LIBS="$am_cv_saved_LIBS" +])# AC_FUNC_GETLOADAVG + + +AC_DEFUN([gl_FUNC_GETLOADAVG], +[ + AC_FUNC_GETLOADAVG([lib]) + dnl Note AC_FUNC_GETLOADAVG does AC_LIBOBJ(getloadavg). + if test $ac_cv_func_getloadavg = no; then + gl_PREREQ_GETLOADAVG + fi +]) + +# Prerequisites of lib/getloadavg.c not done by autoconf's AC_FUNC_GETLOADAVG. +AC_DEFUN([gl_PREREQ_GETLOADAVG], +[ + AC_CHECK_HEADERS_ONCE(fcntl.h unistd.h) ])