You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

ax_compile_check_sizeof.m4 4.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # ===========================================================================
  2. # http://www.gnu.org/software/autoconf-archive/ax_compile_check_sizeof.html
  3. # ===========================================================================
  4. #
  5. # SYNOPSIS
  6. #
  7. # AX_COMPILE_CHECK_SIZEOF(TYPE [, HEADERS [, EXTRA_SIZES...]])
  8. #
  9. # DESCRIPTION
  10. #
  11. # This macro checks for the size of TYPE using compile checks, not run
  12. # checks. You can supply extra HEADERS to look into. the check will cycle
  13. # through 1 2 4 8 16 and any EXTRA_SIZES the user supplies. If a match is
  14. # found, it will #define SIZEOF_`TYPE' to that value. Otherwise it will
  15. # emit a configure time error indicating the size of the type could not be
  16. # determined.
  17. #
  18. # The trick is that C will not allow duplicate case labels. While this is
  19. # valid C code:
  20. #
  21. # switch (0) case 0: case 1:;
  22. #
  23. # The following is not:
  24. #
  25. # switch (0) case 0: case 0:;
  26. #
  27. # Thus, the AC_TRY_COMPILE will fail if the currently tried size does not
  28. # match.
  29. #
  30. # Here is an example skeleton configure.in script, demonstrating the
  31. # macro's usage:
  32. #
  33. # AC_PROG_CC
  34. # AC_CHECK_HEADERS(stddef.h unistd.h)
  35. # AC_TYPE_SIZE_T
  36. # AC_CHECK_TYPE(ssize_t, int)
  37. #
  38. # headers='#ifdef HAVE_STDDEF_H
  39. # #include <stddef.h>
  40. # #endif
  41. # #ifdef HAVE_UNISTD_H
  42. # #include <unistd.h>
  43. # #endif
  44. # '
  45. #
  46. # AX_COMPILE_CHECK_SIZEOF(char)
  47. # AX_COMPILE_CHECK_SIZEOF(short)
  48. # AX_COMPILE_CHECK_SIZEOF(int)
  49. # AX_COMPILE_CHECK_SIZEOF(long)
  50. # AX_COMPILE_CHECK_SIZEOF(unsigned char *)
  51. # AX_COMPILE_CHECK_SIZEOF(void *)
  52. # AX_COMPILE_CHECK_SIZEOF(size_t, $headers)
  53. # AX_COMPILE_CHECK_SIZEOF(ssize_t, $headers)
  54. # AX_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers)
  55. # AX_COMPILE_CHECK_SIZEOF(off_t, $headers)
  56. #
  57. # LICENSE
  58. #
  59. # Copyright (c) 2008 Kaveh Ghazi <ghazi@caip.rutgers.edu>
  60. #
  61. # This program is free software: you can redistribute it and/or modify it
  62. # under the terms of the GNU General Public License as published by the
  63. # Free Software Foundation, either version 3 of the License, or (at your
  64. # option) any later version.
  65. #
  66. # This program is distributed in the hope that it will be useful, but
  67. # WITHOUT ANY WARRANTY; without even the implied warranty of
  68. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  69. # Public License for more details.
  70. #
  71. # You should have received a copy of the GNU General Public License along
  72. # with this program. If not, see <http://www.gnu.org/licenses/>.
  73. #
  74. # As a special exception, the respective Autoconf Macro's copyright owner
  75. # gives unlimited permission to copy, distribute and modify the configure
  76. # scripts that are the output of Autoconf when processing the Macro. You
  77. # need not follow the terms of the GNU General Public License when using
  78. # or distributing such scripts, even though portions of the text of the
  79. # Macro appear in them. The GNU General Public License (GPL) does govern
  80. # all other use of the material that constitutes the Autoconf Macro.
  81. #
  82. # This special exception to the GPL applies to versions of the Autoconf
  83. # Macro released by the Autoconf Archive. When you make and distribute a
  84. # modified version of the Autoconf Macro, you may extend this special
  85. # exception to the GPL to apply to your modified version as well.
  86. #serial 5
  87. AU_ALIAS([AC_COMPILE_CHECK_SIZEOF], [AX_COMPILE_CHECK_SIZEOF])
  88. AC_DEFUN([AX_COMPILE_CHECK_SIZEOF],
  89. [changequote(<<, >>)dnl
  90. dnl The name to #define.
  91. define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl
  92. dnl The cache variable name.
  93. define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
  94. changequote([, ])dnl
  95. AC_MSG_CHECKING(size of $1)
  96. AC_CACHE_VAL(AC_CV_NAME,
  97. [for ac_size in 4 8 1 2 16 $3 ; do # List sizes in rough order of prevalence.
  98. AC_TRY_COMPILE([#include "confdefs.h"
  99. #include <sys/types.h>
  100. $2
  101. ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size)
  102. if test x$AC_CV_NAME != x ; then break; fi
  103. done
  104. ])
  105. if test x$AC_CV_NAME = x ; then
  106. AC_MSG_ERROR([cannot determine a size for $1])
  107. fi
  108. AC_MSG_RESULT($AC_CV_NAME)
  109. AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1])
  110. undefine([AC_TYPE_NAME])dnl
  111. undefine([AC_CV_NAME])dnl
  112. ])