1 dnl GNOME_COMPILE_WARNINGS
2 dnl Turn on many useful compiler warnings
3 dnl For now, only works on GCC
4 AC_DEFUN([GNOME_COMPILE_WARNINGS],[
5 dnl ******************************
6 dnl More compiler warnings
7 dnl ******************************
9 AC_ARG_ENABLE(compile-warnings,
10 AC_HELP_STRING([--enable-compile-warnings=@<:@no/minimum/yes/maximum/error@:>@],
11 [Turn on compiler warnings]),,
12 [enable_compile_warnings="m4_default([$1],[yes])"])
15 if test "x$GCC" != xyes; then
16 enable_compile_warnings=no
20 realsave_CFLAGS="$CFLAGS"
22 case "$enable_compile_warnings" in
30 warning_flags="-Wall -Wmissing-prototypes"
33 warning_flags="-Wall -Wmissing-prototypes -Wnested-externs -Wpointer-arith"
34 CFLAGS="$warning_flags $CFLAGS"
35 for option in -Wno-sign-compare; do
37 CFLAGS="$CFLAGS $option"
38 AC_MSG_CHECKING([whether gcc understands $option])
39 AC_TRY_COMPILE([], [],
43 AC_MSG_RESULT($has_option)
44 if test $has_option = yes; then
45 warning_flags="$warning_flags $option"
51 if test "$enable_compile_warnings" = "error" ; then
52 warning_flags="$warning_flags -Werror"
56 AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
59 CFLAGS="$realsave_CFLAGS"
60 AC_MSG_CHECKING(what warning flags to pass to the C compiler)
61 AC_MSG_RESULT($warning_flags)
64 AC_HELP_STRING([--enable-iso-c],
65 [Try to warn if code is not ISO C ]),,
68 AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
70 if test "x$enable_iso_c" != "xno"; then
71 if test "x$GCC" = "xyes"; then
73 *[\ \ ]-ansi[\ \ ]*) ;;
74 *) complCFLAGS="$complCFLAGS -ansi" ;;
77 *[\ \ ]-pedantic[\ \ ]*) ;;
78 *) complCFLAGS="$complCFLAGS -pedantic" ;;
82 AC_MSG_RESULT($complCFLAGS)
84 WARN_CFLAGS="$warning_flags $complCFLAGS"
88 dnl For C++, do basically the same thing.
90 AC_DEFUN([GNOME_CXX_WARNINGS],[
91 AC_ARG_ENABLE(cxx-warnings,
92 AC_HELP_STRING([--enable-cxx-warnings=@<:@no/minimum/yes@:>@]
93 [Turn on compiler warnings.]),,
94 [enable_cxx_warnings="m4_default([$1],[minimum])"])
96 AC_MSG_CHECKING(what warning flags to pass to the C++ compiler)
98 if test "x$GXX" != xyes; then
99 enable_cxx_warnings=no
101 if test "x$enable_cxx_warnings" != "xno"; then
102 if test "x$GXX" = "xyes"; then
103 case " $CXXFLAGS " in
104 *[\ \ ]-Wall[\ \ ]*) ;;
105 *) warnCXXFLAGS="-Wall -Wno-unused" ;;
108 ## -W is not all that useful. And it cannot be controlled
109 ## with individual -Wno-xxx flags, unlike -Wall
110 if test "x$enable_cxx_warnings" = "xyes"; then
111 warnCXXFLAGS="$warnCXXFLAGS -Wshadow -Woverloaded-virtual"
115 AC_MSG_RESULT($warnCXXFLAGS)
117 AC_ARG_ENABLE(iso-cxx,
118 AC_HELP_STRING([--enable-iso-cxx],
119 [Try to warn if code is not ISO C++ ]),,
122 AC_MSG_CHECKING(what language compliance flags to pass to the C++ compiler)
124 if test "x$enable_iso_cxx" != "xno"; then
125 if test "x$GXX" = "xyes"; then
126 case " $CXXFLAGS " in
127 *[\ \ ]-ansi[\ \ ]*) ;;
128 *) complCXXFLAGS="$complCXXFLAGS -ansi" ;;
131 case " $CXXFLAGS " in
132 *[\ \ ]-pedantic[\ \ ]*) ;;
133 *) complCXXFLAGS="$complCXXFLAGS -pedantic" ;;
137 AC_MSG_RESULT($complCXXFLAGS)
139 WARN_CXXFLAGS="$CXXFLAGS $warnCXXFLAGS $complCXXFLAGS"
140 AC_SUBST(WARN_CXXFLAGS)