xref: /freebsd/sys/contrib/device-tree/Bindings/Makefile (revision e67e85659c0de33e617e5fbf1028c6e8b49eee53)
1c66ec88fSEmmanuel Vadot# SPDX-License-Identifier: GPL-2.0
2c66ec88fSEmmanuel VadotDT_DOC_CHECKER ?= dt-doc-validate
3c66ec88fSEmmanuel VadotDT_EXTRACT_EX ?= dt-extract-example
4c66ec88fSEmmanuel VadotDT_MK_SCHEMA ?= dt-mk-schema
5c66ec88fSEmmanuel Vadot
66be33864SEmmanuel VadotDT_SCHEMA_LINT = $(shell which yamllint)
76be33864SEmmanuel Vadot
82eb4d8dcSEmmanuel VadotDT_SCHEMA_MIN_VERSION = 2021.2.1
9c66ec88fSEmmanuel Vadot
10c66ec88fSEmmanuel VadotPHONY += check_dtschema_version
11c66ec88fSEmmanuel Vadotcheck_dtschema_version:
128cc087a1SEmmanuel Vadot	@which $(DT_DOC_CHECKER) >/dev/null || \
138cc087a1SEmmanuel Vadot		{ echo "Error: '$(DT_DOC_CHECKER)' not found!" >&2; \
148cc087a1SEmmanuel Vadot		  echo "Ensure dtschema python package is installed and in your PATH." >&2; \
158cc087a1SEmmanuel Vadot		  echo "Current PATH is:" >&2; \
168cc087a1SEmmanuel Vadot		  echo "$$PATH" >&2; false; }
17c66ec88fSEmmanuel Vadot	@{ echo $(DT_SCHEMA_MIN_VERSION); \
185def4c47SEmmanuel Vadot	$(DT_DOC_CHECKER) --version 2>/dev/null || echo 0; } | sort -Vc >/dev/null || \
19c66ec88fSEmmanuel Vadot	{ echo "ERROR: dtschema minimum version is v$(DT_SCHEMA_MIN_VERSION)" >&2; false; }
20c66ec88fSEmmanuel Vadot
216be33864SEmmanuel Vadotquiet_cmd_extract_ex = DTEX    $@
226be33864SEmmanuel Vadot      cmd_extract_ex = $(DT_EXTRACT_EX) $< > $@
23c66ec88fSEmmanuel Vadot
24c66ec88fSEmmanuel Vadot$(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE
256be33864SEmmanuel Vadot	$(call if_changed,extract_ex)
26c66ec88fSEmmanuel Vadot
27c66ec88fSEmmanuel Vadot# Use full schemas when checking %.example.dts
286be33864SEmmanuel VadotDT_TMP_SCHEMA := $(obj)/processed-schema-examples.json
29c66ec88fSEmmanuel Vadot
308cc087a1SEmmanuel Vadotfind_all_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \
31c66ec88fSEmmanuel Vadot		-name 'processed-schema*' ! \
32c66ec88fSEmmanuel Vadot		-name '*.example.dt.yaml' \)
33c66ec88fSEmmanuel Vadot
348cc087a1SEmmanuel Vadotifeq ($(DT_SCHEMA_FILES),)
358cc087a1SEmmanuel Vadotfind_cmd = $(find_all_cmd)
368cc087a1SEmmanuel Vadotelse
378cc087a1SEmmanuel Vadotfind_cmd = echo $(addprefix $(srctree)/, $(DT_SCHEMA_FILES))
388cc087a1SEmmanuel Vadotendif
398cc087a1SEmmanuel Vadot
406be33864SEmmanuel Vadotquiet_cmd_yamllint = LINT    $(src)
415def4c47SEmmanuel Vadot      cmd_yamllint = ($(find_cmd) | \
428cc087a1SEmmanuel Vadot                     xargs -n200 -P$$(nproc) \
438cc087a1SEmmanuel Vadot		     $(DT_SCHEMA_LINT) -f parsable -c $(srctree)/$(src)/.yamllint >&2) || true
446be33864SEmmanuel Vadot
456be33864SEmmanuel Vadotquiet_cmd_chk_bindings = CHKDT   $@
465def4c47SEmmanuel Vadot      cmd_chk_bindings = ($(find_cmd) | \
475def4c47SEmmanuel Vadot                         xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(srctree)/$(src)) || true
486be33864SEmmanuel Vadot
49c66ec88fSEmmanuel Vadotquiet_cmd_mk_schema = SCHEMA  $@
506be33864SEmmanuel Vadot      cmd_mk_schema = f=$$(mktemp) ; \
51c66ec88fSEmmanuel Vadot                      $(if $(DT_MK_SCHEMA_FLAGS), \
525def4c47SEmmanuel Vadot                           printf '%s\n' $(real-prereqs), \
538cc087a1SEmmanuel Vadot                           $(find_all_cmd)) > $$f ; \
546be33864SEmmanuel Vadot                      $(DT_MK_SCHEMA) -j $(DT_MK_SCHEMA_FLAGS) @$$f > $@ ; \
556be33864SEmmanuel Vadot		      rm -f $$f
566be33864SEmmanuel Vadot
576be33864SEmmanuel Vadotdefine rule_chkdt
586be33864SEmmanuel Vadot	$(if $(DT_SCHEMA_LINT),$(call cmd,yamllint),)
596be33864SEmmanuel Vadot	$(call cmd,chk_bindings)
606be33864SEmmanuel Vadot	$(call cmd,mk_schema)
616be33864SEmmanuel Vadotendef
62c66ec88fSEmmanuel Vadot
638cc087a1SEmmanuel VadotDT_DOCS = $(patsubst $(srctree)/%,%,$(shell $(find_all_cmd)))
64c66ec88fSEmmanuel Vadot
65c66ec88fSEmmanuel Vadotoverride DTC_FLAGS := \
66c66ec88fSEmmanuel Vadot	-Wno-avoid_unnecessary_addr_size \
67c66ec88fSEmmanuel Vadot	-Wno-graph_child_address \
68*e67e8565SEmmanuel Vadot	-Wno-interrupt_provider \
69*e67e8565SEmmanuel Vadot	-Wno-unique_unit_address \
70*e67e8565SEmmanuel Vadot	-Wunique_unit_address_if_enabled
71c66ec88fSEmmanuel Vadot
722eb4d8dcSEmmanuel Vadot# Disable undocumented compatible checks until warning free
732eb4d8dcSEmmanuel Vadotoverride DT_CHECKER_FLAGS ?=
742eb4d8dcSEmmanuel Vadot
756be33864SEmmanuel Vadot$(obj)/processed-schema-examples.json: $(DT_DOCS) $(src)/.yamllint check_dtschema_version FORCE
766be33864SEmmanuel Vadot	$(call if_changed_rule,chkdt)
77c66ec88fSEmmanuel Vadot
78c66ec88fSEmmanuel Vadotifeq ($(DT_SCHEMA_FILES),)
79c66ec88fSEmmanuel Vadot
80c66ec88fSEmmanuel Vadot# Unless DT_SCHEMA_FILES is specified, use the full schema for dtbs_check too.
816be33864SEmmanuel Vadot# Just copy processed-schema-examples.json
82c66ec88fSEmmanuel Vadot
836be33864SEmmanuel Vadot$(obj)/processed-schema.json: $(obj)/processed-schema-examples.json FORCE
84c66ec88fSEmmanuel Vadot	$(call if_changed,copy)
85c66ec88fSEmmanuel Vadot
86c66ec88fSEmmanuel VadotDT_SCHEMA_FILES = $(DT_DOCS)
87c66ec88fSEmmanuel Vadot
88c66ec88fSEmmanuel Vadotelse
89c66ec88fSEmmanuel Vadot
906be33864SEmmanuel Vadot# If DT_SCHEMA_FILES is specified, use it for processed-schema.json
91c66ec88fSEmmanuel Vadot
926be33864SEmmanuel Vadot$(obj)/processed-schema.json: DT_MK_SCHEMA_FLAGS := -u
936be33864SEmmanuel Vadot$(obj)/processed-schema.json: $(DT_SCHEMA_FILES) check_dtschema_version FORCE
94c66ec88fSEmmanuel Vadot	$(call if_changed,mk_schema)
95c66ec88fSEmmanuel Vadot
96c66ec88fSEmmanuel Vadotendif
97c66ec88fSEmmanuel Vadot
985def4c47SEmmanuel Vadotalways-$(CHECK_DT_BINDING) += processed-schema-examples.json
995def4c47SEmmanuel Vadotalways-$(CHECK_DTBS)       += processed-schema.json
1005def4c47SEmmanuel Vadotalways-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dts, $(DT_SCHEMA_FILES))
1015def4c47SEmmanuel Vadotalways-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dt.yaml, $(DT_SCHEMA_FILES))
102c66ec88fSEmmanuel Vadot
103c66ec88fSEmmanuel Vadot# Hack: avoid 'Argument list too long' error for 'make clean'. Remove most of
104c66ec88fSEmmanuel Vadot# build artifacts here before they are processed by scripts/Makefile.clean
105c66ec88fSEmmanuel Vadotclean-files = $(shell find $(obj) \( -name '*.example.dts' -o \
106c66ec88fSEmmanuel Vadot			-name '*.example.dt.yaml' \) -delete 2>/dev/null)
107