[gtk-vnc] Re-write configure rules to avoid many warnings



commit 28bd4870c0c07758463fabff506efd3d00642cd4
Author: Daniel P. Berrange <berrange redhat com>
Date:   Tue Aug 25 13:01:22 2009 +0100

    Re-write configure rules to avoid many warnings
    
    * acinclude.m4: Add helper function for checking a huge list of
      compile flags. Also test ability to link with the flag, not just
      to compile.
    * configure.ac: gl_EARLY must come before every rule that isnt
      just autoconf/make metadata initialization. Call out to the
      generic compile flag macro. Turn off automake's GNU-make-ism
      warnings.
    * autobuild.sh: Change way compile warnings are turned on
    * src/Makefile.am: Enable compile warning flags on python build

 acinclude.m4    |  117 +++++++++++++++++++++++++++++++++++++++++++++++++++---
 autobuild.sh    |    3 +-
 configure.ac    |   91 ++++++++++++++++---------------------------
 src/Makefile.am |    4 +-
 4 files changed, 147 insertions(+), 68 deletions(-)
---
diff --git a/acinclude.m4 b/acinclude.m4
index cc3dcad..37528a6 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -24,16 +24,119 @@ AC_DEFUN([gl_COMPILER_FLAGS],
   [AC_MSG_CHECKING(whether compiler accepts $1)
    AC_SUBST(COMPILER_FLAGS)
    ac_save_CFLAGS="$CFLAGS"
-   CFLAGS="$CFLAGS $1"
-   AC_TRY_COMPILE(,
-    [int x;],
-    COMPILER_FLAGS="$COMPILER_FLAGS $1"
-    AC_MSG_RESULT(yes),
-    AC_MSG_RESULT(no))
-  CFLAGS="$ac_save_CFLAGS"
+   dnl Some flags are dependant, so we set all previously checked
+   dnl flags when testing. Except for -Werror which we have to
+   dnl check on its own, because some of our compiler flags cause
+   dnl warnings from the autoconf test program!
+   if test "$1" = "-Werror" ; then
+     CFLAGS="$CFLAGS $1"
+   else
+     CFLAGS="$CFLAGS $COMPILER_FLAGS $1"
+   fi
+   AC_TRY_LINK([], [], has_option=yes, has_option=no,)
+   echo 'int x;' >conftest.c
+   $CC $CFLAGS -c conftest.c 2>conftest.err
+   ret=$?
+   if test $ret != 0 -o -s conftest.err -o $has_option = "no"; then
+       AC_MSG_RESULT(no)
+   else
+       AC_MSG_RESULT(yes)
+       COMPILER_FLAGS="$COMPILER_FLAGS $1"
+   fi
+   CFLAGS="$ac_save_CFLAGS"
+   rm -f conftest*
  ])
 
 
+dnl
+dnl Taken from gnome-common/macros2/gnome-compiler-flags.m4
+dnl
+dnl We've added:
+dnl   -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Winline -Wredundant-decls
+dnl We've removed
+dnl   CFLAGS="$realsave_CFLAGS"
+dnl   to avoid clobbering user-specified CFLAGS
+dnl
+AC_DEFUN([GTK_VNC_COMPILE_WARNINGS],[
+    dnl ******************************
+    dnl More compiler warnings
+    dnl ******************************
+
+    AC_ARG_ENABLE(compile-warnings,
+                  AC_HELP_STRING([--enable-compile-warnings=@<:@no/minimum/yes/maximum/error@:>@],
+                                 [Turn on compiler warnings]),,
+                  [enable_compile_warnings="m4_default([$1],[maximum])"])
+
+    warnCFLAGS=
+
+    common_flags="-Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fasynchronous-unwind-tables"
+
+    case "$enable_compile_warnings" in
+    no)
+        try_compiler_flags=""
+	;;
+    minimum)
+	try_compiler_flags="-Wall -Wformat -Wformat-security $common_flags"
+	;;
+    yes)
+	try_compiler_flags="-Wall -Wformat -Wformat-security -Wmissing-prototypes $common_flags"
+	;;
+    maximum|error)
+	try_compiler_flags="-Wall -Wformat -Wformat-security -Wmissing-prototypes -Wnested-externs -Wpointer-arith"
+	try_compiler_flags="$try_compiler_flags -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return"
+	dnl XXX disabled strict-prototypes due  to bug in gtk header files
+	dnl /usr/include/gtk-2.0/gtk/gtkitemfactory.h:47: warning: function declaration isnâ??t a prototype
+	dnl try_compiler_flags="$try_compiler_flags -Wstrict-prototypes -Winline -Wredundant-decls -Wno-sign-compare"
+	try_compiler_flags="$try_compiler_flags -Winline -Wredundant-decls -Wno-sign-compare"
+	try_compiler_flags="$try_compiler_flags $common_flags"
+	if test "$enable_compile_warnings" = "error" ; then
+	    try_compiler_flags="$try_compiler_flags -Werror"
+	fi
+	;;
+    *)
+	AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
+	;;
+    esac
+
+    COMPILER_FLAGS=
+    for option in $try_compiler_flags; do
+        gl_COMPILER_FLAGS($option)
+    done
+    unset option
+    unset try_compiler_flags
+
+    AC_ARG_ENABLE(iso-c,
+                  AC_HELP_STRING([--enable-iso-c],
+                                 [Try to warn if code is not ISO C ]),,
+                  [enable_iso_c=no])
+
+    AC_MSG_CHECKING(what language compliance flags to pass to the C compiler)
+    complCFLAGS=
+    if test "x$enable_iso_c" != "xno"; then
+	if test "x$GCC" = "xyes"; then
+	case " $CFLAGS " in
+	    *[\ \	]-ansi[\ \	]*) ;;
+	    *) complCFLAGS="$complCFLAGS -ansi" ;;
+	esac
+	case " $CFLAGS " in
+	    *[\ \	]-pedantic[\ \	]*) ;;
+	    *) complCFLAGS="$complCFLAGS -pedantic" ;;
+	esac
+	fi
+    fi
+    AC_MSG_RESULT($complCFLAGS)
+
+    WARNING_CFLAGS="$COMPILER_FLAGS $complCFLAGS"
+    AC_SUBST(WARNING_CFLAGS)
+
+    dnl Needed to keep compile quiet on python 2.4
+    COMPILER_FLAGS=
+    gl_COMPILER_FLAGS(-Wno-redundant-decls)
+    WARNING_PYTHON_CFLAGS=$COMPILER_FLAGS
+    AC_SUBST(WARNING_PYTHON_CFLAGS)
+])
+
+
 dnl a macro to check for ability to create python extensions
 dnl  AM_CHECK_PYTHON_HEADERS([ACTION-IF-POSSIBLE], [ACTION-IF-NOT-POSSIBLE])
 dnl function also defines PYTHON_INCLUDES
diff --git a/autobuild.sh b/autobuild.sh
index c900fc6..be26d07 100755
--- a/autobuild.sh
+++ b/autobuild.sh
@@ -10,7 +10,8 @@ rm -rf build
 mkdir build
 cd build
 
-../autogen.sh --prefix=$AUTOBUILD_INSTALL_ROOT --enable-fatal-warnings
+../autogen.sh --prefix=$AUTOBUILD_INSTALL_ROOT \
+    --enable-compile-warnings=error
 
 make
 make install
diff --git a/configure.ac b/configure.ac
index 19e4c63..7f50883 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1,21 +1,21 @@
 dnl Process this file with autoconf to produce a configure script.
 
-AC_INIT([gtk-vnc], [0.3.9], [anthony codemonkey ws])
+AC_INIT([gtk-vnc], [0.3.9])
 AC_CONFIG_SRCDIR([src/gvnc.c])
+AC_CONFIG_AUX_DIR([build-aux])
+AM_CONFIG_HEADER([config.h])
+dnl Make automake keep quiet about wildcards & other GNUmake-isms
+AM_INIT_AUTOMAKE([-Wno-portability])
 
-#*******************************************************************************
-# Internationalization
-#*******************************************************************************
-GETTEXT_PACKAGE=gtk-vnc
-AC_SUBST(GETTEXT_PACKAGE)
-AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [GETTEXT package name])
+# Use the silent-rules feature when possible.
+m4_ifndef([AM_SILENT_RULES], [m4_define([AM_SILENT_RULES],[])])
+AM_SILENT_RULES([yes])
 
-IT_PROG_INTLTOOL([0.35.0])
-AM_GLIB_GNU_GETTEXT
+AC_CANONICAL_HOST
 
-#*******************************************************************************
-# Check required libraries
-#*******************************************************************************
+dnl *******************************************************************************
+dnl Declare required library versions
+dnl *******************************************************************************
 
 GTK_REQUIRED=2.10.0
 AC_SUBST(GTK_REQUIRED)
@@ -31,12 +31,9 @@ NSPR_REQUIRED=4.0.0
 FIREFOX_PLUGIN_REQUIRED=2.0.0
 MOZILLA_PLUGIN_REQUIRED=1.8
 
-AC_CONFIG_HEADERS([config.h:config.hin])
-
-AC_CANONICAL_TARGET
-
-AM_INIT_AUTOMAKE(gtk-vnc, 0.3.9)
-
+dnl *******************************************************************************
+dnl Setup GNULIB - must be before anything else in this file
+dnl *******************************************************************************
 
 dnl gl_INIT uses m4_foreach_w, yet that is not defined in autoconf-2.59.
 dnl In order to accommodate developers with such old tools, here's a
@@ -48,12 +45,29 @@ m4_ifndef([m4_foreach_w],
 gl_EARLY
 gl_INIT
 
+dnl *******************************************************************************
+dnl Setup core compilers / build helpers
+dnl *******************************************************************************
+
 AC_PROG_CC_STDC
 AM_PROG_CC_C_O
-AC_LIBTOOL_WIN32_DLL
 
+AC_LIBTOOL_WIN32_DLL
 AC_PROG_LIBTOOL
 
+dnl *******************************************************************************
+dnl Internationalization
+dnl *******************************************************************************
+GETTEXT_PACKAGE=gtk-vnc
+AC_SUBST(GETTEXT_PACKAGE)
+AC_DEFINE_UNQUOTED(GETTEXT_PACKAGE,"$GETTEXT_PACKAGE", [GETTEXT package name])
+
+IT_PROG_INTLTOOL([0.35.0])
+AM_GLIB_GNU_GETTEXT
+
+dnl *******************************************************************************
+
+
 AC_CHECK_HEADERS([pwd.h winsock2.h])
 
 AC_ARG_WITH(python,
@@ -65,44 +79,7 @@ AC_ARG_WITH(python,
 
 WITH_PYTHON=$withval
 
-AC_ARG_ENABLE(fatal-warnings,
-[  --enable-fatal-warnings make all compiler warnings fatal (not recommended)],
-[case "${enableval}" in
-   yes|no) ;;
-   *)      AC_MSG_ERROR([bad value ${enableval} for fatal-warnings option]) ;;
- esac],
-              [enableval=no])
-if test "${enableval}" = yes; then
-  gl_COMPILER_FLAGS(-Werror)
-  AC_SUBST([WERROR_CFLAGS], [$COMPILER_FLAGS])
-  COMPILER_FLAGS=
-fi
-
-AC_ARG_ENABLE(warnings,
-[  --enable-warnings       turn on lots of compiler warnings (recommended)],
-[case "${enableval}" in
-   yes|no) ;;
-   *)      AC_MSG_ERROR([bad value ${enableval} for warnings option]) ;;
- esac],
-              [enableval=no])
-
-if test "${enableval}" = yes; then
-  gl_COMPILER_FLAGS(-W)
-  gl_COMPILER_FLAGS(-Wall)
-  gl_COMPILER_FLAGS(-Wcast-align)
-  gl_COMPILER_FLAGS(-Wformat)
-  gl_COMPILER_FLAGS(-Wwrite-strings)
-  AC_SUBST([WARNING_CXXFLAGS], [$COMPILER_FLAGS])
-  # The following warnings are not suitable for C++.
-  gl_COMPILER_FLAGS(-Wbad-function-cast)
-  gl_COMPILER_FLAGS(-Wmissing-declarations)
-  gl_COMPILER_FLAGS(-Wmissing-prototypes)
-  gl_COMPILER_FLAGS(-Wshadow)
-  # gl_COMPILER_FLAGS(-Wstrict-prototypes)
-  AC_SUBST([WARNING_CFLAGS], [$COMPILER_FLAGS])
-  AC_DEFINE([lint], 1, [Define to 1 if the compiler is checking for lint.])
-  COMPILER_FLAGS=
-fi
+GTK_VNC_COMPILE_WARNINGS
 
 AC_ARG_WITH(examples,
 [  --with-examples         install example programs],
diff --git a/src/Makefile.am b/src/Makefile.am
index 31c4600..3d60df5 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -51,10 +51,8 @@ if WITH_PYTHON
 pyexec_LTLIBRARIES = gtkvnc.la
 
 gtkvnc_la_LIBADD = libgtk-vnc-1.0.la @PYGTK_LIBS@
-# Auto-generated C code for Python binding is full of compiler warnings :-(
-#gtkvnc_la_CFLAGS = @GTK_CFLAGS@ @WARNING_CFLAGS@ @PYTHON_INCLUDES@ @PYGTK_CFLAGS@
 gtkvnc_la_CFLAGS = @GTK_CFLAGS@ @PYTHON_INCLUDES@ \
-		   @PYGTK_CFLAGS@
+		   @PYGTK_CFLAGS@ @WARNING_PYTHON_CFLAGS@
 gtkvnc_la_LDFLAGS = -module -avoid-version -fPIC
 gtkvnc_la_SOURCES = vncmodule.c vncmodule.defs.c
 



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]