diff mbox

[kvm-unit-tests] build: don't reevaluate cc-option shell command

Message ID b8c291828d51f4bebdabbf9679a278533846820a.1457742064.git.pfeiner@google.com (mailing list archive)
State New, archived
Headers show

Commit Message

Peter Feiner March 12, 2016, 12:21 a.m. UTC
Make was reevaluating the shell commands in CFLAGS for every recipe
because CFLAGS was defined as a recursively-expanded variable. Doing a
simple expansion before putting the command output in CFLAGS prevents
this reevaluation.

The difference this change makes for the x86 build is stark:

BEFORE:
	make -j  6.17s user 5.74s system 167% cpu 7.117 total
	make  6.52s user 5.70s system 89% cpu 13.664 total

AFTER:
	make -j  4.03s user 1.47s system 1036% cpu 0.530 total
	make  3.69s user 2.16s system 92% cpu 6.310 total

Signed-off-by: Peter Feiner <pfeiner@google.com>
---
 Makefile | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

Comments

Paolo Bonzini March 14, 2016, 2:03 p.m. UTC | #1
On 12/03/2016 01:21, Peter Feiner wrote:
> Make was reevaluating the shell commands in CFLAGS for every recipe
> because CFLAGS was defined as a recursively-expanded variable. Doing a
> simple expansion before putting the command output in CFLAGS prevents
> this reevaluation.
> 
> The difference this change makes for the x86 build is stark:
> 
> BEFORE:
> 	make -j  6.17s user 5.74s system 167% cpu 7.117 total
> 	make  6.52s user 5.70s system 89% cpu 13.664 total
> 
> AFTER:
> 	make -j  4.03s user 1.47s system 1036% cpu 0.530 total
> 	make  3.69s user 2.16s system 92% cpu 6.310 total
> 
> Signed-off-by: Peter Feiner <pfeiner@google.com>
> ---
>  Makefile | 10 +++++++---
>  1 file changed, 7 insertions(+), 3 deletions(-)
> 
> diff --git a/Makefile b/Makefile
> index 09999c6..2a2d942 100644
> --- a/Makefile
> +++ b/Makefile
> @@ -42,9 +42,13 @@ cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
>  
>  CFLAGS += -g
>  CFLAGS += $(autodepend-flags) -Wall -Werror
> -CFLAGS += $(call cc-option, -fomit-frame-pointer, "")
> -CFLAGS += $(call cc-option, -fno-stack-protector, "")
> -CFLAGS += $(call cc-option, -fno-stack-protector-all, "")
> +
> +fomit_frame_pointer := $(call cc-option, -fomit-frame-pointer, "")
> +fnostack_protector := $(call cc-option, -fno-stack-protector, "")
> +fnostack_protector_all := $(call cc-option, -fno-stack-protector-all, "")
> +CFLAGS += $(fomit_frame_pointer)
> +CFLAGS += $(fno_stack_protector)
> +CFLAGS += $(fno_stack_protector_all)
>  
>  CXXFLAGS += $(CFLAGS)
>  
> 

Thanks, looks good.

Paolo
--
To unsubscribe from this list: send the line "unsubscribe kvm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/Makefile b/Makefile
index 09999c6..2a2d942 100644
--- a/Makefile
+++ b/Makefile
@@ -42,9 +42,13 @@  cc-option = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null \
 
 CFLAGS += -g
 CFLAGS += $(autodepend-flags) -Wall -Werror
-CFLAGS += $(call cc-option, -fomit-frame-pointer, "")
-CFLAGS += $(call cc-option, -fno-stack-protector, "")
-CFLAGS += $(call cc-option, -fno-stack-protector-all, "")
+
+fomit_frame_pointer := $(call cc-option, -fomit-frame-pointer, "")
+fnostack_protector := $(call cc-option, -fno-stack-protector, "")
+fnostack_protector_all := $(call cc-option, -fno-stack-protector-all, "")
+CFLAGS += $(fomit_frame_pointer)
+CFLAGS += $(fno_stack_protector)
+CFLAGS += $(fno_stack_protector_all)
 
 CXXFLAGS += $(CFLAGS)