Move unicode utility functions from stringprep to own chapter.
[libidn.git] / m4 / ac_compile_check_sizeof.m4
blob61cc1f3c164b39b769e78631f7573885a2a64683
1 dnl @synopsis AC_COMPILE_CHECK_SIZEOF(TYPE [, HEADERS [, EXTRA_SIZES...]])
2 dnl
3 dnl This macro checks for the size of TYPE using compile checks, not
4 dnl run checks. You can supply extra HEADERS to look into. the check
5 dnl will cycle through 1 2 4 8 16 and any EXTRA_SIZES the user
6 dnl supplies. If a match is found, it will #define SIZEOF_`TYPE' to
7 dnl that value. Otherwise it will emit a configure time error
8 dnl indicating the size of the type could not be determined.
9 dnl
10 dnl The trick is that C will not allow duplicate case labels. While
11 dnl this is valid C code:
12 dnl
13 dnl      switch (0) case 0: case 1:;
14 dnl
15 dnl The following is not:
16 dnl
17 dnl      switch (0) case 0: case 0:;
18 dnl
19 dnl Thus, the AC_TRY_COMPILE will fail if the currently tried size
20 dnl does not match.
21 dnl
22 dnl Here is an example skeleton configure.in script, demonstrating the
23 dnl macro's usage:
24 dnl
25 dnl      AC_PROG_CC
26 dnl      AC_CHECK_HEADERS(stddef.h unistd.h)
27 dnl      AC_TYPE_SIZE_T
28 dnl      AC_CHECK_TYPE(ssize_t, int)
29 dnl
30 dnl      headers='#ifdef HAVE_STDDEF_H
31 dnl      #include <stddef.h>
32 dnl      #endif
33 dnl      #ifdef HAVE_UNISTD_H
34 dnl      #include <unistd.h>
35 dnl      #endif
36 dnl      '
37 dnl
38 dnl      AC_COMPILE_CHECK_SIZEOF(char)
39 dnl      AC_COMPILE_CHECK_SIZEOF(short)
40 dnl      AC_COMPILE_CHECK_SIZEOF(int)
41 dnl      AC_COMPILE_CHECK_SIZEOF(long)
42 dnl      AC_COMPILE_CHECK_SIZEOF(unsigned char *)
43 dnl      AC_COMPILE_CHECK_SIZEOF(void *)
44 dnl      AC_COMPILE_CHECK_SIZEOF(size_t, $headers)
45 dnl      AC_COMPILE_CHECK_SIZEOF(ssize_t, $headers)
46 dnl      AC_COMPILE_CHECK_SIZEOF(ptrdiff_t, $headers)
47 dnl      AC_COMPILE_CHECK_SIZEOF(off_t, $headers)
48 dnl
49 dnl @author Kaveh Ghazi <ghazi@caip.rutgers.edu>
50 dnl @version $Id$
51 dnl
52 AC_DEFUN([AC_COMPILE_CHECK_SIZEOF],
53 [changequote(<<, >>)dnl
54 dnl The name to #define.
55 define(<<AC_TYPE_NAME>>, translit(sizeof_$1, [a-z *], [A-Z_P]))dnl
56 dnl The cache variable name.
57 define(<<AC_CV_NAME>>, translit(ac_cv_sizeof_$1, [ *], [_p]))dnl
58 changequote([, ])dnl
59 AC_MSG_CHECKING(size of $1)
60 AC_CACHE_VAL(AC_CV_NAME,
61 [for ac_size in 4 8 1 2 16 $2 ; do # List sizes in rough order of prevalence.
62   AC_TRY_COMPILE([#include "confdefs.h"
63 #include <sys/types.h>
65 ], [switch (0) case 0: case (sizeof ($1) == $ac_size):;], AC_CV_NAME=$ac_size)
66   if test x$AC_CV_NAME != x ; then break; fi
67 done
69 if test x$AC_CV_NAME = x ; then
70   AC_MSG_ERROR([cannot determine a size for $1])
72 AC_MSG_RESULT($AC_CV_NAME)
73 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The number of bytes in type $1])
74 undefine([AC_TYPE_NAME])dnl
75 undefine([AC_CV_NAME])dnl