From b780166499ba95fe0a2356a2c5193d405817d77f Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Thu, 14 Sep 2017 19:05:45 +0200 Subject: [PATCH] BUILD: Makefile: improve detection of support for compiler warnings Some compiler versions don't emit an error when facing an unknown no-warning unless another error is reported, resulting in all -Wno-* options being enabled by default and being reported as wrong with build errors. Let's create a new "cc-nowarn" function to disable warnings only after checking that the positive one is supported. --- Makefile | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index e380ba7cc..ddc32df4d 100644 --- a/Makefile +++ b/Makefile @@ -96,6 +96,12 @@ # call it only once. cc-opt = $(shell set -e; if $(CC) $(1) -c -xc - -o /dev/null &0 2>&0; then echo "$(1)"; fi;) +# Disable a warning when supported by the compiler. Don't put spaces around the +# warning! And don't use cc-opt which doesn't always report an error until +# another one is also returned. +# Usage: CFLAGS += $(call cc-nowarn,warning). Eg: $(call cc-opt,format-truncation) +cc-nowarn = $(shell set -e; if $(CC) -W$(1) -c -xc - -o /dev/null &0 2>&0; then echo "-Wno-$(1)"; fi;) + #### Installation options. DESTDIR = PREFIX = /usr/local @@ -140,9 +146,9 @@ DEBUG_CFLAGS = -g # to be sure we get the intended behavior. SPEC_CFLAGS := -fno-strict-aliasing -Wdeclaration-after-statement SPEC_CFLAGS += $(call cc-opt,-fwrapv) -SPEC_CFLAGS += $(call cc-opt,-Wno-format-truncation) -SPEC_CFLAGS += $(call cc-opt,-Wno-address-of-packed-member) -SPEC_CFLAGS += $(call cc-opt,-Wno-null-dereference) +SPEC_CFLAGS += $(call cc-nowarn,format-truncation) +SPEC_CFLAGS += $(call cc-nowarn,address-of-packed-member) +SPEC_CFLAGS += $(call cc-nowarn,null-dereference) #### Memory usage tuning # If small memory footprint is required, you can reduce the buffer size. There