1*4882a593SmuzhiyunFrom c0f075bdee5edabf8f19b68e0880fbd249a89653 Mon Sep 17 00:00:00 2001
2*4882a593SmuzhiyunFrom: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
3*4882a593SmuzhiyunDate: Sat, 3 Jan 2015 15:09:59 +0100
4*4882a593SmuzhiyunSubject: [PATCH] Add test for -Wunused-but-set-variable
5*4882a593Smuzhiyun
6*4882a593SmuzhiyunThe -Wunused-but-set-variable option does not exist in some old gcc
7*4882a593Smuzhiyunversions (gcc 4.5.x), so using it unconditionally breaks the build
8*4882a593Smuzhiyunwith such compilers.
9*4882a593Smuzhiyun
10*4882a593SmuzhiyunThis commit introduces the AX_CHECK_COMPILE_FLAG m4 macro taken from
11*4882a593Smuzhiyunthe autoconf-archive
12*4882a593Smuzhiyun(http://git.savannah.gnu.org/gitweb/?p=autoconf-archive.git;a=blob_plain;f=m4/ax_check_compile_flag.m4),
13*4882a593Smuzhiyunand uses it to detect if the -Wunused-but-set-variable option is
14*4882a593Smuzhiyunsupported, and only uses it in this case.
15*4882a593Smuzhiyun
16*4882a593SmuzhiyunSigned-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
17*4882a593Smuzhiyun(rebased against v0.1.0)
18*4882a593SmuzhiyunSigned-off-by: Bernd Kuhls <bernd.kuhls@t-online.de>
19*4882a593Smuzhiyun(rebased against v0.6.3)
20*4882a593SmuzhiyunSigned-off-by: Adam Duskett <Aduskett@gmail.com>
21*4882a593Smuzhiyun---
22*4882a593Smuzhiyun Makefile.am                 |  1 +
23*4882a593Smuzhiyun configure.ac                |  6 ++-
24*4882a593Smuzhiyun m4/ax_check_compile_flag.m4 | 74 +++++++++++++++++++++++++++++++++++++
25*4882a593Smuzhiyun 3 files changed, 79 insertions(+), 2 deletions(-)
26*4882a593Smuzhiyun create mode 100644 m4/ax_check_compile_flag.m4
27*4882a593Smuzhiyun
28*4882a593Smuzhiyundiff --git a/Makefile.am b/Makefile.am
29*4882a593Smuzhiyunindex f961fdb..3ddbe59 100644
30*4882a593Smuzhiyun--- a/Makefile.am
31*4882a593Smuzhiyun+++ b/Makefile.am
32*4882a593Smuzhiyun@@ -151,6 +151,7 @@ janus_CFLAGS = \
33*4882a593Smuzhiyun 	-DEVENTDIR=\"$(eventdir)\" \
34*4882a593Smuzhiyun 	-DLOGGERDIR=\"$(loggerdir)\" \
35*4882a593Smuzhiyun 	-DCONFDIR=\"$(confdir)\" \
36*4882a593Smuzhiyun+	@GCC_WARN_UNUSED_BUT_SET@ \
37*4882a593Smuzhiyun 	$(BORINGSSL_CFLAGS) \
38*4882a593Smuzhiyun 	$(NULL)
39*4882a593Smuzhiyun
40*4882a593Smuzhiyundiff --git a/configure.ac b/configure.ac
41*4882a593Smuzhiyunindex ca17a29..beef91a 100644
42*4882a593Smuzhiyun--- a/configure.ac
43*4882a593Smuzhiyun+++ b/configure.ac
44*4882a593Smuzhiyun@@ -13,6 +13,9 @@ AM_SILENT_RULES([yes])
45*4882a593Smuzhiyun AC_USE_SYSTEM_EXTENSIONS
46*4882a593Smuzhiyun
47*4882a593Smuzhiyun AC_PROG_CC
48*4882a593Smuzhiyun+AX_CHECK_COMPILE_FLAG([-Wunused-but-set-variable],
49*4882a593Smuzhiyun+	[GCC_WARN_UNUSED_BUT_SET=-Wunused-but-set-variable])
50*4882a593Smuzhiyun+AC_SUBST(GCC_WARN_UNUSED_BUT_SET)
51*4882a593Smuzhiyun
52*4882a593Smuzhiyun LT_PREREQ([2.2])
53*4882a593Smuzhiyun LT_INIT
54*4882a593Smuzhiyun@@ -64,8 +67,7 @@ clang*)
55*4882a593Smuzhiyun 	CFLAGS="$CFLAGS \
56*4882a593Smuzhiyun 		-Wcast-align \
57*4882a593Smuzhiyun 		-Wno-override-init \
58*4882a593Smuzhiyun-		-Wunsafe-loop-optimizations \
59*4882a593Smuzhiyun-		-Wunused-but-set-variable"
60*4882a593Smuzhiyun+		-Wunsafe-loop-optimizations"
61*4882a593Smuzhiyun esac
62*4882a593Smuzhiyun
63*4882a593Smuzhiyun JANUS_VERSION=103
64*4882a593Smuzhiyundiff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4
65*4882a593Smuzhiyunnew file mode 100644
66*4882a593Smuzhiyunindex 0000000..51df0c0
67*4882a593Smuzhiyun--- /dev/null
68*4882a593Smuzhiyun+++ b/m4/ax_check_compile_flag.m4
69*4882a593Smuzhiyun@@ -0,0 +1,74 @@
70*4882a593Smuzhiyun+# ===========================================================================
71*4882a593Smuzhiyun+#   http://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
72*4882a593Smuzhiyun+# ===========================================================================
73*4882a593Smuzhiyun+#
74*4882a593Smuzhiyun+# SYNOPSIS
75*4882a593Smuzhiyun+#
76*4882a593Smuzhiyun+#   AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
77*4882a593Smuzhiyun+#
78*4882a593Smuzhiyun+# DESCRIPTION
79*4882a593Smuzhiyun+#
80*4882a593Smuzhiyun+#   Check whether the given FLAG works with the current language's compiler
81*4882a593Smuzhiyun+#   or gives an error.  (Warnings, however, are ignored)
82*4882a593Smuzhiyun+#
83*4882a593Smuzhiyun+#   ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
84*4882a593Smuzhiyun+#   success/failure.
85*4882a593Smuzhiyun+#
86*4882a593Smuzhiyun+#   If EXTRA-FLAGS is defined, it is added to the current language's default
87*4882a593Smuzhiyun+#   flags (e.g. CFLAGS) when the check is done.  The check is thus made with
88*4882a593Smuzhiyun+#   the flags: "CFLAGS EXTRA-FLAGS FLAG".  This can for example be used to
89*4882a593Smuzhiyun+#   force the compiler to issue an error when a bad flag is given.
90*4882a593Smuzhiyun+#
91*4882a593Smuzhiyun+#   INPUT gives an alternative input source to AC_COMPILE_IFELSE.
92*4882a593Smuzhiyun+#
93*4882a593Smuzhiyun+#   NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
94*4882a593Smuzhiyun+#   macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
95*4882a593Smuzhiyun+#
96*4882a593Smuzhiyun+# LICENSE
97*4882a593Smuzhiyun+#
98*4882a593Smuzhiyun+#   Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
99*4882a593Smuzhiyun+#   Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
100*4882a593Smuzhiyun+#
101*4882a593Smuzhiyun+#   This program is free software: you can redistribute it and/or modify it
102*4882a593Smuzhiyun+#   under the terms of the GNU General Public License as published by the
103*4882a593Smuzhiyun+#   Free Software Foundation, either version 3 of the License, or (at your
104*4882a593Smuzhiyun+#   option) any later version.
105*4882a593Smuzhiyun+#
106*4882a593Smuzhiyun+#   This program is distributed in the hope that it will be useful, but
107*4882a593Smuzhiyun+#   WITHOUT ANY WARRANTY; without even the implied warranty of
108*4882a593Smuzhiyun+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
109*4882a593Smuzhiyun+#   Public License for more details.
110*4882a593Smuzhiyun+#
111*4882a593Smuzhiyun+#   You should have received a copy of the GNU General Public License along
112*4882a593Smuzhiyun+#   with this program. If not, see <http://www.gnu.org/licenses/>.
113*4882a593Smuzhiyun+#
114*4882a593Smuzhiyun+#   As a special exception, the respective Autoconf Macro's copyright owner
115*4882a593Smuzhiyun+#   gives unlimited permission to copy, distribute and modify the configure
116*4882a593Smuzhiyun+#   scripts that are the output of Autoconf when processing the Macro. You
117*4882a593Smuzhiyun+#   need not follow the terms of the GNU General Public License when using
118*4882a593Smuzhiyun+#   or distributing such scripts, even though portions of the text of the
119*4882a593Smuzhiyun+#   Macro appear in them. The GNU General Public License (GPL) does govern
120*4882a593Smuzhiyun+#   all other use of the material that constitutes the Autoconf Macro.
121*4882a593Smuzhiyun+#
122*4882a593Smuzhiyun+#   This special exception to the GPL applies to versions of the Autoconf
123*4882a593Smuzhiyun+#   Macro released by the Autoconf Archive. When you make and distribute a
124*4882a593Smuzhiyun+#   modified version of the Autoconf Macro, you may extend this special
125*4882a593Smuzhiyun+#   exception to the GPL to apply to your modified version as well.
126*4882a593Smuzhiyun+
127*4882a593Smuzhiyun+#serial 3
128*4882a593Smuzhiyun+
129*4882a593Smuzhiyun+AC_DEFUN([AX_CHECK_COMPILE_FLAG],
130*4882a593Smuzhiyun+[AC_PREREQ(2.59)dnl for _AC_LANG_PREFIX
131*4882a593Smuzhiyun+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
132*4882a593Smuzhiyun+AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
133*4882a593Smuzhiyun+  ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
134*4882a593Smuzhiyun+  _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
135*4882a593Smuzhiyun+  AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
136*4882a593Smuzhiyun+    [AS_VAR_SET(CACHEVAR,[yes])],
137*4882a593Smuzhiyun+    [AS_VAR_SET(CACHEVAR,[no])])
138*4882a593Smuzhiyun+  _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
139*4882a593Smuzhiyun+AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
140*4882a593Smuzhiyun+  [m4_default([$2], :)],
141*4882a593Smuzhiyun+  [m4_default([$3], :)])
142*4882a593Smuzhiyun+AS_VAR_POPDEF([CACHEVAR])dnl
143*4882a593Smuzhiyun+])dnl AX_CHECK_COMPILE_FLAGS
144*4882a593Smuzhiyun--
145*4882a593Smuzhiyun2.20.1
146*4882a593Smuzhiyun
147