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