inttypes.m4 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. # inttypes.m4 serial 26
  2. dnl Copyright (C) 2006-2012 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([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. ])
  26. # Ensure that the PRI* and SCN* macros are defined appropriately.
  27. AC_DEFUN([gl_INTTYPES_PRI_SCN],
  28. [
  29. AC_REQUIRE([gt_INTTYPES_PRI])
  30. PRIPTR_PREFIX=
  31. if test -n "$STDINT_H"; then
  32. dnl Using the gnulib <stdint.h>. It always defines intptr_t to 'long'.
  33. PRIPTR_PREFIX='"l"'
  34. else
  35. dnl Using the system's <stdint.h>.
  36. for glpfx in '' l ll I64; do
  37. case $glpfx in
  38. '') gltype1='int';;
  39. l) gltype1='long int';;
  40. ll) gltype1='long long int';;
  41. I64) gltype1='__int64';;
  42. esac
  43. AC_COMPILE_IFELSE(
  44. [AC_LANG_PROGRAM([[#include <stdint.h>
  45. extern intptr_t foo;
  46. extern $gltype1 foo;]])],
  47. [PRIPTR_PREFIX='"'$glpfx'"'])
  48. test -n "$PRIPTR_PREFIX" && break
  49. done
  50. fi
  51. AC_SUBST([PRIPTR_PREFIX])
  52. gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
  53. [INT32_MAX_LT_INTMAX_MAX],
  54. [defined INT32_MAX && defined INTMAX_MAX],
  55. [INT32_MAX < INTMAX_MAX],
  56. [sizeof (int) < sizeof (long long int)])
  57. if test $APPLE_UNIVERSAL_BUILD = 0; then
  58. gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
  59. [INT64_MAX_EQ_LONG_MAX],
  60. [defined INT64_MAX],
  61. [INT64_MAX == LONG_MAX],
  62. [sizeof (long long int) == sizeof (long int)])
  63. else
  64. INT64_MAX_EQ_LONG_MAX=-1
  65. fi
  66. gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
  67. [UINT32_MAX_LT_UINTMAX_MAX],
  68. [defined UINT32_MAX && defined UINTMAX_MAX],
  69. [UINT32_MAX < UINTMAX_MAX],
  70. [sizeof (unsigned int) < sizeof (unsigned long long int)])
  71. if test $APPLE_UNIVERSAL_BUILD = 0; then
  72. gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION(
  73. [UINT64_MAX_EQ_ULONG_MAX],
  74. [defined UINT64_MAX],
  75. [UINT64_MAX == ULONG_MAX],
  76. [sizeof (unsigned long long int) == sizeof (unsigned long int)])
  77. else
  78. UINT64_MAX_EQ_ULONG_MAX=-1
  79. fi
  80. ])
  81. # Define the symbol $1 to be 1 if the condition is true, 0 otherwise.
  82. # If $2 is true, the condition is $3; otherwise if long long int is supported
  83. # approximate the condition with $4; otherwise, assume the condition is false.
  84. # The condition should work on all C99 platforms; the approximations should be
  85. # good enough to work on all practical pre-C99 platforms.
  86. # $2 is evaluated by the C preprocessor, $3 and $4 as compile-time constants.
  87. AC_DEFUN([gl_INTTYPES_CHECK_LONG_LONG_INT_CONDITION],
  88. [
  89. AC_CACHE_CHECK([whether $3],
  90. [gl_cv_test_$1],
  91. [AC_COMPILE_IFELSE(
  92. [AC_LANG_PROGRAM(
  93. [[/* Work also in C++ mode. */
  94. #define __STDC_LIMIT_MACROS 1
  95. /* Work if build is not clean. */
  96. #define _GL_JUST_INCLUDE_SYSTEM_STDINT_H
  97. #include <limits.h>
  98. #if HAVE_STDINT_H
  99. #include <stdint.h>
  100. #endif
  101. #if $2
  102. #define CONDITION ($3)
  103. #elif HAVE_LONG_LONG_INT
  104. #define CONDITION ($4)
  105. #else
  106. #define CONDITION 0
  107. #endif
  108. int test[CONDITION ? 1 : -1];]])],
  109. [gl_cv_test_$1=yes],
  110. [gl_cv_test_$1=no])])
  111. if test $gl_cv_test_$1 = yes; then
  112. $1=1;
  113. else
  114. $1=0;
  115. fi
  116. AC_SUBST([$1])
  117. ])
  118. AC_DEFUN([gl_INTTYPES_MODULE_INDICATOR],
  119. [
  120. dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
  121. AC_REQUIRE([gl_INTTYPES_H_DEFAULTS])
  122. gl_MODULE_INDICATOR_SET_VARIABLE([$1])
  123. ])
  124. AC_DEFUN([gl_INTTYPES_H_DEFAULTS],
  125. [
  126. GNULIB_IMAXABS=0; AC_SUBST([GNULIB_IMAXABS])
  127. GNULIB_IMAXDIV=0; AC_SUBST([GNULIB_IMAXDIV])
  128. GNULIB_STRTOIMAX=0; AC_SUBST([GNULIB_STRTOIMAX])
  129. GNULIB_STRTOUMAX=0; AC_SUBST([GNULIB_STRTOUMAX])
  130. dnl Assume proper GNU behavior unless another module says otherwise.
  131. HAVE_DECL_IMAXABS=1; AC_SUBST([HAVE_DECL_IMAXABS])
  132. HAVE_DECL_IMAXDIV=1; AC_SUBST([HAVE_DECL_IMAXDIV])
  133. HAVE_DECL_STRTOIMAX=1; AC_SUBST([HAVE_DECL_STRTOIMAX])
  134. HAVE_DECL_STRTOUMAX=1; AC_SUBST([HAVE_DECL_STRTOUMAX])
  135. REPLACE_STRTOIMAX=0; AC_SUBST([REPLACE_STRTOIMAX])
  136. INT32_MAX_LT_INTMAX_MAX=1; AC_SUBST([INT32_MAX_LT_INTMAX_MAX])
  137. INT64_MAX_EQ_LONG_MAX='defined _LP64'; AC_SUBST([INT64_MAX_EQ_LONG_MAX])
  138. PRI_MACROS_BROKEN=0; AC_SUBST([PRI_MACROS_BROKEN])
  139. PRIPTR_PREFIX=__PRIPTR_PREFIX; AC_SUBST([PRIPTR_PREFIX])
  140. UINT32_MAX_LT_UINTMAX_MAX=1; AC_SUBST([UINT32_MAX_LT_UINTMAX_MAX])
  141. UINT64_MAX_EQ_ULONG_MAX='defined _LP64'; AC_SUBST([UINT64_MAX_EQ_ULONG_MAX])
  142. ])