1From 98e9faa4d39cd5b6aaab882877e19ae394ba3810 Mon Sep 17 00:00:00 2001 2From: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 3Date: Mon, 20 Nov 2017 23:10:38 +0100 4Subject: [PATCH] configure: fix build with old compilers 5 6Old gcc versions (gcc 4.7) do not support all warnings flags currently 7hard-coded by configure.ac. In order to fix this, we import the 8AX_CHECK_COMPILE_FLAG() macro from the autoconf-archive, and use it in 9the configure.ac to only use warning flags when the compiler supports 10them. 11 12Submitted-upstream: https://github.com/latchset/jose/pull/51 13Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com> 14--- 15 configure.ac | 46 +++++++++++++++------------- 16 m4/ax_check_compile_flag.m4 | 74 +++++++++++++++++++++++++++++++++++++++++++++ 17 3 files changed, 105 insertions(+), 22 deletions(-) 18 create mode 100644 m4/ax_check_compile_flag.m4 19 20diff --git a/configure.ac b/configure.ac 21index cf8c9a6..6fe4ded 100644 22--- a/configure.ac 23+++ b/configure.ac 24@@ -1,5 +1,6 @@ 25 AC_PREREQ(2.62) 26 AC_INIT(jose, 10) 27+AC_CONFIG_MACRO_DIRS([m4]) 28 AC_CANONICAL_SYSTEM 29 AC_PROG_CC_C99 30 31@@ -18,27 +19,30 @@ PKG_CHECK_MODULES([libcrypto], [libcrypto >= 1.0.2]) 32 AC_OPENMP 33 AC_SUBST([OPENMP_CFLAGS]) 34 35-JOSE_CFLAGS="\ 36--Wall \ 37--Wextra \ 38--Werror \ 39--Wstrict-aliasing \ 40--Wchar-subscripts \ 41--Wformat-security \ 42--Wmissing-declarations \ 43--Wmissing-prototypes \ 44--Wnested-externs \ 45--Wpointer-arith \ 46--Wshadow \ 47--Wsign-compare \ 48--Wstrict-prototypes \ 49--Wtype-limits \ 50--Wunused-function \ 51--Wno-missing-field-initializers \ 52--Wno-unused-command-line-argument \ 53--Wno-unused-parameter \ 54--Wno-unknown-pragmas \ 55-" 56+for flag in \ 57+ -Wall \ 58+ -Wextra \ 59+ -Werror \ 60+ -Wstrict-aliasing \ 61+ -Wchar-subscripts \ 62+ -Wformat-security \ 63+ -Wmissing-declarations \ 64+ -Wmissing-prototypes \ 65+ -Wnested-externs \ 66+ -Wpointer-arith \ 67+ -Wshadow \ 68+ -Wsign-compare \ 69+ -Wstrict-prototypes \ 70+ -Wtype-limits \ 71+ -Wunused-function \ 72+ -Wno-missing-field-initializers \ 73+ -Wno-unused-command-line-argument \ 74+ -Wno-unused-parameter \ 75+ -Wno-unknown-pragmas ; do 76+ AX_CHECK_COMPILE_FLAG([${flag}], 77+ [JOSE_CFLAGS="${JOSE_CFLAGS} ${flag}"]) 78+done 79+ 80 AC_SUBST([JOSE_CFLAGS]) 81 82 AC_MSG_CHECKING([for linker script support]) 83diff --git a/m4/ax_check_compile_flag.m4 b/m4/ax_check_compile_flag.m4 84new file mode 100644 85index 0000000..dcabb92 86--- /dev/null 87+++ b/m4/ax_check_compile_flag.m4 88@@ -0,0 +1,74 @@ 89+# =========================================================================== 90+# https://www.gnu.org/software/autoconf-archive/ax_check_compile_flag.html 91+# =========================================================================== 92+# 93+# SYNOPSIS 94+# 95+# AX_CHECK_COMPILE_FLAG(FLAG, [ACTION-SUCCESS], [ACTION-FAILURE], [EXTRA-FLAGS], [INPUT]) 96+# 97+# DESCRIPTION 98+# 99+# Check whether the given FLAG works with the current language's compiler 100+# or gives an error. (Warnings, however, are ignored) 101+# 102+# ACTION-SUCCESS/ACTION-FAILURE are shell commands to execute on 103+# success/failure. 104+# 105+# If EXTRA-FLAGS is defined, it is added to the current language's default 106+# flags (e.g. CFLAGS) when the check is done. The check is thus made with 107+# the flags: "CFLAGS EXTRA-FLAGS FLAG". This can for example be used to 108+# force the compiler to issue an error when a bad flag is given. 109+# 110+# INPUT gives an alternative input source to AC_COMPILE_IFELSE. 111+# 112+# NOTE: Implementation based on AX_CFLAGS_GCC_OPTION. Please keep this 113+# macro in sync with AX_CHECK_{PREPROC,LINK}_FLAG. 114+# 115+# LICENSE 116+# 117+# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de> 118+# Copyright (c) 2011 Maarten Bosmans <mkbosmans@gmail.com> 119+# 120+# This program is free software: you can redistribute it and/or modify it 121+# under the terms of the GNU General Public License as published by the 122+# Free Software Foundation, either version 3 of the License, or (at your 123+# option) any later version. 124+# 125+# This program is distributed in the hope that it will be useful, but 126+# WITHOUT ANY WARRANTY; without even the implied warranty of 127+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General 128+# Public License for more details. 129+# 130+# You should have received a copy of the GNU General Public License along 131+# with this program. If not, see <https://www.gnu.org/licenses/>. 132+# 133+# As a special exception, the respective Autoconf Macro's copyright owner 134+# gives unlimited permission to copy, distribute and modify the configure 135+# scripts that are the output of Autoconf when processing the Macro. You 136+# need not follow the terms of the GNU General Public License when using 137+# or distributing such scripts, even though portions of the text of the 138+# Macro appear in them. The GNU General Public License (GPL) does govern 139+# all other use of the material that constitutes the Autoconf Macro. 140+# 141+# This special exception to the GPL applies to versions of the Autoconf 142+# Macro released by the Autoconf Archive. When you make and distribute a 143+# modified version of the Autoconf Macro, you may extend this special 144+# exception to the GPL to apply to your modified version as well. 145+ 146+#serial 5 147+ 148+AC_DEFUN([AX_CHECK_COMPILE_FLAG], 149+[AC_PREREQ(2.64)dnl for _AC_LANG_PREFIX and AS_VAR_IF 150+AS_VAR_PUSHDEF([CACHEVAR],[ax_cv_check_[]_AC_LANG_ABBREV[]flags_$4_$1])dnl 151+AC_CACHE_CHECK([whether _AC_LANG compiler accepts $1], CACHEVAR, [ 152+ ax_check_save_flags=$[]_AC_LANG_PREFIX[]FLAGS 153+ _AC_LANG_PREFIX[]FLAGS="$[]_AC_LANG_PREFIX[]FLAGS $4 $1" 154+ AC_COMPILE_IFELSE([m4_default([$5],[AC_LANG_PROGRAM()])], 155+ [AS_VAR_SET(CACHEVAR,[yes])], 156+ [AS_VAR_SET(CACHEVAR,[no])]) 157+ _AC_LANG_PREFIX[]FLAGS=$ax_check_save_flags]) 158+AS_VAR_IF(CACHEVAR,yes, 159+ [m4_default([$2], :)], 160+ [m4_default([$3], :)]) 161+AS_VAR_POPDEF([CACHEVAR])dnl 162+])dnl AX_CHECK_COMPILE_FLAGS 163-- 1642.13.6 165 166