From: Willy Tarreau Date: Thu, 14 Sep 2017 17:05:45 +0000 (+0200) Subject: BUILD: Makefile: improve detection of support for compiler warnings X-Git-Tag: v1.8-dev3~101 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b78016649;p=thirdparty%2Fhaproxy.git 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. --- diff --git a/Makefile b/Makefile index e380ba7cc3..ddc32df4d3 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