]> granicus.if.org Git - postgresql/blob - config/c-compiler.m4
Make prep_buildtree harmless when run on top of the source tree.
[postgresql] / config / c-compiler.m4
1 # Macros to detect C compiler features
2 # $Header: /cvsroot/pgsql/config/c-compiler.m4,v 1.3 2000/08/29 09:36:37 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_C_VOLATILE
21 # ---------------
22 # Check if the C compiler understands `volatile'. Note that if it doesn't
23 # then this will potentially break the program semantics.
24 AC_DEFUN([PGAC_C_VOLATILE],
25 [AC_CACHE_CHECK(for volatile, pgac_cv_c_volatile,
26 [AC_TRY_COMPILE([],
27 [extern volatile int i;],
28 [pgac_cv_c_volatile=yes],
29 [pgac_cv_c_volatile=no])])
30 if test x"$pgac_cv_c_volatile" = xno ; then
31   AC_DEFINE(volatile,, [Define empty if the C compiler does not understand `volatile'])
32 fi])# PGAC_C_VOLATILE
33
34
35
36 # PGAC_TYPE_64BIT_INT(TYPE)
37 # -------------------------
38 # Check if TYPE is a working 64 bit integer type. Set HAVE_TYPE_64 to
39 # yes or no respectively, and define HAVE_TYPE_64 if yes.
40 AC_DEFUN([PGAC_TYPE_64BIT_INT],
41 [define([Ac_define], [translit([have_$1_64], [a-z *], [A-Z_P])])dnl
42 define([Ac_cachevar], [translit([pgac_cv_type_$1_64], [ *], [_p])])dnl
43 AC_CACHE_CHECK([whether $1 is 64 bits], [Ac_cachevar],
44 [AC_TRY_RUN(
45 [typedef $1 int64;
46
47 /*
48  * These are globals to discourage the compiler from folding all the
49  * arithmetic tests down to compile-time constants.
50  */
51 int64 a = 20000001;
52 int64 b = 40000005;
53
54 int does_int64_work()
55 {
56   int64 c,d;
57
58   if (sizeof(int64) != 8)
59     return 0;                   /* definitely not the right size */
60
61   /* Do perfunctory checks to see if 64-bit arithmetic seems to work */
62   c = a * b;
63   d = (c + b) / b;
64   if (d != a+1)
65     return 0;
66   return 1;
67 }
68 main() {
69   exit(! does_int64_work());
70 }],
71 [Ac_cachevar=yes],
72 [Ac_cachevar=no],
73 [Ac_cachevar=no
74 dnl We will do better here with Autoconf 2.50
75 AC_MSG_WARN([64 bit arithmetic disabled when cross-compiling])])])
76
77 Ac_define=$Ac_cachevar
78 if test x"$Ac_cachevar" = xyes ; then
79   AC_DEFINE(Ac_define,, [Set to 1 if `]$1[' is 64 bits])
80 fi
81 undefine([Ac_define])dnl
82 undefine([Ac_cachevar])dnl
83 ])# PGAC_TYPE_64BIT_INT
84
85
86
87 # PGAC_CHECK_ALIGNOF(TYPE)
88 # ------------------------
89 # Find the alignment requirement of the given type. Define the result
90 # as ALIGNOF_TYPE. If cross-compiling, sizeof(type) is used as a
91 # default assumption.
92 #
93 # This is modeled on the standard autoconf macro AC_CHECK_SIZEOF.
94 # That macro never got any points for style.
95 AC_DEFUN([PGAC_CHECK_ALIGNOF],
96 [changequote(<<, >>)dnl
97 dnl The name to #define.
98 define(<<AC_TYPE_NAME>>, translit(alignof_$1, [a-z *], [A-Z_P]))dnl
99 dnl The cache variable name.
100 define(<<AC_CV_NAME>>, translit(pgac_cv_alignof_$1, [ *], [_p]))dnl
101 changequote([, ])dnl
102 AC_MSG_CHECKING(alignment of $1)
103 AC_CACHE_VAL(AC_CV_NAME,
104 [AC_TRY_RUN([#include <stdio.h>
105 struct { char filler; $1 field; } mystruct;
106 main()
107 {
108   FILE *f=fopen("conftestval", "w");
109   if (!f) exit(1);
110   fprintf(f, "%d\n", ((char*) & mystruct.field) - ((char*) & mystruct));
111   exit(0);
112 }], AC_CV_NAME=`cat conftestval`,
113 AC_CV_NAME='sizeof($1)',
114 AC_CV_NAME='sizeof($1)')])dnl
115 AC_MSG_RESULT($AC_CV_NAME)
116 AC_DEFINE_UNQUOTED(AC_TYPE_NAME, $AC_CV_NAME, [The alignment requirement of a `]$1['])
117 undefine([AC_TYPE_NAME])dnl
118 undefine([AC_CV_NAME])dnl
119 ])# PGAC_CHECK_ALIGNOF