1 dnl handle various error-related things
3 dnl Thomas Vander Stichele <thomas@apestaart.org>
4 dnl Tim-Philipp Müller <tim centricular net>
6 dnl Last modification: 2008-02-18
8 dnl AG_GST_SET_ERROR_CFLAGS([ADD-WERROR], [MORE_FLAGS])
9 dnl AG_GST_SET_ERROR_CXXFLAGS([ADD-WERROR], [MORE_FLAGS])
10 dnl AG_GST_SET_LEVEL_DEFAULT([IS-GIT-VERSION])
13 dnl Sets WARNING_CFLAGS and ERROR_CFLAGS to something the compiler
14 dnl will accept and AC_SUBST them so they are available in Makefile
16 dnl WARNING_CFLAGS will contain flags to make the compiler emit more
18 dnl ERROR_CFLAGS will contain flags to make those warnings fatal,
19 dnl unless ADD-WERROR is set to "no"
21 dnl If MORE_FLAGS is set, tries to add each of the given flags
22 dnl to WARNING_CFLAGS if the compiler supports them. Each flag is
23 dnl tested separately.
25 dnl These flags can be overridden at make time:
26 dnl make ERROR_CFLAGS=
27 AC_DEFUN([AG_GST_SET_ERROR_CFLAGS],
29 AC_REQUIRE([AC_PROG_CC])
30 AC_REQUIRE([AS_COMPILER_FLAG])
35 dnl if we support -Wall, set it unconditionally
36 AS_COMPILER_FLAG(-Wall,
37 WARNING_CFLAGS="$WARNING_CFLAGS -Wall")
39 dnl Warn if declarations after statements are used (C99 extension)
40 AS_COMPILER_FLAG(-Wdeclaration-after-statement,
41 WARNING_CFLAGS="$WARNING_CFLAGS -Wdeclaration-after-statement")
43 dnl Warn if variable length arrays are used (C99 extension)
44 AS_COMPILER_FLAG(-Wvla,
45 WARNING_CFLAGS="$WARNING_CFLAGS -Wvla")
47 dnl Warn for invalid pointer arithmetic
48 AS_COMPILER_FLAG(-Wpointer-arith,
49 WARNING_CFLAGS="$WARNING_CFLAGS -Wpointer-arith")
51 dnl if asked for, add -Werror if supported
52 if test "x$1" != "xno"
54 AS_COMPILER_FLAG(-Werror, ERROR_CFLAGS="$ERROR_CFLAGS -Werror")
56 dnl if -Werror isn't suported, try -errwarn=%all (Sun Forte case)
57 if test "x$ERROR_CFLAGS" = "x"
59 AS_COMPILER_FLAG([-errwarn=%all], [
60 ERROR_CFLAGS="-errwarn=%all"
61 dnl try -errwarn=%all,no%E_EMPTY_DECLARATION,
62 dnl no%E_STATEMENT_NOT_REACHED,no%E_ARGUEMENT_MISMATCH,
63 dnl no%E_MACRO_REDEFINED (Sun Forte case)
64 dnl For Forte we need disable "empty declaration" warning produced by un-needed semicolon
65 dnl "statement not reached" disabled because there is g_assert_not_reached () in some places
66 dnl "macro redefined" because of gst/gettext.h
67 dnl FIXME: is it really supposed to be 'ARGUEMENT' and not 'ARGUMENT'?
68 for f in 'no%E_EMPTY_DECLARATION' \
69 'no%E_STATEMENT_NOT_REACHED' \
70 'no%E_ARGUEMENT_MISMATCH' \
71 'no%E_MACRO_REDEFINED' \
72 'no%E_LOOP_NOT_ENTERED_AT_TOP'
74 AS_COMPILER_FLAG([-errwarn=%all,$f], [
75 ERROR_CFLAGS="$ERROR_CFLAGS,$f"
80 dnl Add -fno-strict-aliasing for GLib versions before 2.19.8
81 dnl as before G_LOCK and friends caused strict aliasing compiler
83 PKG_CHECK_EXISTS([glib-2.0 < 2.19.8], [
84 AS_COMPILER_FLAG(-fno-strict-aliasing,
85 ERROR_CFLAGS="$ERROR_CFLAGS -fno-strict-aliasing")
96 AS_COMPILER_FLAG($each,
97 WARNING_CFLAGS="$WARNING_CFLAGS $each",
98 UNSUPPORTED="$UNSUPPORTED $each")
100 if test "X$UNSUPPORTED" != X ; then
101 AC_MSG_NOTICE([unsupported compiler flags: $UNSUPPORTED])
105 AC_SUBST(WARNING_CFLAGS)
106 AC_SUBST(ERROR_CFLAGS)
107 AC_MSG_NOTICE([set WARNING_CFLAGS to $WARNING_CFLAGS])
108 AC_MSG_NOTICE([set ERROR_CFLAGS to $ERROR_CFLAGS])
111 dnl Sets WARNING_CXXFLAGS and ERROR_CXXFLAGS to something the compiler
112 dnl will accept and AC_SUBST them so they are available in Makefile
114 dnl WARNING_CXXFLAGS will contain flags to make the compiler emit more
116 dnl ERROR_CXXFLAGS will contain flags to make those warnings fatal,
117 dnl unless ADD-WERROR is set to "no"
119 dnl If MORE_FLAGS is set, tries to add each of the given flags
120 dnl to WARNING_CFLAGS if the compiler supports them. Each flag is
121 dnl tested separately.
123 dnl These flags can be overridden at make time:
124 dnl make ERROR_CXXFLAGS=
125 AC_DEFUN([AG_GST_SET_ERROR_CXXFLAGS],
127 AC_REQUIRE([AC_PROG_CXX])
128 AC_REQUIRE([AS_CXX_COMPILER_FLAG])
133 dnl if we support -Wall, set it unconditionally
134 AS_CXX_COMPILER_FLAG(-Wall, WARNING_CXXFLAGS="$WARNING_CXXFLAGS -Wall")
136 dnl if asked for, add -Werror if supported
137 if test "x$1" != "xno"
139 AS_CXX_COMPILER_FLAG(-Werror, ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror")
141 if test "x$ERROR_CXXFLAGS" != "x"
144 AS_CXX_COMPILER_FLAG([-Wno-non-virtual-dtor], ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Wno-non-virtual-dtor")
146 dnl Add -fno-strict-aliasing for GLib versions before 2.19.8
147 dnl as before G_LOCK and friends caused strict aliasing compiler
149 PKG_CHECK_EXISTS([glib-2.0 < 2.19.8], [
150 AS_CXX_COMPILER_FLAG([-fno-strict-aliasing],
151 ERROR_CXXFLAGS="$ERROR_CXXFLAGS -fno-strict-aliasing")
154 dnl if -Werror isn't suported, try -errwarn=%all
155 AS_CXX_COMPILER_FLAG([-errwarn=%all], ERROR_CXXFLAGS="$ERROR_CXXFLAGS -errwarn=%all")
156 if test "x$ERROR_CXXFLAGS" != "x"; then
157 dnl try -errwarn=%all,no%E_EMPTY_DECLARATION,
158 dnl no%E_STATEMENT_NOT_REACHED,no%E_ARGUEMENT_MISMATCH,
159 dnl no%E_MACRO_REDEFINED (Sun Forte case)
160 dnl For Forte we need disable "empty declaration" warning produced by un-needed semicolon
161 dnl "statement not reached" disabled because there is g_assert_not_reached () in some places
162 dnl "macro redefined" because of gst/gettext.h
163 dnl FIXME: is it really supposed to be 'ARGUEMENT' and not 'ARGUMENT'?
164 dnl FIXME: do any of these work with the c++ compiler? if not, why
165 dnl do we check at all?
166 for f in 'no%E_EMPTY_DECLARATION' \
167 'no%E_STATEMENT_NOT_REACHED' \
168 'no%E_ARGUEMENT_MISMATCH' \
169 'no%E_MACRO_REDEFINED' \
170 'no%E_LOOP_NOT_ENTERED_AT_TOP'
172 AS_CXX_COMPILER_FLAG([-errwarn=%all,$f], ERROR_CXXFLAGS="$ERROR_CXXFLAGS,$f")
184 AS_CXX_COMPILER_FLAG($each,
185 WARNING_CXXFLAGS="$WARNING_CXXFLAGS $each",
186 UNSUPPORTED="$UNSUPPORTED $each")
188 if test "X$UNSUPPORTED" != X ; then
189 AC_MSG_NOTICE([unsupported compiler flags: $UNSUPPORTED])
193 AC_SUBST(WARNING_CXXFLAGS)
194 AC_SUBST(ERROR_CXXFLAGS)
195 AC_MSG_NOTICE([set WARNING_CXXFLAGS to $WARNING_CXXFLAGS])
196 AC_MSG_NOTICE([set ERROR_CXXFLAGS to $ERROR_CXXFLAGS])
199 dnl Sets the default error level for debugging messages
200 AC_DEFUN([AG_GST_SET_LEVEL_DEFAULT],
202 dnl define correct errorlevel for debugging messages. We want to have
203 dnl GST_ERROR messages printed when running cvs builds
204 if test "x[$1]" = "xyes"; then
205 GST_LEVEL_DEFAULT=GST_LEVEL_ERROR
207 GST_LEVEL_DEFAULT=GST_LEVEL_NONE
209 AC_DEFINE_UNQUOTED(GST_LEVEL_DEFAULT, $GST_LEVEL_DEFAULT,
210 [Default errorlevel to use])
211 dnl AC_SUBST so we can use it for win32/common/config.h
212 AC_SUBST(GST_LEVEL_DEFAULT)