1# SPDX-License-Identifier: GPL-2.0
2DT_DOC_CHECKER ?= dt-doc-validate
3DT_EXTRACT_EX ?= dt-extract-example
4DT_MK_SCHEMA ?= dt-mk-schema
5DT_MK_SCHEMA_USERONLY_FLAG := $(if $(DT_SCHEMA_FILES), -u)
6
7DT_SCHEMA_MIN_VERSION = 2020.5
8
9PHONY += check_dtschema_version
10check_dtschema_version:
11	@{ echo $(DT_SCHEMA_MIN_VERSION); \
12	$(DT_DOC_CHECKER) --version 2>/dev/null || echo 0; } | sort -VC || \
13	{ echo "ERROR: dtschema minimum version is v$(DT_SCHEMA_MIN_VERSION)" >&2; false; }
14
15quiet_cmd_chk_binding = CHKDT   $(patsubst $(srctree)/%,%,$<)
16      cmd_chk_binding = $(DT_DOC_CHECKER) -u $(srctree)/$(src) $< ; \
17                        $(DT_EXTRACT_EX) $< > $@
18
19$(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE
20	$(call if_changed,chk_binding)
21
22# Use full schemas when checking %.example.dts
23DT_TMP_SCHEMA := $(obj)/processed-schema-examples.yaml
24
25find_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \
26		-name 'processed-schema*' ! \
27		-name '*.example.dt.yaml' \)
28
29quiet_cmd_mk_schema = SCHEMA  $@
30      cmd_mk_schema = rm -f $@ ; \
31                      $(if $(DT_MK_SCHEMA_FLAGS), \
32                           echo $(real-prereqs), \
33                           $(find_cmd)) | \
34                      xargs $(DT_MK_SCHEMA) $(DT_MK_SCHEMA_FLAGS) >> $@
35
36DT_DOCS = $(shell $(find_cmd) | sed -e 's|^$(srctree)/||')
37
38DT_SCHEMA_FILES ?= $(DT_DOCS)
39
40extra-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dts, $(DT_SCHEMA_FILES))
41extra-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dt.yaml, $(DT_SCHEMA_FILES))
42extra-$(CHECK_DT_BINDING) += processed-schema-examples.yaml
43
44override DTC_FLAGS := \
45	-Wno-avoid_unnecessary_addr_size \
46	-Wno-graph_child_address
47
48$(obj)/processed-schema-examples.yaml: $(DT_DOCS) check_dtschema_version FORCE
49	$(call if_changed,mk_schema)
50
51$(obj)/processed-schema.yaml: DT_MK_SCHEMA_FLAGS := $(DT_MK_SCHEMA_USERONLY_FLAG)
52$(obj)/processed-schema.yaml: $(DT_SCHEMA_FILES) check_dtschema_version FORCE
53	$(call if_changed,mk_schema)
54
55extra-y += processed-schema.yaml
56