broken out of ../acinclude.m4
authorJim Meyering <jim@meyering.net>
Sat, 21 Dec 1996 01:50:50 +0000 (01:50 +0000)
committerJim Meyering <jim@meyering.net>
Sat, 21 Dec 1996 01:50:50 +0000 (01:50 +0000)
m4/getgroups.m4 [new file with mode: 0644]
m4/getline.m4 [new file with mode: 0644]
m4/getloadavg.m4 [new file with mode: 0644]
m4/jm-mktime.m4 [new file with mode: 0644]
m4/jm-winsz1.m4 [new file with mode: 0644]
m4/jm-winsz2.m4 [new file with mode: 0644]
m4/memcmp.m4 [new file with mode: 0644]
m4/strftime.m4 [new file with mode: 0644]
m4/uptime.m4 [new file with mode: 0644]

diff --git a/m4/getgroups.m4 b/m4/getgroups.m4
new file mode 100644 (file)
index 0000000..7b94162
--- /dev/null
@@ -0,0 +1,31 @@
+#serial 1
+
+dnl From Jim Meyering.
+dnl If you use this macro in a package, you should
+dnl add the following two lines to acconfig.h:
+dnl  /* Define to rpl_getgroups if the replacement function should be used.  */
+dnl  #undef getgroups
+dnl
+
+AC_DEFUN(jm_FUNC_GETGROUPS,
+[AC_REQUIRE([AC_TYPE_GETGROUPS])dnl
+ AC_REQUIRE([AC_TYPE_SIZE_T])dnl
+ AC_CACHE_CHECK([for working getgroups], jm_cv_func_working_getgroups,
+  [AC_TRY_RUN([
+    int
+    main ()
+    {
+      /* On Ultrix 4.3, getgroups (0, 0) always fails.  */
+      exit (getgroups (0, 0) == -1 ? 1 : 0);
+    }
+             ],
+            jm_cv_func_working_getgroups=yes,
+             jm_cv_func_working_getgroups=no,
+            dnl When crosscompiling, assume getgroups is broken.
+            jm_cv_func_working_getgroups=no)
+  ])
+  if test $jm_cv_func_working_getgroups = no; then
+    LIBOBJS="$LIBOBJS getgroups.o"
+    AC_DEFINE_UNQUOTED(getgroups, rpl_getgroups)
+  fi
+])
diff --git a/m4/getline.m4 b/m4/getline.m4
new file mode 100644 (file)
index 0000000..3564472
--- /dev/null
@@ -0,0 +1,45 @@
+#serial 1
+
+dnl See if there's a working, system-supplied version of the getline function.
+dnl We can't just to AC_REPLACE_FUNCS(getline) because some systems
+dnl have a function by that name in -linet that doesn't have anything
+dnl to do with the function we need.
+AC_DEFUN(AM_FUNC_GETLINE,
+[dnl
+  am_getline_needs_run_time_check=no
+  am_cv_func_working_getline=yes
+  AC_CHECK_FUNC(getline,
+               dnl Found it in some library.  Verify that it works.
+               am_getline_needs_run_time_check=yes,
+               am_cv_func_working_getline=no)
+  if test $am_getline_needs_run_time_check = yes; then
+    AC_CACHE_CHECK([for working getline function], am_cv_func_working_getline,
+    [echo fooN |tr -d '\012'|tr N '\012' > conftestdata
+    AC_TRY_RUN([
+#    include <stdio.h>
+#    include <sys/types.h>
+#    if HAVE_STRING_H
+#     include <string.h>
+#    endif
+    int main ()
+    { /* Based on a test program from Karl Heuer.  */
+      char *line = NULL;
+      size_t siz = 0;
+      int len;
+      FILE *in = fopen ("./conftestdata", "r");
+      if (!in)
+       return 1;
+      len = getline (&line, &siz, in);
+      exit ((len == 4 && line && strcmp (line, "foo\n") == 0) ? 0 : 1);
+    }
+    ], am_cv_func_working_getline=yes dnl The library version works.
+    , am_cv_func_working_getline=no dnl The library version does NOT work.
+    , am_cv_func_working_getline=no dnl We're cross compiling.
+    )])
+  fi
+
+  if test $am_cv_func_working_getline = no; then
+    LIBOBJS="$LIBOBJS getline.o"
+    AC_SUBST(LIBOBJS)dnl
+  fi
+])
diff --git a/m4/getloadavg.m4 b/m4/getloadavg.m4
new file mode 100644 (file)
index 0000000..bb52d8a
--- /dev/null
@@ -0,0 +1,124 @@
+#serial 2
+
+AC_DEFUN(AM_FUNC_GETLOADAVG,
+[ac_have_func=no # yes means we've found a way to get the load average.
+
+am_cv_saved_LIBS="$LIBS"
+
+# 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
+
+# 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(kvm, kvm_open, LIBS="-lkvm $LIBS")
+  # Check for the 4.4BSD definition of getloadavg.
+  AC_CHECK_LIB(util, getloadavg,
+    [LIBS="-lutil $LIBS" ac_have_func=yes ac_cv_func_getloadavg_setgid=yes])
+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"
+  LIBS="-L/usr/local/lib $LIBS"
+  AC_CHECK_LIB(getloadavg, getloadavg,
+    LIBS="-lgetloadavg $LIBS", LIBS="$ac_save_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 <dwarf.h>, because Solaris 2 does not use dwarf (it
+  # uses stabs), but it is still SVR4.  We cannot check for <elf.h> 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 <nlist.h>],
+  [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.
+
+# 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_EGREP_CPP([Yowza Am I SETGID yet],
+[#include "$srcdir/lib/getloadavg.c"
+#ifdef LDAV_PRIVILEGED
+Yowza Am I SETGID yet
+#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)
+else
+  NEED_SETGID=false
+fi
+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.
+  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;
+              s/^.[sSrwx-]* *[0-9]* *\([^0-9]*\)  *.*/\1/;
+              / /s/.* //;p;'`
+>>
+changequote([, ])dnl
+)
+  KMEM_GROUP=$ac_cv_group_kmem
+fi
+AC_SUBST(KMEM_GROUP)dnl
+
+if test x = "x$am_cv_saved_LIBS"; then
+  GETLOADAVG_LIBS="$LIBS"
+else
+  GETLOADAVG_LIBS=`echo "$LIBS"|sed "s!$am_cv_saved_LIBS!!"`
+fi
+AC_SUBST(GETLOADAVG_LIBS)dnl
+LIBS="$am_cv_saved_LIBS"
+])
diff --git a/m4/jm-mktime.m4 b/m4/jm-mktime.m4
new file mode 100644 (file)
index 0000000..ab78db7
--- /dev/null
@@ -0,0 +1,14 @@
+#serial 1
+
+dnl From Jim Meyering.
+dnl If you use this macro in a package, you should
+dnl add the following two lines to acconfig.h:
+dnl   /* Define to rpl_mktime if the replacement function should be used.  */
+dnl   #undef mktime
+dnl
+AC_DEFUN(jm_FUNC_MKTIME,
+[AC_REQUIRE([AM_FUNC_MKTIME])dnl
+ if test $am_cv_func_working_mktime = no; then
+   AC_DEFINE_UNQUOTED(mktime, rpl_mktime)
+ fi
+])
diff --git a/m4/jm-winsz1.m4 b/m4/jm-winsz1.m4
new file mode 100644 (file)
index 0000000..346e8dd
--- /dev/null
@@ -0,0 +1,19 @@
+dnl From Jim Meyering.
+#serial 1
+AC_DEFUN(jm_HEADER_TIOCGWINSZ_IN_TERMIOS_H,
+[AC_REQUIRE([AM_SYS_POSIX_TERMIOS])
+ AC_CACHE_CHECK([whether use of TIOCGWINSZ requires termios.h],
+               jm_cv_sys_tiocgwinsz_needs_termios_h,
+  [jm_cv_sys_tiocgwinsz_needs_termios_h=no
+
+   if test $am_cv_sys_posix_termios = yes; then
+     AC_EGREP_CPP([yes],
+     [#include <sys/types.h>
+#      include <termios.h>
+#      ifdef TIOCGWINSZ
+         yes
+#      endif
+     ], jm_cv_sys_tiocgwinsz_needs_termios_h=yes)
+   fi
+  ])
+])
diff --git a/m4/jm-winsz2.m4 b/m4/jm-winsz2.m4
new file mode 100644 (file)
index 0000000..642e1ff
--- /dev/null
@@ -0,0 +1,22 @@
+#serial 2
+
+AC_DEFUN(jm_HEADER_TIOCGWINSZ_NEEDS_SYS_IOCTL,
+[AC_REQUIRE([jm_HEADER_TIOCGWINSZ_IN_TERMIOS_H])
+ AC_CACHE_CHECK([whether use of TIOCGWINSZ requires sys/ioctl.h],
+               jm_cv_sys_tiocgwinsz_needs_sys_ioctl_h,
+  [jm_cv_sys_tiocgwinsz_needs_sys_ioctl_h=no
+
+  if test $jm_cv_sys_tiocgwinsz_needs_termios_h = no; then
+    AC_EGREP_CPP([yes],
+    [#include <sys/types.h>
+#     include <sys/ioctl.h>
+#     ifdef TIOCGWINSZ
+        yes
+#     endif
+    ], jm_cv_sys_tiocgwinsz_needs_sys_ioctl_h=yes)
+  fi
+  ])
+  if test $jm_cv_sys_tiocgwinsz_needs_sys_ioctl_h = yes; then
+    AC_DEFINE(GWINSZ_IN_SYS_IOCTL)
+  fi
+])
diff --git a/m4/memcmp.m4 b/m4/memcmp.m4
new file mode 100644 (file)
index 0000000..e76aeda
--- /dev/null
@@ -0,0 +1,13 @@
+#serial 1
+
+dnl If you use this macro in a package, you should
+dnl add the following two lines to acconfig.h:
+dnl   /* Define to rpl_memcmp if the replacement function should be used.  */
+dnl   #undef memcmp
+dnl
+AC_DEFUN(jm_FUNC_MEMCMP,
+[AC_REQUIRE([AC_FUNC_MEMCMP])dnl
+ if test $ac_cv_func_memcmp_clean = no; then
+   AC_DEFINE_UNQUOTED(memcmp, rpl_memcmp)
+ fi
+])
diff --git a/m4/strftime.m4 b/m4/strftime.m4
new file mode 100644 (file)
index 0000000..8b40a69
--- /dev/null
@@ -0,0 +1,125 @@
+#serial 2
+
+dnl From Jim Meyering.
+dnl If you use this macro in a package, you should
+dnl add the following two lines to acconfig.h:
+dnl   /* Define to gnu_strftime if the replacement function should be used.  */
+dnl   #undef strftime
+dnl
+AC_DEFUN(jm_FUNC_GNU_STRFTIME,
+[AC_REQUIRE([AC_HEADER_TIME])dnl
+ AC_REQUIRE([AC_C_CONST])dnl
+ AC_REQUIRE([AC_HEADER_STDC])dnl
+ AC_CHECK_HEADERS(sys/time.h)
+ AC_CACHE_CHECK([for working GNU strftime], jm_cv_func_working_gnu_strftime,
+  [AC_TRY_RUN(
+changequote(<<, >>)dnl
+<< /* Ulrich Drepper provided parts of the test program.  */
+#if STDC_HEADERS
+# include <stdlib.h>
+#endif
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+static int
+compare (const char *fmt, const struct tm *tm, const char *expected)
+{
+  char buf[99];
+  strftime (buf, 99, fmt, tm);
+  if (strcmp (buf, expected))
+    {
+#ifdef SHOW_FAILURES
+      printf ("fmt: \"%s\", expected \"%s\", got \"%s\"\n",
+             fmt, expected, buf);
+#endif
+      return 1;
+    }
+  return 0;
+}
+
+int
+main ()
+{
+  int n_fail = 0;
+  struct tm *tm;
+  time_t t = 738367; /* Fri Jan  9 13:06:07 1970 */
+  tm = gmtime (&t);
+
+  /* This is necessary to make strftime give consistent zone strings and
+     e.g., seconds since the epoch (%s).  */
+  putenv ("TZ=GMT");
+
+#undef CMP
+#define CMP(Fmt, Expected) n_fail += compare ((Fmt), tm, (Expected))
+
+  CMP ("%-m", "1");            /* GNU */
+  CMP ("%A", "Friday");
+  CMP ("%^A", "FRIDAY");       /* The ^ is a GNU extension.  */
+  CMP ("%B", "January");
+  CMP ("%^B", "JANUARY");
+  CMP ("%C", "19");            /* POSIX.2 */
+  CMP ("%D", "01/09/70");      /* POSIX.2 */
+  CMP ("%G", "1970");          /* GNU */
+  CMP ("%H", "13");
+  CMP ("%I", "01");
+  CMP ("%M", "06");
+  CMP ("%M", "06");
+  CMP ("%R", "13:06");         /* POSIX.2 */
+  CMP ("%S", "07");
+  CMP ("%T", "13:06:07");      /* POSIX.2 */
+  CMP ("%U", "01");
+  CMP ("%V", "02");
+  CMP ("%W", "01");
+  CMP ("%X", "13:06:07");
+  CMP ("%Y", "1970");
+  CMP ("%Z", "GMT");
+  CMP ("%_m", " 1");           /* GNU */
+  CMP ("%a", "Fri");
+  CMP ("%^a", "FRI");
+  CMP ("%b", "Jan");
+  CMP ("%^b", "JAN");
+  CMP ("%c", "Fri Jan  9 13:06:07 1970");
+  CMP ("%^c", "FRI JAN  9 13:06:07 1970");
+  CMP ("%d", "09");
+  CMP ("%e", " 9");            /* POSIX.2 */
+  CMP ("%g", "70");            /* GNU */
+  CMP ("%h", "Jan");           /* POSIX.2 */
+  CMP ("%^h", "JAN");
+  CMP ("%j", "009");
+  CMP ("%k", "13");            /* GNU */
+  CMP ("%l", " 1");            /* GNU */
+  CMP ("%m", "01");
+  CMP ("%n", "\n");            /* POSIX.2 */
+  CMP ("%p", "PM");
+  CMP ("%r", "01:06:07 PM");   /* POSIX.2 */
+  CMP ("%s", "738367");                /* GNU */
+  CMP ("%t", "\t");            /* POSIX.2 */
+  CMP ("%u", "5");             /* POSIX.2 */
+  CMP ("%w", "5");
+  CMP ("%x", "01/09/70");
+  CMP ("%y", "70");
+  CMP ("%z", "+0000");         /* GNU */
+
+  exit (n_fail ? 1 : 0);
+}
+             >>,
+changequote([, ])dnl
+            jm_cv_func_working_gnu_strftime=yes,
+             jm_cv_func_working_gnu_strftime=no,
+            dnl When crosscompiling, assume strftime is missing or broken.
+            jm_cv_func_working_gnu_strftime=no)
+  ])
+  if test $jm_cv_func_working_gnu_strftime = no; then
+    LIBOBJS="$LIBOBJS strftime.o"
+    AC_DEFINE_UNQUOTED(strftime, gnu_strftime)
+  fi
+])
diff --git a/m4/uptime.m4 b/m4/uptime.m4
new file mode 100644 (file)
index 0000000..5df098c
--- /dev/null
@@ -0,0 +1,15 @@
+#serial 1
+
+AC_DEFUN(jm_SYS_PROC_UPTIME,
+[ dnl Require AC_PROG_CC to see if we're cross compiling.
+  AC_REQUIRE([AC_PROG_CC])
+  AC_CACHE_CHECK([for /proc/uptime], jm_cv_have_proc_uptime,
+  [jm_cv_have_proc_uptime=no
+    test -f /proc/uptime \
+      && test $ac_cv_prog_cc_cross = no \
+      && cat < /proc/uptime >/dev/null 2>/dev/null \
+      && jm_cv_have_proc_uptime=yes])
+  if test $jm_cv_have_proc_uptime = yes; then
+    AC_DEFINE(HAVE_PROC_UPTIME)
+  fi
+])