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 -------------------------------------------------------
8 # don't let the AC_PROG_CC macro auto set the CFLAGS
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/])
18 # Set the debug symbol option if we have
19 # --enable-*developer or --enable-debug
20 # and the compiler supports it
22 if test x$ac_cv_prog_cc_g = xyes -a x$debug = xyes; then
26 dnl needed before AC_TRY_COMPILE
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
32 if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
33 precompiled_headers=yes
35 precompiled_headers=no
37 AC_SUBST(precompiled_headers)
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])
48 ############################################
49 # check if the compiler can do immediate structures
50 AC_CACHE_CHECK([for immediate structures],samba_cv_immediate_structures, [
54 typedef struct {unsigned x;} FOOBAR;
55 #define X_FOOBAR(x) ((FOOBAR) { x })
56 #define FOO_ONE X_FOOBAR(1)
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])
68 AC_SUBST(samba_cv_immediate_structures)
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)
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)
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/])
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, [
93 enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
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"
101 AC_MSG_CHECKING([for test routines])
102 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
104 AC_MSG_ERROR([cant find test code. Aborting config]),
105 AC_MSG_WARN([cannot run when cross-compiling]))
108 # Check if the compiler support ELF visibility for symbols
111 visibility_attribute=no
113 if test x"$GCC" = x"yes" ; then
114 AX_CFLAGS_GCC_OPTION([-fvisibility=hidden], VISIBILITY_CFLAGS)
117 if test -n "$VISIBILITY_CFLAGS"; then
118 AC_MSG_CHECKING([whether the C compiler supports the visibility attribute])
121 CFLAGS="$CFLAGS $VISIBILITY_CFLAGS"
123 void vis_foo1(void) {}
124 __attribute__((visibility("default"))) void vis_foo2(void) {}
125 #include "${srcdir-.}/build/tests/trivial.c"
128 AC_DEFINE(HAVE_VISIBILITY_ATTR,1,[Whether the C compiler supports the visibility attribute])
129 visibility_attribute=yes
135 AC_SUBST(visibility_attribute)
138 # Check if the compiler can handle the options we selected by
139 # --enable-*developer
142 if test x$developer = xyes; then
143 OLD_CFLAGS="${CFLAGS}"
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)
161 AX_CFLAGS_IRIX_OPTION(-fullwarn, DEVELOPER_CFLAGS)
164 CFLAGS="${OLD_CFLAGS}"
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"],
172 DEVELOPER_CFLAGS=""; AC_MSG_RESULT(no))
173 CFLAGS="${OLD_CFLAGS}"
176 # allow for --with-hostcc=gcc
177 AC_ARG_WITH(hostcc,[ --with-hostcc=compiler choose host compiler],
180 if test z"$cross_compiling" = "yes"; then
188 AC_PATH_PROG(GCOV,gcov)
190 AC_PATH_PROG(MAKE,make)
192 AC_CACHE_CHECK([whether we have GNU make], samba_cv_gnu_make, [
193 if $ac_cv_path_MAKE --version | head -1 | grep GNU 2>/dev/null >/dev/null
195 samba_cv_gnu_make=yes
201 GNU_MAKE=$samba_cv_gnu_make
204 if test "x$GNU_MAKE" = x"yes"; then
205 AC_CACHE_CHECK([GNU make version], samba_cv_gnu_make_version,[
206 samba_cv_gnu_make_version=`$ac_cv_path_MAKE --version | head -1 | cut -d " " -f 3 2>/dev/null`
208 GNU_MAKE_VERSION=$samba_cv_gnu_make_version
209 AC_SUBST(GNU_MAKE_VERSION)
214 AC_MSG_CHECKING([for GNU make >= 3.81])
215 if test x$GNU_MAKE = x"yes"; then
216 if $PERL -e " \$_ = '$GNU_MAKE_VERSION'; s/@<:@^\d\.@:>@.*//g; exit (\$_ < 3.81);"; then
220 AC_MSG_RESULT($new_make)
221 automatic_dependencies=no
222 AX_CFLAGS_GCC_OPTION([-M -MT conftest.d -MF conftest.o], [], [ automatic_dependencies=$new_make ], [])
223 AC_MSG_CHECKING([Whether to use automatic dependencies])
224 AC_MSG_RESULT($automatic_dependencies)
225 AC_SUBST(automatic_dependencies)