r12836: use: -fvisibility=hidden -D_PUBLIC_="__attribute__((visibility(\"default...
[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 #
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 dnl Check if C compiler understands -c and -o at the same time
30 AC_PROG_CC_C_O
31 if eval "test \"`echo '$ac_cv_prog_cc_'${ac_cc}_c_o`\" = no"; then
32         BROKEN_CC=yes
33 else
34         BROKEN_CC=no
35 fi
36 AC_SUBST(BROKEN_CC)
37
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
40         touch conftest.h
41         if ${CC-cc} conftest.h 2> /dev/null && test -f conftest.h.gch; then
42                 samba_cv_precompiled_headers=yes
43         else
44                 samba_cv_precompiled_headers=no
45         fi])
46 PCH_AVAILABLE="#"
47 if test x"$samba_cv_precompiled_headers" = x"yes"; then
48         PCH_AVAILABLE=""
49 fi
50 AC_SUBST(PCH_AVAILABLE)
51
52
53 dnl Check if the C compiler understands volatile (it should, being ANSI).
54 AC_CACHE_CHECK([that the C compiler understands volatile],samba_cv_volatile, [
55         AC_TRY_COMPILE([#include <sys/types.h>],[volatile int i = 0],
56                 samba_cv_volatile=yes,samba_cv_volatile=no)])
57 if test x"$samba_cv_volatile" = x"yes"; then
58         AC_DEFINE(HAVE_VOLATILE, 1, [Whether the C compiler understands volatile])
59 fi
60
61 ############################################
62 # check if the compiler can do immediate structures
63 AC_CACHE_CHECK([for immediate structures],samba_cv_immediate_structures, [
64     AC_TRY_COMPILE([
65 #include <stdio.h>],
66 [
67    typedef struct {unsigned x;} FOOBAR;
68    #define X_FOOBAR(x) ((FOOBAR) { x })
69    #define FOO_ONE X_FOOBAR(1)
70    FOOBAR f = FOO_ONE;   
71    static struct {
72         FOOBAR y; 
73         } f2[] = {
74                 {FOO_ONE}
75         };   
76 ],
77         samba_cv_immediate_structures=yes,samba_cv_immediate_structures=no)])
78 if test x"$samba_cv_immediate_structures" = x"yes"; then
79    AC_DEFINE(HAVE_IMMEDIATE_STRUCTURES,1,[Whether the compiler supports immediate structures])
80 fi
81
82 ############################################
83 # check if the compiler handles c99 struct initialization
84 SMB_CC_SUPPORTS_C99_STRUCT_INIT(samba_cv_c99_struct_initialization=yes,
85                     samba_cv_c99_struct_initialization=no)
86
87 if test x"$samba_cv_c99_struct_initialization" != x"yes"; then
88         # We might need to add some flags to CC to get c99 behaviour.
89         AX_CFLAGS_IRIX_OPTION(-c99, CFLAGS)
90         SMB_CC_SUPPORTS_C99_STRUCT_INIT(samba_cv_c99_struct_initialization=yes,
91                             samba_cv_c99_struct_initialization=no)
92 fi
93
94 if test x"$samba_cv_c99_struct_initialization" != x"yes"; then
95         AC_MSG_WARN([C compiler does not support c99 struct initialization!])
96         AC_MSG_ERROR([Please Install gcc from http://gcc.gnu.org/])
97 fi
98
99 ############################################
100 # check if the compiler can handle negative enum values
101 AC_CACHE_CHECK([that the C compiler understands negative enum values],SMB_BUILD_CC_NEGATIVE_ENUM_VALUES, [
102     AC_TRY_COMPILE([
103 #include <stdio.h>],
104 [
105         enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
106 ],
107         SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=yes,SMB_BUILD_CC_NEGATIVE_ENUM_VALUES=no)])
108 if test x"$SMB_BUILD_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
109         AC_MSG_WARN([using --unit-enums for pidl])
110         PIDL_ARGS="$PIDL_ARGS --uint-enums"
111 fi
112
113 AC_MSG_CHECKING([for test routines])
114 AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
115             AC_MSG_RESULT(yes),
116             AC_MSG_ERROR([cant find test code. Aborting config]),
117             AC_MSG_WARN([cannot run when cross-compiling]))
118
119 #
120 # Check if the compiler support ELF visibility for symbols
121 #
122 if test x"$GCC" = x"yes" ; then
123     AX_CFLAGS_GCC_OPTION([-fvisibility=hidden], VISIBILITY_CFLAGS)
124 fi
125 if test -n "$VISIBILITY_CFLAGS"; then
126         OLD_CFLAGS="${CFLAGS}"
127         CFLAGS="${CFLAGS} ${VISIBILITY_CFLAGS} -D_PUBLIC_=__attribute__((visibility(\"default\")))"
128         VISIBILITY_CFLAGS="${VISIBILITY_CFLAGS} -D_PUBLIC_=\"__attribute__((visibility(\\\"default\\\")))\""
129         AC_MSG_CHECKING([that the C compiler can use the VISIBILITY_CFLAGS])
130         AC_TRY_RUN([
131                 _PUBLIC_ void vis_foo1(void) {}
132                 __attribute__((visibility("default"))) void vis_foo2(void) {}
133                 #include "${srcdir-.}/build/tests/trivial.c"
134                 ], AC_MSG_RESULT(yes), [AC_MSG_RESULT(no);VISIBILITY_CFLAGS=""])
135         CFLAGS="${OLD_CFLAGS}"
136 fi
137
138 #
139 # Check if the compiler can handle the options we selected by
140 # --enable-*developer
141 #
142 DEVELOPER_CFLAGS=""
143 if test x$developer = xyes; then
144         DEVELOPER_CFLAGS="-DDEBUG_PASSWORD -DDEVELOPER"
145         if test x"$GCC" = x"yes" ; then
146             OLD_CFLAGS="${CFLAGS}"
147             CFLAGS="${CFLAGS} -D_SAMBA_DEVELOPER_DONNOT_USE_O2_"
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             CFLAGS="${OLD_CFLAGS}"
161         fi
162 fi
163 if test -n "$DEVELOPER_CFLAGS"; then
164         OLD_CFLAGS="${CFLAGS}"
165         CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}"
166         AC_MSG_CHECKING([that the C compiler can use the DEVELOPER_CFLAGS])
167         AC_TRY_RUN([#include "${srcdir-.}/build/tests/trivial.c"],
168                 AC_MSG_RESULT(yes),
169                 DEVELOPER_CFLAGS=""; AC_MSG_RESULT(no))
170         CFLAGS="${OLD_CFLAGS}"
171 fi
172
173 # allow for --with-hostcc=gcc
174 AC_ARG_WITH(hostcc,[  --with-hostcc=compiler    choose host compiler],
175 [HOSTCC=$withval],
176 [
177 if test z"$cross_compiling" = "yes"; then 
178         HOSTCC=cc
179 else 
180         HOSTCC=$CC
181 fi
182 ])
183 AC_SUBST(HOSTCC)
184
185 AC_PATH_PROG(GCOV,gcov)