blob: 5069a639c1004de2e1a823f24d86cc9ab3c97cae [file] [log] [blame]
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001From b459c55e4968321e5a82272cb39aa69d4054990f 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---
17 configure.ac | 3 +-
18 m4/ax_check_compile_flag.m4 | 74 +++++++++++++++++++++++++++++++++++++++++++++
19 2 files changed, 76 insertions(+), 1 deletion(-)
20 create mode 100644 m4/ax_check_compile_flag.m4
21
22diff --git a/configure.ac b/configure.ac
Brad Bishopd7bf8c12018-02-25 22:55:05 -050023index 8854542..edb8cfb 100644
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024--- a/configure.ac
25+++ b/configure.ac
26@@ -4,7 +4,6 @@ AC_INIT([collectd],[m4_esyscmd(./version-gen.sh)])
27 AC_CONFIG_SRCDIR(src/target_set.c)
28 AC_CONFIG_HEADERS(src/config.h)
29 AC_CONFIG_AUX_DIR([libltdl/config])
30-
31 dnl older automake's default of ARFLAGS=cru is noisy on newer binutils;
32 dnl we don't really need the 'u' even in older toolchains. Then there is
33 dnl older libtool, which spelled it AR_FLAGS
34@@ -6688,6 +6687,8 @@ then
35 AM_CFLAGS="$AM_CFLAGS -Werror"
36 AM_CXXFLAGS="$AM_CXXFLAGS -Werror"
37 fi
Brad Bishopd7bf8c12018-02-25 22:55:05 -050038+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 Bishop6e60e8b2018-02-01 10:27:11 -050039+
40 AC_SUBST([AM_CFLAGS])
41 AC_SUBST([AM_CXXFLAGS])
42
43diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4
44new file mode 100644
45index 0000000..dcabb92
46--- /dev/null
47+++ b/m4/ax_check_compile_flag.m4
48@@ -0,0 +1,74 @@
49+# ===========================================================================
50+# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html
51+# ===========================================================================
52+#
53+# SYNOPSIS
54+#
55+# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT])
56+#
57+# DESCRIPTION
58+#
59+# Check whether the given FLAG works with the current language's compiler
60+# or gives an error. (Warnings, however, are ignored)
61+#
62+# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on
63+# success/failure.
64+#
65+# If EXTRA-FLAGS is defined, it is added to the current language's default
66+# flags (e.g. CFLAGS) when the check is done. The check is thus made with
67+# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to
68+# force the compiler to issue an error when a bad flag is given.
69+#
70+# INPUT gives an alternative input source to AC_COMPILE_IFELSE.
71+#
72+# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this
73+# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG.
74+#
75+# LICENSE
76+#
77+# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
78+# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com>
79+#
80+# This program is free software: you can redistribute it and/or modify it
81+# under the terms of the GNU General Public License as published by the
82+# Free Software Foundation, either version 3 of the License, or (at your
83+# option) any later version.
84+#
85+# This program is distributed in the hope that it will be useful, but
86+# WITHOUT ANY WARRANTY; without even the implied warranty of
87+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
88+# Public License for more details.
89+#
90+# You should have received a copy of the GNU General Public License along
91+# with this program. If not, see <https://www.gnu.org/licenses/>.
92+#
93+# As a special exception, the respective Autoconf Macro's copyright owner
94+# gives unlimited permission to copy, distribute and modify the configure
95+# scripts that are the output of Autoconf when processing the Macro. You
96+# need not follow the terms of the GNU General Public License when using
97+# or distributing such scripts, even though portions of the text of the
98+# Macro appear in them. The GNU General Public License (GPL) does govern
99+# all other use of the material that constitutes the Autoconf Macro.
100+#
101+# This special exception to the GPL applies to versions of the Autoconf
102+# Macro released by the Autoconf Archive. When you make and distribute a
103+# modified version of the Autoconf Macro, you may extend this special
104+# exception to the GPL to apply to your modified version as well.
105+
106+#serial 5
107+
108+AC_DEFUN([AX_CHECK_COMPILE_FLAG],
109+[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF
110+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl
111+AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [
112+ ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS
113+ _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1"
114+ AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])],
115+ [AS_VAR_SET(CACHEVAR,[yes])],
116+ [AS_VAR_SET(CACHEVAR,[no])])
117+ _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags])
118+AS_VAR_IF(CACHEVAR,yes,
119+ [m4_default([$2], :)],
120+ [m4_default([$3], :)])
121+AS_VAR_POPDEF([CACHEVAR])dnl
122+])dnl AX_CHECK_COMPILE_FLAGS
123--
Brad Bishopd7bf8c12018-02-25 22:55:05 -05001242.13.4
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500125