Bump to m4 1.4.19
[platform/upstream/m4.git] / m4 / stack-direction.m4
1 # stack-direction.m4 serial 6
2 dnl Copyright (C) 2002-2021 Bruno Haible <bruno@clisp.org>
3 dnl Copyright (C) 2002-2021 Free Software Foundation, Inc.
4 dnl This file is free software, distributed under the terms of the GNU
5 dnl General Public License.  As a special exception to the GNU General
6 dnl Public License, this file may be distributed as part of a program
7 dnl that contains a configuration script generated by Autoconf, under
8 dnl the same distribution terms as the rest of that program.
9
10 # Determine the stack direction. Define the C macro STACK_DIRECTION.
11 AC_DEFUN([SV_STACK_DIRECTION],
12 [
13   AC_REQUIRE([AC_CANONICAL_HOST])
14   AC_CACHE_CHECK([for stack direction], [sv_cv_stack_direction_msg], [
15     case "$host_cpu" in
16       dnl See the #define STACK_GROWS_DOWNWARD in gcc-3.1/gcc/config/*/*.h.
17       a29k | \
18       aarch64* | \
19       alpha* | \
20       arc | \
21       arm* | strongarm* | xscale* | \
22       avr | avr32 | \
23       bfin | \
24       c1 | c2 | c32 | c34 | c38 | \
25       clipper | \
26       cris | \
27       d30v | \
28       elxsi | \
29       fr30 | \
30       h8300 | \
31       i?86 | x86_64 | \
32       i860 | \
33       ia64 | \
34       m32r | \
35       m68* | \
36       m88k | \
37       mcore | \
38       microblaze | \
39       mips* | \
40       mmix | \
41       mn10200 | \
42       mn10300 | \
43       nios2 | \
44       nds32* | \
45       ns32k | \
46       pdp11 | \
47       pj* | \
48       powerpc* | rs6000 | \
49       riscv* | \
50       romp | \
51       s390* | \
52       sh* | \
53       sparc* | \
54       v850 | \
55       vax | \
56       xtensa)
57         sv_cv_stack_direction=-1 ;;
58       c4x | \
59       dsp16xx | \
60       i960 | \
61       hppa* | parisc* | \
62       stormy16 | \
63       we32k)
64         sv_cv_stack_direction=1 ;;
65       *)
66         if test $cross_compiling = no; then
67           cat > conftest.c <<EOF
68 #include <stdio.h>
69 int
70 find_stack_direction (int *addr, int depth)
71 {
72   int dir, dummy = 0;
73   if (! addr)
74     addr = &dummy;
75   *addr = addr < &dummy ? 1 : addr == &dummy ? 0 : -1;
76   dir = depth ? find_stack_direction (addr, depth - 1) : 0;
77   return dir + dummy;
78 }
79 int
80 main (int argc, char *argv[])
81 {
82   printf ("%d\n", find_stack_direction (NULL, argc + 20));
83   return 0;
84 }
85 EOF
86           AC_TRY_EVAL([ac_link])
87           sv_cv_stack_direction=`./conftest`
88         else
89           sv_cv_stack_direction=0
90         fi
91         ;;
92     esac
93     case $sv_cv_stack_direction in
94       1)  sv_cv_stack_direction_msg="grows up";;
95       -1) sv_cv_stack_direction_msg="grows down";;
96       *)  sv_cv_stack_direction_msg="unknown";;
97     esac
98   ])
99   AC_DEFINE_UNQUOTED([STACK_DIRECTION], [$sv_cv_stack_direction],
100     [Define as the direction of stack growth for your system.
101      STACK_DIRECTION > 0 => grows toward higher addresses
102      STACK_DIRECTION < 0 => grows toward lower addresses
103      STACK_DIRECTION = 0 => spaghetti stack.])
104 ])