xref: /freebsd/sys/contrib/device-tree/Bindings/Makefile (revision 2eb4d8dc723da3cf7d735a3226ae49da4c8c5dbc)
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
8*2eb4d8dcSEmmanuel VadotDT_SCHEMA_MIN_VERSION = 2021.2.1
9c66ec88fSEmmanuel Vadot
10c66ec88fSEmmanuel VadotPHONY += check_dtschema_version
11c66ec88fSEmmanuel Vadotcheck_dtschema_version:
12c66ec88fSEmmanuel Vadot	@{ echo $(DT_SCHEMA_MIN_VERSION); \
135def4c47SEmmanuel Vadot	$(DT_DOC_CHECKER) --version 2>/dev/null || echo 0; } | sort -Vc >/dev/null || \
14c66ec88fSEmmanuel Vadot	{ echo "ERROR: dtschema minimum version is v$(DT_SCHEMA_MIN_VERSION)" >&2; false; }
15c66ec88fSEmmanuel Vadot
166be33864SEmmanuel Vadotquiet_cmd_extract_ex = DTEX    $@
176be33864SEmmanuel Vadot      cmd_extract_ex = $(DT_EXTRACT_EX) $< > $@
18c66ec88fSEmmanuel Vadot
19c66ec88fSEmmanuel Vadot$(obj)/%.example.dts: $(src)/%.yaml check_dtschema_version FORCE
206be33864SEmmanuel Vadot	$(call if_changed,extract_ex)
21c66ec88fSEmmanuel Vadot
22c66ec88fSEmmanuel Vadot# Use full schemas when checking %.example.dts
236be33864SEmmanuel VadotDT_TMP_SCHEMA := $(obj)/processed-schema-examples.json
24c66ec88fSEmmanuel Vadot
25c66ec88fSEmmanuel Vadotfind_cmd = find $(srctree)/$(src) \( -name '*.yaml' ! \
26c66ec88fSEmmanuel Vadot		-name 'processed-schema*' ! \
27c66ec88fSEmmanuel Vadot		-name '*.example.dt.yaml' \)
28c66ec88fSEmmanuel Vadot
296be33864SEmmanuel Vadotquiet_cmd_yamllint = LINT    $(src)
305def4c47SEmmanuel Vadot      cmd_yamllint = ($(find_cmd) | \
315def4c47SEmmanuel Vadot                     xargs $(DT_SCHEMA_LINT) -f parsable -c $(srctree)/$(src)/.yamllint) || true
326be33864SEmmanuel Vadot
336be33864SEmmanuel Vadotquiet_cmd_chk_bindings = CHKDT   $@
345def4c47SEmmanuel Vadot      cmd_chk_bindings = ($(find_cmd) | \
355def4c47SEmmanuel Vadot                         xargs -n200 -P$$(nproc) $(DT_DOC_CHECKER) -u $(srctree)/$(src)) || true
366be33864SEmmanuel Vadot
37c66ec88fSEmmanuel Vadotquiet_cmd_mk_schema = SCHEMA  $@
386be33864SEmmanuel Vadot      cmd_mk_schema = f=$$(mktemp) ; \
39c66ec88fSEmmanuel Vadot                      $(if $(DT_MK_SCHEMA_FLAGS), \
405def4c47SEmmanuel Vadot                           printf '%s\n' $(real-prereqs), \
416be33864SEmmanuel Vadot                           $(find_cmd)) > $$f ; \
426be33864SEmmanuel Vadot                      $(DT_MK_SCHEMA) -j $(DT_MK_SCHEMA_FLAGS) @$$f > $@ ; \
436be33864SEmmanuel Vadot		      rm -f $$f
446be33864SEmmanuel Vadot
456be33864SEmmanuel Vadotdefine rule_chkdt
466be33864SEmmanuel Vadot	$(if $(DT_SCHEMA_LINT),$(call cmd,yamllint),)
476be33864SEmmanuel Vadot	$(call cmd,chk_bindings)
486be33864SEmmanuel Vadot	$(call cmd,mk_schema)
496be33864SEmmanuel Vadotendef
50c66ec88fSEmmanuel Vadot
51*2eb4d8dcSEmmanuel VadotDT_DOCS = $(patsubst $(srctree)/%,%,$(shell $(find_cmd)))
52c66ec88fSEmmanuel Vadot
53c66ec88fSEmmanuel Vadotoverride DTC_FLAGS := \
54c66ec88fSEmmanuel Vadot	-Wno-avoid_unnecessary_addr_size \
55c66ec88fSEmmanuel Vadot	-Wno-graph_child_address \
56c66ec88fSEmmanuel Vadot	-Wno-interrupt_provider
57c66ec88fSEmmanuel Vadot
58*2eb4d8dcSEmmanuel Vadot# Disable undocumented compatible checks until warning free
59*2eb4d8dcSEmmanuel Vadotoverride DT_CHECKER_FLAGS ?=
60*2eb4d8dcSEmmanuel Vadot
616be33864SEmmanuel Vadot$(obj)/processed-schema-examples.json: $(DT_DOCS) $(src)/.yamllint check_dtschema_version FORCE
626be33864SEmmanuel Vadot	$(call if_changed_rule,chkdt)
63c66ec88fSEmmanuel Vadot
64c66ec88fSEmmanuel Vadotifeq ($(DT_SCHEMA_FILES),)
65c66ec88fSEmmanuel Vadot
66c66ec88fSEmmanuel Vadot# Unless DT_SCHEMA_FILES is specified, use the full schema for dtbs_check too.
676be33864SEmmanuel Vadot# Just copy processed-schema-examples.json
68c66ec88fSEmmanuel Vadot
696be33864SEmmanuel Vadot$(obj)/processed-schema.json: $(obj)/processed-schema-examples.json FORCE
70c66ec88fSEmmanuel Vadot	$(call if_changed,copy)
71c66ec88fSEmmanuel Vadot
72c66ec88fSEmmanuel VadotDT_SCHEMA_FILES = $(DT_DOCS)
73c66ec88fSEmmanuel Vadot
74c66ec88fSEmmanuel Vadotelse
75c66ec88fSEmmanuel Vadot
766be33864SEmmanuel Vadot# If DT_SCHEMA_FILES is specified, use it for processed-schema.json
77c66ec88fSEmmanuel Vadot
786be33864SEmmanuel Vadot$(obj)/processed-schema.json: DT_MK_SCHEMA_FLAGS := -u
796be33864SEmmanuel Vadot$(obj)/processed-schema.json: $(DT_SCHEMA_FILES) check_dtschema_version FORCE
80c66ec88fSEmmanuel Vadot	$(call if_changed,mk_schema)
81c66ec88fSEmmanuel Vadot
82c66ec88fSEmmanuel Vadotendif
83c66ec88fSEmmanuel Vadot
845def4c47SEmmanuel Vadotalways-$(CHECK_DT_BINDING) += processed-schema-examples.json
855def4c47SEmmanuel Vadotalways-$(CHECK_DTBS)       += processed-schema.json
865def4c47SEmmanuel Vadotalways-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dts, $(DT_SCHEMA_FILES))
875def4c47SEmmanuel Vadotalways-$(CHECK_DT_BINDING) += $(patsubst $(src)/%.yaml,%.example.dt.yaml, $(DT_SCHEMA_FILES))
88c66ec88fSEmmanuel Vadot
89c66ec88fSEmmanuel Vadot# Hack: avoid 'Argument list too long' error for 'make clean'. Remove most of
90c66ec88fSEmmanuel Vadot# build artifacts here before they are processed by scripts/Makefile.clean
91c66ec88fSEmmanuel Vadotclean-files = $(shell find $(obj) \( -name '*.example.dts' -o \
92c66ec88fSEmmanuel Vadot			-name '*.example.dt.yaml' \) -delete 2>/dev/null)
93