Merge "Optional autogen.sh flag --enable-kdbus-transport added allowing to compile...
[platform/upstream/dbus.git] / m4 / tp-compiler-warnings.m4
1 dnl TP_COMPILER_WARNINGS(VARIABLE, WERROR_BY_DEFAULT, DESIRABLE, UNDESIRABLE)
2 dnl $1 (VARIABLE): the variable to put flags into
3 dnl $2 (WERROR_BY_DEFAULT): a command returning true if -Werror should be the
4 dnl     default
5 dnl $3 (DESIRABLE): warning flags we want (e.g. all extra shadow)
6 dnl $4 (UNDESIRABLE): warning flags we don't want (e.g.
7 dnl   missing-field-initializers unused-parameter)
8 AC_DEFUN([TP_COMPILER_WARNINGS],
9 [
10   AC_REQUIRE([AC_ARG_ENABLE])dnl
11   AC_REQUIRE([AC_HELP_STRING])dnl
12   AC_REQUIRE([TP_COMPILER_FLAG])dnl
13
14   tp_warnings=""
15   for tp_flag in $3; do
16     TP_COMPILER_FLAG([-W$tp_flag], [tp_warnings="$tp_warnings -W$tp_flag"])
17   done
18
19   tp_error_flags="-Werror"
20   TP_COMPILER_FLAG([-Werror], [tp_werror=yes], [tp_werror=no])
21
22   for tp_flag in $4; do
23     TP_COMPILER_FLAG([-Wno-$tp_flag],
24       [tp_warnings="$tp_warnings -Wno-$tp_flag"])
25 dnl Yes, we do need to use both -Wno-foo and -Wno-error=foo. Simon says:
26 dnl     some warnings we explicitly don't want, like unused-parameter, but
27 dnl     they're in -Wall. when a distro using cdbs compiles us, we have:
28 dnl       -Werror -Wno-unused-parameter      -Wall
29 dnl         ^ from us                         ^ from cdbs
30 dnl     which turns -Wunused-parameter back on, in effect
31     TP_COMPILER_FLAG([-Wno-error=$tp_flag],
32       [tp_error_flags="$tp_error_flags -Wno-error=$tp_flag"], [tp_werror=no])
33   done
34
35   AC_ARG_ENABLE([Werror],
36     AC_HELP_STRING([--disable-Werror],
37       [compile without -Werror (normally enabled in development builds)]),
38     tp_werror=$enableval, :)
39
40   if test "x$tp_werror" = xyes && $2; then
41 dnl We put -Wno-error=foo before -Wno-foo because clang interprets -Wall
42 dnl -Werror -Wno-foo -Wno-error=foo as “make foo a non-fatal warning”, but does
43 dnl what we want if you reverse them.
44     $1="$tp_error_flags $tp_warnings"
45   else
46     $1="$tp_warnings"
47   fi
48
49 ])