blob: d2c726800581abde7348507f51e7541d20409a95 [file] [log] [blame]
Brad Bishop1a4b7ee2018-12-16 17:11:34 -08001From b0a64db90a24469e36978c748417ebe456b34d59 Mon Sep 17 00:00:00 2001
Brad Bishop6e60e8b2018-02-01 10:27:11 -05002From: Khem Raj <raj.khem@gmail.com>
3Date: Sat, 22 Apr 2017 11:54:57 -0700
4Subject: [PATCH] configure: Check for -Wno-error=format-truncation compiler
5 option
6
7If this option is supported by compiler then disable it ( gcc7+)
Brad Bishopd7bf8c12018-02-25 22:55:05 -05008Use -Werror to elevate the warning to an error in case compiler like clang
9which warn about unknown options but not error out unless asked for
10
Brad Bishop6e60e8b2018-02-01 10:27:11 -050011Fixes
12client.c:834:23: error: '%s' directive output may be truncated writing up to 1023 bytes into a region of size 1010 [-Werror=format-truncation=]
13
14Signed-off-by: Khem Raj <raj.khem@gmail.com>
Brad Bishopd7bf8c12018-02-25 22:55:05 -050015
Brad Bishop6e60e8b2018-02-01 10:27:11 -050016---
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080017 configure.ac | 1 +
18 m4/ax_check_compile_flag.m4 | 74 +++++++++++++++++++++++++++++++++++++
19 2 files changed, 75 insertions(+)
Brad Bishop6e60e8b2018-02-01 10:27:11 -050020 create mode 100644 m4/ax_check_compile_flag.m4
21
22diff --git a/configure.ac b/configure.ac
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080023index a7eca97d..560eb988 100644
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024--- a/configure.ac
25+++ b/configure.ac
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080026@@ -6794,6 +6794,7 @@ if test "x$enable_werror" != "xno"; then
27 AM_CFLAGS="$AM_CFLAGS -Werror"
28 AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -050030+AX_CHECK_COMPILE_FLAG([-Werror -Werror=format-truncation],[AM_CFLAGS="$AM_CFLAGS -Wno-error=format-truncation" AM_CXXFLAGS="$AM_CXXFLAGS -Wno-error=format-truncation"])
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080031
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032 AC_SUBST([AM_CFLAGS])
33 AC_SUBST([AM_CXXFLAGS])
Brad Bishop6e60e8b2018-02-01 10:27:11 -050034diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4
35new file mode 100644
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080036index 00000000..dcabb92a
Brad Bishop6e60e8b2018-02-01 10:27:11 -050037--- /dev/null
38+++ b/m4/ax_check_compile_flag.m4
39@@ -0,0 +1,74 @@
40+# ===========================================================================
41+# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
42+# ===========================================================================
43+#
44+# SYNOPSIS
45+#
46+# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
47+#
48+# DESCRIPTION
49+#
50+# Check whether the given FLAG works with the current language's compiler
51+# or gives an error. (Warnings, however, are ignored)
52+#
53+# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
54+# success/failure.
55+#
56+# If EXTRA-FLAGS is defined, it is added to the current language's default
57+# flags (e.g. CFLAGS) when the check is done. The check is thus made with
58+# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
59+# force the compiler to issue an error when a bad flag is given.
60+#
61+# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
62+#
63+# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
64+# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
65+#
66+# LICENSE
67+#
68+# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
69+# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
70+#
71+# This program is free software: you can redistribute it and/or modify it
72+# under the terms of the GNU General Public License as published by the
73+# Free Software Foundation, either version 3 of the License, or (at your
74+# option) any later version.
75+#
76+# This program is distributed in the hope that it will be useful, but
77+# WITHOUT ANY WARRANTY; without even the implied warranty of
78+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
79+# Public License for more details.
80+#
81+# You should have received a copy of the GNU General Public License along
82+# with this program. If not, see <https://www.gnu.org/licenses/>.
83+#
84+# As a special exception, the respective Autoconf Macro's copyright owner
85+# gives unlimited permission to copy, distribute and modify the configure
86+# scripts that are the output of Autoconf when processing the Macro. You
87+# need not follow the terms of the GNU General Public License when using
88+# or distributing such scripts, even though portions of the text of the
89+# Macro appear in them. The GNU General Public License (GPL) does govern
90+# all other use of the material that constitutes the Autoconf Macro.
91+#
92+# This special exception to the GPL applies to versions of the Autoconf
93+# Macro released by the Autoconf Archive. When you make and distribute a
94+# modified version of the Autoconf Macro, you may extend this special
95+# exception to the GPL to apply to your modified version as well.
96+
97+#serial 5
98+
99+AC_DEFUN([AX_CHECK_COMPILE_FLAG],
100+[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
101+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
102+AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
103+ ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
104+ _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
105+ AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
106+ [AS_VAR_SET(CACHEVAR,[yes])],
107+ [AS_VAR_SET(CACHEVAR,[no])])
108+ _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
109+AS_VAR_IF(CACHEVAR,yes,
110+ [m4_default([$2], :)],
111+ [m4_default([$3], :)])
112+AS_VAR_POPDEF([CACHEVAR])dnl
113+])dnl AX_CHECK_COMPILE_FLAGS