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 ******************************
10 default_compile_warnings=no
12 default_compile_warnings="$1"
15 AC_ARG_ENABLE(compile-warnings,
16 [ --enable-compile-warnings=[no/minimum/yes/maximum/error] Turn on compiler warnings.],, [enable_compile_warnings="$default_compile_warnings"])
19 if test "x$GCC" != xyes; then
20 enable_compile_warnings=no
24 realsave_CFLAGS="$CFLAGS"
26 case "$enable_compile_warnings" in
34 warning_flags="-Wall -Wmissing-prototypes"
37 warning_flags="-Wall -Wmissing-prototypes -Wnested-externs -Wpointer-arith"
38 CFLAGS="$warning_flags $CFLAGS"
39 for option in -Wno-sign-compare; do
41 CFLAGS="$CFLAGS $option"
42 AC_MSG_CHECKING([whether gcc understands $option])
43 AC_TRY_COMPILE([], [],
47 AC_MSG_RESULT($has_option)
48 if test $has_option = yes; then
49 warning_flags="$warning_flags $option"
55 if test "$enable_compile_warnings" = "error" ; then
56 warning_flags="$warning_flags -Werror"
60 AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
63 CFLAGS="$realsave_CFLAGS"
64 AC_MSG_CHECKING(what warning flags to pass to the C compiler)
65 AC_MSG_RESULT($warning_flags)
68 [ --enable-iso-c Try to warn if code is not ISO C ],,
71 AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
73 if test "x$enable_iso_c" != "xno"; then
74 if test "x$GCC" = "xyes"; then
76 *[\ \ ]-ansi[\ \ ]*) ;;
77 *) complCFLAGS="$complCFLAGS -ansi" ;;
80 *[\ \ ]-pedantic[\ \ ]*) ;;
81 *) complCFLAGS="$complCFLAGS -pedantic" ;;
85 AC_MSG_RESULT($complCFLAGS)
87 WARN_CFLAGS="$warning_flags $complCFLAGS"
91 dnl For C++, do basically the same thing.
93 AC_DEFUN([GNOME_CXX_WARNINGS],[
94 AC_ARG_ENABLE(cxx-warnings,
95 [ --enable-cxx-warnings=[no/minimum/yes] Turn on compiler warnings.],,enable_cxx_warnings=minimum)
97 AC_MSG_CHECKING(what warning flags to pass to the C++ compiler)
99 if test "x$GCC" != xyes; then
100 enable_compile_warnings=no
102 if test "x$enable_cxx_warnings" != "xno"; then
103 if test "x$GCC" = "xyes"; then
104 case " $CXXFLAGS " in
105 *[\ \ ]-Wall[\ \ ]*) ;;
106 *) warnCXXFLAGS="-Wall -Wno-unused" ;;
109 ## -W is not all that useful. And it cannot be controlled
110 ## with individual -Wno-xxx flags, unlike -Wall
111 if test "x$enable_cxx_warnings" = "xyes"; then
112 warnCXXFLAGS="$warnCXXFLAGS -Wmissing-prototypes -Wmissing-declarations -Wshadow -Woverloaded-virtual"
116 AC_MSG_RESULT($warnCXXFLAGS)
118 AC_ARG_ENABLE(iso-cxx,
119 [ --enable-iso-cxx 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$GCC" = "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)
138 if test "x$cxxflags_set" != "xyes"; then
139 CXXFLAGS="$CXXFLAGS $warnCXXFLAGS $complCXXFLAGS"
141 AC_SUBST(cxxflags_set)