1 dnl Copyright (C) 2009 Sun Microsystems
2 dnl This file is free software; Sun Microsystems
3 dnl gives unlimited permission to copy and/or distribute it,
4 dnl with or without modifications, as long as this notice is preserved.
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
10 dnl @TODO: remove less-warnings option as soon as Drizzle is clean enough to
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],[$*],[
21 m4_undefine([PW_LESS_WARNINGS])
22 m4_define([PW_LESS_WARNINGS],[yes])
24 [warnings-always-on],[
25 m4_undefine([PW_WARN_ALWAYS_ON])
26 m4_define([PW_WARN_ALWAYS_ON],[yes])
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 "$ac_cv_building_from_vc" = "yes"],
34 [ac_cv_warnings_as_errors=yes],
35 [ac_cv_warnings_as_errors=no]))
37 AC_ARG_ENABLE([profiling],
38 [AS_HELP_STRING([--enable-profiling],
39 [Toggle profiling @<:@default=off@:>@])],
40 [ac_profiling="$enableval"],
43 AC_ARG_ENABLE([coverage],
44 [AS_HELP_STRING([--enable-coverage],
45 [Toggle coverage @<:@default=off@:>@])],
46 [ac_coverage="$enableval"],
49 AS_IF([test "$GCC" = "yes"],[
51 AS_IF([test "$ac_profiling" = "yes"],[
55 AC_CHECK_LIB(c_p, read)
63 AS_IF([test "$ac_coverage" = "yes"],
64 [CC_COVERAGE="-fprofile-arcs -ftest-coverage"])
66 AS_IF([test "$ac_cv_warnings_as_errors" = "yes"],
69 AC_CACHE_CHECK([whether it is safe to use -fdiagnostics-show-option],
70 [ac_cv_safe_to_use_fdiagnostics_show_option_],
71 [save_CFLAGS="$CFLAGS"
72 CFLAGS="-fdiagnostics-show-option ${AM_CFLAGS} ${CFLAGS}"
74 [AC_LANG_PROGRAM([],[])],
75 [ac_cv_safe_to_use_fdiagnostics_show_option_=yes],
76 [ac_cv_safe_to_use_fdiagnostics_show_option_=no])
77 CFLAGS="$save_CFLAGS"])
79 AS_IF([test "$ac_cv_safe_to_use_fdiagnostics_show_option_" = "yes"],
81 F_DIAGNOSTICS_SHOW_OPTION="-fdiagnostics-show-option"
84 AC_CACHE_CHECK([whether it is safe to use -Wconversion],
85 [ac_cv_safe_to_use_wconversion_],
86 [save_CFLAGS="$CFLAGS"
87 dnl Use -Werror here instead of ${W_FAIL} so that we don't spew
88 dnl conversion warnings to all the tarball folks
89 CFLAGS="-Wconversion -Werror -pedantic ${AM_CFLAGS} ${CFLAGS}"
100 [ac_cv_safe_to_use_wconversion_=yes],
101 [ac_cv_safe_to_use_wconversion_=no])
102 CFLAGS="$save_CFLAGS"])
104 AS_IF([test "$ac_cv_safe_to_use_wconversion_" = "yes"],
105 [W_CONVERSION="-Wconversion"
106 AC_CACHE_CHECK([whether it is safe to use -Wconversion with htons],
107 [ac_cv_safe_to_use_Wconversion_],
108 [save_CFLAGS="$CFLAGS"
109 dnl Use -Werror here instead of ${W_FAIL} so that we don't spew
110 dnl conversion warnings to all the tarball folks
111 CFLAGS="-Wconversion -Werror -pedantic ${AM_CFLAGS} ${CFLAGS}"
115 #include <netinet/in.h>
117 uint16_t x= htons(80);
119 [ac_cv_safe_to_use_Wconversion_=yes],
120 [ac_cv_safe_to_use_Wconversion_=no])
121 CFLAGS="$save_CFLAGS"])
123 AS_IF([test "$ac_cv_safe_to_use_Wconversion_" = "no"],
124 [NO_CONVERSION="-Wno-conversion"])
127 NO_STRICT_ALIASING="-fno-strict-aliasing -Wno-strict-aliasing"
128 NO_SHADOW="-Wno-shadow"
130 AS_IF([test "$INTELCC" = "yes"],[
131 m4_if(PW_LESS_WARNINGS,[no],[
132 BASE_WARNINGS="-w1 -Wall -Werror -Wcheck -Wformat -Wp64 -Woverloaded-virtual -Wcast-qual"
134 BASE_WARNINGS="-w1 -Wall -Wcheck -Wformat -Wp64 -Woverloaded-virtual -Wcast-qual -diag-disable 981"
136 CC_WARNINGS="${BASE_WARNINGS}"
137 CXX_WARNINGS="${BASE_WARNINGS}"
139 m4_if(PW_LESS_WARNINGS,[no],[
140 BASE_WARNINGS_FULL="-Wformat=2 ${W_CONVERSION} -Wstrict-aliasing"
141 CC_WARNINGS_FULL="-Wswitch-default -Wswitch-enum -Wwrite-strings"
142 CXX_WARNINGS_FULL="-Weffc++ -Wold-style-cast"
144 BASE_WARNINGS_FULL="-Wformat ${NO_STRICT_ALIASING}"
147 AS_IF([test "${ac_cv_assert}" = "no"],
148 [NO_UNUSED="-Wno-unused-variable -Wno-unused-parameter"])
150 AC_CACHE_CHECK([whether it is safe to use -Wextra],
151 [ac_cv_safe_to_use_Wextra_],
152 [save_CFLAGS="$CFLAGS"
153 CFLAGS="${W_FAIL} -pedantic -Wextra ${AM_CFLAGS} ${CFLAGS}"
160 [ac_cv_safe_to_use_Wextra_=yes],
161 [ac_cv_safe_to_use_Wextra_=no])
162 CFLAGS="$save_CFLAGS"])
164 BASE_WARNINGS="${W_FAIL} -pedantic -Wall -Wundef -Wshadow ${NO_UNUSED} ${F_DIAGNOSTICS_SHOW_OPTION} ${CFLAG_VISIBILITY} ${BASE_WARNINGS_FULL}"
165 AS_IF([test "$ac_cv_safe_to_use_Wextra_" = "yes"],
166 [BASE_WARNINGS="${BASE_WARNINGS} -Wextra"],
167 [BASE_WARNINGS="${BASE_WARNINGS} -W"])
169 CC_WARNINGS="${BASE_WARNINGS} -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls -Wmissing-declarations -Wcast-align ${CC_WARNINGS_FULL}"
170 CXX_WARNINGS="${BASE_WARNINGS} -Woverloaded-virtual -Wnon-virtual-dtor -Wctor-dtor-privacy -Wno-long-long ${CXX_WARNINGS_FULL}"
172 AC_CACHE_CHECK([whether it is safe to use -Wmissing-declarations from C++],
173 [ac_cv_safe_to_use_Wmissing_declarations_],
175 save_CXXFLAGS="$CXXFLAGS"
176 CXXFLAGS="-Werror -pedantic -Wmissing-declarations ${AM_CXXFLAGS}"
183 [ac_cv_safe_to_use_Wmissing_declarations_=yes],
184 [ac_cv_safe_to_use_Wmissing_declarations_=no])
185 CXXFLAGS="$save_CXXFLAGS"
188 AS_IF([test "$ac_cv_safe_to_use_Wmissing_declarations_" = "yes"],
189 [CXX_WARNINGS="${CXX_WARNINGS} -Wmissing-declarations"])
191 AC_CACHE_CHECK([whether it is safe to use -Wlogical-op],
192 [ac_cv_safe_to_use_Wlogical_op_],
193 [save_CFLAGS="$CFLAGS"
194 CFLAGS="${W_FAIL} -pedantic -Wlogical-op ${AM_CFLAGS} ${CFLAGS}"
201 [ac_cv_safe_to_use_Wlogical_op_=yes],
202 [ac_cv_safe_to_use_Wlogical_op_=no])
203 CFLAGS="$save_CFLAGS"])
204 AS_IF([test "$ac_cv_safe_to_use_Wlogical_op_" = "yes"],
205 [CC_WARNINGS="${CC_WARNINGS} -Wlogical-op"])
207 AC_CACHE_CHECK([whether it is safe to use -Wredundant-decls from C++],
208 [ac_cv_safe_to_use_Wredundant_decls_],
210 save_CXXFLAGS="${CXXFLAGS}"
211 CXXFLAGS="${W_FAIL} -pedantic -Wredundant-decls ${AM_CXXFLAGS}"
214 template <typename E> struct C { void foo(); };
215 template <typename E> void C<E>::foo() { }
216 template <> void C<int>::foo();
217 AC_INCLUDES_DEFAULT])],
218 [ac_cv_safe_to_use_Wredundant_decls_=yes],
219 [ac_cv_safe_to_use_Wredundant_decls_=no])
220 CXXFLAGS="${save_CXXFLAGS}"
222 AS_IF([test "$ac_cv_safe_to_use_Wredundant_decls_" = "yes"],
223 [CXX_WARNINGS="${CXX_WARNINGS} -Wredundant-decls"],
224 [CXX_WARNINGS="${CXX_WARNINGS} -Wno-redundant-decls"])
226 AC_CACHE_CHECK([whether it is safe to use -Wattributes from C++],
227 [ac_cv_safe_to_use_Wattributes_],
229 save_CXXFLAGS="${CXXFLAGS}"
230 CXXFLAGS="${W_FAIL} -pedantic -Wattributes -fvisibility=hidden ${AM_CXXFLAGS}"
233 #include <google/protobuf/message.h>
234 #include <google/protobuf/descriptor.h>
237 const ::google::protobuf::EnumDescriptor* Table_TableOptions_RowType_descriptor();
238 enum Table_TableOptions_RowType {
239 Table_TableOptions_RowType_ROW_TYPE_DEFAULT = 0,
240 Table_TableOptions_RowType_ROW_TYPE_FIXED = 1,
241 Table_TableOptions_RowType_ROW_TYPE_DYNAMIC = 2,
242 Table_TableOptions_RowType_ROW_TYPE_COMPRESSED = 3,
243 Table_TableOptions_RowType_ROW_TYPE_REDUNDANT = 4,
244 Table_TableOptions_RowType_ROW_TYPE_COMPACT = 5,
245 Table_TableOptions_RowType_ROW_TYPE_PAGE = 6
251 inline const EnumDescriptor* GetEnumDescriptor<Table_TableOptions_RowType>() {
252 return Table_TableOptions_RowType_descriptor();
257 [ac_cv_safe_to_use_Wattributes_=yes],
258 [ac_cv_safe_to_use_Wattributes_=no])
259 CXXFLAGS="${save_CXXFLAGS}"
261 AC_CACHE_CHECK([whether it is safe to use -Wno-attributes],
262 [ac_cv_safe_to_use_Wno_attributes_],
263 [save_CFLAGS="$CFLAGS"
264 CFLAGS="${W_FAIL} -pedantic -Wno_attributes_ ${AM_CFLAGS} ${CFLAGS}"
271 [ac_cv_safe_to_use_Wno_attributes_=yes],
272 [ac_cv_safe_to_use_Wno_attributes_=no])
273 CFLAGS="$save_CFLAGS"])
275 dnl GCC 3.4 doesn't have -Wno-attributes, so we can't turn them off
277 AS_IF([test "$ac_cv_safe_to_use_Wattributes_" != "yes"],[
278 AS_IF([test "$ac_cv_safe_to_use_Wno_attributes_" = "yes"],[
279 CC_WARNINGS="${CC_WARNINGS} -Wno-attributes"
280 NO_ATTRIBUTES="-Wno-attributes"])])
283 NO_REDUNDANT_DECLS="-Wno-redundant-decls"
284 dnl TODO: Figure out a better way to deal with this:
285 PROTOSKIP_WARNINGS="-Wno-effc++ -Wno-shadow -Wno-missing-braces ${NO_ATTRIBUTES}"
286 NO_WERROR="-Wno-error"
287 INNOBASE_SKIP_WARNINGS="-Wno-shadow -Wno-cast-align"
292 AS_IF([test "$SUNCC" = "yes"],[
294 AS_IF([test "$ac_profiling" = "yes"],
295 [CC_PROFILING="-xinstrument=datarace"])
297 AS_IF([test "$ac_cv_warnings_as_errors" = "yes"],
298 [W_FAIL="-errwarn=%all"])
300 AC_CACHE_CHECK([whether E_PASTE_RESULT_NOT_TOKEN is usable],
301 [ac_cv_paste_result],
303 save_CFLAGS="${CFLAGS}"
304 CFLAGS="-errwarn=%all -erroff=E_PASTE_RESULT_NOT_TOKEN ${CFLAGS}"
310 [ac_cv_paste_result=yes],
311 [ac_cv_paste_result=no])
312 CFLAGS="${save_CFLAGS}"
314 AS_IF([test $ac_cv_paste_result = yes],
315 [W_PASTE_RESULT=",E_PASTE_RESULT_NOT_TOKEN"])
318 m4_if(PW_LESS_WARNINGS, [no],[
319 CC_WARNINGS_FULL="-erroff=E_INTEGER_OVERFLOW_DETECTED${W_PASTE_RESULT}"
320 CXX_WARNINGS_FULL="-erroff=inllargeuse"
322 CC_WARNINGS_FULL="-erroff=E_ATTRIBUTE_NOT_VAR"
323 CXX_WARNINGS_FULL="-erroff=attrskipunsup,doubunder,reftotemp,inllargeuse,truncwarn1,signextwarn,inllargeint"
326 CC_WARNINGS="-v -errtags=yes ${W_FAIL} ${CC_WARNINGS_FULL}"
327 CXX_WARNINGS="+w +w2 -xwe -xport64 -errtags=yes ${CXX_WARNINGS_FULL} ${W_FAIL}"
328 PROTOSKIP_WARNINGS="-erroff=attrskipunsup,doubunder,reftotemp,wbadinitl,identexpected,inllargeuse,truncwarn1,signextwarn,partinit,notused,badargtype2w,wbadinit"
329 NO_UNREACHED="-erroff=E_STATEMENT_NOT_REACHED"
330 NO_WERROR="-errwarn=%none"
334 AC_SUBST(NO_CONVERSION)
335 AC_SUBST(NO_REDUNDANT_DECLS)
336 AC_SUBST(NO_UNREACHED)
338 AC_SUBST(NO_STRICT_ALIASING)
339 AC_SUBST(PROTOSKIP_WARNINGS)
340 AC_SUBST(INNOBASE_SKIP_WARNINGS)