Blame m4/alloca.m4

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