aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMasahiro Yamada <yamada.masahiro@socionext.com>2017-11-13 05:29:34 -0500
committerMasahiro Yamada <yamada.masahiro@socionext.com>2017-11-15 19:07:32 -0500
commit9a234a2e384349f21afac8d718aa294a668ad4fa (patch)
tree43d0b8a9ca7c6aa953a0bf849e457813e3892108
parent859fd5860cd1bbbd0370ba4f20725999681b66c8 (diff)
kbuild: create directory for make cache only when necessary
Currently, the existence of $(dir $(make-cache)) is always checked, and created if it is missing. We can avoid unnecessary system calls by some tricks. [1] If KBUILD_SRC is unset, we are building in the source tree. The output directory checks can be entirely skipped. [2] If at least one cache data is found, it means the cache file was included. Obviously its directory exists. Skip "mkdir -p". [3] If Makefile does not contain any call of __run-and-store, it will not create a cache file. No need to create its directory. [4] The "mkdir -p" should be only invoked by the first call of __run-and-store Signed-off-by: Masahiro Yamada <yamada.masahiro@socionext.com> Reviewed-by: Douglas Anderson <dianders@chromium.org>
-rw-r--r--scripts/Kbuild.include13
1 files changed, 9 insertions, 4 deletions
diff --git a/scripts/Kbuild.include b/scripts/Kbuild.include
index be1c9d65eaf4..065324a8046f 100644
--- a/scripts/Kbuild.include
+++ b/scripts/Kbuild.include
@@ -99,18 +99,19 @@ cc-cross-prefix = \
99 99
100# Include values from last time 100# Include values from last time
101make-cache := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/,$(if $(obj),$(obj)/)).cache.mk 101make-cache := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/,$(if $(obj),$(obj)/)).cache.mk
102ifeq ($(wildcard $(dir $(make-cache))),)
103$(shell mkdir -p '$(dir $(make-cache))')
104endif
105$(make-cache): ; 102$(make-cache): ;
106-include $(make-cache) 103-include $(make-cache)
107 104
105cached-data := $(filter __cached_%, $(.VARIABLES))
106
108# If cache exceeds 1000 lines, shrink it down to 500. 107# If cache exceeds 1000 lines, shrink it down to 500.
109ifneq ($(word 1000,$(filter __cached_%, $(.VARIABLES))),) 108ifneq ($(word 1000,$(cached-data)),)
110$(shell tail -n 500 $(make-cache) > $(make-cache).tmp; \ 109$(shell tail -n 500 $(make-cache) > $(make-cache).tmp; \
111 mv $(make-cache).tmp $(make-cache)) 110 mv $(make-cache).tmp $(make-cache))
112endif 111endif
113 112
113create-cache-dir := $(if $(KBUILD_SRC),$(if $(cache-data),,1))
114
114# Usage: $(call __sanitize-opt,Hello=Hola$(comma)Goodbye Adios) 115# Usage: $(call __sanitize-opt,Hello=Hola$(comma)Goodbye Adios)
115# 116#
116# Convert all '$', ')', '(', '\', '=', ' ', ',', ':' to '_' 117# Convert all '$', ')', '(', '\', '=', ' ', ',', ':' to '_'
@@ -136,6 +137,10 @@ __sanitize-opt = $(subst $$,_,$(subst $(right_paren),_,$(subst $(left_paren),_,$
136define __run-and-store 137define __run-and-store
137ifeq ($(origin $(1)),undefined) 138ifeq ($(origin $(1)),undefined)
138 $$(eval $(1) := $$(shell $$(2))) 139 $$(eval $(1) := $$(shell $$(2)))
140ifeq ($(create-cache-dir),1)
141 $$(shell mkdir -p $(dir $(make-cache)))
142 $$(eval create-cache-dir :=)
143endif
139 $$(shell echo '$(1) := $$($(1))' >> $(make-cache)) 144 $$(shell echo '$(1) := $$($(1))' >> $(make-cache))
140endif 145endif
141endef 146endef