source: trunk/src/sed/m4/alloca.m4@ 3669

Last change on this file since 3669 was 3611, checked in by bird, 10 months ago

vendor/sed/current: GNU sed 4.9 (sed-4.9.tar.xz sha256:6e226b732e1cd739464ad6862bd1a1aba42d7982922da7a53519631d24975181)

File size: 3.7 KB
Line 
1# alloca.m4 serial 21
2dnl Copyright (C) 2002-2004, 2006-2007, 2009-2022 Free Software Foundation,
3dnl Inc.
4dnl This file is free software; the Free Software Foundation
5dnl gives unlimited permission to copy and/or distribute it,
6dnl with or without modifications, as long as this notice is preserved.
7
8AC_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 GL_GENERATE_ALLOCA_H=true
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 GL_GENERATE_ALLOCA_H=false
34 fi
35 else
36 GL_GENERATE_ALLOCA_H=true
37 fi
38
39 if test $ac_cv_working_alloca_h = yes; then
40 HAVE_ALLOCA_H=1
41 else
42 HAVE_ALLOCA_H=0
43 fi
44 AC_SUBST([HAVE_ALLOCA_H])
45])
46
47# Prerequisites of lib/alloca.c.
48# STACK_DIRECTION is already handled by AC_FUNC_ALLOCA.
49AC_DEFUN([gl_PREREQ_ALLOCA], [:])
50
51m4_version_prereq([2.70], [], [
52
53# This works around a bug in autoconf <= 2.68 and has simplifications
54# from 2.70. See:
55# https://lists.gnu.org/r/bug-gnulib/2011-06/msg00277.html
56# https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=6cd9f12520b0d6f76d3230d7565feba1ecf29497
57# https://git.savannah.gnu.org/cgit/autoconf.git/commit/?id=15edf7fd8094fd14a89d9891dd72a9624762597a
58
59# _AC_LIBOBJ_ALLOCA
60# -----------------
61# Set up the LIBOBJ replacement of 'alloca'. Well, not exactly
62# AC_LIBOBJ since we actually set the output variable 'ALLOCA'.
63# Nevertheless, for Automake, AC_LIBSOURCES it.
64m4_define([_AC_LIBOBJ_ALLOCA],
65[# The SVR3 libPW and SVR4 libucb both contain incompatible functions
66# that cause trouble. Some versions do not even contain alloca or
67# contain a buggy version. If you still want to use their alloca,
68# use ar to extract alloca.o from them instead of compiling alloca.c.
69AC_LIBSOURCES(alloca.c)
70AC_SUBST([ALLOCA], [\${LIBOBJDIR}alloca.$ac_objext])dnl
71AC_DEFINE(C_ALLOCA, 1, [Define to 1 if using 'alloca.c'.])
72
73AC_CACHE_CHECK([stack direction for C alloca],
74 [ac_cv_c_stack_direction],
75[AC_RUN_IFELSE([AC_LANG_SOURCE(
76[AC_INCLUDES_DEFAULT
77int
78find_stack_direction (int *addr, int depth)
79{
80 int dir, dummy = 0;
81 if (! addr)
82 addr = &dummy;
83 *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
84 dir = depth ? find_stack_direction (addr, depth - 1) : 0;
85 return dir + dummy;
86}
87
88int
89main (int argc, char **argv)
90{
91 return find_stack_direction (0, argc + !argv + 20) < 0;
92}])],
93 [ac_cv_c_stack_direction=1],
94 [ac_cv_c_stack_direction=-1],
95 [ac_cv_c_stack_direction=0])])
96AH_VERBATIM([STACK_DIRECTION],
97[/* If using the C implementation of alloca, define if you know the
98 direction of stack growth for your system; otherwise it will be
99 automatically deduced at runtime.
100 STACK_DIRECTION > 0 => grows toward higher addresses
101 STACK_DIRECTION < 0 => grows toward lower addresses
102 STACK_DIRECTION = 0 => direction of growth unknown */
103#undef STACK_DIRECTION])dnl
104AC_DEFINE_UNQUOTED(STACK_DIRECTION, $ac_cv_c_stack_direction)
105])# _AC_LIBOBJ_ALLOCA
106])
Note: See TracBrowser for help on using the repository browser.