1dnl handle various error-related things
2
3dnl Thomas Vander Stichele <thomas@apestaart.org>
4dnl Tim-Philipp Müller <tim centricular net>
5
6dnl Last modification: 2008-02-18
7
8dnl AG_GST_SET_ERROR_CFLAGS([ADD-WERROR], [MORE_FLAGS])
9dnl AG_GST_SET_ERROR_CXXFLAGS([ADD-WERROR], [MORE_FLAGS])
10dnl AG_GST_SET_LEVEL_DEFAULT([IS-GIT-VERSION])
11
12
13dnl Sets WARNING_CFLAGS and ERROR_CFLAGS to something the compiler
14dnl will accept and AC_SUBST them so they are available in Makefile
15dnl
16dnl WARNING_CFLAGS will contain flags to make the compiler emit more
17dnl   warnings.
18dnl ERROR_CFLAGS will contain flags to make those warnings fatal,
19dnl   unless ADD-WERROR is set to "no"
20dnl
21dnl If MORE_FLAGS is set, tries to add each of the given flags
22dnl to WARNING_CFLAGS if the compiler supports them. Each flag is
23dnl tested separately.
24dnl
25dnl These flags can be overridden at make time:
26dnl make ERROR_CFLAGS=
27AC_DEFUN([AG_GST_SET_ERROR_CFLAGS],
28[
29  AC_REQUIRE([AC_PROG_CC])
30  AC_REQUIRE([AS_COMPILER_FLAG])
31
32  WARNING_CFLAGS=""
33  ERROR_CFLAGS=""
34
35  dnl if we support -Wall, set it unconditionally
36  AS_COMPILER_FLAG(-Wall,
37                   WARNING_CFLAGS="$WARNING_CFLAGS -Wall")
38
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")
42
43  dnl Warn if variable length arrays are used (C99 extension)
44  AS_COMPILER_FLAG(-Wvla,
45        WARNING_CFLAGS="$WARNING_CFLAGS -Wvla")
46
47  dnl Warn for invalid pointer arithmetic
48  AS_COMPILER_FLAG(-Wpointer-arith,
49        WARNING_CFLAGS="$WARNING_CFLAGS -Wpointer-arith")
50
51  dnl if asked for, add -Werror if supported
52  if test "x$1" != "xno"
53  then
54    AS_COMPILER_FLAG(-Werror, ERROR_CFLAGS="$ERROR_CFLAGS -Werror")
55  fi
56
57  if test "x$2" != "x"
58  then
59    UNSUPPORTED=""
60    list="$2"
61    for each in $list
62    do
63      AS_COMPILER_FLAG($each,
64          WARNING_CFLAGS="$WARNING_CFLAGS $each",
65          UNSUPPORTED="$UNSUPPORTED $each")
66    done
67    if test "X$UNSUPPORTED" != X ; then
68      AC_MSG_NOTICE([unsupported compiler flags: $UNSUPPORTED])
69    fi
70  fi
71
72  AC_SUBST(WARNING_CFLAGS)
73  AC_SUBST(ERROR_CFLAGS)
74  AC_MSG_NOTICE([set WARNING_CFLAGS to $WARNING_CFLAGS])
75  AC_MSG_NOTICE([set ERROR_CFLAGS to $ERROR_CFLAGS])
76])
77
78dnl Sets WARNING_CXXFLAGS and ERROR_CXXFLAGS to something the compiler
79dnl will accept and AC_SUBST them so they are available in Makefile
80dnl
81dnl WARNING_CXXFLAGS will contain flags to make the compiler emit more
82dnl   warnings.
83dnl ERROR_CXXFLAGS will contain flags to make those warnings fatal,
84dnl   unless ADD-WERROR is set to "no"
85dnl
86dnl If MORE_FLAGS is set, tries to add each of the given flags
87dnl to WARNING_CFLAGS if the compiler supports them. Each flag is
88dnl tested separately.
89dnl
90dnl These flags can be overridden at make time:
91dnl make ERROR_CXXFLAGS=
92AC_DEFUN([AG_GST_SET_ERROR_CXXFLAGS],
93[
94  AC_REQUIRE([AC_PROG_CXX])
95  AC_REQUIRE([AS_CXX_COMPILER_FLAG])
96
97  ERROR_CXXFLAGS=""
98  WARNING_CXXFLAGS=""
99
100  dnl if we support -Wall, set it unconditionally
101  AS_CXX_COMPILER_FLAG(-Wall, WARNING_CXXFLAGS="$WARNING_CXXFLAGS -Wall")
102
103  dnl if asked for, add -Werror if supported
104  if test "x$1" != "xno"
105  then
106    AS_CXX_COMPILER_FLAG(-Werror, ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror")
107
108    if test "x$ERROR_CXXFLAGS" != "x"
109    then
110        dnl add exceptions
111        AS_CXX_COMPILER_FLAG([-Wno-non-virtual-dtor], ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Wno-non-virtual-dtor")
112
113	dnl Add -fno-strict-aliasing for GLib versions before 2.19.8
114	dnl as before G_LOCK and friends caused strict aliasing compiler
115	dnl warnings.
116	PKG_CHECK_EXISTS([glib-2.0 < 2.19.8], [
117	  AS_CXX_COMPILER_FLAG([-fno-strict-aliasing],
118	    ERROR_CXXFLAGS="$ERROR_CXXFLAGS -fno-strict-aliasing")
119	  ])
120    fi
121  fi
122
123  if test "x$2" != "x"
124  then
125    UNSUPPORTED=""
126    list="$2"
127    for each in $list
128    do
129      AS_CXX_COMPILER_FLAG($each,
130          WARNING_CXXFLAGS="$WARNING_CXXFLAGS $each",
131          UNSUPPORTED="$UNSUPPORTED $each")
132    done
133    if test "X$UNSUPPORTED" != X ; then
134      AC_MSG_NOTICE([unsupported compiler flags: $UNSUPPORTED])
135    fi
136  fi
137
138  AC_SUBST(WARNING_CXXFLAGS)
139  AC_SUBST(ERROR_CXXFLAGS)
140  AC_MSG_NOTICE([set WARNING_CXXFLAGS to $WARNING_CXXFLAGS])
141  AC_MSG_NOTICE([set ERROR_CXXFLAGS to $ERROR_CXXFLAGS])
142])
143
144dnl Sets WARNING_OBJCFLAGS and ERROR_OBJCFLAGS to something the compiler
145dnl will accept and AC_SUBST them so they are available in Makefile
146dnl
147dnl WARNING_OBJCFLAGS will contain flags to make the compiler emit more
148dnl   warnings.
149dnl ERROR_OBJCFLAGS will contain flags to make those warnings fatal,
150dnl   unless ADD-WERROR is set to "no"
151dnl
152dnl If MORE_FLAGS is set, tries to add each of the given flags
153dnl to WARNING_CFLAGS if the compiler supports them. Each flag is
154dnl tested separately.
155dnl
156dnl These flags can be overridden at make time:
157dnl make ERROR_OBJCFLAGS=
158AC_DEFUN([AG_GST_SET_ERROR_OBJCFLAGS],
159[
160  AC_REQUIRE([AC_PROG_OBJC])
161  AC_REQUIRE([AS_OBJC_COMPILER_FLAG])
162
163  ERROR_OBJCFLAGS=""
164  WARNING_OBJCFLAGS=""
165
166  dnl if we support -Wall, set it unconditionally
167  AS_OBJC_COMPILER_FLAG(-Wall, WARNING_OBJCFLAGS="$WARNING_OBJCFLAGS -Wall")
168
169  dnl if asked for, add -Werror if supported
170  if test "x$1" != "xno"
171  then
172    AS_OBJC_COMPILER_FLAG(-Werror, ERROR_OBJCFLAGS="$ERROR_OBJCFLAGS -Werror")
173
174    if test "x$ERROR_OBJCFLAGS" != "x"
175    then
176	dnl Add -fno-strict-aliasing for GLib versions before 2.19.8
177	dnl as before G_LOCK and friends caused strict aliasing compiler
178	dnl warnings.
179	PKG_CHECK_EXISTS([glib-2.0 < 2.19.8], [
180	  AS_OBJC_COMPILER_FLAG([-fno-strict-aliasing],
181	    ERROR_OBJCFLAGS="$ERROR_OBJCFLAGS -fno-strict-aliasing")
182	  ])
183    fi
184  fi
185
186  if test "x$2" != "x"
187  then
188    UNSUPPORTED=""
189    list="$2"
190    for each in $list
191    do
192      AS_OBJC_COMPILER_FLAG($each,
193          WARNING_OBJCFLAGS="$WARNING_OBJCFLAGS $each",
194          UNSUPPORTED="$UNSUPPORTED $each")
195    done
196    if test "X$UNSUPPORTED" != X ; then
197      AC_MSG_NOTICE([unsupported compiler flags: $UNSUPPORTED])
198    fi
199  fi
200
201  AC_SUBST(WARNING_OBJCFLAGS)
202  AC_SUBST(ERROR_OBJCFLAGS)
203  AC_MSG_NOTICE([set WARNING_OBJCFLAGS to $WARNING_OBJCFLAGS])
204  AC_MSG_NOTICE([set ERROR_OBJCFLAGS to $ERROR_OBJCFLAGS])
205])
206
207dnl Sets the default error level for debugging messages
208AC_DEFUN([AG_GST_SET_LEVEL_DEFAULT],
209[
210  dnl define correct errorlevel for debugging messages. We want to have
211  dnl GST_ERROR messages printed when running cvs builds
212  if test "x[$1]" = "xyes"; then
213    GST_LEVEL_DEFAULT=GST_LEVEL_ERROR
214  else
215    GST_LEVEL_DEFAULT=GST_LEVEL_NONE
216  fi
217  AC_DEFINE_UNQUOTED(GST_LEVEL_DEFAULT, $GST_LEVEL_DEFAULT,
218    [Default errorlevel to use])
219  dnl AC_SUBST so we can use it for win32/common/config.h
220  AC_SUBST(GST_LEVEL_DEFAULT)
221])
222