1dnl Use lots of warning flags with with gcc and compatible compilers
2
3dnl Note: if you change the following variable, the cache is automatically
4dnl skipped and all flags rechecked.  So there's no need to do anything
5dnl else.  If for any reason you need to force a recheck, just change
6dnl 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
11MAYBE_WARN="-Wall -Wextra \
12-Wold-style-definition -Wdeclaration-after-statement \
13-Wmissing-declarations -Werror-implicit-function-declaration \
14-Wnested-externs -Wpointer-arith -Wwrite-strings \
15-Wsign-compare -Wstrict-prototypes -Wmissing-prototypes \
16-Wpacked -Wswitch-enum -Wmissing-format-attribute \
17-Wbad-function-cast -Wvolatile-register-var \
18-Wstrict-aliasing=2 -Winit-self -Wunsafe-loop-optimizations \
19-Wno-missing-field-initializers -Wno-unused-parameter \
20-Wno-attributes -Wno-long-long -Winline -Wlogical-op"
21
22dnl Sun Studio 12 likes to rag at us for abusing enums like
23dnl having cairo_status_t variables hold cairo_int_status_t
24dnl values.  It's bad, we know.  Now please be quiet.
25MAYBE_WARN="$MAYBE_WARN -erroff=E_ENUM_TYPE_MISMATCH_ARG \
26			-erroff=E_ENUM_TYPE_MISMATCH_OP"
27
28dnl We also abuse the warning-flag facility to enable other compiler
29dnl options.  Namely, the following:
30MAYBE_WARN="$MAYBE_WARN -fno-strict-aliasing -fno-common -flto"
31
32dnl Also to turn various gcc/glibc-specific preprocessor checks
33MAYBE_WARN="$MAYBE_WARN -Wp,-D_FORTIFY_SOURCE=2"
34
35# invalidate cached value if MAYBE_WARN has changed
36if test "x$cairo_cv_warn_maybe" != "x$MAYBE_WARN"; then
37	unset cairo_cv_warn_cflags
38fi
39AC_CACHE_CHECK([for supported warning flags], cairo_cv_warn_cflags, [
40	echo
41	WARN_CFLAGS=""
42
43	# Some warning options are not supported by all versions of
44	# gcc, so test all desired options against the current
45	# compiler.
46	#
47	# Note that there are some order dependencies
48	# here. Specifically, an option that disables a warning will
49	# have no net effect if a later option then enables that
50	# warnings, (perhaps implicitly). So we put some grouped
51	# options (-Wall and -Wextra) up front and the -Wno options
52	# last.
53
54	for W in $MAYBE_WARN; do
55		CAIRO_CC_TRY_FLAG([$W],, [WARN_CFLAGS="$WARN_CFLAGS $W"])
56	done
57
58	cairo_cv_warn_cflags=$WARN_CFLAGS
59	cairo_cv_warn_maybe=$MAYBE_WARN
60
61	AC_MSG_CHECKING([which warning flags were supported])
62])
63WARN_CFLAGS="$cairo_cv_warn_cflags"
64CAIRO_CFLAGS="$CAIRO_CFLAGS $WARN_CFLAGS"
65
66# We only wish to enable attribute(warn_unused_result) if we can prevent
67# gcc from generating thousands of warnings about the misapplication of the
68# attribute to void functions and variables.
69AC_CACHE_CHECK([how to enable unused result warnings], cairo_cv_warn_unused_result, [
70	cairo_cv_warn_unused_result=""
71	if echo $WARN_CFLAGS | grep -e '-Wno-attributes' >/dev/null; then
72	    CAIRO_CC_TRY_FLAG_SILENT(
73			[-Wno-attributes],
74			[__attribute__((__warn_unused_result__)) void f (void) {}
75			 __attribute__((__warn_unused_result__)) int g;],
76			[cairo_cv_warn_unused_result="__attribute__((__warn_unused_result__))"])
77	fi
78])
79AC_DEFINE_UNQUOTED([WARN_UNUSED_RESULT], [$cairo_cv_warn_unused_result],
80	  [Define to the value your compiler uses to support the warn-unused-result attribute])
81
82dnl check linker flags
83AC_CACHE_CHECK([how to allow undefined symbols in shared libraries used by test suite], cairo_cv_test_undefined_ldflags,
84	       [CAIRO_CC_TRY_FLAG([-Wl,--allow-shlib-undefined], [],
85				  [cairo_cv_test_undefined_ldflags="-Wl,--allow-shlib-undefined]")])
86CAIRO_TEST_UNDEFINED_LDFLAGS="$cairo_cv_test_undefined_ldflags"
87AC_SUBST(CAIRO_TEST_UNDEFINED_LDFLAGS)
88