64f44cd6ff76e1014c9231cc982d89bcc47efd06
[samba.git] / source / build / m4 / check_cc.m4
1 dnl SMB Build Environment CC Checks
2 dnl -------------------------------------------------------
3 dnl  Copyright (C) Stefan (metze) Metzmacher 2004
4 dnl  Released under the GNU GPL
5 dnl -------------------------------------------------------
6 dnl
7
8 # don't let the AC_PROG_CC macro auto set the CFLAGS
9 OLD_CFLAGS="${CFLAGS}"
10 AC_PROG_CC
11 CFLAGS="${OLD_CFLAGS}"
12 if test x"$CC" = x""; then
13         AC_MSG_WARN([No c compiler was not found!])
14         AC_MSG_ERROR([Please Install gcc from http://gcc.gnu.org/])
15 fi
16
17 #
18 # Set the debug symbol option if we have
19 # --enable-*developer or --enable-debug
20 # and the compiler supports it
21 #
22 if test x$ac_cv_prog_cc_g = xyes -a x$debug = xyes; then
23         CFLAGS="${CFLAGS} -g"
24 fi
25
26 dnl needed before AC_TRY_COMPILE
27 AC_ISC_POSIX
28
29 AC_CACHE_CHECK([that the C compiler can precompile header files],samba_cv_precompiled_headers, [
30         dnl Check whether the compiler can generate precompiled headers
31         touch conftest.h
32         if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
33                 precompiled_headers=yes
34         else
35                 precompiled_headers=no
36         fi])
37 AC_SUBST(precompiled_headers)
38
39
40 dnl Check if the C compiler understands volatile (it should, being ANSI).
41 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
42         AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
43                 samba_cv_volatile=yes,samba_cv_volatile=no)])
44 if test x"$samba_cv_volatile" = x"yes"; then
45         AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
46 fi
47
48 ############################################
49 # check if the compiler can do immediate structures
50 AC_CACHE_CHECK([for immediate structures],samba_cv_immediate_structures, [
51     AC_TRY_COMPILE([
52 #include <stdio.h>],
53 [
54    typedef struct {unsigned x;} FOOBAR;
55    #define X_FOOBAR(x) ((FOOBAR) { x })
56    #define FOO_ONE X_FOOBAR(1)
57    FOOBAR f = FOO_ONE;   
58    static struct {
59         FOOBAR y; 
60         } f2[] = {
61                 {FOO_ONE}
62         };   
63 ],
64         samba_cv_immediate_structures=yes,samba_cv_immediate_structures=no)])
65 if test x"$samba_cv_immediate_structures" = x"yes"; then
66    AC_DEFINE(HAVE_IMMEDIATE_STRUCTURES,1,[Whether the compiler supports immediate structures])
67 fi
68 AC_SUBST(samba_cv_immediate_structures)
69
70 ############################################
71 # check if the compiler handles c99 struct initialization
72 SMB_CC_SUPPORTS_C99_STRUCT_INIT(samba_cv_c99_struct_initialization=yes,
73                     samba_cv_c99_struct_initialization=no)
74
75 if test x"$samba_cv_c99_struct_initialization" != x"yes"; then
76         # We might need to add some flags to CC to get c99 behaviour.
77         AX_CFLAGS_IRIX_OPTION(-c99, CFLAGS)
78         SMB_CC_SUPPORTS_C99_STRUCT_INIT(samba_cv_c99_struct_initialization=yes,
79                             samba_cv_c99_struct_initialization=no)
80 fi
81
82 if test x"$samba_cv_c99_struct_initialization" != x"yes"; then
83         AC_MSG_WARN([C compiler does not support c99 struct initialization!])
84         AC_MSG_ERROR([Please Install gcc from http://gcc.gnu.org/])
85 fi
86
87 ############################################
88 # check if the compiler can handle negative enum values
89 AC_CACHE_CHECK([that the C compiler understands negative enum values],SMB_BUILD_CC_NEGATIVE_ENUM_VALUES, [
90     AC_TRY_COMPILE([
91 #include <stdio.h>],
92 [
93         enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
94 ],
95         SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=yes,SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=no)])
96 if test x"$SMB_BUILD_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
97         AC_MSG_WARN([using --unit-enums for pidl])
98         PIDL_ARGS="$PIDL_ARGS --uint-enums"
99 fi
100
101 AC_MSG_CHECKING([for test routines])
102 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
103             AC_MSG_RESULT(yes),
104             AC_MSG_ERROR([cant find test code. Aborting config]),
105             AC_MSG_WARN([cannot run when cross-compiling]))
106
107 #
108 # Check if the compiler support ELF visibility for symbols
109 #
110
111 visibility_attribute=no
112 VISIBILITY_CFLAGS=""
113 if test x"$GCC" = x"yes" ; then
114         AX_CFLAGS_GCC_OPTION([-fvisibility=hidden], VISIBILITY_CFLAGS)
115 fi
116
117 if test -n "$VISIBILITY_CFLAGS"; then
118         AC_MSG_CHECKING([whether the C compiler supports the visibility attribute])
119         OLD_CFLAGS="$CFLAGS"
120
121         CFLAGS="$CFLAGS $VISIBILITY_CFLAGS"
122         AC_TRY_RUN([
123                 void vis_foo1(void) {}
124                 __attribute__((visibility("default"))) void vis_foo2(void) {}
125                 #include "${srcdir-.}/build/tests/trivial.c"
126         ],[
127                 AC_MSG_RESULT(yes)
128                 AC_DEFINE(HAVE_VISIBILITY_ATTR,1,[Whether the C compiler supports the visibility attribute])
129                 visibility_attribute=yes
130         ],[
131                 AC_MSG_RESULT(no)
132         ])
133         CFLAGS="$OLD_CFLAGS"
134 fi
135 AC_SUBST(visibility_attribute)
136
137 #
138 # Check if the compiler can handle the options we selected by
139 # --enable-*developer
140 #
141 DEVELOPER_CFLAGS=""
142 if test x$developer = xyes; then
143         OLD_CFLAGS="${CFLAGS}"
144
145         CFLAGS="${CFLAGS} -D_SAMBA_DEVELOPER_DONNOT_USE_O2_"
146         DEVELOPER_CFLAGS="-DDEBUG_PASSWORD -DDEVELOPER"
147         if test x"$GCC" = x"yes" ; then
148             AX_CFLAGS_GCC_OPTION(-Wall, DEVELOPER_CFLAGS)
149             AX_CFLAGS_GCC_OPTION(-Wshadow, DEVELOPER_CFLAGS)
150             AX_CFLAGS_GCC_OPTION(-Werror-implicit-function-declaration, DEVELOPER_CFLAGS)
151             AX_CFLAGS_GCC_OPTION(-Wstrict-prototypes, DEVELOPER_CFLAGS)
152             AX_CFLAGS_GCC_OPTION(-Wpointer-arith, DEVELOPER_CFLAGS)
153             AX_CFLAGS_GCC_OPTION(-Wcast-qual, DEVELOPER_CFLAGS)
154             AX_CFLAGS_GCC_OPTION(-Wcast-align, DEVELOPER_CFLAGS)
155             AX_CFLAGS_GCC_OPTION(-Wwrite-strings, DEVELOPER_CFLAGS)
156             AX_CFLAGS_GCC_OPTION(-Wmissing-format-attribute, DEVELOPER_CFLAGS)
157             AX_CFLAGS_GCC_OPTION(-Wformat=2, DEVELOPER_CFLAGS)
158             AX_CFLAGS_GCC_OPTION(-Wno-format-y2k, DEVELOPER_CFLAGS)
159             AX_CFLAGS_GCC_OPTION(-Wno-declaration-after-statement, DEVELOPER_CFLAGS)
160         else
161             AX_CFLAGS_IRIX_OPTION(-fullwarn, DEVELOPER_CFLAGS)
162         fi
163
164         CFLAGS="${OLD_CFLAGS}"
165 fi
166 if test -n "$DEVELOPER_CFLAGS"; then
167         OLD_CFLAGS="${CFLAGS}"
168         CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}"
169         AC_MSG_CHECKING([that the C compiler can use the DEVELOPER_CFLAGS])
170         AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
171                 AC_MSG_RESULT(yes),
172                 DEVELOPER_CFLAGS=""; AC_MSG_RESULT(no))
173         CFLAGS="${OLD_CFLAGS}"
174 fi
175
176 # allow for --with-hostcc=gcc
177 AC_ARG_WITH(hostcc,[  --with-hostcc=compiler    choose host compiler],
178 [HOSTCC=$withval],
179 [
180 if test z"$cross_compiling" = "yes"; then 
181         HOSTCC=cc
182 else 
183         HOSTCC=$CC
184 fi
185 ])
186 AC_SUBST(HOSTCC)
187
188 AC_PATH_PROG(GCOV,gcov)
189
190 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
191 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
192 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
193 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
194     AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])
195 fi
196
197 AC_PATH_PROG(MAKE,make)
198
199 AC_CACHE_CHECK([whether we have GNU make], samba_cv_gnu_make, [
200 if $ac_cv_path_MAKE --version | head -1 | grep GNU 2>/dev/null >/dev/null
201 then
202         samba_cv_gnu_make=yes
203 else
204         samba_cv_gnu_make=no
205 fi
206 ])
207
208 GNU_MAKE=$samba_cv_gnu_make
209 AC_SUBST(GNU_MAKE)
210
211 if test "x$GNU_MAKE" = x"yes"; then
212         AC_CACHE_CHECK([GNU make version], samba_cv_gnu_make_version,[
213                 samba_cv_gnu_make_version=`$ac_cv_path_MAKE --version | head -1 | cut -d " " -f 3 2>/dev/null`
214         ])
215         GNU_MAKE_VERSION=$samba_cv_gnu_make_version
216         AC_SUBST(GNU_MAKE_VERSION)
217 fi
218
219
220 new_make=no
221 AC_MSG_CHECKING([for GNU make >= 3.81])
222 if test x$GNU_MAKE = x"yes"; then
223         if $PERL -e " \$_ = '$GNU_MAKE_VERSION'; s/@<:@^\d\.@:>@.*//g; exit (\$_ < 3.81);"; then
224                 new_make=yes
225         fi
226 fi
227 AC_MSG_RESULT($new_make)
228 automatic_dependencies=no
229 AX_CFLAGS_GCC_OPTION([-M -MT conftest.d -MF conftest.o], [], [ automatic_dependencies=$new_make ], [])
230 AC_MSG_CHECKING([Whether to use automatic dependencies])
231 AC_MSG_RESULT($automatic_dependencies)
232 AC_SUBST(automatic_dependencies)