14f0e3a57SRob Herring# SPDX-License-Identifier: GPL-2.0
24f0e3a57SRob HerringDT_DOC_CHECKER ?= dt-doc-validate
34f0e3a57SRob HerringDT_EXTRACT_EX ?= dt-extract-example
44f0e3a57SRob HerringDT_MK_SCHEMA ?= dt-mk-schema
54f0e3a57SRob Herring
6*6b49f340SNathan ChancellorDT_SCHEMA_LINT = $(shell which yamllint || \
7b3e664a7SRob Herring  echo "warning: python package 'yamllint' not installed, skipping" >&2)
844ec8b20SRob Herring
92783a7f5SRob HerringDT_SCHEMA_MIN_VERSION = 2022.3
10ea5b8b5eSRob Herring
11ea5b8b5eSRob HerringPHONY += check_dtschema_version
12ea5b8b5eSRob Herringcheck_dtschema_version:
1328ead0a4SRob Herring	@which $(DT_DOC_CHECKER) >/dev/null || \
1428ead0a4SRob Herring		{ echo "Error: '$(DT_DOC_CHECKER)' not found!" >&2; \
1528ead0a4SRob Herring		  echo "Ensure dtschema python package is installed and in your PATH." >&2; \
1628ead0a4SRob Herring		  echo "Current PATH is:" >&2; \
1728ead0a4SRob Herring		  echo "$$PATH" >&2; false; }
18ea5b8b5eSRob Herring	@{ echo $(DT_SCHEMA_MIN_VERSION); \
19a21ca2daSIskren Chernev	$(DT_DOC_CHECKER) --version 2>/dev/null || echo 0; } | sort -Vc >/dev/null || \
20ea5b8b5eSRob Herring	{ echo "ERROR: dtschema minimum version is v$(DT_SCHEMA_MIN_VERSION)" >&2; false; }
21ea5b8b5eSRob Herring
227ba58fffSRob Herringquiet_cmd_extract_ex = DTEX    $@
237ba58fffSRob Herring      cmd_extract_ex = $(DT_EXTRACT_EX) $< > $@
244f0e3a57SRob Herring
25ea5b8b5eSRob Herring$(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE
267ba58fffSRob Herring	$(call if_changed,extract_ex)
274f0e3a57SRob Herring
28378be0ccSGeert Uytterhoevenfind_all_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \
29ef8795f3SRob Herring		-name 'processed-schema*' \)
308b6b8021SRob Herring
31309d9559SRob Herringfind_cmd = $(find_all_cmd) | grep -F "$(DT_SCHEMA_FILES)"
32309d9559SRob HerringCHK_DT_DOCS := $(shell $(find_cmd))
33378be0ccSGeert Uytterhoeven
3444ec8b20SRob Herringquiet_cmd_yamllint = LINT    $(src)
353e95dfb3SRob Herring      cmd_yamllint = ($(find_cmd) | \
36378be0ccSGeert Uytterhoeven                     xargs -n200 -P$$(nproc) \
37378be0ccSGeert Uytterhoeven		     $(DT_SCHEMA_LINT) -f parsable -c $(srctree)/$(src)/.yamllint >&2) || true
3844ec8b20SRob Herring
397ba58fffSRob Herringquiet_cmd_chk_bindings = CHKDT   $@
403e95dfb3SRob Herring      cmd_chk_bindings = ($(find_cmd) | \
413e95dfb3SRob Herring                         xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(srctree)/$(src)) || true
427ba58fffSRob Herring
438b6b8021SRob Herringquiet_cmd_mk_schema = SCHEMA  $@
44b8a49399SAndrei Ziureaev      cmd_mk_schema = f=$$(mktemp) ; \
458b6b8021SRob Herring                      $(if $(DT_MK_SCHEMA_FLAGS), \
4696993a59SCristian Ciocaltea                           printf '%s\n' $(real-prereqs), \
47378be0ccSGeert Uytterhoeven                           $(find_all_cmd)) > $$f ; \
48b8a49399SAndrei Ziureaev                      $(DT_MK_SCHEMA) -j $(DT_MK_SCHEMA_FLAGS) @$$f > $@ ; \
49b8a49399SAndrei Ziureaev		      rm -f $$f
508b6b8021SRob Herring
517ba58fffSRob Herringdefine rule_chkdt
5244ec8b20SRob Herring	$(if $(DT_SCHEMA_LINT),$(call cmd,yamllint),)
537ba58fffSRob Herring	$(call cmd,chk_bindings)
547ba58fffSRob Herring	$(call cmd,mk_schema)
557ba58fffSRob Herringendef
567ba58fffSRob Herring
57378be0ccSGeert UytterhoevenDT_DOCS = $(patsubst $(srctree)/%,%,$(shell $(find_all_cmd)))
585fa98c2eSRob Herring
5965220630SRob Herringoverride DTC_FLAGS := \
6065220630SRob Herring	-Wno-avoid_unnecessary_addr_size \
613eb619b2SRob Herring	-Wno-graph_child_address \
624b7c49f7SSam Protsenko	-Wno-interrupt_provider \
634b7c49f7SSam Protsenko	-Wno-unique_unit_address \
644b7c49f7SSam Protsenko	-Wunique_unit_address_if_enabled
6565220630SRob Herring
66c59773d2SRob Herring# Disable undocumented compatible checks until warning free
67c59773d2SRob Herringoverride DT_CHECKER_FLAGS ?=
68c59773d2SRob Herring
692783a7f5SRob Herring$(obj)/processed-schema.json: $(DT_DOCS) $(src)/.yamllint check_dtschema_version FORCE
707ba58fffSRob Herring	$(call if_changed_rule,chkdt)
714f0e3a57SRob Herring
722783a7f5SRob Herringalways-y += processed-schema.json
73309d9559SRob Herringalways-$(CHECK_DT_BINDING) += $(patsubst $(srctree)/$(src)/%.yaml,%.example.dts, $(CHK_DT_DOCS))
74ef8795f3SRob Herringalways-$(CHECK_DT_BINDING) += $(patsubst $(srctree)/$(src)/%.yaml,%.example.dtb, $(CHK_DT_DOCS))
75fa714cf5SMasahiro Yamada
76fa714cf5SMasahiro Yamada# Hack: avoid 'Argument list too long' error for 'make clean'. Remove most of
77fa714cf5SMasahiro Yamada# build artifacts here before they are processed by scripts/Makefile.clean
78fa714cf5SMasahiro Yamadaclean-files = $(shell find $(obj) \( -name '*.example.dts' -o \
79ef8795f3SRob Herring			-name '*.example.dtb' \) -delete 2>/dev/null)
80