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 dnl Check if C compiler understands -c and -o at the same time
31 if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" = no"; then
38 AC_CACHE_CHECK([that the C compiler can precompile header files],samba_cv_precompiled_headers, [
39 dnl Check whether the compiler can generate precompiled headers
41 if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
42 precompiled_headers=yes
44 precompiled_headers=no
46 AC_SUBST(precompiled_headers)
49 dnl Check if the C compiler understands volatile (it should, being ANSI).
50 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
51 AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
52 samba_cv_volatile=yes,samba_cv_volatile=no)])
53 if test x"$samba_cv_volatile" = x"yes"; then
54 AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
57 ############################################
58 # check if the compiler can do immediate structures
59 AC_CACHE_CHECK([for immediate structures],samba_cv_immediate_structures, [
63 typedef struct {unsigned x;} FOOBAR;
64 #define X_FOOBAR(x) ((FOOBAR) { x })
65 #define FOO_ONE X_FOOBAR(1)
73 samba_cv_immediate_structures=yes,samba_cv_immediate_structures=no)])
74 if test x"$samba_cv_immediate_structures" = x"yes"; then
75 AC_DEFINE(HAVE_IMMEDIATE_STRUCTURES,1,[Whether the compiler supports immediate structures])
78 ############################################
79 # check if the compiler handles c99 struct initialization
80 SMB_CC_SUPPORTS_C99_STRUCT_INIT(samba_cv_c99_struct_initialization=yes,
81 samba_cv_c99_struct_initialization=no)
83 if test x"$samba_cv_c99_struct_initialization" != x"yes"; then
84 # We might need to add some flags to CC to get c99 behaviour.
85 AX_CFLAGS_IRIX_OPTION(-c99, CFLAGS)
86 SMB_CC_SUPPORTS_C99_STRUCT_INIT(samba_cv_c99_struct_initialization=yes,
87 samba_cv_c99_struct_initialization=no)
90 if test x"$samba_cv_c99_struct_initialization" != x"yes"; then
91 AC_MSG_WARN([C compiler does not support c99 struct initialization!])
92 AC_MSG_ERROR([Please Install gcc from http://gcc.gnu.org/])
95 ############################################
96 # check if the compiler can handle negative enum values
97 AC_CACHE_CHECK([that the C compiler understands negative enum values],SMB_BUILD_CC_NEGATIVE_ENUM_VALUES, [
101 enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
103 SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=yes,SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=no)])
104 if test x"$SMB_BUILD_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
105 AC_MSG_WARN([using --unit-enums for pidl])
106 PIDL_ARGS="$PIDL_ARGS --uint-enums"
109 AC_MSG_CHECKING([for test routines])
110 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
112 AC_MSG_ERROR([cant find test code. Aborting config]),
113 AC_MSG_WARN([cannot run when cross-compiling]))
116 # Check if the compiler support ELF visibility for symbols
119 visibility_attribute=no
121 if test x"$GCC" = x"yes" ; then
122 AX_CFLAGS_GCC_OPTION([-fvisibility=hidden], VISIBILITY_CFLAGS)
125 if test -n "$VISIBILITY_CFLAGS"; then
126 AC_MSG_CHECKING([whether the C compiler supports the visibility attribute])
129 CFLAGS="$CFLAGS $VISIBILITY_CFLAGS"
131 void vis_foo1(void) {}
132 __attribute__((visibility("default"))) void vis_foo2(void) {}
133 #include "${srcdir-.}/build/tests/trivial.c"
136 AC_DEFINE(HAVE_VISIBILITY_ATTR,1,[Whether the C compiler supports the visibility attribute])
137 visibility_attribute=yes
143 AC_SUBST(visibility_attribute)
146 # Check if the compiler can handle the options we selected by
147 # --enable-*developer
150 if test x$developer = xyes; then
151 OLD_CFLAGS="${CFLAGS}"
153 CFLAGS="${CFLAGS} -D_SAMBA_DEVELOPER_DONNOT_USE_O2_"
154 DEVELOPER_CFLAGS="-DDEBUG_PASSWORD -DDEVELOPER"
155 if test x"$GCC" = x"yes" ; then
156 AX_CFLAGS_GCC_OPTION(-Wall, DEVELOPER_CFLAGS)
157 AX_CFLAGS_GCC_OPTION(-Wshadow, DEVELOPER_CFLAGS)
158 AX_CFLAGS_GCC_OPTION(-Werror-implicit-function-declaration, DEVELOPER_CFLAGS)
159 AX_CFLAGS_GCC_OPTION(-Wstrict-prototypes, DEVELOPER_CFLAGS)
160 AX_CFLAGS_GCC_OPTION(-Wpointer-arith, DEVELOPER_CFLAGS)
161 AX_CFLAGS_GCC_OPTION(-Wcast-qual, DEVELOPER_CFLAGS)
162 AX_CFLAGS_GCC_OPTION(-Wcast-align, DEVELOPER_CFLAGS)
163 AX_CFLAGS_GCC_OPTION(-Wwrite-strings, DEVELOPER_CFLAGS)
164 AX_CFLAGS_GCC_OPTION(-Wmissing-format-attribute, DEVELOPER_CFLAGS)
165 AX_CFLAGS_GCC_OPTION(-Wformat=2, DEVELOPER_CFLAGS)
166 AX_CFLAGS_GCC_OPTION(-Wno-format-y2k, DEVELOPER_CFLAGS)
167 AX_CFLAGS_GCC_OPTION(-Wno-declaration-after-statement, DEVELOPER_CFLAGS)
169 AX_CFLAGS_IRIX_OPTION(-fullwarn, DEVELOPER_CFLAGS)
172 CFLAGS="${OLD_CFLAGS}"
174 if test -n "$DEVELOPER_CFLAGS"; then
175 OLD_CFLAGS="${CFLAGS}"
176 CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}"
177 AC_MSG_CHECKING([that the C compiler can use the DEVELOPER_CFLAGS])
178 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
180 DEVELOPER_CFLAGS=""; AC_MSG_RESULT(no))
181 CFLAGS="${OLD_CFLAGS}"
184 # allow for --with-hostcc=gcc
185 AC_ARG_WITH(hostcc,[ --with-hostcc=compiler choose host compiler],
188 if test z"$cross_compiling" = "yes"; then
196 AC_PATH_PROG(GCOV,gcov)
198 AC_CACHE_CHECK([for __FUNCTION__ macro],samba_cv_HAVE_FUNCTION_MACRO,[
199 AC_TRY_COMPILE([#include <stdio.h>], [printf("%s\n", __FUNCTION__);],
200 samba_cv_HAVE_FUNCTION_MACRO=yes,samba_cv_HAVE_FUNCTION_MACRO=no)])
201 if test x"$samba_cv_HAVE_FUNCTION_MACRO" = x"yes"; then
202 AC_DEFINE(HAVE_FUNCTION_MACRO,1,[Whether there is a __FUNCTION__ macro])