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