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