tizen 2.3.1 release
[framework/graphics/cairo.git] / build / configure.ac.warnings
1 dnl Use lots of warning flags with with gcc and compatible compilers
2
3 dnl Note: if you change the following variable, the cache is automatically
4 dnl skipped and all flags rechecked.  So there's no need to do anything
5 dnl else.  If for any reason you need to force a recheck, just change
6 dnl MAYBE_WARN in an ignorable way (like adding whitespace)
7
8 # -Wcast-align generates lots of false positive reports we need to
9 # cast image data from uint8_t to uin32_t.
10
11 # -Wlogical-op causes too much noise from strcmp("literal", str)
12
13 MAYBE_WARN="-Wall -Wextra \
14 -Wold-style-definition -Wdeclaration-after-statement \
15 -Wmissing-declarations -Werror-implicit-function-declaration \
16 -Wnested-externs -Wpointer-arith -Wwrite-strings \
17 -Wsign-compare -Wstrict-prototypes -Wmissing-prototypes \
18 -Wpacked -Wswitch-enum -Wmissing-format-attribute \
19 -Wbad-function-cast -Wvolatile-register-var \
20 -Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \
21 -Wno-missing-field-initializers -Wno-unused-parameter \
22 -Wno-attributes -Wno-long-long -Winline"
23
24 # New -Wno options should be added here
25 # gcc-4.4 and later accept every -Wno- option but may complain later that this
26 # option is unknow each time another warning happen.
27 # -Wunused-but-set-variable is too noisy at present
28 NO_WARN="unused-but-set-variable"
29
30 dnl Sun Studio 12 likes to rag at us for abusing enums like
31 dnl having cairo_status_t variables hold cairo_int_status_t
32 dnl values.  It's bad, we know.  Now please be quiet.
33 MAYBE_WARN="$MAYBE_WARN -erroff=E_ENUM_TYPE_MISMATCH_ARG \
34                         -erroff=E_ENUM_TYPE_MISMATCH_OP"
35
36 dnl We also abuse the warning-flag facility to enable other compiler
37 dnl options.  Namely, the following:
38
39 dnl -flto working really needs a test link, not just a compile
40
41 safe_MAYBE_WARN="$MAYBE_WARN"
42 MAYBE_WARN="$MAYBE_WARN -flto"
43 AC_TRY_LINK([],[
44         int main(int argc, char **argv) { return 0; }
45 ],[],[
46         MAYBE_WARN="$safe_MAYBE_WARN"
47 ])
48
49 MAYBE_WARN="$MAYBE_WARN -fno-strict-aliasing -fno-common"
50
51 dnl Also to turn various gcc/glibc-specific preprocessor checks
52 MAYBE_WARN="$MAYBE_WARN -Wp,-D_FORTIFY_SOURCE=2"
53
54 # invalidate cached value if MAYBE_WARN has changed
55 if test "x$cairo_cv_warn_maybe" != "x$MAYBE_WARN"; then
56         unset cairo_cv_warn_cflags
57 fi
58 AC_CACHE_CHECK([for supported warning flags], cairo_cv_warn_cflags, [
59         echo
60         WARN_CFLAGS=""
61
62         # Some warning options are not supported by all versions of
63         # gcc, so test all desired options against the current
64         # compiler.
65         #
66         # Note that there are some order dependencies
67         # here. Specifically, an option that disables a warning will
68         # have no net effect if a later option then enables that
69         # warnings, (perhaps implicitly). So we put some grouped
70         # options (-Wall and -Wextra) up front and the -Wno options
71         # last.
72
73         for W in $MAYBE_WARN; do
74                 CAIRO_CC_TRY_FLAG([$W],, [WARN_CFLAGS="$WARN_CFLAGS $W"])
75         done
76         for W in $NO_WARN; do
77                 CAIRO_CC_TRY_FLAG([-W$W -Wno-$W],, [WARN_CFLAGS="$WARN_CFLAGS -Wno-$W"])
78         done
79         cairo_cv_warn_cflags=$WARN_CFLAGS
80         cairo_cv_warn_maybe=$MAYBE_WARN
81
82         AC_MSG_CHECKING([which warning flags were supported])
83 ])
84 WARN_CFLAGS="$cairo_cv_warn_cflags"
85 CAIRO_CFLAGS="$CAIRO_CFLAGS $WARN_CFLAGS"
86
87 # We only wish to enable attribute(warn_unused_result) if we can prevent
88 # gcc from generating thousands of warnings about the misapplication of the
89 # attribute to void functions and variables.
90 AC_CACHE_CHECK([how to enable unused result warnings], cairo_cv_warn_unused_result, [
91         AC_REQUIRE([AC_PROG_GREP])
92         cairo_cv_warn_unused_result=""
93         if echo $WARN_CFLAGS | $GREP -e '-Wno-attributes' >/dev/null; then
94             CAIRO_CC_TRY_FLAG_SILENT(
95                         [-Wno-attributes],
96                         [__attribute__((__warn_unused_result__)) void f (void) {}
97                          __attribute__((__warn_unused_result__)) int g;],
98                         [cairo_cv_warn_unused_result="__attribute__((__warn_unused_result__))"])
99         fi
100 ])
101 AC_DEFINE_UNQUOTED([WARN_UNUSED_RESULT], [$cairo_cv_warn_unused_result],
102           [Define to the value your compiler uses to support the warn-unused-result attribute])
103
104 dnl check linker flags
105 AC_CACHE_CHECK([how to allow undefined symbols in shared libraries used by test suite], cairo_cv_test_undefined_ldflags,
106                [CAIRO_CC_TRY_FLAG_SILENT([-Wl,--allow-shlib-undefined], [],
107                                   [cairo_cv_test_undefined_ldflags="-Wl,--allow-shlib-undefined]")])
108 CAIRO_TEST_UNDEFINED_LDFLAGS="$cairo_cv_test_undefined_ldflags"
109 AC_SUBST(CAIRO_TEST_UNDEFINED_LDFLAGS)