From c0f075bdee5edabf8f19b68e0880fbd249a89653 Mon Sep 17 00:00:00 2001
From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Date: Sat, 3 Jan 2015 15:09:59 +0100
Subject: [PATCH] Add test for -Wunused-but-set-variable
The -Wunused-but-set-variable option does not exist in some old gcc
versions (gcc 4.5.x), so using it unconditionally breaks the build
This commit introduces the AX_CHECK_COMPILE_FLAG m4 macro taken from
(http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_check_compile_flag.m4),
and uses it to detect if the -Wunused-but-set-variable option is
supported, and only uses it in this case.
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Signed-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
m4/ax_check_compile_flag.m4 | 74 +++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 78 insertions(+), 1 deletion(-)
create mode 100644 m4/ax_check_compile_flag.m4
diff --git a/Makefile.am b/Makefile.am
index 5d23e0b..0f51f6a 100644
@@ -6,7 +6,7 @@ AM_CFLAGS = \
-Wnested-externs -Wstrict-prototypes -Wunsafe-loop-optimizations \
-Wwrite-strings -Wno-missing-field-initializers -Wno-unused-parameter \
-Wcast-align -Wformat-nonliteral -Wformat-security -Wswitch-default \
- -Wmissing-include-dirs -Wno-aggregate-return -Wunused-but-set-variable \
+ -Wmissing-include-dirs -Wno-aggregate-return @GCC_WARN_UNUSED_BUT_SET@ \
-Warray-bounds -Wold-style-definition -Wsign-compare -Wlarger-than=65537
AM_CFLAGS += -Wno-undef # sophiasip is not -Wundef--safe
AM_CFLAGS += -Wno-redundant-decls # sophiasip also contains redundant declarations
diff --git a/configure.ac b/configure.ac
index 17870a7..f9bb1e4 100644
@@ -7,6 +7,9 @@ AM_SILENT_RULES([yes])
+AX_CHECK_COMPILE_FLAG([-Wunused-but-set-variable],
+ [GCC_WARN_UNUSED_BUT_SET=-Wunused-but-set-variable])
+AC_SUBST(GCC_WARN_UNUSED_BUT_SET)
diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4
+++ b/m4/ax_check_compile_flag.m4
+# ===========================================================================
+# http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
+# ===========================================================================