Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

certs: simplify $(srctree)/ handling and remove config_filename macro

The complex macro, config_filename, was introduced to do:

[1] drop double-quotes from the string value
[2] add $(srctree)/ prefix in case the file is not found in $(objtree)
[3] escape spaces and more

[1] will be more generally handled by Kconfig later.

As for [2], Kbuild uses VPATH to search for files in $(objtree),
$(srctree) in this order. GNU Make can natively handle it.

As for [3], converting $(space) to $(space_escape) back and forth looks
questionable to me. It is well-known that GNU Make cannot handle file
paths with spaces in the first place.

Instead of using the complex macro, use $< so it will be expanded to
the file path of the key.

Remove config_filename, finally.

Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>

+13 -66
+13 -19
certs/Makefile
··· 15 15 quiet_cmd_extract_certs = CERT $@ 16 16 cmd_extract_certs = scripts/extract-cert $(2) $@ 17 17 18 - ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y) 19 - 20 - $(eval $(call config_filename,SYSTEM_TRUSTED_KEYS)) 21 - 22 18 $(obj)/system_certificates.o: $(obj)/x509_certificate_list 23 19 24 - $(obj)/x509_certificate_list: scripts/extract-cert $(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(SYSTEM_TRUSTED_KEYS_FILENAME) FORCE 25 - $(call if_changed,extract_certs,$(SYSTEM_TRUSTED_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_TRUSTED_KEYS)) 26 - endif # CONFIG_SYSTEM_TRUSTED_KEYRING 20 + CONFIG_SYSTEM_TRUSTED_KEYS := $(CONFIG_SYSTEM_TRUSTED_KEYS:"%"=%) 21 + 22 + $(obj)/x509_certificate_list: $(CONFIG_SYSTEM_TRUSTED_KEYS) scripts/extract-cert FORCE 23 + $(call if_changed,extract_certs,$(if $(CONFIG_SYSTEM_TRUSTED_KEYS),$<,"")) 27 24 28 25 targets += x509_certificate_list 29 26 ··· 69 72 70 73 endif # CONFIG_MODULE_SIG_KEY 71 74 72 - $(eval $(call config_filename,MODULE_SIG_KEY)) 75 + CONFIG_MODULE_SIG_KEY := $(CONFIG_MODULE_SIG_KEY:"%"=%) 73 76 74 77 # If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it 75 - ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME))) 76 - X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME) 78 + ifneq ($(filter-out pkcs11:%, %(CONFIG_MODULE_SIG_KEY)),) 79 + X509_DEP := $(CONFIG_MODULE_SIG_KEY) 77 80 endif 78 81 79 82 $(obj)/system_certificates.o: $(obj)/signing_key.x509 80 83 81 - $(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE 82 - $(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY)) 84 + $(obj)/signing_key.x509: $(X509_DEP) scripts/extract-cert FORCE 85 + $(call if_changed,extract_certs,$(if $(X509_DEP),$<,$(CONFIG_MODULE_SIG_KEY))) 83 86 endif # CONFIG_MODULE_SIG 84 87 85 88 targets += signing_key.x509 86 89 87 - ifeq ($(CONFIG_SYSTEM_REVOCATION_LIST),y) 88 - 89 - $(eval $(call config_filename,SYSTEM_REVOCATION_KEYS)) 90 - 91 90 $(obj)/revocation_certificates.o: $(obj)/x509_revocation_list 92 91 93 - $(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE 94 - $(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS)) 95 - endif 92 + CONFIG_SYSTEM_REVOCATION_KEYS := $(CONFIG_SYSTEM_REVOCATION_KEYS:"%"=%) 93 + 94 + $(obj)/x509_revocation_list: $(CONFIG_SYSTEM_REVOCATION_KEYS) scripts/extract-cert FORCE 95 + $(call if_changed,extract_certs,$(if $(CONFIG_SYSTEM_REVOCATION_KEYS),$<,"")) 96 96 97 97 targets += x509_revocation_list
-47
scripts/Kbuild.include
··· 196 196 endif 197 197 198 198 ############################################################################### 199 - # 200 - # When a Kconfig string contains a filename, it is suitable for 201 - # passing to shell commands. It is surrounded by double-quotes, and 202 - # any double-quotes or backslashes within it are escaped by 203 - # backslashes. 204 - # 205 - # This is no use for dependencies or $(wildcard). We need to strip the 206 - # surrounding quotes and the escaping from quotes and backslashes, and 207 - # we *do* need to escape any spaces in the string. So, for example: 208 - # 209 - # Usage: $(eval $(call config_filename,FOO)) 210 - # 211 - # Defines FOO_FILENAME based on the contents of the CONFIG_FOO option, 212 - # transformed as described above to be suitable for use within the 213 - # makefile. 214 - # 215 - # Also, if the filename is a relative filename and exists in the source 216 - # tree but not the build tree, define FOO_SRCPREFIX as $(srctree)/ to 217 - # be prefixed to *both* command invocation and dependencies. 218 - # 219 - # Note: We also print the filenames in the quiet_cmd_foo text, and 220 - # perhaps ought to have a version specially escaped for that purpose. 221 - # But it's only cosmetic, and $(patsubst "%",%,$(CONFIG_FOO)) is good 222 - # enough. It'll strip the quotes in the common case where there's no 223 - # space and it's a simple filename, and it'll retain the quotes when 224 - # there's a space. There are some esoteric cases in which it'll print 225 - # the wrong thing, but we don't really care. The actual dependencies 226 - # and commands *do* get it right, with various combinations of single 227 - # and double quotes, backslashes and spaces in the filenames. 228 - # 229 - ############################################################################### 230 - # 231 - define config_filename 232 - ifneq ($$(CONFIG_$(1)),"") 233 - $(1)_FILENAME := $$(subst \\,\,$$(subst \$$(quote),$$(quote),$$(subst $$(space_escape),\$$(space),$$(patsubst "%",%,$$(subst $$(space),$$(space_escape),$$(CONFIG_$(1))))))) 234 - ifneq ($$(patsubst /%,%,$$(firstword $$($(1)_FILENAME))),$$(firstword $$($(1)_FILENAME))) 235 - else 236 - ifeq ($$(wildcard $$($(1)_FILENAME)),) 237 - ifneq ($$(wildcard $$(srctree)/$$($(1)_FILENAME)),) 238 - $(1)_SRCPREFIX := $(srctree)/ 239 - endif 240 - endif 241 - endif 242 - endif 243 - endef 244 - # 245 - ############################################################################### 246 199 247 200 # delete partially updated (i.e. corrupted) files on error 248 201 .DELETE_ON_ERROR: