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

Add lots of warning flags to CFLAGS [was Re: [Libvir] Remote patch, 2007-02-28]



On Thu, 2007-03-01 at 12:20 +0000, Mark McLoughlin wrote:

> >  dnl
> >  dnl make CFLAGS very pedantic at least during the devel phase for everybody
> > +dnl (Overriding $CFLAGS here is very wrong.  See discussion of AM_CFLAGS
> > +dnl in the automake info. - RWMJ)
> >  dnl
> >      if test "${GCC}" = "yes" ; then
> >         CFLAGS="-g -O -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wall"
> 
> 	I'll fix this ... patch incoming soon.

	Okay, here's a patch which adds a LIBVIRT_COMPILE_WARNINGS autoconf
macro from GNOME which I've always found very, very useful.

	I've changed it to include all the flags we were using.

	The brilliant thing about this is that you can choose, while hacking,
to build with --enable-compile-warnings=error if you want to use -Werror
to catch any warnings you've introduced.

Cheers,
Mark.
Index: libvirt/configure.in
===================================================================
--- libvirt.orig/configure.in	2007-02-23 12:50:58.000000000 +0000
+++ libvirt.orig/configure.in	2007-02-23 12:50:58.000000000 +0000
@@ -50,6 +50,8 @@ test "x$U" != "x" && AC_MSG_ERROR(Compil
 
 AM_PROG_LIBTOOL
 
+LIBVIRT_COMPILE_WARNINGS(maximum)
+
 dnl Specific dir for HTML output ?
 AC_ARG_WITH(html-dir, AC_HELP_STRING([--with-html-dir=path],
             [path to base html directory, default $datadir/doc/html]),
@@ -75,7 +77,7 @@ dnl
 dnl make CFLAGS very pedantic at least during the devel phase for everybody
 dnl
     if test "${GCC}" = "yes" ; then
-	CFLAGS="-g -O -W -Wformat -Wunused -Wimplicit -Wreturn-type -Wswitch -Wcomment -Wtrigraphs -Wformat -Wchar-subscripts -Wuninitialized -Wparentheses -Wshadow -Wpointer-arith -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Wmissing-prototypes -Wnested-externs -Winline -Wredundant-decls -Wall"
+	CFLAGS="-Wshadow -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Winline -Wredundant-decls"
     fi
 
 dnl --enable-debug=(yes|no)
Index: libvirt/proxy/Makefile.am
===================================================================
--- libvirt.orig/proxy/Makefile.am	2006-09-21 16:24:37.000000000 +0100
+++ libvirt.orig/proxy/Makefile.am	2006-09-21 16:24:37.000000000 +0100
@@ -3,7 +3,7 @@
 INCLUDES = -I$(top_builddir)/include -I top_srcdir@/include \
            -I top_srcdir@/proxy -I top_srcdir@/src @LIBXML_CFLAGS@ \
 	   -DPROXY  -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
-           -DGETTEXT_PACKAGE=\"$(PACKAGE)\"
+           -DGETTEXT_PACKAGE=\"$(PACKAGE)\" $(WARN_CFLAGS)
 
 libexec_PROGRAMS = libvirt_proxy
 
Index: libvirt/python/Makefile.am
===================================================================
--- libvirt.orig/python/Makefile.am	2006-02-28 14:22:33.000000000 +0000
+++ libvirt.orig/python/Makefile.am	2006-02-28 14:22:33.000000000 +0000
@@ -3,6 +3,7 @@
 SUBDIRS= . tests
 
 INCLUDES = \
+        $(WARN_CFLAGS) \
         -I$(PYTHON_INCLUDES) \
 	-I$(top_srcdir)/include \
 	-I$(top_builddir)/include \
Index: libvirt/qemud/Makefile.am
===================================================================
--- libvirt.orig/qemud/Makefile.am	2007-02-26 15:32:27.000000000 +0000
+++ libvirt.orig/qemud/Makefile.am	2007-02-26 15:32:27.000000000 +0000
@@ -14,7 +14,7 @@ libvirt_qemud_SOURCES = qemud.c internal
 #-D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED=1 -D_POSIX_C_SOURCE=199506L
 libvirt_qemud_CFLAGS = \
         -I$(top_srcdir)/include -I$(top_builddir)/include $(LIBXML_CFLAGS) \
-        -Wall -Wextra -DLOCAL_STATE_DIR="\"$(localstatedir)\"" \
+        $(WARN_CFLAGS) -DLOCAL_STATE_DIR="\"$(localstatedir)\"" \
         -DSYSCONF_DIR="\"$(sysconfdir)\""
 libvirt_qemud_LDFLAGS = $(LIBXML_LIBS) $(SYSFS_LIBS)
 libvirt_qemud_DEPENDENCIES =
Index: libvirt/src/Makefile.am
===================================================================
--- libvirt.orig/src/Makefile.am	2007-02-23 12:46:35.000000000 +0000
+++ libvirt.orig/src/Makefile.am	2007-02-23 12:46:35.000000000 +0000
@@ -3,7 +3,7 @@
 INCLUDES = -I$(top_builddir)/include -I top_srcdir@/include @LIBXML_CFLAGS@ -I top_srcdir@/qemud \
 	   -DBINDIR=\""$(libexecdir)"\" -DSBINDIR=\""$(sbindir)"\" -DLOCALEBASEDIR=\""$(datadir)/locale"\" \
            -DLOCAL_STATE_DIR=\""$(localstatedir)"\" \
-           -DGETTEXT_PACKAGE=\"$(PACKAGE)\"
+           -DGETTEXT_PACKAGE=\"$(PACKAGE)\" $(WARN_CFLAGS)
 DEPS = libvirt.la
 LDADDS = @STATIC_BINARIES@ libvirt.la
 VIRSH_LIBS = @VIRSH_LIBS@
Index: libvirt/tests/Makefile.am
===================================================================
--- libvirt.orig/tests/Makefile.am	2007-02-16 16:56:47.000000000 +0000
+++ libvirt.orig/tests/Makefile.am	2007-02-16 16:56:47.000000000 +0000
@@ -18,7 +18,8 @@ INCLUDES = \
 	@LIBXML_CFLAGS@ \
         -D_XOPEN_SOURCE=600 -D_POSIX_C_SOURCE=199506L \
         -DGETTEXT_PACKAGE=\"$(PACKAGE)\" \
-         $(COVERAGE_CFLAGS)
+         $(COVERAGE_CFLAGS) \
+         $(WARN_CFLAGS)
 
 LDADDS = \
 	@STATIC_BINARIES@ \
Index: libvirt/acinclude.m4
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ /dev/null	1970-01-01 00:00:00.000000000 +0000
@@ -0,0 +1,90 @@
+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
+AC_DEFUN([LIBVIRT_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],[yes])"])
+
+    warnCFLAGS=
+    if test "x$GCC" != xyes; then
+	enable_compile_warnings=no
+    fi
+
+    warning_flags=
+    realsave_CFLAGS="$CFLAGS"
+
+    case "$enable_compile_warnings" in
+    no)
+	warning_flags=
+	;;
+    minimum)
+	warning_flags="-Wall"
+	;;
+    yes)
+	warning_flags="-Wall -Wmissing-prototypes"
+	;;
+    maximum|error)
+	warning_flags="-Wall -Wmissing-prototypes -Wnested-externs -Wpointer-arith"
+        warning_flags="$warning_flags -Wextra -Wshadow -Wcast-align -Wwrite-strings -Waggregate-return -Wstrict-prototypes -Winline -Wredundant-decls"
+	CFLAGS="$warning_flags $CFLAGS"
+	for option in -Wno-sign-compare; do
+		SAVE_CFLAGS="$CFLAGS"
+		CFLAGS="$CFLAGS $option"
+		AC_MSG_CHECKING([whether gcc understands $option])
+		AC_TRY_COMPILE([], [],
+			has_option=yes,
+			has_option=no,)
+		CFLAGS="$SAVE_CFLAGS"
+		AC_MSG_RESULT($has_option)
+		if test $has_option = yes; then
+		  warning_flags="$warning_flags $option"
+		fi
+		unset has_option
+		unset SAVE_CFLAGS
+	done
+	unset option
+	if test "$enable_compile_warnings" = "error" ; then
+	    warning_flags="$warning_flags -Werror"
+	fi
+	;;
+    *)
+	AC_MSG_ERROR(Unknown argument '$enable_compile_warnings' to --enable-compile-warnings)
+	;;
+    esac
+    CFLAGS="$realsave_CFLAGS"
+    AC_MSG_CHECKING(what warning flags to pass to the C compiler)
+    AC_MSG_RESULT($warning_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)
+
+    WARN_CFLAGS="$warning_flags $complCFLAGS"
+    AC_SUBST(WARN_CFLAGS)
+])

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