1 dnl GNOME_COMPILE_WARNINGS
2 dnl Turn on many useful compiler warnings
3 dnl For now, only works on GCC
5 # serial 3 Fix to correctly handle provided default values
8 # pwi 2009-05-15 shamelessly copied from gnome-compiler-flags.m4
9 # two patch have been submitted (see gnome-common #582860)
12 AC_DEFUN([NA_GNOME_COMPILE_WARNINGS],[
14 _ac_warning_def=m4_default([$1],[yes])
15 _ac_compliant_def=m4_default(["$2"],[no])
17 dnl ******************************
18 dnl More compiler warnings
19 dnl ******************************
21 AC_ARG_ENABLE(compile-warnings,
22 AC_HELP_STRING([--enable-compile-warnings=@<:@no/minimum/yes/maximum/error@:>@],
23 [Turn on compiler warnings]),,
24 [enable_compile_warnings="${_ac_warning_def}"])
27 if test "x$GCC" != xyes; then
28 enable_compile_warnings=no
32 realsave_CFLAGS="$CFLAGS"
34 case "$enable_compile_warnings" in
42 warning_flags="-Wall -Wmissing-prototypes"
45 warning_flags="-Wall -Wmissing-prototypes -Wnested-externs -Wpointer-arith"
46 CFLAGS="$warning_flags $CFLAGS"
47 for option in -Wno-sign-compare; do
49 CFLAGS="$CFLAGS $option"
50 AC_MSG_CHECKING([whether gcc understands $option])
51 AC_TRY_COMPILE([], [],
55 AC_MSG_RESULT($has_option)
56 if test $has_option = yes; then
57 warning_flags="$warning_flags $option"
63 if test "$enable_compile_warnings" = "error" ; then
64 warning_flags="$warning_flags -Werror"
68 AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
71 CFLAGS="$realsave_CFLAGS"
72 AC_MSG_CHECKING(what warning flags to pass to the C compiler)
73 AC_MSG_RESULT($warning_flags)
76 AC_HELP_STRING([--enable-iso-c],
77 [Try to warn if code is not ISO C ]),,
78 [enable_iso_c="${_ac_compliant_def}"])
80 AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
82 if test "x$enable_iso_c" != "xno"; then
83 if test "x$GCC" = "xyes"; then
84 if test "x${_ac_compliant_def}" = "x"; then
86 *[\ \ ]-ansi[\ \ ]*) ;;
87 *) complCFLAGS="$complCFLAGS -ansi" ;;
90 *[\ \ ]-pedantic[\ \ ]*) ;;
91 *) complCFLAGS="$complCFLAGS -pedantic" ;;
94 complCFLAGS="$complCFLAGS ${_ac_compliant_def}"
98 AC_MSG_RESULT($complCFLAGS)
100 WARN_CFLAGS="$warning_flags $complCFLAGS"
101 AC_SUBST(WARN_CFLAGS)
104 dnl For C++, do basically the same thing.
106 AC_DEFUN([GNOME_CXX_WARNINGS],[
107 AC_ARG_ENABLE(cxx-warnings,
108 AC_HELP_STRING([--enable-cxx-warnings=@<:@no/minimum/yes@:>@]
109 [Turn on compiler warnings.]),,
110 [enable_cxx_warnings="m4_default([$1],[minimum])"])
112 AC_MSG_CHECKING(what warning flags to pass to the C++ compiler)
114 if test "x$GXX" != xyes; then
115 enable_cxx_warnings=no
117 if test "x$enable_cxx_warnings" != "xno"; then
118 if test "x$GXX" = "xyes"; then
119 case " $CXXFLAGS " in
120 *[\ \ ]-Wall[\ \ ]*) ;;
121 *) warnCXXFLAGS="-Wall -Wno-unused" ;;
124 ## -W is not all that useful. And it cannot be controlled
125 ## with individual -Wno-xxx flags, unlike -Wall
126 if test "x$enable_cxx_warnings" = "xyes"; then
127 warnCXXFLAGS="$warnCXXFLAGS -Wshadow -Woverloaded-virtual"
131 AC_MSG_RESULT($warnCXXFLAGS)
133 AC_ARG_ENABLE(iso-cxx,
134 AC_HELP_STRING([--enable-iso-cxx],
135 [Try to warn if code is not ISO C++ ]),,
138 AC_MSG_CHECKING(what language compliance flags to pass to the C++ compiler)
140 if test "x$enable_iso_cxx" != "xno"; then
141 if test "x$GXX" = "xyes"; then
142 case " $CXXFLAGS " in
143 *[\ \ ]-ansi[\ \ ]*) ;;
144 *) complCXXFLAGS="$complCXXFLAGS -ansi" ;;
147 case " $CXXFLAGS " in
148 *[\ \ ]-pedantic[\ \ ]*) ;;
149 *) complCXXFLAGS="$complCXXFLAGS -pedantic" ;;
153 AC_MSG_RESULT($complCXXFLAGS)
155 WARN_CXXFLAGS="$CXXFLAGS $warnCXXFLAGS $complCXXFLAGS"
156 AC_SUBST(WARN_CXXFLAGS)