1
# Macros to detect C compiler features
2
# $PostgreSQL: pgsql/config/c-compiler.m4,v 1.14 2004-12-16 17:48:25 momjian 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.
35
ac_int64 a = 20000001;
36
ac_int64 b = 40000005;
42
if (sizeof(ac_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
124
# PGAC_PROG_CC_CFLAGS_OPT
125
# -----------------------
126
# Given a string, check if the compiler supports the string as a
127
# command-line option. If it does, add the string to CFLAGS.
128
AC_DEFUN([PGAC_PROG_CC_CFLAGS_OPT],
129
[AC_MSG_CHECKING([if $CC supports $1])
130
pgac_save_CFLAGS=$CFLAGS
131
CFLAGS="$pgac_save_CFLAGS $1"
132
_AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
134
[CFLAGS="$pgac_save_CFLAGS"
136
])# PGAC_PROG_CC_CFLAGS_OPT
138
# The below backpatches the following Autoconf change:
140
# 2002-03-28 Kevin Ryde <user42@zip.com.au>
142
# * lib/autoconf/c.m4 (AC_C_INLINE): Test with a typedef return value,
143
# to avoid versions of HP C which don't allow that.
145
# When we upgrade to Autoconf >= 2.53a then we can drop this and rely
146
# on the standard macro.
150
# Do nothing if the compiler accepts the inline keyword.
151
# Otherwise define inline to __inline__ or __inline if one of those work,
152
# otherwise define inline to be empty.
153
AC_DEFUN([AC_C_INLINE],
154
[AC_REQUIRE([AC_PROG_CC_STDC])dnl
155
AC_CACHE_CHECK([for inline], ac_cv_c_inline,
157
for ac_kw in inline __inline__ __inline; do
158
AC_COMPILE_IFELSE([AC_LANG_SOURCE(
161
static $ac_kw foo_t static_foo () {return 0; }
162
$ac_kw int foo () {return 0; }
165
[ac_cv_c_inline=$ac_kw; break])
168
case $ac_cv_c_inline in
170
no) AC_DEFINE(inline,,
171
[Define as `__inline' if that's what the C compiler calls it,
172
or to nothing if it is not supported.]) ;;
173
*) AC_DEFINE_UNQUOTED(inline, $ac_cv_c_inline) ;;