|
| 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 <[email protected]> |
| 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 | + |
| 87 | +#serial 5 |
| 88 | + |
| 89 | +AU_ALIAS([AC_COMPILE_CHECK_SIZEOF], [AX_COMPILE_CHECK_SIZEOF]) |
| 90 | +AC_DEFUN([AX_COMPILE_CHECK_SIZEOF], |
| 91 | +[changequote(<<, >>)dnl |
| 92 | +dnl The name to #define. |
| 93 | +define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl |
| 94 | +dnl The cache variable name. |
| 95 | +define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl |
| 96 | +changequote([, ])dnl |
| 97 | +AC_MSG_CHECKING(size of $1) |
| 98 | +AC_CACHE_VAL(AC_CV_NAME, |
| 99 | +[for ac_size in 4 8 1 2 16 $3 ; do # List sizes in rough order of prevalence. |
| 100 | + AC_TRY_COMPILE([#include "confdefs.h" |
| 101 | +#include <sys/types.h> |
| 102 | +$2 |
| 103 | +], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size) |
| 104 | + if test x$AC_CV_NAME != x ; then break; fi |
| 105 | +done |
| 106 | +]) |
| 107 | +if test x$AC_CV_NAME = x ; then |
| 108 | + AC_MSG_ERROR([cannot determine a size for $1]) |
| 109 | +fi |
| 110 | +AC_MSG_RESULT($AC_CV_NAME) |
| 111 | +AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1]) |
| 112 | +undefine([AC_TYPE_NAME])dnl |
| 113 | +undefine([AC_CV_NAME])dnl |
| 114 | +]) |
0 commit comments