summaryrefslogtreecommitdiff
path: root/m4/gst-error.m4
blob: 006758804c7f3bc9691e57f322db1d44e8165d62 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
dnl handle various error-related things

dnl Thomas Vander Stichele <thomas@apestaart.org>
dnl Tim-Philipp Müller <tim centricular net>

dnl Last modification: 2008-02-18

dnl AG_GST_SET_ERROR_CFLAGS([ADD-WERROR], [MORE_FLAGS])
dnl AG_GST_SET_ERROR_CXXFLAGS([ADD-WERROR], [MORE_FLAGS])
dnl AG_GST_SET_LEVEL_DEFAULT([IS-GIT-VERSION])


dnl Sets WARNING_CFLAGS and ERROR_CFLAGS to something the compiler 
dnl will accept and AC_SUBST them so they are available in Makefile
dnl
dnl WARNING_CFLAGS will contain flags to make the compiler emit more
dnl   warnings.
dnl ERROR_CFLAGS will contain flags to make those warnings fatal,
dnl   unless ADD-WERROR is set to "no"
dnl 
dnl If MORE_FLAGS is set, tries to add each of the given flags
dnl to WARNING_CFLAGS if the compiler supports them. Each flag is 
dnl tested separately.
dnl
dnl These flags can be overridden at make time:
dnl make ERROR_CFLAGS=
AC_DEFUN([AG_GST_SET_ERROR_CFLAGS],
[
  AC_REQUIRE([AC_PROG_CC])
  AC_REQUIRE([AS_COMPILER_FLAG])

  WARNING_CFLAGS=""
  ERROR_CFLAGS=""

  dnl if we support -Wall, set it unconditionally
  AS_COMPILER_FLAG(-Wall,
                   WARNING_CFLAGS="$WARNING_CFLAGS -Wall")

  dnl Warn if declarations after statements are used (C99 extension)
  AS_COMPILER_FLAG(-Wdeclaration-after-statement,
        WARNING_CFLAGS="$WARNING_CFLAGS -Wdeclaration-after-statement")

  dnl Warn if variable length arrays are used (C99 extension)
  AS_COMPILER_FLAG(-Wvla,
        WARNING_CFLAGS="$WARNING_CFLAGS -Wvla")

  dnl Warn for invalid pointer arithmetic
  AS_COMPILER_FLAG(-Wpointer-arith,
        WARNING_CFLAGS="$WARNING_CFLAGS -Wpointer-arith")

  dnl if asked for, add -Werror if supported
  if test "x$1" != "xno"
  then
    AS_COMPILER_FLAG(-Werror, ERROR_CFLAGS="$ERROR_CFLAGS -Werror")
  fi

  if test "x$2" != "x"
  then
    UNSUPPORTED=""
    list="$2"
    for each in $list
    do
      AS_COMPILER_FLAG($each,
          WARNING_CFLAGS="$WARNING_CFLAGS $each",
          UNSUPPORTED="$UNSUPPORTED $each")
    done
    if test "X$UNSUPPORTED" != X ; then
      AC_MSG_NOTICE([unsupported compiler flags: $UNSUPPORTED])
    fi
  fi

  AC_SUBST(WARNING_CFLAGS)
  AC_SUBST(ERROR_CFLAGS)
  AC_MSG_NOTICE([set WARNING_CFLAGS to $WARNING_CFLAGS])
  AC_MSG_NOTICE([set ERROR_CFLAGS to $ERROR_CFLAGS])
])

dnl Sets WARNING_CXXFLAGS and ERROR_CXXFLAGS to something the compiler 
dnl will accept and AC_SUBST them so they are available in Makefile
dnl
dnl WARNING_CXXFLAGS will contain flags to make the compiler emit more
dnl   warnings.
dnl ERROR_CXXFLAGS will contain flags to make those warnings fatal,
dnl   unless ADD-WERROR is set to "no"
dnl 
dnl If MORE_FLAGS is set, tries to add each of the given flags
dnl to WARNING_CFLAGS if the compiler supports them. Each flag is 
dnl tested separately.
dnl
dnl These flags can be overridden at make time:
dnl make ERROR_CXXFLAGS=
AC_DEFUN([AG_GST_SET_ERROR_CXXFLAGS],
[
  AC_REQUIRE([AC_PROG_CXX])
  AC_REQUIRE([AS_CXX_COMPILER_FLAG])

  ERROR_CXXFLAGS=""
  WARNING_CXXFLAGS=""

  dnl if we support -Wall, set it unconditionally
  AS_CXX_COMPILER_FLAG(-Wall, WARNING_CXXFLAGS="$WARNING_CXXFLAGS -Wall")

  dnl if asked for, add -Werror if supported
  if test "x$1" != "xno"
  then
    AS_CXX_COMPILER_FLAG(-Werror, ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Werror")

    if test "x$ERROR_CXXFLAGS" != "x"
    then
        dnl add exceptions
        AS_CXX_COMPILER_FLAG([-Wno-non-virtual-dtor], ERROR_CXXFLAGS="$ERROR_CXXFLAGS -Wno-non-virtual-dtor")

	dnl Add -fno-strict-aliasing for GLib versions before 2.19.8
	dnl as before G_LOCK and friends caused strict aliasing compiler
	dnl warnings.
	PKG_CHECK_EXISTS([glib-2.0 < 2.19.8], [
	  AS_CXX_COMPILER_FLAG([-fno-strict-aliasing],
	    ERROR_CXXFLAGS="$ERROR_CXXFLAGS -fno-strict-aliasing")
	  ])
    fi
  fi

  if test "x$2" != "x"
  then
    UNSUPPORTED=""
    list="$2"
    for each in $list
    do
      AS_CXX_COMPILER_FLAG($each,
          WARNING_CXXFLAGS="$WARNING_CXXFLAGS $each",
          UNSUPPORTED="$UNSUPPORTED $each")
    done
    if test "X$UNSUPPORTED" != X ; then
      AC_MSG_NOTICE([unsupported compiler flags: $UNSUPPORTED])
    fi
  fi

  AC_SUBST(WARNING_CXXFLAGS)
  AC_SUBST(ERROR_CXXFLAGS)
  AC_MSG_NOTICE([set WARNING_CXXFLAGS to $WARNING_CXXFLAGS])
  AC_MSG_NOTICE([set ERROR_CXXFLAGS to $ERROR_CXXFLAGS])
])

dnl Sets WARNING_OBJCFLAGS and ERROR_OBJCFLAGS to something the compiler 
dnl will accept and AC_SUBST them so they are available in Makefile
dnl
dnl WARNING_OBJCFLAGS will contain flags to make the compiler emit more
dnl   warnings.
dnl ERROR_OBJCFLAGS will contain flags to make those warnings fatal,
dnl   unless ADD-WERROR is set to "no"
dnl 
dnl If MORE_FLAGS is set, tries to add each of the given flags
dnl to WARNING_CFLAGS if the compiler supports them. Each flag is 
dnl tested separately.
dnl
dnl These flags can be overridden at make time:
dnl make ERROR_OBJCFLAGS=
AC_DEFUN([AG_GST_SET_ERROR_OBJCFLAGS],
[
  AC_REQUIRE([AC_PROG_OBJC])
  AC_REQUIRE([AS_OBJC_COMPILER_FLAG])

  ERROR_OBJCFLAGS=""
  WARNING_OBJCFLAGS=""

  dnl if we support -Wall, set it unconditionally
  AS_OBJC_COMPILER_FLAG(-Wall, WARNING_OBJCFLAGS="$WARNING_OBJCFLAGS -Wall")

  dnl if asked for, add -Werror if supported
  if test "x$1" != "xno"
  then
    AS_OBJC_COMPILER_FLAG(-Werror, ERROR_OBJCFLAGS="$ERROR_OBJCFLAGS -Werror")

    if test "x$ERROR_OBJCFLAGS" != "x"
    then
	dnl Add -fno-strict-aliasing for GLib versions before 2.19.8
	dnl as before G_LOCK and friends caused strict aliasing compiler
	dnl warnings.
	PKG_CHECK_EXISTS([glib-2.0 < 2.19.8], [
	  AS_OBJC_COMPILER_FLAG([-fno-strict-aliasing],
	    ERROR_OBJCFLAGS="$ERROR_OBJCFLAGS -fno-strict-aliasing")
	  ])
    fi
  fi

  if test "x$2" != "x"
  then
    UNSUPPORTED=""
    list="$2"
    for each in $list
    do
      AS_OBJC_COMPILER_FLAG($each,
          WARNING_OBJCFLAGS="$WARNING_OBJCFLAGS $each",
          UNSUPPORTED="$UNSUPPORTED $each")
    done
    if test "X$UNSUPPORTED" != X ; then
      AC_MSG_NOTICE([unsupported compiler flags: $UNSUPPORTED])
    fi
  fi

  AC_SUBST(WARNING_OBJCFLAGS)
  AC_SUBST(ERROR_OBJCFLAGS)
  AC_MSG_NOTICE([set WARNING_OBJCFLAGS to $WARNING_OBJCFLAGS])
  AC_MSG_NOTICE([set ERROR_OBJCFLAGS to $ERROR_OBJCFLAGS])
])

dnl Sets the default error level for debugging messages
AC_DEFUN([AG_GST_SET_LEVEL_DEFAULT],
[
  dnl define correct errorlevel for debugging messages. We want to have
  dnl GST_ERROR messages printed when running cvs builds
  if test "x[$1]" = "xyes"; then
    GST_LEVEL_DEFAULT=GST_LEVEL_ERROR
  else
    GST_LEVEL_DEFAULT=GST_LEVEL_NONE
  fi
  AC_DEFINE_UNQUOTED(GST_LEVEL_DEFAULT, $GST_LEVEL_DEFAULT,
    [Default errorlevel to use])
  dnl AC_SUBST so we can use it for win32/common/config.h
  AC_SUBST(GST_LEVEL_DEFAULT)
])