BUILD: Makefile: add a function to detect support by the compiler of certain options

The recent gcc and clang are utterly broken and apparently written by
people who don't use them anymore, because they emit warnings that are
impossible to disable in the code, which is the opposite of what a
warning should do. It is however possible to disable these warnings on
the command line, but not in a backwards-compatible way.

Thus here we create a new function which detect if the compiler supports
certain options, and which adds them if supported.
diff --git a/Makefile b/Makefile
index 60dd99b..089f588 100644
--- a/Makefile
+++ b/Makefile
@@ -90,6 +90,12 @@
 #   SUBVERS        : add a sub-version (eg: platform, model, ...).
 #   VERDATE        : force haproxy's release date.
 
+# Function used to detect support of a given option by the compiler.
+# Usage: CFLAGS += $(call cc-opt,option). Eg: $(call cc-opt,-fwrapv)
+# Note: ensure the referencing variable is assigned using ":=" and not "=" to
+#       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;)
+
 #### Installation options.
 DESTDIR =
 PREFIX = /usr/local
@@ -132,7 +138,8 @@
 # We rely on signed integer wraparound on overflow, however clang think it
 # can do whatever it wants since it's an undefined behavior, so use -fwrapv
 # to be sure we get the intended behavior.
-SPEC_CFLAGS = -fno-strict-aliasing -Wdeclaration-after-statement -fwrapv
+SPEC_CFLAGS := -fno-strict-aliasing -Wdeclaration-after-statement
+SPEC_CFLAGS += $(call cc-opt,-fwrapv)
 
 #### Memory usage tuning
 # If small memory footprint is required, you can reduce the buffer size. There