]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
BUILD: makefile: only compute alternative options if required
authorWilly Tarreau <w@1wt.eu>
Mon, 31 Jan 2022 14:27:58 +0000 (15:27 +0100)
committerWilly Tarreau <w@1wt.eu>
Mon, 31 Jan 2022 20:00:35 +0000 (21:00 +0100)
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.

Makefile

index 1facdcebf15237f1e682d9cf7775ea25e9a30d81..b97bbf5c9fc7465259b2fa77e33fedaaa2d2c2e4 100644 (file)
--- 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 </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 </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 </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)