1 # Macros to detect C compiler features
2 # $PostgreSQL: pgsql/config/c-compiler.m4,v 1.11 2003/11/29 19:51:17 pgsql Exp $
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,
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 to empty if the C compiler does not understand signed types.])
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],
32 * These are globals to discourage the compiler from folding all the
33 * arithmetic tests down to compile-time constants.
42 if (sizeof(int64) != 8)
43 return 0; /* definitely not the right size */
45 /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
53 exit(! does_int64_work());
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])],
63 Ac_define=$Ac_cachevar
64 if test x"$Ac_cachevar" = xyes ; then
65 AC_DEFINE(Ac_define,, [Define to 1 if `]$1[' works and is 64 bits.])
67 undefine([Ac_define])dnl
68 undefine([Ac_cachevar])dnl
69 ])# PGAC_TYPE_64BIT_INT
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.)
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])])
91 AS_TR_SH([pgac_cv_alignof_$1])=0
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
99 # PGAC_C_FUNCNAME_SUPPORT
100 # -----------------------
101 # Check if the C compiler understands __func__ (C99) or __FUNCTION__ (gcc).
102 # Define HAVE_FUNCNAME__FUNC or HAVE_FUNCNAME__FUNCTION accordingly.
103 AC_DEFUN([PGAC_C_FUNCNAME_SUPPORT],
104 [AC_CACHE_CHECK(for __func__, pgac_cv_funcname_func_support,
105 [AC_TRY_COMPILE([#include <stdio.h>],
106 [printf("%s\n", __func__);],
107 [pgac_cv_funcname_func_support=yes],
108 [pgac_cv_funcname_func_support=no])])
109 if test x"$pgac_cv_funcname_func_support" = xyes ; then
110 AC_DEFINE(HAVE_FUNCNAME__FUNC, 1,
111 [Define to 1 if your compiler understands __func__.])
113 AC_CACHE_CHECK(for __FUNCTION__, pgac_cv_funcname_function_support,
114 [AC_TRY_COMPILE([#include <stdio.h>],
115 [printf("%s\n", __FUNCTION__);],
116 [pgac_cv_funcname_function_support=yes],
117 [pgac_cv_funcname_function_support=no])])
118 if test x"$pgac_cv_funcname_function_support" = xyes ; then
119 AC_DEFINE(HAVE_FUNCNAME__FUNCTION, 1,
120 [Define to 1 if your compiler understands __FUNCTION__.])
122 fi])# PGAC_C_FUNCNAME_SUPPORT
125 # PGAC_PROG_CC_NO_STRICT_ALIASING
126 # -------------------------------
127 # Find out how to turn off strict aliasing in the C compiler.
128 AC_DEFUN([PGAC_PROG_CC_NO_STRICT_ALIASING],
129 [AC_CACHE_CHECK([how to turn off strict aliasing in $CC],
130 pgac_cv_prog_cc_no_strict_aliasing,
131 [pgac_save_CFLAGS=$CFLAGS
132 if test "$GCC" = yes; then
133 pgac_try="-fno-strict-aliasing"
135 # Maybe fill in later...
139 for pgac_flag in $pgac_try; do
140 CFLAGS="$pgac_save_CFLAGS $pgac_flag"
141 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
142 [pgac_cv_prog_cc_no_strict_aliasing=$pgac_try
146 CFLAGS=$pgac_save_CFLAGS
149 if test "$ac_env_CFLAGS_set" != set; then
150 CFLAGS="$CFLAGS $pgac_cv_prog_cc_no_strict_aliasing"
151 fi])# PGAC_PROG_CC_NO_STRICT_ALIASING
154 # The below backpatches the following Autoconf change:
156 # 2002-03-28 Kevin Ryde <user42@zip.com.au>
158 # * lib/autoconf/c.m4 (AC_C_INLINE): Test with a typedef return value,
159 # to avoid versions of HP C which don't allow that.
161 # When we upgrade to Autoconf >= 2.53a then we can drop this and rely
162 # on the standard macro.
166 # Do nothing if the compiler accepts the inline keyword.
167 # Otherwise define inline to __inline__ or __inline if one of those work,
168 # otherwise define inline to be empty.
169 AC_DEFUN([AC_C_INLINE],
170 [AC_REQUIRE([AC_PROG_CC_STDC])dnl
171 AC_CACHE_CHECK([for inline], ac_cv_c_inline,
173 for ac_kw in inline __inline__ __inline; do
174 AC_COMPILE_IFELSE([AC_LANG_SOURCE(
177 static $ac_kw foo_t static_foo () {return 0; }
178 $ac_kw int foo () {return 0; }
181 [ac_cv_c_inline=$ac_kw; break])
184 case $ac_cv_c_inline in
186 no) AC_DEFINE(inline,,
187 [Define as `__inline' if that's what the C compiler calls it,
188 or to nothing if it is not supported.]) ;;
189 *) AC_DEFINE_UNQUOTED(inline, $ac_cv_c_inline) ;;