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