xref: /linux/Documentation/devicetree/bindings/Makefile (revision cbac924200b838cfb8d8b1415113d788089dc50b)
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
5
6DT_SCHEMA_LINT = $(shell which yamllint || \
7  echo "warning: python package 'yamllint' not installed, skipping" >&2)
8
9DT_SCHEMA_MIN_VERSION = 2022.3
10
11PHONY += check_dtschema_version
12check_dtschema_version:
13	@which $(DT_DOC_CHECKER) >/dev/null || \
14		{ echo "Error: '$(DT_DOC_CHECKER)' not found!" >&2; \
15		  echo "Ensure dtschema python package is installed and in your PATH." >&2; \
16		  echo "Current PATH is:" >&2; \
17		  echo "$$PATH" >&2; false; }
18	@{ echo $(DT_SCHEMA_MIN_VERSION); \
19	$(DT_DOC_CHECKER) --version 2>/dev/null || echo 0; } | sort -Vc >/dev/null || \
20	{ echo "ERROR: dtschema minimum version is v$(DT_SCHEMA_MIN_VERSION)" >&2; false; }
21
22quiet_cmd_extract_ex = DTEX    $@
23      cmd_extract_ex = $(DT_EXTRACT_EX) $< > $@
24
25$(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE
26	$(call if_changed,extract_ex)
27
28find_all_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \
29		-name 'processed-schema*' \)
30
31find_cmd = $(find_all_cmd) | grep -F "$(DT_SCHEMA_FILES)"
32CHK_DT_DOCS := $(shell $(find_cmd))
33
34quiet_cmd_yamllint = LINT    $(src)
35      cmd_yamllint = ($(find_cmd) | \
36                     xargs -n200 -P$$(nproc) \
37		     $(DT_SCHEMA_LINT) -f parsable -c $(srctree)/$(src)/.yamllint >&2) || true
38
39quiet_cmd_chk_bindings = CHKDT   $@
40      cmd_chk_bindings = ($(find_cmd) | \
41                         xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(srctree)/$(src)) || true
42
43quiet_cmd_mk_schema = SCHEMA  $@
44      cmd_mk_schema = f=$$(mktemp) ; \
45                      $(if $(DT_MK_SCHEMA_FLAGS), \
46                           printf '%s\n' $(real-prereqs), \
47                           $(find_all_cmd)) > $$f ; \
48                      $(DT_MK_SCHEMA) -j $(DT_MK_SCHEMA_FLAGS) @$$f > $@ ; \
49		      rm -f $$f
50
51define rule_chkdt
52	$(if $(DT_SCHEMA_LINT),$(call cmd,yamllint),)
53	$(call cmd,chk_bindings)
54	$(call cmd,mk_schema)
55endef
56
57DT_DOCS = $(patsubst $(srctree)/%,%,$(shell $(find_all_cmd)))
58
59override DTC_FLAGS := \
60	-Wno-avoid_unnecessary_addr_size \
61	-Wno-graph_child_address \
62	-Wno-interrupt_provider \
63	-Wno-unique_unit_address \
64	-Wunique_unit_address_if_enabled
65
66# Disable undocumented compatible checks until warning free
67override DT_CHECKER_FLAGS ?=
68
69$(obj)/processed-schema.json: $(DT_DOCS) $(src)/.yamllint check_dtschema_version FORCE
70	$(call if_changed_rule,chkdt)
71
72always-y += processed-schema.json
73always-$(CHECK_DT_BINDING) += $(patsubst $(srctree)/$(src)/%.yaml,%.example.dts, $(CHK_DT_DOCS))
74always-$(CHECK_DT_BINDING) += $(patsubst $(srctree)/$(src)/%.yaml,%.example.dtb, $(CHK_DT_DOCS))
75
76# Hack: avoid 'Argument list too long' error for 'make clean'. Remove most of
77# build artifacts here before they are processed by scripts/Makefile.clean
78clean-files = $(shell find $(obj) \( -name '*.example.dts' -o \
79			-name '*.example.dtb' \) -delete 2>/dev/null)
80