Skip to content

Commit b8c96a6

Browse files
committed
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 <[email protected]>
1 parent 4db9c2e commit b8c96a6

File tree

2 files changed

+13
-66
lines changed

2 files changed

+13
-66
lines changed

certs/Makefile

Lines changed: 13 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ endif
1515
quiet_cmd_extract_certs = CERT $@
1616
cmd_extract_certs = scripts/extract-cert $(2) $@
1717

18-
ifeq ($(CONFIG_SYSTEM_TRUSTED_KEYRING),y)
19-
20-
$(eval $(call config_filename,SYSTEM_TRUSTED_KEYS))
21-
2218
$(obj)/system_certificates.o: $(obj)/x509_certificate_list
2319

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),$<,""))
2724

2825
targets += x509_certificate_list
2926

@@ -72,29 +69,26 @@ $(obj)/x509.genkey:
7269

7370
endif # CONFIG_MODULE_SIG_KEY
7471

75-
$(eval $(call config_filename,MODULE_SIG_KEY))
72+
CONFIG_MODULE_SIG_KEY := $(CONFIG_MODULE_SIG_KEY:"%"=%)
7673

7774
# If CONFIG_MODULE_SIG_KEY isn't a PKCS#11 URI, depend on it
78-
ifeq ($(patsubst pkcs11:%,%,$(firstword $(MODULE_SIG_KEY_FILENAME))),$(firstword $(MODULE_SIG_KEY_FILENAME)))
79-
X509_DEP := $(MODULE_SIG_KEY_SRCPREFIX)$(MODULE_SIG_KEY_FILENAME)
75+
ifneq ($(filter-out pkcs11:%, %(CONFIG_MODULE_SIG_KEY)),)
76+
X509_DEP := $(CONFIG_MODULE_SIG_KEY)
8077
endif
8178

8279
$(obj)/system_certificates.o: $(obj)/signing_key.x509
8380

84-
$(obj)/signing_key.x509: scripts/extract-cert $(X509_DEP) FORCE
85-
$(call if_changed,extract_certs,$(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY))
81+
$(obj)/signing_key.x509: $(X509_DEP) scripts/extract-cert FORCE
82+
$(call if_changed,extract_certs,$(if $(X509_DEP),$<,$(CONFIG_MODULE_SIG_KEY)))
8683
endif # CONFIG_MODULE_SIG
8784

8885
targets += signing_key.x509
8986

90-
ifeq ($(CONFIG_SYSTEM_REVOCATION_LIST),y)
91-
92-
$(eval $(call config_filename,SYSTEM_REVOCATION_KEYS))
93-
9487
$(obj)/revocation_certificates.o: $(obj)/x509_revocation_list
9588

96-
$(obj)/x509_revocation_list: scripts/extract-cert $(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(SYSTEM_REVOCATION_KEYS_FILENAME) FORCE
97-
$(call if_changed,extract_certs,$(SYSTEM_REVOCATION_KEYS_SRCPREFIX)$(CONFIG_SYSTEM_REVOCATION_KEYS))
98-
endif
89+
CONFIG_SYSTEM_REVOCATION_KEYS := $(CONFIG_SYSTEM_REVOCATION_KEYS:"%"=%)
90+
91+
$(obj)/x509_revocation_list: $(CONFIG_SYSTEM_REVOCATION_KEYS) scripts/extract-cert FORCE
92+
$(call if_changed,extract_certs,$(if $(CONFIG_SYSTEM_REVOCATION_KEYS),$<,""))
9993

10094
targets += x509_revocation_list

scripts/Kbuild.include

Lines changed: 0 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -195,53 +195,6 @@ why = \
195195
echo-why = $(call escsq, $(strip $(why)))
196196
endif
197197

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-
#
245198
###############################################################################
246199

247200
# delete partially updated (i.e. corrupted) files on error

0 commit comments

Comments
 (0)