OSDN Git Service

Factor out the code that detects the long long int snprintf format into a
[pg-rex/syncrep.git] / config / c-compiler.m4
1 # Macros to detect C compiler features
2 # $Header: /cvsroot/pgsql/config/c-compiler.m4,v 1.6 2003/01/28 21:57:12 petere Exp $
3
4
5 # PGAC_C_SIGNED
6 # -------------
7 # Check if the C compiler understands signed types.
8 AC_DEFUN([PGAC_C_SIGNED],
9 [AC_CACHE_CHECK(for signed types, pgac_cv_c_signed,
10 [AC_TRY_COMPILE([],
11 [signed char c; signed short s; signed int i;],
12 [pgac_cv_c_signed=yes],
13 [pgac_cv_c_signed=no])])
14 if test x"$pgac_cv_c_signed" = xno ; then
15   AC_DEFINE(signed,, [Define empty if the C compiler does not understand signed types])
16 fi])# PGAC_C_SIGNED
17
18
19
20 # PGAC_TYPE_64BIT_INT(TYPE)
21 # -------------------------
22 # Check if TYPE is a working 64 bit integer type. Set HAVE_TYPE_64 to
23 # yes or no respectively, and define HAVE_TYPE_64 if yes.
24 AC_DEFUN([PGAC_TYPE_64BIT_INT],
25 [define([Ac_define], [translit([have_$1_64], [a-z *], [A-Z_P])])dnl
26 define([Ac_cachevar], [translit([pgac_cv_type_$1_64], [ *], [_p])])dnl
27 AC_CACHE_CHECK([whether $1 is 64 bits], [Ac_cachevar],
28 [AC_TRY_RUN(
29 [typedef $1 int64;
30
31 /*
32  * These are globals to discourage the compiler from folding all the
33  * arithmetic tests down to compile-time constants.
34  */
35 int64 a = 20000001;
36 int64 b = 40000005;
37
38 int does_int64_work()
39 {
40   int64 c,d;
41
42   if (sizeof(int64) != 8)
43     return 0;                   /* definitely not the right size */
44
45   /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
46   c = a * b;
47   d = (c + b) / b;
48   if (d != a+1)
49     return 0;
50   return 1;
51 }
52 main() {
53   exit(! does_int64_work());
54 }],
55 [Ac_cachevar=yes],
56 [Ac_cachevar=no],
57 [# If cross-compiling, check the size reported by the compiler and
58 # trust that the arithmetic works.
59 AC_COMPILE_IFELSE([AC_LANG_BOOL_COMPILE_TRY([], [sizeof($1) == 8])],
60                   Ac_cachevar=yes,
61                   Ac_cachevar=no)])])
62
63 Ac_define=$Ac_cachevar
64 if test x"$Ac_cachevar" = xyes ; then
65   AC_DEFINE(Ac_define,, [Set to 1 if `]$1[' is 64 bits])
66 fi
67 undefine([Ac_define])dnl
68 undefine([Ac_cachevar])dnl
69 ])# PGAC_TYPE_64BIT_INT
70
71
72
73 # PGAC_CHECK_ALIGNOF(TYPE, [INCLUDES = DEFAULT-INCLUDES])
74 # -----------------------------------------------------
75 # Find the alignment requirement of the given type. Define the result
76 # as ALIGNOF_TYPE.  This macro works even when cross compiling.
77 # (Modelled after AC_CHECK_SIZEOF.)
78
79 AC_DEFUN([PGAC_CHECK_ALIGNOF],
80 [AS_LITERAL_IF([$1], [],
81                [AC_FATAL([$0: requires literal arguments])])dnl
82 AC_CHECK_TYPE([$1], [], [], [$2])
83 AC_CACHE_CHECK([alignment of $1], [AS_TR_SH([pgac_cv_alignof_$1])],
84 [if test "$AS_TR_SH([ac_cv_type_$1])" = yes; then
85   _AC_COMPUTE_INT([((char*) & pgac_struct.field) - ((char*) & pgac_struct)],
86                   [AS_TR_SH([pgac_cv_alignof_$1])],
87                   [AC_INCLUDES_DEFAULT([$2])
88 struct { char filler; $1 field; } pgac_struct;],
89                   [AC_MSG_ERROR([cannot compute alignment of $1, 77])])
90 else
91   AS_TR_SH([pgac_cv_alignof_$1])=0
92 fi])dnl
93 AC_DEFINE_UNQUOTED(AS_TR_CPP(alignof_$1),
94                    [$AS_TR_SH([pgac_cv_alignof_$1])],
95                    [The alignment requirement of a `$1'])
96 ])# PGAC_CHECK_ALIGNOF