inttypes.m4 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. # inttypes.m4 serial 36
  2. dnl Copyright (C) 2006-2023 Free Software Foundation, Inc.
  3. dnl This file is free software; the Free Software Foundation
  4. dnl gives unlimited permission to copy and/or distribute it,
  5. dnl with or without modifications, as long as this notice is preserved.
  6. dnl From Derek Price, Bruno Haible.
  7. dnl Test whether <inttypes.h> is supported or must be substituted.
  8. AC_DEFUN_ONCE([gl_INTTYPES_H],
  9. [
  10. AC_REQUIRE([gl_INTTYPES_INCOMPLETE])
  11. gl_INTTYPES_PRI_SCN
  12. ])
  13. AC_DEFUN_ONCE([gl_INTTYPES_INCOMPLETE],
  14. [
  15. AC_REQUIRE([gl_STDINT_H])
  16. AC_CHECK_HEADERS_ONCE([inttypes.h])
  17. dnl Override <inttypes.h> always, so that the portability warnings work.
  18. AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
  19. gl_CHECK_NEXT_HEADERS([inttypes.h])
  20. AC_REQUIRE([gl_MULTIARCH])
  21. dnl Check for declarations of anything we want to poison if the
  22. dnl corresponding gnulib module is not in use.
  23. gl_WARN_ON_USE_PREPARE([[#include <inttypes.h>
  24. ]], [imaxabs imaxdiv strtoimax strtoumax])
  25. AC_REQUIRE([AC_C_RESTRICT])
  26. ])
  27. # Ensure that the PRI* and SCN* macros are defined appropriately.
  28. AC_DEFUN([gl_INTTYPES_PRI_SCN],
  29. [
  30. PRIPTR_PREFIX=
  31. if $GL_GENERATE_STDINT_H; then
  32. dnl Using the gnulib <stdint.h>. It defines intptr_t to 'long' or
  33. dnl 'long long', depending on _WIN64.
  34. AC_COMPILE_IFELSE(
  35. [AC_LANG_PROGRAM([[
  36. #ifdef _WIN64
  37. LLP64
  38. #endif
  39. ]])
  40. ],
  41. [PRIPTR_PREFIX='"l"'],
  42. [PRIPTR_PREFIX='"ll"'])
  43. else
  44. dnl Using the system's <stdint.h>.
  45. for glpfx in '' l ll I64; do
  46. case $glpfx in
  47. '') gltype1='int';;
  48. l) gltype1='long int';;
  49. ll) gltype1='long long int';;
  50. I64) gltype1='__int64';;
  51. esac
  52. AC_COMPILE_IFELSE(
  53. [AC_LANG_PROGRAM([[#include <stdint.h>
  54. extern intptr_t foo;
  55. extern $gltype1 foo;]])],
  56. [PRIPTR_PREFIX='"'$glpfx'"'])
  57. test -n "$PRIPTR_PREFIX" && break
  58. done
  59. fi
  60. AC_SUBST([PRIPTR_PREFIX])
  61. gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
  62. [INT32_MAX_LT_INTMAX_MAX],
  63. [defined INT32_MAX && defined INTMAX_MAX],
  64. [INT32_MAX < INTMAX_MAX],
  65. [sizeof (int) < sizeof (long long int)])
  66. if test $APPLE_UNIVERSAL_BUILD = 0; then
  67. gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
  68. [INT64_MAX_EQ_LONG_MAX],
  69. [defined INT64_MAX],
  70. [INT64_MAX == LONG_MAX],
  71. [sizeof (long long int) == sizeof (long int)])
  72. else
  73. INT64_MAX_EQ_LONG_MAX=-1
  74. fi
  75. gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
  76. [UINT32_MAX_LT_UINTMAX_MAX],
  77. [defined UINT32_MAX && defined UINTMAX_MAX],
  78. [UINT32_MAX < UINTMAX_MAX],
  79. [sizeof (unsigned int) < sizeof (unsigned long long int)])
  80. if test $APPLE_UNIVERSAL_BUILD = 0; then
  81. gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
  82. [UINT64_MAX_EQ_ULONG_MAX],
  83. [defined UINT64_MAX],
  84. [UINT64_MAX == ULONG_MAX],
  85. [sizeof (unsigned long long int) == sizeof (unsigned long int)])
  86. else
  87. UINT64_MAX_EQ_ULONG_MAX=-1
  88. fi
  89. ])
  90. # Define the symbol $1 to be 1 if the condition is true, 0 otherwise.
  91. # If $2 is true, the condition is $3; otherwise if long long int is supported
  92. # approximate the condition with $4; otherwise, assume the condition is false.
  93. # The condition should work on all C99 platforms; the approximations should be
  94. # good enough to work on all practical pre-C99 platforms.
  95. # $2 is evaluated by the C preprocessor, $3 and $4 as compile-time constants.
  96. AC_DEFUN([gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION],
  97. [
  98. AC_CACHE_CHECK([whether $3],
  99. [gl_cv_test_$1],
  100. [AC_COMPILE_IFELSE(
  101. [AC_LANG_PROGRAM(
  102. [[/* Work also in C++ mode. */
  103. #define __STDC_LIMIT_MACROS 1
  104. /* Work if build is not clean. */
  105. #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H
  106. #include <limits.h>
  107. #if HAVE_STDINT_H
  108. #include <stdint.h>
  109. #endif
  110. #if $2
  111. #define CONDITION ($3)
  112. #else
  113. #define CONDITION ($4)
  114. #endif
  115. int test[CONDITION ? 1 : -1];]])],
  116. [gl_cv_test_$1=yes],
  117. [gl_cv_test_$1=no])])
  118. if test $gl_cv_test_$1 = yes; then
  119. $1=1;
  120. else
  121. $1=0;
  122. fi
  123. AC_SUBST([$1])
  124. ])
  125. # gl_INTTYPES_MODULE_INDICATOR([modulename])
  126. # sets the shell variable that indicates the presence of the given module
  127. # to a C preprocessor expression that will evaluate to 1.
  128. # This macro invocation must not occur in macros that are AC_REQUIREd.
  129. AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
  130. [
  131. dnl Ensure to expand the default settings once only.
  132. gl_INTTYPES_H_REQUIRE_DEFAULTS
  133. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  134. ])
  135. # Initializes the default values for AC_SUBSTed shell variables.
  136. # This macro must not be AC_REQUIREd. It must only be invoked, and only
  137. # outside of macros or in macros that are not AC_REQUIREd.
  138. AC_DEFUN([gl_INTTYPES_H_REQUIRE_DEFAULTS],
  139. [
  140. m4_defun(GL_MODULE_INDICATOR_PREFIX[_INTTYPES_H_MODULE_INDICATOR_DEFAULTS], [
  141. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_IMAXABS])
  142. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_IMAXDIV])
  143. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOIMAX])
  144. gl_MODULE_INDICATOR_INIT_VARIABLE([GNULIB_STRTOUMAX])
  145. ])
  146. m4_require(GL_MODULE_INDICATOR_PREFIX[_INTTYPES_H_MODULE_INDICATOR_DEFAULTS])
  147. AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
  148. ])
  149. AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
  150. [
  151. dnl Assume proper GNU behavior unless another module says otherwise.
  152. HAVE_DECL_IMAXABS=1; AC_SUBST([HAVE_DECL_IMAXABS])
  153. HAVE_DECL_IMAXDIV=1; AC_SUBST([HAVE_DECL_IMAXDIV])
  154. HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
  155. HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])
  156. HAVE_IMAXDIV_T=1; AC_SUBST([HAVE_IMAXDIV_T])
  157. REPLACE_STRTOIMAX=0; AC_SUBST([REPLACE_STRTOIMAX])
  158. REPLACE_STRTOUMAX=0; AC_SUBST([REPLACE_STRTOUMAX])
  159. INT32_MAX_LT_INTMAX_MAX=1; AC_SUBST([INT32_MAX_LT_INTMAX_MAX])
  160. INT64_MAX_EQ_LONG_MAX='defined _LP64'; AC_SUBST([INT64_MAX_EQ_LONG_MAX])
  161. PRIPTR_PREFIX=__PRIPTR_PREFIX; AC_SUBST([PRIPTR_PREFIX])
  162. UINT32_MAX_LT_UINTMAX_MAX=1; AC_SUBST([UINT32_MAX_LT_UINTMAX_MAX])
  163. UINT64_MAX_EQ_ULONG_MAX='defined _LP64'; AC_SUBST([UINT64_MAX_EQ_ULONG_MAX])
  164. ])