Blame gnulib/m4/alloca.m4

Packit 06dd63
# alloca.m4 serial 15
Packit 06dd63
dnl Copyright (C) 2002-2004, 2006-2007, 2009-2019 Free Software Foundation,
Packit 06dd63
dnl Inc.
Packit 06dd63
dnl This file is free software; the Free Software Foundation
Packit 06dd63
dnl gives unlimited permission to copy and/or distribute it,
Packit 06dd63
dnl with or without modifications, as long as this notice is preserved.
Packit 06dd63
Packit 06dd63
AC_DEFUN([gl_FUNC_ALLOCA],
Packit 06dd63
[
Packit 06dd63
  AC_REQUIRE([AC_FUNC_ALLOCA])
Packit 06dd63
  if test $ac_cv_func_alloca_works = no; then
Packit 06dd63
    gl_PREREQ_ALLOCA
Packit 06dd63
  fi
Packit 06dd63
Packit 06dd63
  # Define an additional variable used in the Makefile substitution.
Packit 06dd63
  if test $ac_cv_working_alloca_h = yes; then
Packit 06dd63
    AC_CACHE_CHECK([for alloca as a compiler built-in], [gl_cv_rpl_alloca], [
Packit 06dd63
      AC_EGREP_CPP([Need own alloca], [
Packit 06dd63
#if defined __GNUC__ || defined _AIX || defined _MSC_VER
Packit 06dd63
        Need own alloca
Packit 06dd63
#endif
Packit 06dd63
        ], [gl_cv_rpl_alloca=yes], [gl_cv_rpl_alloca=no])
Packit 06dd63
    ])
Packit 06dd63
    if test $gl_cv_rpl_alloca = yes; then
Packit 06dd63
      dnl OK, alloca can be implemented through a compiler built-in.
Packit 06dd63
      AC_DEFINE([HAVE_ALLOCA], [1],
Packit 06dd63
        [Define to 1 if you have 'alloca' after including <alloca.h>,
Packit 06dd63
         a header that may be supplied by this distribution.])
Packit 06dd63
      ALLOCA_H=alloca.h
Packit 06dd63
    else
Packit 06dd63
      dnl alloca exists as a library function, i.e. it is slow and probably
Packit 06dd63
      dnl a memory leak. Don't define HAVE_ALLOCA in this case.
Packit 06dd63
      ALLOCA_H=
Packit 06dd63
    fi
Packit 06dd63
  else
Packit 06dd63
    ALLOCA_H=alloca.h
Packit 06dd63
  fi
Packit 06dd63
  AC_SUBST([ALLOCA_H])
Packit 06dd63
  AM_CONDITIONAL([GL_GENERATE_ALLOCA_H], [test -n "$ALLOCA_H"])
Packit 06dd63
Packit 06dd63
  if test $ac_cv_working_alloca_h = yes; then
Packit 06dd63
    HAVE_ALLOCA_H=1
Packit 06dd63
  else
Packit 06dd63
    HAVE_ALLOCA_H=0
Packit 06dd63
  fi
Packit 06dd63
  AC_SUBST([HAVE_ALLOCA_H])
Packit 06dd63
])
Packit 06dd63
Packit 06dd63
# Prerequisites of lib/alloca.c.
Packit 06dd63
# STACK_DIRECTION is already handled by AC_FUNC_ALLOCA.
Packit 06dd63
AC_DEFUN([gl_PREREQ_ALLOCA], [:])
Packit 06dd63
Packit 06dd63
# This works around a bug in autoconf <= 2.68.
Packit 06dd63
# See <https://lists.gnu.org/r/bug-gnulib/2011-06/msg00277.html>.
Packit 06dd63
Packit 06dd63
m4_version_prereq([2.69], [] ,[
Packit 06dd63
Packit 06dd63
# This is taken from the following Autoconf patch:
Packit 06dd63
# https://git.savannah.gnu.org/gitweb/?p=autoconf.git;a=commitdiff;h=6cd9f12520b0d6f76d3230d7565feba1ecf29497
Packit 06dd63
Packit 06dd63
# _AC_LIBOBJ_ALLOCA
Packit 06dd63
# -----------------
Packit 06dd63
# Set up the LIBOBJ replacement of 'alloca'.  Well, not exactly
Packit 06dd63
# AC_LIBOBJ since we actually set the output variable 'ALLOCA'.
Packit 06dd63
# Nevertheless, for Automake, AC_LIBSOURCES it.
Packit 06dd63
m4_define([_AC_LIBOBJ_ALLOCA],
Packit 06dd63
[# The SVR3 libPW and SVR4 libucb both contain incompatible functions
Packit 06dd63
# that cause trouble.  Some versions do not even contain alloca or
Packit 06dd63
# contain a buggy version.  If you still want to use their alloca,
Packit 06dd63
# use ar to extract alloca.o from them instead of compiling alloca.c.
Packit 06dd63
AC_LIBSOURCES(alloca.c)
Packit 06dd63
AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl
Packit 06dd63
AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using 'alloca.c'.])
Packit 06dd63
Packit 06dd63
AC_CACHE_CHECK(whether 'alloca.c' needs Cray hooks, ac_cv_os_cray,
Packit 06dd63
[AC_EGREP_CPP(webecray,
Packit 06dd63
[#if defined CRAY && ! defined CRAY2
Packit 06dd63
webecray
Packit 06dd63
#else
Packit 06dd63
wenotbecray
Packit 06dd63
#endif
Packit 06dd63
], ac_cv_os_cray=yes, ac_cv_os_cray=no)])
Packit 06dd63
if test $ac_cv_os_cray = yes; then
Packit 06dd63
  for ac_func in _getb67 GETB67 getb67; do
Packit 06dd63
    AC_CHECK_FUNC($ac_func,
Packit 06dd63
                  [AC_DEFINE_UNQUOTED(CRAY_STACKSEG_END, $ac_func,
Packit 06dd63
                                      [Define to one of '_getb67', 'GETB67',
Packit 06dd63
                                       'getb67' for Cray-2 and Cray-YMP
Packit 06dd63
                                       systems. This function is required for
Packit 06dd63
                                       'alloca.c' support on those systems.])
Packit 06dd63
    break])
Packit 06dd63
  done
Packit 06dd63
fi
Packit 06dd63
Packit 06dd63
AC_CACHE_CHECK([stack direction for C alloca],
Packit 06dd63
               [ac_cv_c_stack_direction],
Packit 06dd63
[AC_RUN_IFELSE([AC_LANG_SOURCE(
Packit 06dd63
[AC_INCLUDES_DEFAULT
Packit 06dd63
int
Packit 06dd63
find_stack_direction (int *addr, int depth)
Packit 06dd63
{
Packit 06dd63
  int dir, dummy = 0;
Packit 06dd63
  if (! addr)
Packit 06dd63
    addr = &dummy;
Packit 06dd63
  *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
Packit 06dd63
  dir = depth ? find_stack_direction (addr, depth - 1) : 0;
Packit 06dd63
  return dir + dummy;
Packit 06dd63
}
Packit 06dd63
Packit 06dd63
int
Packit 06dd63
main (int argc, char **argv)
Packit 06dd63
{
Packit 06dd63
  return find_stack_direction (0, argc + !argv + 20) < 0;
Packit 06dd63
}])],
Packit 06dd63
               [ac_cv_c_stack_direction=1],
Packit 06dd63
               [ac_cv_c_stack_direction=-1],
Packit 06dd63
               [ac_cv_c_stack_direction=0])])
Packit 06dd63
AH_VERBATIM([STACK_DIRECTION],
Packit 06dd63
[/* If using the C implementation of alloca, define if you know the
Packit 06dd63
   direction of stack growth for your system; otherwise it will be
Packit 06dd63
   automatically deduced at runtime.
Packit 06dd63
        STACK_DIRECTION > 0 => grows toward higher addresses
Packit 06dd63
        STACK_DIRECTION < 0 => grows toward lower addresses
Packit 06dd63
        STACK_DIRECTION = 0 => direction of growth unknown */
Packit 06dd63
@%:@undef STACK_DIRECTION])dnl
Packit 06dd63
AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
Packit 06dd63
])# _AC_LIBOBJ_ALLOCA
Packit 06dd63
])