Update from latest ddm4
[awesomized/libmemcached] / m4 / pandora_warnings.m4
1 dnl Copyright (C) 2009 Sun Microsystems, Inc.
2 dnl This file is free software; Sun Microsystems, Inc.
3 dnl gives unlimited permission to copy and/or distribute it,
4 dnl with or without modifications, as long as this notice is preserved.
5
6 dnl AC_PANDORA_WARNINGS([less-warnings|warnings-always-on])
7 dnl less-warnings turn on a limited set of warnings
8 dnl warnings-always-on always set warnings=error regardless of tarball/vc
9
10 dnl @TODO: remove less-warnings option as soon as Drizzle is clean enough to
11 dnl allow it
12
13 AC_DEFUN([PANDORA_WARNINGS],[
14 m4_define([PW_LESS_WARNINGS],[no])
15 m4_define([PW_WARN_ALWAYS_ON],[no])
16 ifdef([m4_define],,[define([m4_define], defn([define]))])
17 ifdef([m4_undefine],,[define([m4_undefine], defn([undefine]))])
18 m4_foreach([pw_arg],[$*],[
19 m4_case(pw_arg,
20 [less-warnings],[
21 m4_undefine([PW_LESS_WARNINGS])
22 m4_define([PW_LESS_WARNINGS],[yes])
23 ],
24 [warnings-always-on],[
25 m4_undefine([PW_WARN_ALWAYS_ON])
26 m4_define([PW_WARN_ALWAYS_ON],[yes])
27 ])
28 ])
29
30 m4_if(PW_WARN_ALWAYS_ON, [yes],
31 [ac_cv_warnings_as_errors=yes],
32 AS_IF([test "$pandora_building_from_vc" = "yes"],
33 [ac_cv_warnings_as_errors=yes],
34 [ac_cv_warnings_as_errors=no]))
35
36 AC_ARG_ENABLE([gcc-profile-mode],
37 [AS_HELP_STRING([--enable-gcc-profile-mode],
38 [Toggle gcc profile mode @<:@default=off@:>@])],
39 [ac_gcc_profile_mode="$enableval"],
40 [ac_gcc_profile_mode="no"])
41
42 AC_ARG_ENABLE([profiling],
43 [AS_HELP_STRING([--enable-profiling],
44 [Toggle profiling @<:@default=off@:>@])],
45 [ac_profiling="$enableval"],
46 [ac_profiling="no"])
47
48 AC_ARG_ENABLE([coverage],
49 [AS_HELP_STRING([--enable-coverage],
50 [Toggle coverage @<:@default=off@:>@])],
51 [ac_coverage="$enableval"],
52 [ac_coverage="no"])
53
54 AS_IF([test "$GCC" = "yes"],[
55
56 AS_IF([test "$ac_profiling" = "yes"],[
57 CC_PROFILING="-pg"
58 GCOV_LIBS="-pg -lgcov"
59 save_LIBS="${LIBS}"
60 LIBS=""
61 AC_CHECK_LIB(c_p, read)
62 LIBC_P="${LIBS}"
63 LIBS="${save_LIBS}"
64 AC_SUBST(LIBC_P)
65 ],[
66 CC_PROFILING=" "
67 ])
68
69 AS_IF([test "$ac_coverage" = "yes"],
70 [
71 CC_COVERAGE="--coverage"
72 GCOV_LIBS="-lgcov"
73 ])
74
75
76
77 AS_IF([test "$ac_cv_warnings_as_errors" = "yes"],[
78 W_FAIL="-Werror"
79 SPHINX_WARNINGS="-W -n"
80 INTLTOOL_WARNINGS="yes"
81 ])
82
83 AC_CACHE_CHECK([whether it is safe to use -fdiagnostics-show-option],
84 [ac_cv_safe_to_use_fdiagnostics_show_option_],
85 [save_CFLAGS="$CFLAGS"
86 CFLAGS="-fdiagnostics-show-option ${AM_CFLAGS} ${CFLAGS}"
87 AC_COMPILE_IFELSE(
88 [AC_LANG_PROGRAM([],[])],
89 [ac_cv_safe_to_use_fdiagnostics_show_option_=yes],
90 [ac_cv_safe_to_use_fdiagnostics_show_option_=no])
91 CFLAGS="$save_CFLAGS"])
92
93 AS_IF([test "$ac_cv_safe_to_use_fdiagnostics_show_option_" = "yes"],
94 [
95 F_DIAGNOSTICS_SHOW_OPTION="-fdiagnostics-show-option"
96 ])
97
98 AC_CACHE_CHECK([whether it is safe to use -floop-parallelize-all],
99 [ac_cv_safe_to_use_floop_parallelize_all_],
100 [save_CFLAGS="$CFLAGS"
101 CFLAGS="-Werror -floop-parallelize-all ${AM_CFLAGS} ${CFLAGS}"
102 AC_COMPILE_IFELSE(
103 [AC_LANG_PROGRAM([],[])],
104 [ac_cv_safe_to_use_floop_parallelize_all_=yes],
105 [ac_cv_safe_to_use_floop_parallelize_all_=no])
106 CFLAGS="$save_CFLAGS"])
107
108 AS_IF([test "$ac_cv_safe_to_use_floop_parallelize_all_" = "yes"],
109 [
110 F_LOOP_PARALLELIZE_ALL="-floop-parallelize-all"
111 ])
112
113 NO_STRICT_ALIASING="-fno-strict-aliasing -Wno-strict-aliasing"
114 NO_SHADOW="-Wno-shadow"
115
116 AS_IF([test "$INTELCC" = "yes"],[
117 m4_if(PW_LESS_WARNINGS,[no],[
118 BASE_WARNINGS="-w1 -Werror -Wcheck -Wp64 -Woverloaded-virtual -Wcast-qual -diag-disable 188"
119 ],[
120 dnl 2203 is like old-style-cast
121 dnl 1684 is like strict-aliasing
122 dnl 188 is about using enums as bitfields
123 dnl 1683 is a warning about _EXPLICIT_ casting, which we want
124 BASE_WARNINGS="-w1 -Werror -Wcheck -Wp64 -Woverloaded-virtual -Wcast-qual -diag-disable 188,981,2259,2203,1683,1684"
125 ])
126 CC_WARNINGS="${BASE_WARNINGS}"
127 CXX_WARNINGS="${BASE_WARNINGS}"
128 PROTOSKIP_WARNINGS="-diag-disable 188,981,967,2259,1683,1684,2203"
129
130 ],[
131 m4_if(PW_LESS_WARNINGS,[no],[
132 BASE_WARNINGS_FULL="${W_CONVERSION} -Wstrict-aliasing -Wswitch-enum "
133 CC_WARNINGS_FULL="-Wswitch-default -Wswitch-enum -Wwrite-strings"
134 CXX_WARNINGS_FULL=""
135 NO_OLD_STYLE_CAST="-Wno-old-style-cast"
136 NO_EFF_CXX="-Wno-effc++"
137 ],[
138 BASE_WARNINGS_FULL="${NO_STRICT_ALIASING}"
139 ])
140
141 AS_IF([test "${ac_cv_assert}" = "no"],
142 [NO_UNUSED="-Wno-unused-variable -Wno-unused-parameter"])
143
144 AC_CACHE_CHECK([whether it is safe to use -Wextra],
145 [ac_cv_safe_to_use_Wextra_],
146 [save_CFLAGS="$CFLAGS"
147 CFLAGS="${W_FAIL} -pedantic -Wextra ${AM_CFLAGS} ${CFLAGS}"
148 AC_COMPILE_IFELSE([
149 AC_LANG_PROGRAM(
150 [[
151 #include <stdio.h>
152 ]], [[]])
153 ],
154 [ac_cv_safe_to_use_Wextra_=yes],
155 [ac_cv_safe_to_use_Wextra_=no])
156 CFLAGS="$save_CFLAGS"])
157
158 BASE_WARNINGS="${W_FAIL} -pedantic -Wall -Wundef -Wshadow -Wparentheses ${NO_UNUSED} ${F_DIAGNOSTICS_SHOW_OPTION} ${F_LOOP_PARALLELIZE_ALL} ${BASE_WARNINGS_FULL}"
159 AS_IF([test "$ac_cv_safe_to_use_Wextra_" = "yes"],
160 [BASE_WARNINGS="${BASE_WARNINGS} -Wextra"],
161 [BASE_WARNINGS="${BASE_WARNINGS} -W"])
162
163 AC_CACHE_CHECK([whether it is safe to use -Wformat],
164 [ac_cv_safe_to_use_wformat_],
165 [save_CFLAGS="$CFLAGS"
166 dnl Use -Werror here instead of ${W_FAIL} so that we don't spew
167 dnl conversion warnings to all the tarball folks
168 CFLAGS="-Wformat -Werror -pedantic ${AM_CFLAGS} ${CFLAGS}"
169 AC_COMPILE_IFELSE(
170 [AC_LANG_PROGRAM([[
171 #include <stdio.h>
172 #include <stdint.h>
173 #include <inttypes.h>
174 void foo();
175 void foo()
176 {
177 uint64_t test_u= 0;
178 printf("This is a %" PRIu64 "test\n", test_u);
179 }
180 ]],[[
181 foo();
182 ]])],
183 [ac_cv_safe_to_use_wformat_=yes],
184 [ac_cv_safe_to_use_wformat_=no])
185 CFLAGS="$save_CFLAGS"])
186 AS_IF([test "$ac_cv_safe_to_use_wformat_" = "yes"],[
187 BASE_WARNINGS="${BASE_WARNINGS} -Wformat -Wno-format-nonliteral -Wformat-security"
188 BASE_WARNINGS_FULL="${BASE_WARNINGS_FULL} -Wformat=2 -Wno-format-nonliteral -Wformat-security"
189 ],[
190 BASE_WARNINGS="${BASE_WARNINGS} -Wno-format"
191 BASE_WARNINGS_FULL="${BASE_WARNINGS_FULL} -Wno-format"
192 ])
193
194
195
196 AC_CACHE_CHECK([whether it is safe to use -Wconversion],
197 [ac_cv_safe_to_use_wconversion_],
198 [save_CFLAGS="$CFLAGS"
199 dnl Use -Werror here instead of ${W_FAIL} so that we don't spew
200 dnl conversion warnings to all the tarball folks
201 CFLAGS="-Wconversion -Werror -pedantic ${AM_CFLAGS} ${CFLAGS}"
202 AC_COMPILE_IFELSE(
203 [AC_LANG_PROGRAM([[
204 #include <stdbool.h>
205 void foo(bool a)
206 {
207 (void)a;
208 }
209 ]],[[
210 foo(0);
211 ]])],
212 [ac_cv_safe_to_use_wconversion_=yes],
213 [ac_cv_safe_to_use_wconversion_=no])
214 CFLAGS="$save_CFLAGS"])
215
216 AS_IF([test "$ac_cv_safe_to_use_wconversion_" = "yes"],
217 [W_CONVERSION="-Wconversion"
218 AC_CACHE_CHECK([whether it is safe to use -Wconversion with htons],
219 [ac_cv_safe_to_use_Wconversion_],
220 [save_CFLAGS="$CFLAGS"
221 dnl Use -Werror here instead of ${W_FAIL} so that we don't spew
222 dnl conversion warnings to all the tarball folks
223 CFLAGS="-Wconversion -Werror -pedantic ${AM_CFLAGS} ${CFLAGS}"
224 AC_COMPILE_IFELSE(
225 [AC_LANG_PROGRAM(
226 [[
227 #include <netinet/in.h>
228 ]],[[
229 uint16_t x= htons(80);
230 ]])],
231 [ac_cv_safe_to_use_Wconversion_=yes],
232 [ac_cv_safe_to_use_Wconversion_=no])
233 CFLAGS="$save_CFLAGS"])
234
235 AS_IF([test "$ac_cv_safe_to_use_Wconversion_" = "no"],
236 [NO_CONVERSION="-Wno-conversion"])
237 ])
238
239 CC_WARNINGS="${BASE_WARNINGS} -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wmissing-declarations -Wcast-align -Wsign-compare ${CC_WARNINGS_FULL}"
240 CXX_WARNINGS="${BASE_WARNINGS} -Woverloaded-virtual -Wnon-virtual-dtor -Wctor-dtor-privacy -Wno-long-long -Wsign-compare ${CXX_WARNINGS_FULL}"
241
242 AC_CACHE_CHECK([whether it is safe to use -Wmissing-declarations from C++],
243 [ac_cv_safe_to_use_Wmissing_declarations_],
244 [AC_LANG_PUSH(C++)
245 save_CXXFLAGS="$CXXFLAGS"
246 CXXFLAGS="-Werror -pedantic -Wmissing-declarations ${AM_CXXFLAGS}"
247 AC_COMPILE_IFELSE([
248 AC_LANG_PROGRAM(
249 [[
250 #include <stdio.h>
251 ]], [[]])
252 ],
253 [ac_cv_safe_to_use_Wmissing_declarations_=yes],
254 [ac_cv_safe_to_use_Wmissing_declarations_=no])
255 CXXFLAGS="$save_CXXFLAGS"
256 AC_LANG_POP()
257 ])
258 AS_IF([test "$ac_cv_safe_to_use_Wmissing_declarations_" = "yes"],
259 [CXX_WARNINGS="${CXX_WARNINGS} -Wmissing-declarations"])
260
261 AC_CACHE_CHECK([whether it is safe to use -Wframe-larger-than],
262 [ac_cv_safe_to_use_Wframe_larger_than_],
263 [AC_LANG_PUSH(C++)
264 save_CXXFLAGS="$CXXFLAGS"
265 CXXFLAGS="-Werror -pedantic -Wframe-larger-than=32768 ${AM_CXXFLAGS}"
266 AC_COMPILE_IFELSE([
267 AC_LANG_PROGRAM(
268 [[
269 #include <stdio.h>
270 ]], [[]])
271 ],
272 [ac_cv_safe_to_use_Wframe_larger_than_=yes],
273 [ac_cv_safe_to_use_Wframe_larger_than_=no])
274 CXXFLAGS="$save_CXXFLAGS"
275 AC_LANG_POP()
276 ])
277 AS_IF([test "$ac_cv_safe_to_use_Wframe_larger_than_" = "yes"],
278 [CXX_WARNINGS="${CXX_WARNINGS} -Wframe-larger-than=32768"])
279
280 AC_CACHE_CHECK([whether it is safe to use -Wredundant-decls from C++],
281 [ac_cv_safe_to_use_Wredundant_decls_],
282 [AC_LANG_PUSH(C++)
283 save_CXXFLAGS="${CXXFLAGS}"
284 CXXFLAGS="${W_FAIL} -pedantic -Wredundant-decls ${AM_CXXFLAGS}"
285 AC_COMPILE_IFELSE(
286 [AC_LANG_PROGRAM([
287 template <typename E> struct C { void foo(); };
288 template <typename E> void C<E>::foo() { }
289 template <> void C<int>::foo();
290 AC_INCLUDES_DEFAULT])],
291 [ac_cv_safe_to_use_Wredundant_decls_=yes],
292 [ac_cv_safe_to_use_Wredundant_decls_=no])
293 CXXFLAGS="${save_CXXFLAGS}"
294 AC_LANG_POP()])
295 AS_IF([test "$ac_cv_safe_to_use_Wredundant_decls_" = "yes"],
296 [CXX_WARNINGS="${CXX_WARNINGS} -Wredundant-decls"],
297 [CXX_WARNINGS="${CXX_WARNINGS} -Wno-redundant-decls"])
298
299 AC_CACHE_CHECK([whether it is safe to use -Wattributes from C++],
300 [ac_cv_safe_to_use_Wattributes_],
301 [AC_LANG_PUSH(C++)
302 save_CXXFLAGS="${CXXFLAGS}"
303 CXXFLAGS="${W_FAIL} -pedantic -Wattributes -fvisibility=hidden ${AM_CXXFLAGS}"
304 AC_COMPILE_IFELSE(
305 [AC_LANG_PROGRAM([
306 #include <google/protobuf/message.h>
307 #include <google/protobuf/descriptor.h>
308
309
310 const ::google::protobuf::EnumDescriptor* Table_TableOptions_RowType_descriptor();
311 enum Table_TableOptions_RowType {
312 Table_TableOptions_RowType_ROW_TYPE_DEFAULT = 0,
313 Table_TableOptions_RowType_ROW_TYPE_FIXED = 1,
314 Table_TableOptions_RowType_ROW_TYPE_DYNAMIC = 2,
315 Table_TableOptions_RowType_ROW_TYPE_COMPRESSED = 3,
316 Table_TableOptions_RowType_ROW_TYPE_REDUNDANT = 4,
317 Table_TableOptions_RowType_ROW_TYPE_COMPACT = 5,
318 Table_TableOptions_RowType_ROW_TYPE_PAGE = 6
319 };
320
321 namespace google {
322 namespace protobuf {
323 template <>
324 inline const EnumDescriptor* GetEnumDescriptor<Table_TableOptions_RowType>() {
325 return Table_TableOptions_RowType_descriptor();
326 }
327 }
328 }
329 ])],
330 [ac_cv_safe_to_use_Wattributes_=yes],
331 [ac_cv_safe_to_use_Wattributes_=no])
332 CXXFLAGS="${save_CXXFLAGS}"
333 AC_LANG_POP()])
334 AC_CACHE_CHECK([whether it is safe to use -Wno-attributes],
335 [ac_cv_safe_to_use_Wno_attributes_],
336 [save_CFLAGS="$CFLAGS"
337 CFLAGS="${W_FAIL} -pedantic -Wno_attributes_ ${AM_CFLAGS} ${CFLAGS}"
338 AC_COMPILE_IFELSE([
339 AC_LANG_PROGRAM(
340 [[
341 #include <stdio.h>
342 ]], [[]])
343 ],
344 [ac_cv_safe_to_use_Wno_attributes_=yes],
345 [ac_cv_safe_to_use_Wno_attributes_=no])
346 CFLAGS="$save_CFLAGS"])
347
348 dnl GCC 3.4 doesn't have -Wno-attributes, so we can't turn them off
349 dnl by using that.
350 AS_IF([test "$ac_cv_safe_to_use_Wattributes_" != "yes"],[
351 AS_IF([test "$ac_cv_safe_to_use_Wno_attributes_" = "yes"],[
352 CC_WARNINGS="${CC_WARNINGS} -Wno-attributes"
353 NO_ATTRIBUTES="-Wno-attributes"])])
354
355
356 NO_REDUNDANT_DECLS="-Wno-redundant-decls"
357 dnl TODO: Figure out a better way to deal with this:
358 PROTOSKIP_WARNINGS="-Wno-effc++ -Wno-shadow -Wno-missing-braces ${NO_ATTRIBUTES}"
359 NO_WERROR="-Wno-error"
360 PERMISSIVE_WARNINGS="-Wno-error -Wno-unused-function -fpermissive"
361 PERMISSIVE_C_WARNINGS="-Wno-error -Wno-redundant-decls"
362 AS_IF([test "$host_vendor" = "apple"],[
363 BOOSTSKIP_WARNINGS="-Wno-uninitialized"
364 ])
365 ])
366 ])
367
368 AS_IF([test "$SUNCC" = "yes"],[
369
370 AS_IF([test "$ac_profiling" = "yes"],
371 [CC_PROFILING="-xinstrument=datarace"])
372
373 AS_IF([test "$ac_cv_warnings_as_errors" = "yes"],
374 [W_FAIL="-errwarn=%all"])
375
376 AC_CACHE_CHECK([whether E_PASTE_RESULT_NOT_TOKEN is usable],
377 [ac_cv_paste_result],
378 [
379 save_CFLAGS="${CFLAGS}"
380 CFLAGS="-errwarn=%all -erroff=E_PASTE_RESULT_NOT_TOKEN ${CFLAGS}"
381 AC_COMPILE_IFELSE(
382 [AC_LANG_PROGRAM([
383 AC_INCLUDES_DEFAULT
384 ],[
385 int x= 0;])],
386 [ac_cv_paste_result=yes],
387 [ac_cv_paste_result=no])
388 CFLAGS="${save_CFLAGS}"
389 ])
390 AS_IF([test $ac_cv_paste_result = yes],
391 [W_PASTE_RESULT=",E_PASTE_RESULT_NOT_TOKEN"])
392
393
394 m4_if(PW_LESS_WARNINGS, [no],[
395 CC_WARNINGS_FULL="-erroff=E_STATEMENT_NOT_REACHED,E_INTEGER_OVERFLOW_DETECTED${W_PASTE_RESULT}"
396 CXX_WARNINGS_FULL="-erroff=inllargeuse"
397 ],[
398 CC_WARNINGS_FULL="-erroff=E_ATTRIBUTE_NOT_VAR,E_STATEMENT_NOT_REACHED"
399 CXX_WARNINGS_FULL="-erroff=attrskipunsup,doubunder,reftotemp,inllargeuse,truncwarn1,signextwarn,inllargeint"
400 ])
401
402 CC_WARNINGS="-v -errtags=yes ${W_FAIL} ${CC_WARNINGS_FULL}"
403 CXX_WARNINGS="+w +w2 -xwe -xport64 -errtags=yes ${CXX_WARNINGS_FULL} ${W_FAIL}"
404 PROTOSKIP_WARNINGS="-erroff=attrskipunsup,doubunder,reftotemp,wbadinitl,identexpected,inllargeuse,truncwarn1,signextwarn,partinit,notused,badargtype2w,wbadinit"
405 BOOSTSKIP_WARNINGS="-erroff=attrskipunsup,doubunder,reftotemp,inllargeuse,truncwarn1,signextwarn,inllargeint,hidef,wvarhidenmem"
406 PERMISSIVE_WARNINGS="-erroff=attrskipunsup,doubunder,reftotemp,inllargeuse,truncwarn1,signextwarn,inllargeint,hidef,wvarhidenmem,notused,badargtype2w,wunreachable"
407 INNOBASE_SKIP_WARNINGS="-erroff=attrskipunsup,doubunder,reftotemp,wbadinitl,identexpected,inllargeuse,truncwarn1,signextwarn,partinit,notused,badargtype2w,wbadinit,wunreachable"
408 NO_UNREACHED="-erroff=E_STATEMENT_NOT_REACHED"
409 NO_WERROR="-errwarn=%none"
410
411 ])
412
413 AC_SUBST(NO_CONVERSION)
414 AC_SUBST(NO_REDUNDANT_DECLS)
415 AC_SUBST(NO_UNREACHED)
416 AC_SUBST(NO_SHADOW)
417 AC_SUBST(NO_STRICT_ALIASING)
418 AC_SUBST(NO_EFF_CXX)
419 AC_SUBST(NO_OLD_STYLE_CAST)
420 AC_SUBST(PROTOSKIP_WARNINGS)
421 AC_SUBST(INNOBASE_SKIP_WARNINGS)
422 AC_SUBST(BOOSTSKIP_WARNINGS)
423 AC_SUBST(PERMISSIVE_WARNINGS)
424 AC_SUBST(PERMISSIVE_C_WARNINGS)
425 AC_SUBST(NO_WERROR)
426 AC_SUBST([GCOV_LIBS])
427 AC_SUBST([SPHINX_WARNINGS])
428 AC_SUBST([INTLTOOL_WARNINGS])
429
430 ])