alloca.m4 4.2 KB

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