OSDN Git Service

Allow AIX to use --enable-thread-safety by passing PTHREAD_LIBS to
[pg-rex/syncrep.git] / config / c-compiler.m4
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 $
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 to 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 ac_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 ac_int64 a = 20000001;
36 ac_int64 b = 40000005;
37
38 int does_int64_work()
39 {
40   ac_int64 c,d;
41
42   if (sizeof(ac_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,, [Define to 1 if `]$1[' works and 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
97
98
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__.])
112 else
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__.])
121 fi
122 fi])# PGAC_C_FUNCNAME_SUPPORT
123
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()],
133                    AC_MSG_RESULT(yes),
134                    [CFLAGS="$pgac_save_CFLAGS"
135                     AC_MSG_RESULT(no)])
136 ])# PGAC_PROG_CC_CFLAGS_OPT
137
138 # The below backpatches the following Autoconf change:
139 #
140 # 2002-03-28  Kevin Ryde  <user42@zip.com.au>
141 #
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.
144 #
145 # When we upgrade to Autoconf >= 2.53a then we can drop this and rely
146 # on the standard macro.
147
148 # AC_C_INLINE
149 # -----------
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,
156 [ac_cv_c_inline=no
157 for ac_kw in inline __inline__ __inline; do
158   AC_COMPILE_IFELSE([AC_LANG_SOURCE(
159 [#ifndef __cplusplus
160 typedef int foo_t;
161 static $ac_kw foo_t static_foo () {return 0; }
162 $ac_kw int foo () {return 0; }
163 #endif
164 ])],
165                     [ac_cv_c_inline=$ac_kw; break])
166 done
167 ])
168 case $ac_cv_c_inline in
169   inline | yes) ;;
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) ;;
174 esac
175 ])# AC_C_INLINE