Clean up ecpg's use of mmerror(): const-ify the format argument, add an
[PostgreSQL.git] / config / c-compiler.m4
blob9ac2c30d459732ec510ae7acdd4b83c790e84b7d
1 # Macros to detect C compiler features
2 # $PostgreSQL$
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
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;
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;
38 int does_int64_work()
40   ac_int64 c,d;
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 */
46   c = a * b;
47   d = (c + b) / b;
48   if (d != a+1)
49     return 0;
50   return 1;
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)])])
63 Ac_define=$Ac_cachevar
64 if test x"$Ac_cachevar" = xyes ; then
65   AC_DEFINE(Ac_define, 1, [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_C_FUNCNAME_SUPPORT
74 # -----------------------
75 # Check if the C compiler understands __func__ (C99) or __FUNCTION__ (gcc).
76 # Define HAVE_FUNCNAME__FUNC or HAVE_FUNCNAME__FUNCTION accordingly.
77 AC_DEFUN([PGAC_C_FUNCNAME_SUPPORT],
78 [AC_CACHE_CHECK(for __func__, pgac_cv_funcname_func_support,
79 [AC_TRY_COMPILE([#include <stdio.h>],
80 [printf("%s\n", __func__);],
81 [pgac_cv_funcname_func_support=yes],
82 [pgac_cv_funcname_func_support=no])])
83 if test x"$pgac_cv_funcname_func_support" = xyes ; then
84 AC_DEFINE(HAVE_FUNCNAME__FUNC, 1,
85           [Define to 1 if your compiler understands __func__.])
86 else
87 AC_CACHE_CHECK(for __FUNCTION__, pgac_cv_funcname_function_support,
88 [AC_TRY_COMPILE([#include <stdio.h>],
89 [printf("%s\n", __FUNCTION__);],
90 [pgac_cv_funcname_function_support=yes],
91 [pgac_cv_funcname_function_support=no])])
92 if test x"$pgac_cv_funcname_function_support" = xyes ; then
93 AC_DEFINE(HAVE_FUNCNAME__FUNCTION, 1,
94           [Define to 1 if your compiler understands __FUNCTION__.])
96 fi])# PGAC_C_FUNCNAME_SUPPORT
100 # PGAC_PROG_CC_CFLAGS_OPT
101 # -----------------------
102 # Given a string, check if the compiler supports the string as a
103 # command-line option. If it does, add the string to CFLAGS.
104 AC_DEFUN([PGAC_PROG_CC_CFLAGS_OPT],
105 [AC_MSG_CHECKING([if $CC supports $1])
106 pgac_save_CFLAGS=$CFLAGS
107 CFLAGS="$pgac_save_CFLAGS $1"
108 _AC_COMPILE_IFELSE([AC_LANG_PROGRAM()],
109                    AC_MSG_RESULT(yes),
110                    [CFLAGS="$pgac_save_CFLAGS"
111                     AC_MSG_RESULT(no)])
112 ])# PGAC_PROG_CC_CFLAGS_OPT
116 # PGAC_PROG_CC_LDFLAGS_OPT
117 # ------------------------
118 # Given a string, check if the compiler supports the string as a
119 # command-line option. If it does, add the string to LDFLAGS.
120 # For reasons you'd really rather not know about, this checks whether
121 # you can link to a particular function, not just whether you can link.
122 # In fact, we must actually check that the resulting program runs :-(
123 AC_DEFUN([PGAC_PROG_CC_LDFLAGS_OPT],
124 [AC_MSG_CHECKING([if $CC supports $1])
125 pgac_save_LDFLAGS=$LDFLAGS
126 LDFLAGS="$pgac_save_LDFLAGS $1"
127 AC_RUN_IFELSE([AC_LANG_PROGRAM([extern void $2 (); void (*fptr) () = $2;],[])],
128               AC_MSG_RESULT(yes),
129               [LDFLAGS="$pgac_save_LDFLAGS"
130                AC_MSG_RESULT(no)],
131               [LDFLAGS="$pgac_save_LDFLAGS"
132                AC_MSG_RESULT(assuming no)])
133 ])# PGAC_PROG_CC_LDFLAGS_OPT