aclocal.m4 revision 89857
177298Sobriendnl See whether strncmp reads past the end of its string parameters.
277298Sobriendnl On some versions of SunOS4 at least, strncmp reads a word at a time
377298Sobriendnl but erroneously reads past the end of strings.  This can cause
477298Sobriendnl a SEGV in some cases.
577298SobrienAC_DEFUN(libiberty_AC_FUNC_STRNCMP,
677298Sobrien[AC_REQUIRE([AC_FUNC_MMAP])
777298SobrienAC_CACHE_CHECK([for working strncmp], ac_cv_func_strncmp_works,
877298Sobrien[AC_TRY_RUN([
977298Sobrien/* Test by Jim Wilson and Kaveh Ghazi.
1077298Sobrien   Check whether strncmp reads past the end of its string parameters. */
1177298Sobrien#include <sys/types.h>
1277298Sobrien
1377298Sobrien#ifdef HAVE_FCNTL_H
1477298Sobrien#include <fcntl.h>
1577298Sobrien#endif
1677298Sobrien
1777298Sobrien#ifdef HAVE_SYS_MMAN_H
1877298Sobrien#include <sys/mman.h>
1977298Sobrien#endif
2077298Sobrien
2177298Sobrien#ifndef MAP_ANON
2277298Sobrien#ifdef MAP_ANONYMOUS
2377298Sobrien#define MAP_ANON MAP_ANONYMOUS
2477298Sobrien#else
2577298Sobrien#define MAP_ANON MAP_FILE
2677298Sobrien#endif
2777298Sobrien#endif
2877298Sobrien
2977298Sobrien#ifndef MAP_FILE
3077298Sobrien#define MAP_FILE 0
3177298Sobrien#endif
3277298Sobrien#ifndef O_RDONLY
3377298Sobrien#define O_RDONLY 0
3477298Sobrien#endif
3577298Sobrien
3677298Sobrien#define MAP_LEN 0x10000
3777298Sobrien
3877298Sobrienmain ()
3977298Sobrien{
4077298Sobrien#if defined(HAVE_MMAP) || defined(HAVE_MMAP_ANYWHERE)
4177298Sobrien  char *p;
4277298Sobrien  int dev_zero;
4377298Sobrien
4477298Sobrien  dev_zero = open ("/dev/zero", O_RDONLY);
4577298Sobrien  if (dev_zero < 0)
4677298Sobrien    exit (1);
4777298Sobrien  
4877298Sobrien  p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
4977298Sobrien		     MAP_ANON|MAP_PRIVATE, dev_zero, 0);
5077298Sobrien  if (p == (char *)-1)
5189857Sobrien    p = (char *) mmap (0, MAP_LEN, PROT_READ|PROT_WRITE,
5289857Sobrien		       MAP_ANON|MAP_PRIVATE, -1, 0);
5389857Sobrien  if (p == (char *)-1)
5477298Sobrien    exit (2);
5577298Sobrien  else
5677298Sobrien    {
5777298Sobrien      char *string = "__si_type_info";
5877298Sobrien      char *q = (char *) p + MAP_LEN - strlen (string) - 2;
5977298Sobrien      char *r = (char *) p + 0xe;
6077298Sobrien
6177298Sobrien      strcpy (q, string);
6277298Sobrien      strcpy (r, string);
6377298Sobrien      strncmp (r, q, 14);
6477298Sobrien    }
6577298Sobrien#endif /* HAVE_MMAP || HAVE_MMAP_ANYWHERE */
6677298Sobrien  exit (0);
6777298Sobrien}
6877298Sobrien], ac_cv_func_strncmp_works=yes, ac_cv_func_strncmp_works=no,
6977298Sobrien  ac_cv_func_strncmp_works=no)
7077298Sobrienrm -f core core.* *.core])
7177298Sobrienif test $ac_cv_func_strncmp_works = no ; then
7277298Sobrien  LIBOBJS="$LIBOBJS strncmp.o"
7377298Sobrienfi
7477298Sobrien])
7577298Sobrien
7677298Sobriendnl See if errno must be declared even when <errno.h> is included.
7777298SobrienAC_DEFUN(libiberty_AC_DECLARE_ERRNO,
7877298Sobrien[AC_CACHE_CHECK(whether errno must be declared, libiberty_cv_declare_errno,
7977298Sobrien[AC_TRY_COMPILE(
8077298Sobrien[#include <errno.h>],
8177298Sobrien[int x = errno;],
8277298Sobrienlibiberty_cv_declare_errno=no,
8377298Sobrienlibiberty_cv_declare_errno=yes)])
8477298Sobrienif test $libiberty_cv_declare_errno = yes
8577298Sobrienthen AC_DEFINE(NEED_DECLARATION_ERRNO, 1,
8677298Sobrien  [Define if errno must be declared even when <errno.h> is included.])
8777298Sobrienfi
8877298Sobrien])
8977298Sobrien
9077298Sobrien# FIXME: We temporarily define our own version of AC_PROG_CC.  This is
9177298Sobrien# copied from autoconf 2.12, but does not call AC_PROG_CC_WORKS.  We
9277298Sobrien# are probably using a cross compiler, which will not be able to fully
9377298Sobrien# link an executable.  This should really be fixed in autoconf
9477298Sobrien# itself.
9577298Sobrien
9677298SobrienAC_DEFUN(LIB_AC_PROG_CC,
9777298Sobrien[AC_BEFORE([$0], [AC_PROG_CPP])dnl
9877298SobrienAC_PROVIDE([AC_PROG_CC])
9977298SobrienAC_CHECK_PROG(CC, gcc, gcc)
10077298Sobrienif test -z "$CC"; then
10177298Sobrien  AC_CHECK_PROG(CC, cc, cc, , , /usr/ucb/cc)
10277298Sobrien  test -z "$CC" && AC_MSG_ERROR([no acceptable cc found in \$PATH])
10377298Sobrienfi
10477298Sobrien
10577298SobrienAC_PROG_CC_GNU
10677298Sobrien
10777298Sobrienif test $ac_cv_prog_gcc = yes; then
10877298Sobrien  GCC=yes
10977298Sobrien  ac_libiberty_warn_cflags='-W -Wall -Wtraditional -pedantic'
11077298Sobriendnl Check whether -g works, even if CFLAGS is set, in case the package
11177298Sobriendnl plays around with CFLAGS (such as to build both debugging and
11277298Sobriendnl normal versions of a library), tasteless as that idea is.
11377298Sobrien  ac_test_CFLAGS="${CFLAGS+set}"
11477298Sobrien  ac_save_CFLAGS="$CFLAGS"
11577298Sobrien  CFLAGS=
11677298Sobrien  AC_PROG_CC_G
11777298Sobrien  if test "$ac_test_CFLAGS" = set; then
11877298Sobrien    CFLAGS="$ac_save_CFLAGS"
11977298Sobrien  elif test $ac_cv_prog_cc_g = yes; then
12077298Sobrien    CFLAGS="-g -O2"
12177298Sobrien  else
12277298Sobrien    CFLAGS="-O2"
12377298Sobrien  fi
12477298Sobrienelse
12577298Sobrien  GCC=
12677298Sobrien  ac_libiberty_warn_cflags=
12777298Sobrien  test "${CFLAGS+set}" = set || CFLAGS="-g"
12877298Sobrienfi
12977298SobrienAC_SUBST(ac_libiberty_warn_cflags)
13077298Sobrien])
13177298Sobrien
13277298Sobrien# Work around a bug in autoheader.  This can go away when we switch to
13377298Sobrien# autoconf >2.50.  The use of define instead of AC_DEFUN is
13477298Sobrien# deliberate.
13577298Sobriendefine(AC_DEFINE_NOAUTOHEADER,
13677298Sobrien[cat >> confdefs.h <<\EOF
13777298Sobrien[#define] $1 ifelse($#, 2, [$2], $#, 3, [$2], 1)
13877298SobrienEOF
13977298Sobrien])
14089857Sobrien
14189857Sobrien# We always want a C version of alloca() compiled into libiberty,
14289857Sobrien# because native-compiler support for the real alloca is so !@#$%
14389857Sobrien# unreliable that GCC has decided to use it only when being compiled
14489857Sobrien# by GCC.  This is the part of AC_FUNC_ALLOCA that calculates the
14589857Sobrien# information alloca.c needs.
14689857SobrienAC_DEFUN(libiberty_AC_FUNC_C_ALLOCA,
14789857Sobrien[AC_CACHE_CHECK(whether alloca needs Cray hooks, ac_cv_os_cray,
14889857Sobrien[AC_EGREP_CPP(webecray,
14989857Sobrien[#if defined(CRAY) && ! defined(CRAY2)
15089857Sobrienwebecray
15189857Sobrien#else
15289857Sobrienwenotbecray
15389857Sobrien#endif
15489857Sobrien], ac_cv_os_cray=yes, ac_cv_os_cray=no)])
15589857Sobrienif test $ac_cv_os_cray = yes; then
15689857Sobrien  for ac_func in _getb67 GETB67 getb67; do
15789857Sobrien    AC_CHECK_FUNC($ac_func, 
15889857Sobrien      [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func, 
15989857Sobrien  [Define to one of _getb67, GETB67, getb67 for Cray-2 and Cray-YMP
16089857Sobrien   systems. This function is required for alloca.c support on those
16189857Sobrien   systems.])  break])
16289857Sobrien  done
16389857Sobrienfi
16489857Sobrien
16589857SobrienAC_CACHE_CHECK(stack direction for C alloca, ac_cv_c_stack_direction,
16689857Sobrien[AC_TRY_RUN([find_stack_direction ()
16789857Sobrien{
16889857Sobrien  static char *addr = 0;
16989857Sobrien  auto char dummy;
17089857Sobrien  if (addr == 0)
17189857Sobrien    {
17289857Sobrien      addr = &dummy;
17389857Sobrien      return find_stack_direction ();
17489857Sobrien    }
17589857Sobrien  else
17689857Sobrien    return (&dummy > addr) ? 1 : -1;
17789857Sobrien}
17889857Sobrienmain ()
17989857Sobrien{
18089857Sobrien  exit (find_stack_direction() < 0);
18189857Sobrien}], 
18289857Sobrien  ac_cv_c_stack_direction=1,
18389857Sobrien  ac_cv_c_stack_direction=-1,
18489857Sobrien  ac_cv_c_stack_direction=0)])
18589857SobrienAC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction,
18689857Sobrien  [Define if you know the direction of stack growth for your system;
18789857Sobrien   otherwise it will be automatically deduced at run-time.
18889857Sobrien        STACK_DIRECTION > 0 => grows toward higher addresses
18989857Sobrien        STACK_DIRECTION < 0 => grows toward lower addresses
19089857Sobrien        STACK_DIRECTION = 0 => direction of growth unknown])
19189857Sobrien])
192