Merge of warnings.
[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"
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="-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 ${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 -Wlogical-op],
281 [ac_cv_safe_to_use_Wlogical_op_],
282 [save_CFLAGS="$CFLAGS"
283 CFLAGS="${W_FAIL} -pedantic -Wlogical-op ${AM_CFLAGS} ${CFLAGS}"
284 AC_COMPILE_IFELSE([
285 AC_LANG_PROGRAM(
286 [[
287 #include <stdio.h>
288 ]], [[]])
289 ],
290 [ac_cv_safe_to_use_Wlogical_op_=yes],
291 [ac_cv_safe_to_use_Wlogical_op_=no])
292 CFLAGS="$save_CFLAGS"])
293 AS_IF([test "$ac_cv_safe_to_use_Wlogical_op_" = "yes"],
294 [CC_WARNINGS="${CC_WARNINGS} -Wlogical-op"])
295
296 AC_CACHE_CHECK([whether it is safe to use -Wredundant-decls from C++],
297 [ac_cv_safe_to_use_Wredundant_decls_],
298 [AC_LANG_PUSH(C++)
299 save_CXXFLAGS="${CXXFLAGS}"
300 CXXFLAGS="${W_FAIL} -pedantic -Wredundant-decls ${AM_CXXFLAGS}"
301 AC_COMPILE_IFELSE(
302 [AC_LANG_PROGRAM([
303 template <typename E> struct C { void foo(); };
304 template <typename E> void C<E>::foo() { }
305 template <> void C<int>::foo();
306 AC_INCLUDES_DEFAULT])],
307 [ac_cv_safe_to_use_Wredundant_decls_=yes],
308 [ac_cv_safe_to_use_Wredundant_decls_=no])
309 CXXFLAGS="${save_CXXFLAGS}"
310 AC_LANG_POP()])
311 AS_IF([test "$ac_cv_safe_to_use_Wredundant_decls_" = "yes"],
312 [CXX_WARNINGS="${CXX_WARNINGS} -Wredundant-decls"],
313 [CXX_WARNINGS="${CXX_WARNINGS} -Wno-redundant-decls"])
314
315 AC_CACHE_CHECK([whether it is safe to use -Wattributes from C++],
316 [ac_cv_safe_to_use_Wattributes_],
317 [AC_LANG_PUSH(C++)
318 save_CXXFLAGS="${CXXFLAGS}"
319 CXXFLAGS="${W_FAIL} -pedantic -Wattributes -fvisibility=hidden ${AM_CXXFLAGS}"
320 AC_COMPILE_IFELSE(
321 [AC_LANG_PROGRAM([
322 #include <google/protobuf/message.h>
323 #include <google/protobuf/descriptor.h>
324
325
326 const ::google::protobuf::EnumDescriptor* Table_TableOptions_RowType_descriptor();
327 enum Table_TableOptions_RowType {
328 Table_TableOptions_RowType_ROW_TYPE_DEFAULT = 0,
329 Table_TableOptions_RowType_ROW_TYPE_FIXED = 1,
330 Table_TableOptions_RowType_ROW_TYPE_DYNAMIC = 2,
331 Table_TableOptions_RowType_ROW_TYPE_COMPRESSED = 3,
332 Table_TableOptions_RowType_ROW_TYPE_REDUNDANT = 4,
333 Table_TableOptions_RowType_ROW_TYPE_COMPACT = 5,
334 Table_TableOptions_RowType_ROW_TYPE_PAGE = 6
335 };
336
337 namespace google {
338 namespace protobuf {
339 template <>
340 inline const EnumDescriptor* GetEnumDescriptor<Table_TableOptions_RowType>() {
341 return Table_TableOptions_RowType_descriptor();
342 }
343 }
344 }
345 ])],
346 [ac_cv_safe_to_use_Wattributes_=yes],
347 [ac_cv_safe_to_use_Wattributes_=no])
348 CXXFLAGS="${save_CXXFLAGS}"
349 AC_LANG_POP()])
350 AC_CACHE_CHECK([whether it is safe to use -Wno-attributes],
351 [ac_cv_safe_to_use_Wno_attributes_],
352 [save_CFLAGS="$CFLAGS"
353 CFLAGS="${W_FAIL} -pedantic -Wno_attributes_ ${AM_CFLAGS} ${CFLAGS}"
354 AC_COMPILE_IFELSE([
355 AC_LANG_PROGRAM(
356 [[
357 #include <stdio.h>
358 ]], [[]])
359 ],
360 [ac_cv_safe_to_use_Wno_attributes_=yes],
361 [ac_cv_safe_to_use_Wno_attributes_=no])
362 CFLAGS="$save_CFLAGS"])
363
364 dnl GCC 3.4 doesn't have -Wno-attributes, so we can't turn them off
365 dnl by using that.
366 AS_IF([test "$ac_cv_safe_to_use_Wattributes_" != "yes"],[
367 AS_IF([test "$ac_cv_safe_to_use_Wno_attributes_" = "yes"],[
368 CC_WARNINGS="${CC_WARNINGS} -Wno-attributes"
369 NO_ATTRIBUTES="-Wno-attributes"])])
370
371
372 NO_REDUNDANT_DECLS="-Wno-redundant-decls"
373 dnl TODO: Figure out a better way to deal with this:
374 PROTOSKIP_WARNINGS="-Wno-effc++ -Wno-shadow -Wno-missing-braces ${NO_ATTRIBUTES}"
375 NO_WERROR="-Wno-error"
376 PERMISSIVE_WARNINGS="-Wno-error -Wno-unused-function -fpermissive"
377 PERMISSIVE_C_WARNINGS="-Wno-error -Wno-redundant-decls"
378 AS_IF([test "$host_vendor" = "apple"],[
379 BOOSTSKIP_WARNINGS="-Wno-uninitialized"
380 ])
381 ])
382 ])
383
384 AS_IF([test "$SUNCC" = "yes"],[
385
386 AS_IF([test "$ac_profiling" = "yes"],
387 [CC_PROFILING="-xinstrument=datarace"])
388
389 AS_IF([test "$ac_cv_warnings_as_errors" = "yes"],
390 [W_FAIL="-errwarn=%all"])
391
392 AC_CACHE_CHECK([whether E_PASTE_RESULT_NOT_TOKEN is usable],
393 [ac_cv_paste_result],
394 [
395 save_CFLAGS="${CFLAGS}"
396 CFLAGS="-errwarn=%all -erroff=E_PASTE_RESULT_NOT_TOKEN ${CFLAGS}"
397 AC_COMPILE_IFELSE(
398 [AC_LANG_PROGRAM([
399 AC_INCLUDES_DEFAULT
400 ],[
401 int x= 0;])],
402 [ac_cv_paste_result=yes],
403 [ac_cv_paste_result=no])
404 CFLAGS="${save_CFLAGS}"
405 ])
406 AS_IF([test $ac_cv_paste_result = yes],
407 [W_PASTE_RESULT=",E_PASTE_RESULT_NOT_TOKEN"])
408
409
410 m4_if(PW_LESS_WARNINGS, [no],[
411 CC_WARNINGS_FULL="-erroff=E_STATEMENT_NOT_REACHED,E_INTEGER_OVERFLOW_DETECTED${W_PASTE_RESULT}"
412 CXX_WARNINGS_FULL="-erroff=inllargeuse"
413 ],[
414 CC_WARNINGS_FULL="-erroff=E_ATTRIBUTE_NOT_VAR,E_STATEMENT_NOT_REACHED"
415 CXX_WARNINGS_FULL="-erroff=attrskipunsup,doubunder,reftotemp,inllargeuse,truncwarn1,signextwarn,inllargeint"
416 ])
417
418 CC_WARNINGS="-v -errtags=yes ${W_FAIL} ${CC_WARNINGS_FULL}"
419 CXX_WARNINGS="+w +w2 -xwe -xport64 -errtags=yes ${CXX_WARNINGS_FULL} ${W_FAIL}"
420 PROTOSKIP_WARNINGS="-erroff=attrskipunsup,doubunder,reftotemp,wbadinitl,identexpected,inllargeuse,truncwarn1,signextwarn,partinit,notused,badargtype2w,wbadinit"
421 BOOSTSKIP_WARNINGS="-erroff=attrskipunsup,doubunder,reftotemp,inllargeuse,truncwarn1,signextwarn,inllargeint,hidef,wvarhidenmem"
422 PERMISSIVE_WARNINGS="-erroff=attrskipunsup,doubunder,reftotemp,inllargeuse,truncwarn1,signextwarn,inllargeint,hidef,wvarhidenmem,notused,badargtype2w,wunreachable"
423 INNOBASE_SKIP_WARNINGS="-erroff=attrskipunsup,doubunder,reftotemp,wbadinitl,identexpected,inllargeuse,truncwarn1,signextwarn,partinit,notused,badargtype2w,wbadinit,wunreachable"
424 NO_UNREACHED="-erroff=E_STATEMENT_NOT_REACHED"
425 NO_WERROR="-errwarn=%none"
426
427 ])
428
429 AC_SUBST(NO_CONVERSION)
430 AC_SUBST(NO_REDUNDANT_DECLS)
431 AC_SUBST(NO_UNREACHED)
432 AC_SUBST(NO_SHADOW)
433 AC_SUBST(NO_STRICT_ALIASING)
434 AC_SUBST(NO_EFF_CXX)
435 AC_SUBST(NO_OLD_STYLE_CAST)
436 AC_SUBST(PROTOSKIP_WARNINGS)
437 AC_SUBST(INNOBASE_SKIP_WARNINGS)
438 AC_SUBST(BOOSTSKIP_WARNINGS)
439 AC_SUBST(PERMISSIVE_WARNINGS)
440 AC_SUBST(PERMISSIVE_C_WARNINGS)
441 AC_SUBST(NO_WERROR)
442 AC_SUBST([GCOV_LIBS])
443 AC_SUBST([SPHINX_WARNINGS])
444 AC_SUBST([INTLTOOL_WARNINGS])
445
446 ])