[PATCH] build: disable compile warnings from vala code

Zbigniew Jędrzejewski-Szmek zbyszek at in.waw.pl
Tue Sep 7 01:33:24 PDT 2010


In the sprit of https://bugs.freedesktop.org/show_bug.cgi?id=28093.

Short version: use DEFAULT_CFLAGS to store detected cflags, not CFLAGS.
Add -Wno-sign-compare and -Wno-strict-prototypes to vala code.

Long version:
Previously, CFLAGS was used to store default compile options.
Automake manual goes on at length why this should be done differently
http://www.gnu.org/software/hello/manual/automake/Flag-Variables-Ordering.html.

In our case one thing matters: the order of AM_CFLAGS, systemd_CFLAGS and
bare CFLAGS. CFLAGS is always applied by automake last, which means that
it's not possible to pass e.g. -Wno-sign-compare as a compilation flag
for vala generated code in systemd_CFLAGS, because it would be overridden
by CFLAGS anyway.

Following the automake manual, let's add a new variable DEFAULT_CFLAGS,
which is used to store supported flags. They are detected by autoconf.
This variable is then AC_SUBSTed and used to initialize AM_CFLAGS in Makefiles.

Since we test for gcc support for various -Woption flags, I think we should
also test for the -Wno-option flags, so I reused the detection mechanism
for the -Wno-option flags used for vala (in NOWARNING_CFLAGS).

The goal is to remove spurious compile warnings from vala code.
Now -Wno-sign-compare and -Wno-strict-prototypes can be added (despite
-Wsign-compare being present in CFLAGS). This kills of the following warnings
on my system:
In file included from /usr/include/gtk-2.0/gtk/gtk.h:233,
                 from src/systemadm.c:7:
/usr/include/gtk-2.0/gtk/gtkitemfactory.h:47: warning: function declaration isn’t a prototype [-Wstrict-prototypes]
glib-2.0.vapi: In function ‘g_time_local’:
glib-2.0.vapi:2190: warning: declaration of ‘time’ shadows a global declaration [-Wshadow]
/usr/include/time.h:186: warning: shadowed declaration is here [-Wshadow]
glib-2.0.vapi: In function ‘g_time_format’:
glib-2.0.vapi:2202: warning: format not a string literal, format string not checked [-Wformat-nonliteral]
src/systemd-interfaces.c: In function ‘_dbus_properties_get’:
src/systemd-interfaces.c:14760: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
src/systemd-interfaces.c: In function ‘_dbus_properties_properties_changed’:
src/systemd-interfaces.c:14881: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]

After this change the generated binary is identical, so hopefully
nothing is broken :).
---
 Makefile.am      |    7 +++----
 configure.ac     |   13 ++++++++++++-
 m4/attributes.m4 |   20 ++++++++++----------
 3 files changed, 25 insertions(+), 15 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 944b871..8903ba7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -17,6 +17,8 @@
 
 ACLOCAL_AMFLAGS = -I m4
 
+AM_CFLAGS = $(DEFAULT_CFLAGS)
+
 # Dirs of external packages
 dbuspolicydir=@dbuspolicydir@
 dbussessionservicedir=@dbussessionservicedir@
@@ -667,10 +669,7 @@ systemadm_CFLAGS = \
 	$(AM_CFLAGS) \
 	$(DBUSGLIB_CFLAGS) \
 	$(GTK_CFLAGS) \
-	-Wno-unused-variable \
-	-Wno-unused-function \
-	-Wno-shadow \
-	-Wno-format-nonliteral
+	$(NOWARNING_CFLAGS)
 
 systemadm_VALAFLAGS = \
 	--pkg=dbus-glib-1 \
diff --git a/configure.ac b/configure.ac
index ba9bbf8..9a4a5de 100644
--- a/configure.ac
+++ b/configure.ac
@@ -47,7 +47,7 @@ AM_PROG_CC_C_O
 AC_PROG_GCC_TRADITIONAL
 AC_USE_SYSTEM_EXTENSIONS
 
-CC_CHECK_CFLAGS_APPEND([ \
+CC_CHECK_CFLAGS_APPEND([DEFAULT_CFLAGS], [ \
         -pipe \
         -Wall \
         -W \
@@ -86,6 +86,17 @@ CC_CHECK_CFLAGS_APPEND([ \
         -fno-common \
         -fdiagnostics-show-option \
         -fno-strict-aliasing])
+AC_SUBST(DEFAULT_CFLAGS)
+
+CC_CHECK_CFLAGS_APPEND([NOWARNING_CFLAGS], [ \
+	-Wno-unused-variable \
+	-Wno-unused-function \
+	-Wno-shadow \
+	-Wno-format-nonliteral \
+	-Wno-sign-compare \
+	-Wno-strict-prototypes ])
+AC_SUBST(NOWARNING_CFLAGS)
+
 
 LT_PREREQ(2.2)
 LT_INIT
diff --git a/m4/attributes.m4 b/m4/attributes.m4
index 3bf96a3..21171ca 100644
--- a/m4/attributes.m4
+++ b/m4/attributes.m4
@@ -62,22 +62,22 @@ AC_DEFUN([CC_CHECK_CFLAGS], [
     [$2], [$3])
 ])
 
-dnl CC_CHECK_CFLAG_APPEND(FLAG, [action-if-found], [action-if-not-found])
-dnl Check for CFLAG and appends them to CFLAGS if supported
+dnl CC_CHECK_CFLAG_APPEND(VAR, FLAG, [action-if-found], [action-if-not-found])
+dnl Check for CFLAG and appends them to VAR if supported
 AC_DEFUN([CC_CHECK_CFLAG_APPEND], [
-  AC_CACHE_CHECK([if $CC supports $1 flag],
-    AS_TR_SH([cc_cv_cflags_$1]),
-    CC_CHECK_CFLAGS_SILENT([$1]) dnl Don't execute actions here!
+  AC_CACHE_CHECK([if $CC supports $2 flag],
+    AS_TR_SH([cc_cv_cflags_$2]),
+    CC_CHECK_CFLAGS_SILENT([$2]) dnl Don't execute actions here!
   )
 
-  AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$1])[ = xyes],
-    [CFLAGS="$CFLAGS $1"; DEBUG_CFLAGS="$DEBUG_CFLAGS $1"; $2], [$3])
+  AS_IF([eval test x$]AS_TR_SH([cc_cv_cflags_$2])[ = xyes],
+    [AS_VAR_APPEND([$1], [" $2"]); $3], [$4])
 ])
 
-dnl CC_CHECK_CFLAGS_APPEND([FLAG1 FLAG2], [action-if-found], [action-if-not])
+dnl CC_CHECK_CFLAGS_APPEND([VAR], [FLAG1 FLAG2], [action-if-found], [action-if-not])
 AC_DEFUN([CC_CHECK_CFLAGS_APPEND], [
-  for flag in $1; do
-    CC_CHECK_CFLAG_APPEND($flag, [$2], [$3])
+  for flag in $2; do
+    CC_CHECK_CFLAG_APPEND($1, $flag, [$3], [$4])
   done
 ])
 
-- 
1.7.1



More information about the systemd-devel mailing list