Home | History | Annotate | Line # | Download | only in m4
      1  1.1.1.2  christos # alloca.m4 serial 21
      2  1.1.1.2  christos dnl Copyright (C) 2002-2004, 2006-2007, 2009-2022 Free Software Foundation,
      3      1.1  christos dnl Inc.
      4      1.1  christos dnl This file is free software; the Free Software Foundation
      5      1.1  christos dnl gives unlimited permission to copy and/or distribute it,
      6      1.1  christos dnl with or without modifications, as long as this notice is preserved.
      7      1.1  christos 
      8      1.1  christos AC_DEFUN([gl_FUNC_ALLOCA],
      9      1.1  christos [
     10      1.1  christos   AC_REQUIRE([AC_FUNC_ALLOCA])
     11      1.1  christos   if test $ac_cv_func_alloca_works = no; then
     12      1.1  christos     gl_PREREQ_ALLOCA
     13      1.1  christos   fi
     14      1.1  christos 
     15      1.1  christos   # Define an additional variable used in the Makefile substitution.
     16      1.1  christos   if test $ac_cv_working_alloca_h = yes; then
     17      1.1  christos     AC_CACHE_CHECK([for alloca as a compiler built-in], [gl_cv_rpl_alloca], [
     18      1.1  christos       AC_EGREP_CPP([Need own alloca], [
     19      1.1  christos #if defined __GNUC__ || defined _AIX || defined _MSC_VER
     20      1.1  christos         Need own alloca
     21      1.1  christos #endif
     22      1.1  christos         ], [gl_cv_rpl_alloca=yes], [gl_cv_rpl_alloca=no])
     23      1.1  christos     ])
     24      1.1  christos     if test $gl_cv_rpl_alloca = yes; then
     25      1.1  christos       dnl OK, alloca can be implemented through a compiler built-in.
     26      1.1  christos       AC_DEFINE([HAVE_ALLOCA], [1],
     27      1.1  christos         [Define to 1 if you have 'alloca' after including <alloca.h>,
     28      1.1  christos          a header that may be supplied by this distribution.])
     29  1.1.1.2  christos       GL_GENERATE_ALLOCA_H=true
     30      1.1  christos     else
     31      1.1  christos       dnl alloca exists as a library function, i.e. it is slow and probably
     32      1.1  christos       dnl a memory leak. Don't define HAVE_ALLOCA in this case.
     33  1.1.1.2  christos       GL_GENERATE_ALLOCA_H=false
     34      1.1  christos     fi
     35      1.1  christos   else
     36  1.1.1.2  christos     GL_GENERATE_ALLOCA_H=true
     37      1.1  christos   fi
     38      1.1  christos 
     39      1.1  christos   if test $ac_cv_working_alloca_h = yes; then
     40      1.1  christos     HAVE_ALLOCA_H=1
     41      1.1  christos   else
     42      1.1  christos     HAVE_ALLOCA_H=0
     43      1.1  christos   fi
     44      1.1  christos   AC_SUBST([HAVE_ALLOCA_H])
     45      1.1  christos ])
     46      1.1  christos 
     47      1.1  christos # Prerequisites of lib/alloca.c.
     48      1.1  christos # STACK_DIRECTION is already handled by AC_FUNC_ALLOCA.
     49      1.1  christos AC_DEFUN([gl_PREREQ_ALLOCA], [:])
     50      1.1  christos 
     51  1.1.1.2  christos m4_version_prereq([2.70], [], [
     52      1.1  christos 
     53  1.1.1.2  christos # This works around a bug in autoconf <= 2.68 and has simplifications
     54  1.1.1.2  christos # from 2.70.  See:
     55  1.1.1.2  christos # https://lists.gnu.org/r/bug-gnulib/2011-06/msg00277.html
     56  1.1.1.2  christos # https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6cd9f12520b0d6f76d3230d7565feba1ecf29497
     57  1.1.1.2  christos # https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=15edf7fd8094fd14a89d9891dd72a9624762597a
     58      1.1  christos 
     59      1.1  christos # _AC_LIBOBJ_ALLOCA
     60      1.1  christos # -----------------
     61      1.1  christos # Set up the LIBOBJ replacement of 'alloca'.  Well, not exactly
     62      1.1  christos # AC_LIBOBJ since we actually set the output variable 'ALLOCA'.
     63      1.1  christos # Nevertheless, for Automake, AC_LIBSOURCES it.
     64      1.1  christos m4_define([_AC_LIBOBJ_ALLOCA],
     65      1.1  christos [# The SVR3 libPW and SVR4 libucb both contain incompatible functions
     66      1.1  christos # that cause trouble.  Some versions do not even contain alloca or
     67      1.1  christos # contain a buggy version.  If you still want to use their alloca,
     68      1.1  christos # use ar to extract alloca.o from them instead of compiling alloca.c.
     69      1.1  christos AC_LIBSOURCES(alloca.c)
     70      1.1  christos AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl
     71      1.1  christos AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using 'alloca.c'.])
     72      1.1  christos 
     73      1.1  christos AC_CACHE_CHECK([stack direction for C alloca],
     74      1.1  christos                [ac_cv_c_stack_direction],
     75      1.1  christos [AC_RUN_IFELSE([AC_LANG_SOURCE(
     76      1.1  christos [AC_INCLUDES_DEFAULT
     77      1.1  christos int
     78      1.1  christos find_stack_direction (int *addr, int depth)
     79      1.1  christos {
     80      1.1  christos   int dir, dummy = 0;
     81      1.1  christos   if (! addr)
     82      1.1  christos     addr = &dummy;
     83      1.1  christos   *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
     84      1.1  christos   dir = depth ? find_stack_direction (addr, depth - 1) : 0;
     85      1.1  christos   return dir + dummy;
     86      1.1  christos }
     87      1.1  christos 
     88      1.1  christos int
     89      1.1  christos main (int argc, char **argv)
     90      1.1  christos {
     91      1.1  christos   return find_stack_direction (0, argc + !argv + 20) < 0;
     92      1.1  christos }])],
     93      1.1  christos                [ac_cv_c_stack_direction=1],
     94      1.1  christos                [ac_cv_c_stack_direction=-1],
     95      1.1  christos                [ac_cv_c_stack_direction=0])])
     96      1.1  christos AH_VERBATIM([STACK_DIRECTION],
     97      1.1  christos [/* If using the C implementation of alloca, define if you know the
     98      1.1  christos    direction of stack growth for your system; otherwise it will be
     99      1.1  christos    automatically deduced at runtime.
    100      1.1  christos         STACK_DIRECTION > 0 => grows toward higher addresses
    101      1.1  christos         STACK_DIRECTION < 0 => grows toward lower addresses
    102      1.1  christos         STACK_DIRECTION = 0 => direction of growth unknown */
    103  1.1.1.2  christos #undef STACK_DIRECTION])dnl
    104      1.1  christos AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
    105      1.1  christos ])# _AC_LIBOBJ_ALLOCA
    106      1.1  christos ])
    107