[PATCH] Add option to control compiler warnings for gcc

Anton Lundin glance at acc.umu.se
Tue Jan 6 14:28:39 PST 2015


This adds a configure option, --enable-gcc-compile-warnings which
controls which CFLAGS to pass to gcc. It defaults to -Wall but can with
the configure argument be turned to different levels.

Signed-off-by: Anton Lundin <glance at acc.umu.se>
---

I think i kinda over-did-it, but hey.

I had something quite close laying around from another project so i picked
the whole thingie.

 configure.ac         | 26 ++++++++++++++++++++++++++
 examples/Makefile.am |  2 +-
 src/Makefile.am      |  2 +-
 3 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/configure.ac b/configure.ac
index 047b3f0..78de1df 100644
--- a/configure.ac
+++ b/configure.ac
@@ -28,6 +28,32 @@ LT_PREREQ([2.2.0])
 LT_INIT([win32-dll])
 LT_PROG_RC
 
+# If were running gcc, give the option for some warnings, and enable -Wall by default
+WARNING_CFLAGS=""
+AC_ARG_ENABLE([gcc-compile-warnings],
+	[AS_HELP_STRING([--enable-gcc-compile-warnings=@<:@no/yes/maximum/error@:>@],
+		[Turn on compiler warnings @<:@default=yes@:>@])],
+	[case "$enableval" in
+		no)
+			;;
+		'' | yes)
+			WARNING_CFLAGS="-Wall"
+			;;
+		maximum)
+			WARNING_CFLAGS="-Wall -Wextra -pedantic"
+			;;
+		error)
+			WARNING_CFLAGS="-Wall -Werror -Wextra -pedantic"
+			;;
+		*)
+			AC_MSG_ERROR([Unknown argument '$enableval' to --enable-gcc-compile-warnings])
+			;;
+	esac],
+	[WARNING_CFLAGS="-Wall"])
+AS_IF([test "x$GCC" = "xyes"], [
+	AC_SUBST([WARNING_CFLAGS])
+])
+
 # Logging support.
 AC_ARG_ENABLE([logging],
 	[AS_HELP_STRING([--enable-logging=@<:@yes/no@:>@],
diff --git a/examples/Makefile.am b/examples/Makefile.am
index d77db45..32a5e72 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -1,4 +1,4 @@
-AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
+AM_CPPFLAGS = $(WARNING_CFLAGS) -I$(top_builddir)/include -I$(top_srcdir)/include
 LDADD = $(top_builddir)/src/libdivecomputer.la
 
 bin_PROGRAMS = \
diff --git a/src/Makefile.am b/src/Makefile.am
index 821bc1b..1c110b8 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,5 +1,5 @@
 AM_CPPFLAGS = -I$(top_builddir)/include -I$(top_srcdir)/include
-AM_CFLAGS = $(LIBUSB_CFLAGS)
+AM_CFLAGS = $(WARNING_CFLAGS) $(LIBUSB_CFLAGS)
 
 lib_LTLIBRARIES = libdivecomputer.la
 
-- 
2.1.0



More information about the devel mailing list