inttypes.m4 5.9 KB

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