311caa342ec5022fbbb6a3ff9214060f9b2df79a
[samba.git] / source4 / 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 if test x"$GCC" = x"yes" ; then
18         AC_MSG_CHECKING([for version of gcc])
19         GCC_VERSION=`$CC -dumpversion`
20         AC_MSG_RESULT(${GCC_VERSION})
21 fi
22
23 #
24 # Set the debug symbol option if we have
25 # --enable-*developer or --enable-debug
26 # and the compiler supports it
27 #
28 if test x$ac_cv_prog_cc_g = xyes -a x$debug = xyes; then
29         CFLAGS="${CFLAGS} -g"
30 fi
31
32 dnl needed before AC_TRY_COMPILE
33 AC_ISC_POSIX
34
35 ############################################
36 # check if the compiler handles c99 struct initialization
37 LIBREPLACE_C99_STRUCT_INIT(samba_cv_c99_struct_initialization=yes,
38                     samba_cv_c99_struct_initialization=no)
39
40 if test x"$samba_cv_c99_struct_initialization" != x"yes"; then
41         AC_MSG_WARN([C compiler does not support c99 struct initialization!])
42         AC_MSG_ERROR([Please Install gcc from http://gcc.gnu.org/])
43 fi
44
45 ############################################
46 # check if the compiler can handle negative enum values
47 # and don't truncate the values to INT_MAX
48 # a runtime test is needed here
49 AC_CACHE_CHECK([that the C compiler understands negative enum values],SMB_BUILD_CC_NEGATIVE_ENUM_VALUES, [
50     AC_TRY_RUN(
51 [
52         #include <stdio.h>
53         enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
54         int main(void) {
55                 enum negative_values v1 = NEGATIVE_VALUE;
56                 unsigned v2 = NEGATIVE_VALUE;
57
58                 if (v1 != 0xFFFFFFFF) {
59                         printf("%u != 0xFFFFFFFF\n", v1);
60                         return 1;
61                 }
62                 if (v2 != 0xFFFFFFFF) {
63                         printf("%u != 0xFFFFFFFF\n", v2);
64                         return 1;
65                 }
66
67                 return 0;
68         }
69 ],
70         SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=yes,SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=no)])
71 if test x"$SMB_BUILD_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
72         AC_MSG_WARN([using --unit-enums for pidl])
73         PIDL_ARGS="$PIDL_ARGS --uint-enums"
74 fi
75
76 AC_MSG_CHECKING([for test routines])
77 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
78             AC_MSG_RESULT(yes),
79             AC_MSG_ERROR([cant find test code. Aborting config]),
80             AC_MSG_WARN([cannot run when cross-compiling]))
81
82 #
83 # Check if the compiler support ELF visibility for symbols
84 #
85
86 visibility_attribute=no
87 VISIBILITY_CFLAGS=""
88 if test x"$GCC" = x"yes" ; then
89         AX_CFLAGS_GCC_OPTION([-fvisibility=hidden], VISIBILITY_CFLAGS)
90 fi
91
92 if test -n "$VISIBILITY_CFLAGS"; then
93         AC_MSG_CHECKING([whether the C compiler supports the visibility attribute])
94         OLD_CFLAGS="$CFLAGS"
95
96         CFLAGS="$CFLAGS $VISIBILITY_CFLAGS"
97         AC_TRY_RUN([
98                 void vis_foo1(void) {}
99                 __attribute__((visibility("default"))) void vis_foo2(void) {}
100                 #include "${srcdir-.}/build/tests/trivial.c"
101         ],[
102                 AC_MSG_RESULT(yes)
103                 AC_DEFINE(HAVE_VISIBILITY_ATTR,1,[Whether the C compiler supports the visibility attribute])
104                 visibility_attribute=yes
105         ],[
106                 AC_MSG_RESULT(no)
107         ])
108         CFLAGS="$OLD_CFLAGS"
109 fi
110 AC_SUBST(visibility_attribute)
111
112 #
113 # Check if the compiler can handle the options we selected by
114 # --enable-*developer
115 #
116 DEVELOPER_CFLAGS=""
117 if test x$developer = xyes; then
118         OLD_CFLAGS="${CFLAGS}"
119
120         CFLAGS="${CFLAGS} -D_SAMBA_DEVELOPER_DONNOT_USE_O2_"
121         DEVELOPER_CFLAGS="-DDEBUG_PASSWORD -DDEVELOPER"
122         if test x"$GCC" = x"yes" ; then
123             #
124             # warnings we want...
125             #
126             AX_CFLAGS_GCC_OPTION(-Wall, DEVELOPER_CFLAGS)
127             AX_CFLAGS_GCC_OPTION(-Wshadow, DEVELOPER_CFLAGS)
128             AX_CFLAGS_GCC_OPTION(-Werror-implicit-function-declaration, DEVELOPER_CFLAGS)
129             AX_CFLAGS_GCC_OPTION(-Wstrict-prototypes, DEVELOPER_CFLAGS)
130             AX_CFLAGS_GCC_OPTION(-Wpointer-arith, DEVELOPER_CFLAGS)
131             AX_CFLAGS_GCC_OPTION(-Wcast-qual, DEVELOPER_CFLAGS)
132             AX_CFLAGS_GCC_OPTION(-Wcast-align, DEVELOPER_CFLAGS)
133             AX_CFLAGS_GCC_OPTION(-Wwrite-strings, DEVELOPER_CFLAGS)
134             AX_CFLAGS_GCC_OPTION(-Wmissing-format-attribute, DEVELOPER_CFLAGS)
135             AX_CFLAGS_GCC_OPTION(-Wformat=2, DEVELOPER_CFLAGS)
136             AX_CFLAGS_GCC_OPTION(-Wdeclaration-after-statement, DEVELOPER_CFLAGS)
137             AX_CFLAGS_GCC_OPTION(-Wunused-macros, DEVELOPER_CFLAGS)
138 #           AX_CFLAGS_GCC_OPTION(-Wextra, DEVELOPER_CFLAGS)
139 #           AX_CFLAGS_GCC_OPTION(-Wc++-compat, DEVELOPER_CFLAGS)
140 #           AX_CFLAGS_GCC_OPTION(-Wmissing-prototypes, DEVELOPER_CFLAGS)
141 #           AX_CFLAGS_GCC_OPTION(-Wmissing-declarations, DEVELOPER_CFLAGS)
142 #           AX_CFLAGS_GCC_OPTION(-Wmissing-field-initializers, DEVELOPER_CFLAGS)
143             #
144             # warnings we don't want...
145             #
146             AX_CFLAGS_GCC_OPTION(-Wno-format-y2k, DEVELOPER_CFLAGS)
147             AX_CFLAGS_GCC_OPTION(-Wno-unused-parameter, DEVELOPER_CFLAGS)
148         else
149             AX_CFLAGS_IRIX_OPTION(-fullwarn, DEVELOPER_CFLAGS)
150         fi
151
152         CFLAGS="${OLD_CFLAGS}"
153 fi
154 if test -n "$DEVELOPER_CFLAGS"; then
155         OLD_CFLAGS="${CFLAGS}"
156         CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}"
157         AC_MSG_CHECKING([that the C compiler can use the DEVELOPER_CFLAGS])
158         AC_TRY_COMPILE([],[],
159                 AC_MSG_RESULT(yes),
160                 DEVELOPER_CFLAGS=""; AC_MSG_RESULT(no))
161         CFLAGS="${OLD_CFLAGS}"
162 fi
163
164 #
165 # Config CPPFLAG settings for strange OS's that must be set
166 # before other tests.
167 #
168 case "$host_os" in
169         # Try to work out if this is the native HPUX compiler that uses the -Ae flag.
170         *hpux*)
171                 # mmap on HPUX is completely broken...
172                 AC_DEFINE(MMAP_BLACKLIST, 1, [Whether MMAP is broken])
173                 ;;
174
175         *aix*)
176                 if test "${GCC}" != "yes"; then
177                         ## for funky AIX compiler using strncpy()
178                         CFLAGS="$CFLAGS -D_LINUX_SOURCE_COMPAT -qmaxmem=32000"
179                 fi
180                 ;;
181
182         #
183         # VOS may need to have POSIX support and System V compatibility enabled.
184         #
185         *vos*)
186                 case "$CPPFLAGS" in
187                         *-D_POSIX_C_SOURCE*);;
188                         *)
189                                 CPPFLAGS="$CPPFLAGS -D_POSIX_C_SOURCE=200112L"
190                                 AC_DEFINE(_POSIX_C_SOURCE, 200112L, [Whether to enable POSIX support])
191                                 ;;
192                 esac
193                 case "$CPPFLAGS" in
194                         *-D_SYSV*|*-D_SVID_SOURCE*);;
195                         *)
196                                 CPPFLAGS="$CPPFLAGS -D_SYSV"
197                                 AC_DEFINE(_SYSV, 1, [Whether to enable System V compatibility])
198                                 ;;
199                 esac
200                 ;;
201 esac
202
203 # allow for --with-hostcc=gcc
204 AC_ARG_WITH(hostcc,[  --with-hostcc=compiler    choose host compiler],
205 [HOSTCC=$withval],
206 [
207 if test z"$cross_compiling" = "yes"; then 
208         HOSTCC=cc
209 else 
210         HOSTCC=$CC
211 fi
212 ])
213 AC_SUBST(HOSTCC)
214
215 AC_PATH_PROG(GCOV,gcov)
216
217 AC_PATH_PROG(MAKE,make)
218
219 AC_CACHE_CHECK([whether we have GNU make], samba_cv_gnu_make, [
220 if $ac_cv_path_MAKE --version | head -1 | grep GNU 2>/dev/null >/dev/null
221 then
222         samba_cv_gnu_make=yes
223 else
224         samba_cv_gnu_make=no
225 fi
226 ])
227
228 GNU_MAKE=$samba_cv_gnu_make
229 AC_SUBST(GNU_MAKE)
230
231 if test "x$GNU_MAKE" = x"yes"; then
232         AC_CACHE_CHECK([GNU make version], samba_cv_gnu_make_version,[
233                 samba_cv_gnu_make_version=`$ac_cv_path_MAKE --version | head -1 | cut -d " " -f 3 2>/dev/null`
234         ])
235         GNU_MAKE_VERSION=$samba_cv_gnu_make_version
236         AC_SUBST(GNU_MAKE_VERSION)
237 fi
238
239
240 new_make=no
241 AC_MSG_CHECKING([for GNU make >= 3.81])
242 if test x$GNU_MAKE = x"yes"; then
243         if $PERL -e " \$_ = '$GNU_MAKE_VERSION'; s/@<:@^\d\.@:>@.*//g; exit (\$_ < 3.81);"; then
244                 new_make=yes
245         fi
246 fi
247 AC_MSG_RESULT($new_make)
248 automatic_dependencies=no
249 AX_CFLAGS_GCC_OPTION([-M -MT conftest.d -MF conftest.o], [], [ automatic_dependencies=$new_make ], [])
250 AC_MSG_CHECKING([Whether to use automatic dependencies])
251 AC_MSG_RESULT($automatic_dependencies)
252 AC_SUBST(automatic_dependencies)