xref: /freebsd/sys/contrib/device-tree/Bindings/Makefile (revision 8d13bc63c0e1d50bc9e47ac1f26329c999bfecf0)
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
6c9ccf3a3SEmmanuel VadotDT_SCHEMA_LINT = $(shell which yamllint || \
7c9ccf3a3SEmmanuel Vadot  echo "warning: python package 'yamllint' not installed, skipping" >&2)
86be33864SEmmanuel Vadot
984943d6fSEmmanuel VadotDT_SCHEMA_MIN_VERSION = 2023.9
10c66ec88fSEmmanuel Vadot
11c66ec88fSEmmanuel VadotPHONY += check_dtschema_version
12c66ec88fSEmmanuel Vadotcheck_dtschema_version:
138cc087a1SEmmanuel Vadot	@which $(DT_DOC_CHECKER) >/dev/null || \
148cc087a1SEmmanuel Vadot		{ echo "Error: '$(DT_DOC_CHECKER)' not found!" >&2; \
158cc087a1SEmmanuel Vadot		  echo "Ensure dtschema python package is installed and in your PATH." >&2; \
168cc087a1SEmmanuel Vadot		  echo "Current PATH is:" >&2; \
178cc087a1SEmmanuel Vadot		  echo "$$PATH" >&2; false; }
18c66ec88fSEmmanuel Vadot	@{ echo $(DT_SCHEMA_MIN_VERSION); \
195def4c47SEmmanuel Vadot	$(DT_DOC_CHECKER) --version 2>/dev/null || echo 0; } | sort -Vc >/dev/null || \
20c66ec88fSEmmanuel Vadot	{ echo "ERROR: dtschema minimum version is v$(DT_SCHEMA_MIN_VERSION)" >&2; false; }
21c66ec88fSEmmanuel Vadot
226be33864SEmmanuel Vadotquiet_cmd_extract_ex = DTEX    $@
236be33864SEmmanuel Vadot      cmd_extract_ex = $(DT_EXTRACT_EX) $< > $@
24c66ec88fSEmmanuel Vadot
25c66ec88fSEmmanuel Vadot$(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE
266be33864SEmmanuel Vadot	$(call if_changed,extract_ex)
27c66ec88fSEmmanuel Vadot
288cc087a1SEmmanuel Vadotfind_all_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \
29c9ccf3a3SEmmanuel Vadot		-name 'processed-schema*' \)
30c66ec88fSEmmanuel Vadot
31*8d13bc63SEmmanuel Vadotfind_cmd = $(find_all_cmd) | \
32*8d13bc63SEmmanuel Vadot		sed 's|^$(srctree)/||' | \
33*8d13bc63SEmmanuel Vadot		grep -F -e "$(subst :," -e ",$(DT_SCHEMA_FILES))" | \
34*8d13bc63SEmmanuel Vadot		sed 's|^|$(srctree)/|'
35c9ccf3a3SEmmanuel VadotCHK_DT_DOCS := $(shell $(find_cmd))
368cc087a1SEmmanuel Vadot
376be33864SEmmanuel Vadotquiet_cmd_yamllint = LINT    $(src)
385def4c47SEmmanuel Vadot      cmd_yamllint = ($(find_cmd) | \
398cc087a1SEmmanuel Vadot                     xargs -n200 -P$$(nproc) \
408cc087a1SEmmanuel Vadot		     $(DT_SCHEMA_LINT) -f parsable -c $(srctree)/$(src)/.yamllint >&2) || true
416be33864SEmmanuel Vadot
426be33864SEmmanuel Vadotquiet_cmd_chk_bindings = CHKDT   $@
435def4c47SEmmanuel Vadot      cmd_chk_bindings = ($(find_cmd) | \
445def4c47SEmmanuel Vadot                         xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(srctree)/$(src)) || true
456be33864SEmmanuel Vadot
46c66ec88fSEmmanuel Vadotquiet_cmd_mk_schema = SCHEMA  $@
476be33864SEmmanuel Vadot      cmd_mk_schema = f=$$(mktemp) ; \
48b97ee269SEmmanuel Vadot                      $(find_all_cmd) > $$f ; \
496be33864SEmmanuel Vadot                      $(DT_MK_SCHEMA) -j $(DT_MK_SCHEMA_FLAGS) @$$f > $@ ; \
506be33864SEmmanuel Vadot		      rm -f $$f
516be33864SEmmanuel Vadot
526be33864SEmmanuel Vadotdefine rule_chkdt
536be33864SEmmanuel Vadot	$(if $(DT_SCHEMA_LINT),$(call cmd,yamllint),)
546be33864SEmmanuel Vadot	$(call cmd,chk_bindings)
556be33864SEmmanuel Vadot	$(call cmd,mk_schema)
566be33864SEmmanuel Vadotendef
57c66ec88fSEmmanuel Vadot
588cc087a1SEmmanuel VadotDT_DOCS = $(patsubst $(srctree)/%,%,$(shell $(find_all_cmd)))
59c66ec88fSEmmanuel Vadot
60c66ec88fSEmmanuel Vadotoverride DTC_FLAGS := \
61c66ec88fSEmmanuel Vadot	-Wno-avoid_unnecessary_addr_size \
62c66ec88fSEmmanuel Vadot	-Wno-graph_child_address \
63e67e8565SEmmanuel Vadot	-Wno-interrupt_provider \
64e67e8565SEmmanuel Vadot	-Wno-unique_unit_address \
65e67e8565SEmmanuel Vadot	-Wunique_unit_address_if_enabled
66c66ec88fSEmmanuel Vadot
672eb4d8dcSEmmanuel Vadot# Disable undocumented compatible checks until warning free
682eb4d8dcSEmmanuel Vadotoverride DT_CHECKER_FLAGS ?=
692eb4d8dcSEmmanuel Vadot
70c9ccf3a3SEmmanuel Vadot$(obj)/processed-schema.json: $(DT_DOCS) $(src)/.yamllint check_dtschema_version FORCE
716be33864SEmmanuel Vadot	$(call if_changed_rule,chkdt)
72c66ec88fSEmmanuel Vadot
73c9ccf3a3SEmmanuel Vadotalways-y += processed-schema.json
74c9ccf3a3SEmmanuel Vadotalways-$(CHECK_DT_BINDING) += $(patsubst $(srctree)/$(src)/%.yaml,%.example.dts, $(CHK_DT_DOCS))
75c9ccf3a3SEmmanuel Vadotalways-$(CHECK_DT_BINDING) += $(patsubst $(srctree)/$(src)/%.yaml,%.example.dtb, $(CHK_DT_DOCS))
76c66ec88fSEmmanuel Vadot
77c66ec88fSEmmanuel Vadot# Hack: avoid 'Argument list too long' error for 'make clean'. Remove most of
78c66ec88fSEmmanuel Vadot# build artifacts here before they are processed by scripts/Makefile.clean
79c66ec88fSEmmanuel Vadotclean-files = $(shell find $(obj) \( -name '*.example.dts' -o \
80c9ccf3a3SEmmanuel Vadot			-name '*.example.dtb' \) -delete 2>/dev/null)
817ef62cebSEmmanuel Vadot
827ef62cebSEmmanuel Vadotdt_compatible_check: $(obj)/processed-schema.json
837ef62cebSEmmanuel Vadot	$(Q)$(srctree)/scripts/dtc/dt-extract-compatibles $(srctree) | xargs dt-check-compatible -v -s $<
84