From 119d30145e74ff3df503bcacc079ff96d14c3207 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 11 Aug 2022 10:56:59 +0200 Subject: [PATCH] m4: add NM_COMPILER_WARNING_FLAG() macro We used COMPILER_FLAG(LIBSYSTEMD_NM_CFLAGS, "-Wno-gnu-variable-sized-type-not-at-end") to detect whether the flag is supported. However, that does not work with GCC since version 4.4 due to https://gcc.gnu.org/wiki/FAQ#wnowarning. Note that we already had NM_COMPILER_WARNING(), but that again does something rather different. --- m4/compiler_options.m4 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/m4/compiler_options.m4 b/m4/compiler_options.m4 index b4b5e78dcc..b2e9d80e0d 100644 --- a/m4/compiler_options.m4 +++ b/m4/compiler_options.m4 @@ -29,8 +29,17 @@ AC_DEFUN([NM_COMPILER_FLAG], [ ], [$4]) ]) +dnl Check whether a particular warning is supported. If yes, the flag +dnl is appended to [ENV-VAR]. +dnl NM_COMPILER_WARNING_FLAG([ENV-VAR], [WARNING]) +AC_DEFUN([NM_COMPILER_WARNING_FLAG], [ + dnl "-Wno-*" requires special handling, see https://gcc.gnu.org/wiki/FAQ#wnowarning. + _NM_COMPILER_FLAG([-Wall $(printf '%s' "$2" | sed -e 's/^-W\(no-\|no-error=\)/-W/')], [], [eval "AS_TR_SH([$1])='$$1 $2'"], []) +]) + dnl Check whether a particular warning is not emitted with code provided, dnl append an option to disable the warning to a specified variable if the check fails. +dnl Note that this always either adds -W$2 or -Wno-$2, depending on whether it's supported. dnl NM_COMPILER_WARNING([ENV-VAR], [WARNING], [C-SNIPPET]) AC_DEFUN([NM_COMPILER_WARNING], [ _NM_COMPILER_FLAG([-W$2], [$3], [eval "AS_TR_SH([$1])='$$1 -W$2'"], [eval "AS_TR_SH([$1])='$$1 -Wno-$2'"])