@@ -8,8 +8,6 @@ squote := '
88empty :=
99space := $(empty) $(empty)
1010space_escape := _-_SPACE_-_
11- right_paren := )
12- left_paren := (
1311pound := \#
1412
1513###
@@ -82,108 +80,37 @@ cc-cross-prefix = \
8280 echo $(c); \
8381 fi)))
8482
85- # Tools for caching Makefile variables that are "expensive" to compute.
86- #
87- # Here we want to help deal with variables that take a long time to compute
88- # by making it easy to store these variables in a cache.
89- #
90- # The canonical example here is testing for compiler flags. On a simple system
91- # each call to the compiler takes 10 ms, but on a system with a compiler that's
92- # called through various wrappers it can take upwards of 100 ms. If we have
93- # 100 calls to the compiler this can take 1 second (on a simple system) or 10
94- # seconds (on a complicated system).
95- #
96- # The "cache" will be in Makefile syntax and can be directly included.
97- # Any time we try to reference a variable that's not in the cache we'll
98- # calculate it and store it in the cache for next time.
99-
100- # Include values from last time
101- make-cache := $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/,$(if $(obj),$(obj)/)).cache.mk
102- $(make-cache): ;
103- -include $(make-cache)
104-
105- cached-data := $(filter __cached_%, $(.VARIABLES))
106-
107- # If cache exceeds 1000 lines, shrink it down to 500.
108- ifneq ($(word 1000,$(cached-data)),)
109- $(shell tail -n 500 $(make-cache) > $(make-cache).tmp; \
110- mv $(make-cache).tmp $(make-cache))
111- endif
112-
113- create-cache-dir := $(if $(KBUILD_SRC),$(if $(cache-data),,1))
114-
115- # Usage: $(call __sanitize-opt,Hello=Hola$(comma)Goodbye Adios)
116- #
117- # Convert all '$', ')', '(', '\', '=', ' ', ',', ':' to '_'
118- __sanitize-opt = $(subst $$,_,$(subst $(right_paren),_,$(subst $(left_paren),_,$(subst \,_,$(subst =,_,$(subst $(space),_,$(subst $(comma),_,$(subst :,_,$(1)))))))))
119-
120- # Usage: $(call shell-cached,shell_command)
121- # Example: $(call shell-cached,md5sum /usr/bin/gcc)
122- #
123- # If we've already seen a call to this exact shell command (even in a
124- # previous invocation of make!) we'll return the value. If not, we'll
125- # compute it and store the result for future runs.
126- #
127- # This is a bit of voodoo, but basic explanation is that if the variable
128- # was undefined then we'll evaluate the shell command and store the result
129- # into the variable. We'll then store that value in the cache and finally
130- # output the value.
131- #
132- # NOTE: The $$(2) here isn't actually a parameter to __run-and-store. We
133- # happen to know that the caller will have their shell command in $(2) so the
134- # result of "call"ing this will produce a reference to that $(2). The reason
135- # for this strangeness is to avoid an extra level of eval (and escaping) of
136- # $(2).
137- define __run-and-store
138- ifeq ($(origin $(1)),undefined)
139- $$(eval $(1) := $$(shell $$(2)))
140- ifeq ($(create-cache-dir),1)
141- $$(shell mkdir -p $(dir $(make-cache)))
142- $$(eval create-cache-dir :=)
143- endif
144- $$(shell echo '$(1) := $$($(1))' >> $(make-cache))
145- endif
146- endef
147- __shell-cached = $(eval $(call __run-and-store,$(1)))$($(1))
148- shell-cached = $(call __shell-cached,__cached_$(call __sanitize-opt,$(1)),$(1))
149-
15083# output directory for tests below
15184TMPOUT := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/)
15285
15386# try-run
15487# Usage: option = $(call try-run, $(CC)...-o "$$TMP",option-ok,otherwise)
15588# Exit code chooses option. "$$TMP" serves as a temporary file and is
15689# automatically cleaned up.
157- __try -run = set -e; \
90+ try -run = $(shell set -e; \
15891 TMP="$(TMPOUT).$$$$.tmp"; \
15992 TMPO="$(TMPOUT).$$$$.o"; \
16093 if ($(1)) >/dev/null 2>&1; \
16194 then echo "$(2)"; \
16295 else echo "$(3)"; \
16396 fi; \
164- rm -f "$$TMP" "$$TMPO"
165-
166- try-run = $(shell $(__try-run))
167-
168- # try-run-cached
169- # This works like try-run, but the result is cached.
170- try-run-cached = $(call shell-cached,$(__try-run))
97+ rm -f "$$TMP" "$$TMPO")
17198
17299# as-option
173100# Usage: cflags-y += $(call as-option,-Wa$(comma)-isa=foo,)
174101
175- as-option = $(call try-run-cached ,\
102+ as-option = $(call try-run,\
176103 $(CC) $(KBUILD_CFLAGS) $(1) -c -x assembler /dev/null -o "$$TMP",$(1),$(2))
177104
178105# as-instr
179106# Usage: cflags-y += $(call as-instr,instr,option1,option2)
180107
181- as-instr = $(call try-run-cached ,\
108+ as-instr = $(call try-run,\
182109 printf "%b\n" "$(1)" | $(CC) $(KBUILD_AFLAGS) -c -x assembler -o "$$TMP" -,$(2),$(3))
183110
184111# __cc-option
185112# Usage: MY_CFLAGS += $(call __cc-option,$(CC),$(MY_CFLAGS),-march=winchip-c6,-march=i586)
186- __cc-option = $(call try-run-cached ,\
113+ __cc-option = $(call try-run,\
187114 $(1) -Werror $(2) $(3) -c -x c /dev/null -o "$$TMP",$(3),$(4))
188115
189116# Do not attempt to build with gcc plugins during cc-option tests.
@@ -203,23 +130,23 @@ hostcc-option = $(call __cc-option, $(HOSTCC),\
203130
204131# cc-option-yn
205132# Usage: flag := $(call cc-option-yn,-march=winchip-c6)
206- cc-option-yn = $(call try-run-cached ,\
133+ cc-option-yn = $(call try-run,\
207134 $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) $(1) -c -x c /dev/null -o "$$TMP",y,n)
208135
209136# cc-disable-warning
210137# Usage: cflags-y += $(call cc-disable-warning,unused-but-set-variable)
211- cc-disable-warning = $(call try-run-cached ,\
138+ cc-disable-warning = $(call try-run,\
212139 $(CC) -Werror $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -W$(strip $(1)) -c -x c /dev/null -o "$$TMP",-Wno-$(strip $(1)))
213140
214141# cc-name
215142# Expands to either gcc or clang
216- cc-name = $(call shell-cached, $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)
143+ cc-name = $(shell $(CC) -v 2>&1 | grep -q "clang version" && echo clang || echo gcc)
217144
218145# cc-version
219- cc-version = $(call shell-cached, $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
146+ cc-version = $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-version.sh $(CC))
220147
221148# cc-fullversion
222- cc-fullversion = $(call shell-cached, $(CONFIG_SHELL) \
149+ cc-fullversion = $(shell $(CONFIG_SHELL) \
223150 $(srctree)/scripts/gcc-version.sh -p $(CC))
224151
225152# cc-ifversion
@@ -232,21 +159,21 @@ cc-if-fullversion = $(shell [ $(cc-fullversion) $(1) $(2) ] && echo $(3) || echo
232159
233160# cc-ldoption
234161# Usage: ldflags += $(call cc-ldoption, -Wl$(comma)--hash-style=both)
235- cc-ldoption = $(call try-run-cached ,\
162+ cc-ldoption = $(call try-run,\
236163 $(CC) $(1) $(KBUILD_CPPFLAGS) $(CC_OPTION_CFLAGS) -nostdlib -x c /dev/null -o "$$TMP",$(1),$(2))
237164
238165# ld-option
239166# Usage: LDFLAGS += $(call ld-option, -X)
240- ld-option = $(call try-run-cached , $(LD) $(LDFLAGS) $(1) -v,$(1),$(2))
167+ ld-option = $(call try-run, $(LD) $(LDFLAGS) $(1) -v,$(1),$(2))
241168
242169# ar-option
243170# Usage: KBUILD_ARFLAGS := $(call ar-option,D)
244171# Important: no spaces around options
245- ar-option = $(call try-run-cached , $(AR) rc$(1) "$$TMP",$(1),$(2))
172+ ar-option = $(call try-run, $(AR) rc$(1) "$$TMP",$(1),$(2))
246173
247174# ld-version
248175# Note this is mainly for HJ Lu's 3 number binutil versions
249- ld-version = $(call shell-cached, $(LD) --version | $(srctree)/scripts/ld-version.sh)
176+ ld-version = $(shell $(LD) --version | $(srctree)/scripts/ld-version.sh)
250177
251178# ld-ifversion
252179# Usage: $(call ld-ifversion, -ge, 22252, y)
0 commit comments