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 e380ba7..ddc32df 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 </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 </dev/null >&0 2>&0; then echo "-Wno-$(1)"; fi;)
+
 #### Installation options.
 DESTDIR =
 PREFIX = /usr/local
@@ -140,9 +146,9 @@
 # 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