1 # ============================================================================ 2 # https://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 (a] caip.rutgers.edu> 60 # Copyright (c) 2017 Reini Urban <rurban (a] cpan.org> 61 # 62 # This program is free software: you can redistribute it and/or modify it 63 # under the terms of the GNU General Public License as published by the 64 # Free Software Foundation, either version 3 of the License, or (at your 65 # option) any later version. 66 # 67 # This program is distributed in the hope that it will be useful, but 68 # WITHOUT ANY WARRANTY; without even the implied warranty of 69 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 70 # Public License for more details. 71 # 72 # You should have received a copy of the GNU General Public License along 73 # with this program. If not, see <https://www.gnu.org/licenses/>. 74 # 75 # As a special exception, the respective Autoconf Macro's copyright owner 76 # gives unlimited permission to copy, distribute and modify the configure 77 # scripts that are the output of Autoconf when processing the Macro. You 78 # need not follow the terms of the GNU General Public License when using 79 # or distributing such scripts, even though portions of the text of the 80 # Macro appear in them. The GNU General Public License (GPL) does govern 81 # all other use of the material that constitutes the Autoconf Macro. 82 # 83 # This special exception to the GPL applies to versions of the Autoconf 84 # Macro released by the Autoconf Archive. When you make and distribute a 85 # modified version of the Autoconf Macro, you may extend this special 86 # exception to the GPL to apply to your modified version as well. 87 88 #serial 7 89 90 AU_ALIAS([AC_COMPILE_CHECK_SIZEOF], [AX_COMPILE_CHECK_SIZEOF]) 91 AC_DEFUN([AX_COMPILE_CHECK_SIZEOF], 92 [changequote(<<, >>)dnl 93 dnl The name to #define. 94 define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl 95 dnl The cache variable name. 96 define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl 97 changequote([, ])dnl 98 AC_MSG_CHECKING(size of $1) 99 AC_CACHE_VAL(AC_CV_NAME, 100 [for ac_size in 4 8 1 2 16 $3 ; do # List sizes in rough order of prevalence. 101 AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ 102 #include <sys/types.h> 103 $2 104 ]], [[switch (0) case 0: case (sizeof ($1) == $ac_size):;]])], [AC_CV_NAME=$ac_size]) 105 if test x$AC_CV_NAME != x ; then break; fi 106 done 107 ]) 108 if test x$AC_CV_NAME = x ; then 109 AC_MSG_ERROR([cannot determine a size for $1]) 110 fi 111 AC_MSG_RESULT($AC_CV_NAME) 112 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1]) 113 undefine([AC_TYPE_NAME])dnl 114 undefine([AC_CV_NAME])dnl 115 ]) 116