2 dnl Copyright (C) 1993-2003 Free Software Foundation, Inc.
3 dnl This file is free software, distributed under the terms of the GNU
4 dnl General Public License. As a special exception to the GNU General
5 dnl Public License, this file may be distributed as part of a program
6 dnl that contains a configuration script generated by Autoconf, under
7 dnl the same distribution terms as the rest of that program.
9 dnl From Bruno Haible, Marcus Daniels, Sam Steingold, Peter Burwood, Sam Steingold.
14 [AC_CHECK_HEADERS(sys/resource.h sys/times.h)dnl
15 if test $ac_cv_header_sys_resource_h = yes; then
16 dnl HAVE_SYS_RESOURCE_H defined
17 CL_LINK_CHECK([getrusage], cl_cv_func_getrusage,
18 [#include <sys/types.h> /* NetBSD 1.0 needs this */
20 #include <sys/resource.h>],
21 [struct rusage x; int y = RUSAGE_SELF; getrusage(y,&x); x.ru_utime.tv_sec;])dnl
22 if test $cl_cv_func_getrusage = yes; then
23 CL_PROTO([getrusage], [
29 #include <sys/types.h> /* NetBSD 1.0 needs this */
31 #include <sys/resource.h>
33 [int getrusage (int who, struct rusage * rusage);],
34 [cl_cv_proto_getrusage_arg1="int"],
35 [cl_cv_proto_getrusage_arg1="enum __rusage_who"])
36 ], [extern int getrusage ($cl_cv_proto_getrusage_arg1, struct rusage *);])dnl
37 AC_CACHE_CHECK(whether getrusage works, cl_cv_func_getrusage_works, [
38 AC_RUN_IFELSE([AC_LANG_SOURCE([[
40 #include <sys/types.h> /* NetBSD 1.0 needs this */
42 #include <time.h> /* for time(2) */
43 #include <sys/resource.h>
46 struct rusage used, prev;
47 time_t end = time(NULL)+2;
50 if ((count = getrusage(RUSAGE_SELF, &prev))) {
51 /* getrusage is defined but does not do anything. */
52 /*fprintf(stderr,"getrusage failed: return=%d\n",count);*/
55 while (time(NULL) < end) {
57 getrusage(RUSAGE_SELF, &used);
58 if ((used.ru_utime.tv_usec != prev.ru_utime.tv_usec)
59 || (used.ru_utime.tv_sec != prev.ru_utime.tv_sec)
60 || (used.ru_stime.tv_usec != prev.ru_stime.tv_usec)
61 || (used.ru_stime.tv_sec != prev.ru_stime.tv_sec)) {
62 /*fprintf(stderr,"success after %d runs\n",count);*/
66 /* getrusage is defined but does not work. */
67 /*fprintf(stderr,"failure after %d runs\n",count);*/
70 [cl_cv_func_getrusage_works=yes],
71 [cl_cv_func_getrusage_works=no],
72 dnl When cross-compiling, don't assume anything.
73 [cl_cv_func_getrusage_works="guessing no"])])
75 if test "$cl_cv_func_getrusage_works" = yes; then
76 AC_DEFINE(HAVE_GETRUSAGE,,[have <sys/time.h>, the getrusage() function, the struct rusage type, and <sys/resource.h> defines RUSAGE_SELF])
77 AC_DEFINE_UNQUOTED(RUSAGE_WHO_T,$cl_cv_proto_getrusage_arg1,[type of `who' in getrusage() declaration])