13cb660
dnl GNOME_COMPILE_WARNINGS
13cb660
dnl Turn on many useful compiler warnings
13cb660
dnl For now, only works on GCC
13cb660
AC_DEFUN([GNOME_COMPILE_WARNINGS],[
13cb660
    dnl ******************************
13cb660
    dnl More compiler warnings
13cb660
    dnl ******************************
13cb660
13cb660
    AC_ARG_ENABLE(compile-warnings, 
13cb660
                  AC_HELP_STRING([--enable-compile-warnings=@<:@no/minimum/yes/maximum/error@:>@],
13cb660
                                 [Turn on compiler warnings]),,
13cb660
                  [enable_compile_warnings="m4_default([$1],[yes])"])
13cb660
13cb660
    warnCFLAGS=
13cb660
    if test "x$GCC" != xyes; then
13cb660
	enable_compile_warnings=no
13cb660
    fi
13cb660
13cb660
    warning_flags=
13cb660
    realsave_CFLAGS="$CFLAGS"
13cb660
13cb660
    case "$enable_compile_warnings" in
13cb660
    no)
13cb660
	warning_flags=
13cb660
	;;
13cb660
    minimum)
13cb660
	warning_flags="-Wall"
13cb660
	;;
13cb660
    yes)
13cb660
	warning_flags="-Wall -Wmissing-prototypes"
13cb660
	;;
13cb660
    maximum|error)
13cb660
	warning_flags="-Wall -Wmissing-prototypes -Wnested-externs -Wpointer-arith"
13cb660
	CFLAGS="$warning_flags $CFLAGS"
13cb660
	for option in -Wno-sign-compare; do
13cb660
		SAVE_CFLAGS="$CFLAGS"
13cb660
		CFLAGS="$CFLAGS $option"
13cb660
		AC_MSG_CHECKING([whether gcc understands $option])
13cb660
		AC_TRY_COMPILE([], [],
13cb660
			has_option=yes,
13cb660
			has_option=no,)
13cb660
		CFLAGS="$SAVE_CFLAGS"
13cb660
		AC_MSG_RESULT($has_option)
13cb660
		if test $has_option = yes; then
13cb660
		  warning_flags="$warning_flags $option"
13cb660
		fi
13cb660
		unset has_option
13cb660
		unset SAVE_CFLAGS
13cb660
	done
13cb660
	unset option
13cb660
	if test "$enable_compile_warnings" = "error" ; then
13cb660
	    warning_flags="$warning_flags -Werror"
13cb660
	fi
13cb660
	;;
13cb660
    *)
13cb660
	AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
13cb660
	;;
13cb660
    esac
13cb660
    CFLAGS="$realsave_CFLAGS"
13cb660
    AC_MSG_CHECKING(what warning flags to pass to the C compiler)
13cb660
    AC_MSG_RESULT($warning_flags)
13cb660
13cb660
    AC_ARG_ENABLE(iso-c,
13cb660
                  AC_HELP_STRING([--enable-iso-c],
13cb660
                                 [Try to warn if code is not ISO C ]),,
13cb660
                  [enable_iso_c=no])
13cb660
13cb660
    AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
13cb660
    complCFLAGS=
13cb660
    if test "x$enable_iso_c" != "xno"; then
13cb660
	if test "x$GCC" = "xyes"; then
13cb660
	case " $CFLAGS " in
13cb660
	    *[\ \	]-ansi[\ \	]*) ;;
13cb660
	    *) complCFLAGS="$complCFLAGS -ansi" ;;
13cb660
	esac
13cb660
	case " $CFLAGS " in
13cb660
	    *[\ \	]-pedantic[\ \	]*) ;;
13cb660
	    *) complCFLAGS="$complCFLAGS -pedantic" ;;
13cb660
	esac
13cb660
	fi
13cb660
    fi
13cb660
    AC_MSG_RESULT($complCFLAGS)
13cb660
13cb660
    WARN_CFLAGS="$warning_flags $complCFLAGS"
13cb660
    AC_SUBST(WARN_CFLAGS)
13cb660
])
13cb660
13cb660
dnl For C++, do basically the same thing.
13cb660
13cb660
AC_DEFUN([GNOME_CXX_WARNINGS],[
13cb660
  AC_ARG_ENABLE(cxx-warnings,
13cb660
                AC_HELP_STRING([--enable-cxx-warnings=@<:@no/minimum/yes@:>@]
13cb660
                               [Turn on compiler warnings.]),,
13cb660
                [enable_cxx_warnings="m4_default([$1],[minimum])"])
13cb660
13cb660
  AC_MSG_CHECKING(what warning flags to pass to the C++ compiler)
13cb660
  warnCXXFLAGS=
13cb660
  if test "x$GCC" != xyes; then
13cb660
    enable_compile_warnings=no
13cb660
  fi
13cb660
  if test "x$enable_cxx_warnings" != "xno"; then
13cb660
    if test "x$GCC" = "xyes"; then
13cb660
      case " $CXXFLAGS " in
13cb660
      *[\ \	]-Wall[\ \	]*) ;;
13cb660
      *) warnCXXFLAGS="-Wall -Wno-unused" ;;
13cb660
      esac
13cb660
13cb660
      ## -W is not all that useful.  And it cannot be controlled
13cb660
      ## with individual -Wno-xxx flags, unlike -Wall
13cb660
      if test "x$enable_cxx_warnings" = "xyes"; then
13cb660
	warnCXXFLAGS="$warnCXXFLAGS -Wshadow -Woverloaded-virtual"
13cb660
      fi
13cb660
    fi
13cb660
  fi
13cb660
  AC_MSG_RESULT($warnCXXFLAGS)
13cb660
13cb660
   AC_ARG_ENABLE(iso-cxx,
13cb660
                 AC_HELP_STRING([--enable-iso-cxx],
13cb660
                                [Try to warn if code is not ISO C++ ]),,
13cb660
                 [enable_iso_cxx=no])
13cb660
13cb660
   AC_MSG_CHECKING(what language compliance flags to pass to the C++ compiler)
13cb660
   complCXXFLAGS=
13cb660
   if test "x$enable_iso_cxx" != "xno"; then
13cb660
     if test "x$GCC" = "xyes"; then
13cb660
      case " $CXXFLAGS " in
13cb660
      *[\ \	]-ansi[\ \	]*) ;;
13cb660
      *) complCXXFLAGS="$complCXXFLAGS -ansi" ;;
13cb660
      esac
13cb660
13cb660
      case " $CXXFLAGS " in
13cb660
      *[\ \	]-pedantic[\ \	]*) ;;
13cb660
      *) complCXXFLAGS="$complCXXFLAGS -pedantic" ;;
13cb660
      esac
13cb660
     fi
13cb660
   fi
13cb660
  AC_MSG_RESULT($complCXXFLAGS)
13cb660
13cb660
  WARN_CXXFLAGS="$CXXFLAGS $warnCXXFLAGS $complCXXFLAGS"
13cb660
  AC_SUBST(WARN_CXXFLAGS)
13cb660
])