From d3a7f40359e59a0c44e929efa91761ad21d38167 Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Wed, 13 Sep 2017 16:54:28 +0200 Subject: [PATCH] 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. --- Makefile | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 60dd99b328..089f5889f0 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 &0 2>&0; then echo "$(1)"; fi;) + #### Installation options. DESTDIR = PREFIX = /usr/local @@ -132,7 +138,8 @@ DEBUG_CFLAGS = -g # 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 -- 2.39.5