s4:samldb LDB module - make the "userAccountControl" and "groupType" modify handlers...
[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 AC_LIBREPLACE_CC_CHECKS
9
10 #
11 # Set the debug symbol option if we have
12 # --enable-*developer or --enable-debug
13 # and the compiler supports it
14 #
15 if test x$ac_cv_prog_cc_g = xyes -a x$debug = xyes; then
16         CFLAGS="${CFLAGS} -g"
17 fi
18
19 dnl ###########################################################################
20 dnl _AC_LANG_COMPILER_SUNCC
21 dnl Check whether the compiler for the current language is really Sun compiler.
22 dnl ###########################################################################
23 m4_define([AC_LANG_COMPILER_SUNCC],
24 [AC_CACHE_CHECK([whether we are really using the Sun _AC_LANG compiler],
25                 [ac_cv_[]_AC_LANG_ABBREV[]_compiler_suncc],
26 [_AC_COMPILE_IFELSE([AC_LANG_PROGRAM([], [[#ifndef __SUNPRO_C
27        choke me
28 #endif
29 ]])],
30                    [ac_compiler_suncc=yes],
31                    [ac_compiler_suncc=no])
32 ac_cv_[]_AC_LANG_ABBREV[]_compiler_suncc=$ac_compiler_suncc
33 ])])
34
35 AC_LANG_COMPILER_SUNCC
36
37 ############################################
38 # check if the compiler handles c99 struct initialization
39 LIBREPLACE_C99_STRUCT_INIT(samba_cv_c99_struct_initialization=yes,
40                     samba_cv_c99_struct_initialization=no)
41
42 if test x"$samba_cv_c99_struct_initialization" != x"yes"; then
43         AC_MSG_WARN([C compiler does not support c99 struct initialization!])
44         AC_MSG_ERROR([Please Install gcc from http://gcc.gnu.org/])
45 fi
46
47 ############################################
48 # check if the compiler can handle negative enum values
49 # and don't truncate the values to INT_MAX
50 # a runtime test is needed here
51 AC_CACHE_CHECK([that the C compiler understands negative enum values],samba_cv_CC_NEGATIVE_ENUM_VALUES, [
52     AC_TRY_RUN(
53 [
54         #include <stdio.h>
55         enum negative_values { NEGATIVE_VALUE = 0xFFFFFFFF };
56         int main(void) {
57                 enum negative_values v1 = NEGATIVE_VALUE;
58                 unsigned v2 = 0xFFFFFFFF;
59                 if (v1 != v2) {
60                         printf("v1=0x%08x v2=0x%08x\n", v1, v2);
61                         return 1;
62                 }
63                 return 0;
64         }
65 ],
66         samba_cv_CC_NEGATIVE_ENUM_VALUES=yes,
67         samba_cv_CC_NEGATIVE_ENUM_VALUES=no,
68         samba_cv_CC_NEGATIVE_ENUM_VALUES=yes)])
69 if test x"$samba_cv_CC_NEGATIVE_ENUM_VALUES" != x"yes"; then
70         AC_DEFINE(USE_UINT_ENUMS, 1, [Whether the compiler has uint enum support])
71 fi
72
73 AC_MSG_CHECKING([for test routines])
74 AC_TRY_RUN([#include "${srcdir-.}/../tests/trivial.c"],
75             AC_MSG_RESULT(yes),
76             AC_MSG_ERROR([cant find test code. Aborting config]),
77             AC_MSG_WARN([cannot run when cross-compiling]))
78
79 #
80 # Check if the compiler support ELF visibility for symbols
81 #
82
83 visibility_attribute=no
84 VISIBILITY_CFLAGS=""
85 if test x"$GCC" = x"yes" ; then
86         AX_CFLAGS_GCC_OPTION([-fvisibility=hidden], VISIBILITY_CFLAGS)
87 fi
88
89 if test -n "$VISIBILITY_CFLAGS"; then
90         AC_MSG_CHECKING([whether the C compiler supports the visibility attribute])
91         OLD_CFLAGS="$CFLAGS"
92
93         CFLAGS="$CFLAGS $VISIBILITY_CFLAGS"
94         AC_TRY_LINK([
95                 void vis_foo1(void) {}
96                 __attribute__((visibility("default"))) void vis_foo2(void) {}
97         ],[
98         ],[
99                 AC_MSG_RESULT(yes)
100                 AC_DEFINE(HAVE_VISIBILITY_ATTR,1,[Whether the C compiler supports the visibility attribute])
101                 visibility_attribute=yes
102         ],[
103                 AC_MSG_RESULT(no)
104         ])
105         CFLAGS="$OLD_CFLAGS"
106 fi
107 AC_SUBST(visibility_attribute)
108
109 #
110 # Check if the compiler can handle the options we selected by
111 # --enable-*developer
112 #
113 DEVELOPER_CFLAGS=""
114 if test x$developer = xyes; then
115         OLD_CFLAGS="${CFLAGS}"
116
117         CFLAGS="${CFLAGS} -D_SAMBA_DEVELOPER_DONNOT_USE_O2_"
118         DEVELOPER_CFLAGS="-DDEBUG_PASSWORD -DDEVELOPER"
119         if test x"$GCC" = x"yes" ; then
120             #
121             # warnings we want...
122             #
123             AX_CFLAGS_GCC_OPTION(-Wall, DEVELOPER_CFLAGS)
124             AX_CFLAGS_GCC_OPTION(-Wshadow, DEVELOPER_CFLAGS)
125             AX_CFLAGS_GCC_OPTION(-Werror-implicit-function-declaration, DEVELOPER_CFLAGS)
126             AX_CFLAGS_GCC_OPTION(-Wstrict-prototypes, DEVELOPER_CFLAGS)
127             AX_CFLAGS_GCC_OPTION(-Wpointer-arith, DEVELOPER_CFLAGS)
128             AX_CFLAGS_GCC_OPTION(-Wcast-qual, DEVELOPER_CFLAGS)
129             AX_CFLAGS_GCC_OPTION(-Wcast-align, DEVELOPER_CFLAGS)
130             AX_CFLAGS_GCC_OPTION(-Wwrite-strings, DEVELOPER_CFLAGS)
131             AX_CFLAGS_GCC_OPTION(-Wmissing-format-attribute, DEVELOPER_CFLAGS)
132             AX_CFLAGS_GCC_OPTION(-Wformat=2, DEVELOPER_CFLAGS)
133             AX_CFLAGS_GCC_OPTION(-Wdeclaration-after-statement, DEVELOPER_CFLAGS)
134             AX_CFLAGS_GCC_OPTION(-Wunused-macros, DEVELOPER_CFLAGS)
135 #           AX_CFLAGS_GCC_OPTION(-Wextra, DEVELOPER_CFLAGS)
136 #           AX_CFLAGS_GCC_OPTION(-Wc++-compat, DEVELOPER_CFLAGS)
137 #           AX_CFLAGS_GCC_OPTION(-Wmissing-prototypes, DEVELOPER_CFLAGS)
138 #           AX_CFLAGS_GCC_OPTION(-Wmissing-declarations, DEVELOPER_CFLAGS)
139 #           AX_CFLAGS_GCC_OPTION(-Wmissing-field-initializers, DEVELOPER_CFLAGS)
140             #
141             # warnings we don't want...
142             #
143             AX_CFLAGS_GCC_OPTION(-Wno-format-y2k, DEVELOPER_CFLAGS)
144             AX_CFLAGS_GCC_OPTION(-Wno-unused-parameter, DEVELOPER_CFLAGS)
145             #
146             # warnings we don't want just for some files e.g. swig bindings
147             #
148             AX_CFLAGS_GCC_OPTION(-Wno-cast-qual, CFLAG_NO_CAST_QUAL)
149             AC_SUBST(CFLAG_NO_CAST_QUAL)
150             AX_CFLAGS_GCC_OPTION(-Wno-unused-macros, CFLAG_NO_UNUSED_MACROS)
151             AC_SUBST(CFLAG_NO_UNUSED_MACROS)
152         elif test x"$ac_cv_c_compiler_suncc" != x"yes"; then
153             AX_CFLAGS_IRIX_OPTION(-fullwarn, DEVELOPER_CFLAGS)
154         fi
155
156         CFLAGS="${OLD_CFLAGS}"
157 fi
158 if test -n "$DEVELOPER_CFLAGS"; then
159         OLD_CFLAGS="${CFLAGS}"
160         CFLAGS="${CFLAGS} ${DEVELOPER_CFLAGS}"
161         AC_MSG_CHECKING([that the C compiler can use the DEVELOPER_CFLAGS])
162         AC_TRY_COMPILE([],[],
163                 AC_MSG_RESULT(yes),
164                 DEVELOPER_CFLAGS=""; AC_MSG_RESULT(no))
165         CFLAGS="${OLD_CFLAGS}"
166 fi
167
168 # allow for --with-hostcc=gcc
169 AC_ARG_WITH(hostcc,[  --with-hostcc=compiler  choose host compiler],
170 [HOSTCC=$withval],
171 [
172 if test z"$cross_compiling" = "yes"; then 
173         HOSTCC=cc
174 else 
175         HOSTCC=$CC
176 fi
177 ])
178 AC_SUBST(HOSTCC)
179
180 AC_PATH_PROG(GCOV,gcov)