From: Willy Tarreau Date: Mon, 31 Jan 2022 14:27:58 +0000 (+0100) Subject: BUILD: makefile: only compute alternative options if required X-Git-Tag: v2.6-dev1~11 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ea9fa62e227ba7d1a26f1edebd2acbaf3213331;p=thirdparty%2Fhaproxy.git BUILD: makefile: only compute alternative options if required Currently, the way the "cc-opt-alt" macro works consists in always pre-calculating the alternative value for the case the main one would not work, and pass both to an "if" clause in shell. Most of the time we evaluate the second one for no reason. Let's change this to use an internal "if" function instead, and directly pass both option names to cc-opt-alt instead of passing a pre-calculated expression. This saves one fork/exec per option and makes the option easier to use. --- diff --git a/Makefile b/Makefile index 1facdcebf1..b97bbf5c9f 100644 --- a/Makefile +++ b/Makefile @@ -135,8 +135,8 @@ endif # call it only once. cc-opt = $(shell set -e; if $(CC) -Werror $(1) -E -xc - -o /dev/null &0 2>/dev/null; then echo "$(1)"; fi;) -# same but emits $2 if $1 is not supported -cc-opt-alt = $(shell set -e; if $(CC) -Werror $(1) -E -xc - -o /dev/null &0 2>/dev/null; then echo "$(1)"; else echo "$(2)"; fi;) +# same but tries with $2 if $1 is not supported +cc-opt-alt = $(if $(shell set -e; if $(CC) -Werror $(1) -E -xc - -o /dev/null &0 2>/dev/null; then echo 1;fi),$(1),$(call cc-opt,$(2))) # validate a list of options one at a time cc-all-opts = $(foreach a,$(1),$(call cc-opt,$(a))) @@ -221,7 +221,7 @@ WARN_CFLAGS := -Wtype-limits -Wshift-negative-value -Wshift-overflow=2 \ SPEC_CFLAGS := -Wall -Wextra -Wundef -Wdeclaration-after-statement SPEC_CFLAGS += $(call cc-all-fast,$(WARN_CFLAGS)) -SPEC_CFLAGS += $(call cc-opt-alt,-fwrapv,$(call cc-opt,-fno-strict-overflow)) +SPEC_CFLAGS += $(call cc-opt-alt,-fwrapv,-fno-strict-overflow) SPEC_CFLAGS += $(cc-wnouwo) SPEC_CFLAGS += $(call cc-nowarn,address-of-packed-member) SPEC_CFLAGS += $(call cc-nowarn,unused-label)