xref: /freebsd/sys/contrib/device-tree/Makefile (revision 5b56413d04e608379c9a306373554a8e4d321bc0)
1DTC ?= dtc
2CPP ?= cpp
3
4# Disable noisy checks by default
5ifeq ($(findstring 1,$(DTC_VERBOSE)),)
6DTC_FLAGS += -Wno-unit_address_vs_reg \
7        -Wno-unit_address_format \
8        -Wno-avoid_unnecessary_addr_size \
9        -Wno-alias_paths \
10        -Wno-graph_child_address \
11        -Wno-simple_bus_reg \
12        -Wno-unique_unit_address \
13        -Wno-pci_device_reg
14endif
15
16ifneq ($(findstring 2,$(DTC_VERBOSE)),)
17DTC_FLAGS += -Wnode_name_chars_strict \
18        -Wproperty_name_chars_strict
19endif
20
21MAKEFLAGS += -rR --no-print-directory
22
23ALL_ARCHES := $(patsubst src/%,%,$(wildcard src/*))
24
25PHONY += all
26all: $(foreach i,$(ALL_ARCHES),all_$(i))
27
28PHONY += clean
29clean: $(foreach i,$(ALL_ARCHES),clean_$(i))
30
31# Do not:
32# o  use make's built-in rules and variables
33#    (this increases performance and avoids hard-to-debug behaviour);
34# o  print "Entering directory ...";
35MAKEFLAGS += -rR --no-print-directory
36
37# To put more focus on warnings, be less verbose as default
38# Use 'make V=1' to see the full commands
39
40ifeq ("$(origin V)", "command line")
41  KBUILD_VERBOSE = $(V)
42endif
43ifndef KBUILD_VERBOSE
44  KBUILD_VERBOSE = 0
45endif
46
47# Beautify output
48# ---------------------------------------------------------------------------
49#
50# Normally, we echo the whole command before executing it. By making
51# that echo $($(quiet)$(cmd)), we now have the possibility to set
52# $(quiet) to choose other forms of output instead, e.g.
53#
54#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
55#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
56#
57# If $(quiet) is empty, the whole command will be printed.
58# If it is set to "quiet_", only the short version will be printed.
59# If it is set to "silent_", nothing will be printed at all, since
60# the variable $(silent_cmd_cc_o_c) doesn't exist.
61#
62# A simple variant is to prefix commands with $(Q) - that's useful
63# for commands that shall be hidden in non-verbose mode.
64#
65#       $(Q)ln $@ :<
66#
67# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
68# If KBUILD_VERBOSE equals 1 then the above command is displayed.
69
70ifeq ($(KBUILD_VERBOSE),1)
71  quiet =
72  Q =
73else
74  quiet=quiet_
75  Q = @
76endif
77
78# If the user is running make -s (silent mode), suppress echoing of
79# commands
80
81ifneq ($(filter 4.%,$(MAKE_VERSION)),)	# make-4
82ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
83  quiet=silent_
84endif
85else					# make-3.8x
86ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
87  quiet=silent_
88endif
89endif
90
91export quiet Q KBUILD_VERBOSE
92
93all_%:
94	$(Q)$(MAKE) ARCH=$* all_arch
95
96clean_%:
97	$(Q)$(MAKE) ARCH=$* clean_arch
98
99ifeq ($(ARCH),)
100
101ALL_DTS		:= $(shell find src/* -name \*.dts)
102
103ALL_DTB		:= $(patsubst %.dts,%.dtb,$(ALL_DTS))
104
105$(ALL_DTB): ARCH=$(word 2,$(subst /, ,$@))
106$(ALL_DTB): FORCE
107	$(Q)$(MAKE) ARCH=$(ARCH) $@
108
109else
110
111ARCH_DTS	:= $(shell find src/$(ARCH) -name \*.dts)
112
113ARCH_DTB	:= $(patsubst %.dts,%.dtb,$(ARCH_DTS))
114
115src	:= src/$(ARCH)
116obj	:= src/$(ARCH)
117
118include scripts/Kbuild.include
119
120cmd_files := $(wildcard $(foreach f,$(ARCH_DTB),$(dir $(f)).$(notdir $(f)).cmd))
121
122ifneq ($(cmd_files),)
123  include $(cmd_files)
124endif
125
126quiet_cmd_clean    = CLEAN   $(obj)
127      cmd_clean    = rm -f $(__clean-files)
128
129dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
130
131dtc_cpp_flags  = -Wp,-MD,$(depfile).pre.tmp -nostdinc		\
132                 -Iinclude -I$(src) -Isrc -Itestcase-data	\
133                 -undef -D__DTS__
134
135quiet_cmd_dtc = DTC     $@
136cmd_dtc = $(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
137        $(DTC) -O dtb -o $@ -b 0 \
138                -i $(src) $(DTC_FLAGS) \
139                -d $(depfile).dtc.tmp $(dtc-tmp) ; \
140        cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
141
142$(obj)/%.dtb: $(src)/%.dts FORCE
143	$(call if_changed_dep,dtc)
144
145PHONY += all_arch
146all_arch: $(ARCH_DTB)
147	@:
148
149RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o -name CVS \
150                   -o -name .pc -o -name .hg -o -name .git \) -prune -o
151
152PHONY += clean_arch
153clean_arch: __clean-files = $(ARCH_DTB)
154clean_arch: FORCE
155	$(call cmd,clean)
156	@find . $(RCS_FIND_IGNORE) \
157		\( -name '.*.cmd' \
158		-o -name '.*.d' \
159		-o -name '.*.tmp' \
160		\) -type f -print | xargs rm -f
161
162endif
163
164help:
165	@echo "Targets:"
166	@echo "  all:                   Build all device tree binaries for all architectures"
167	@echo "  clean:                 Clean all generated files"
168	@echo ""
169	@echo "  all_<ARCH>:            Build all device tree binaries for <ARCH>"
170	@echo "  clean_<ARCH>:          Clean all generated files for <ARCH>"
171	@echo ""
172	@echo "  src/<ARCH>/<DTS>.dtb   Build a single device tree binary"
173	@echo ""
174	@echo "Architectures: $(ALL_ARCHES)"
175
176PHONY += FORCE
177FORCE:
178
179.PHONY: $(PHONY)
180