Blame view

scripts/Makefile.lib 17.9 KB
b24413180   Greg Kroah-Hartman   License cleanup: ...
1
  # SPDX-License-Identifier: GPL-2.0
f77bf0142   Sam Ravnborg   kbuild: introduce...
2
3
4
5
6
  # Backward compatibility
  asflags-y  += $(EXTRA_AFLAGS)
  ccflags-y  += $(EXTRA_CFLAGS)
  cppflags-y += $(EXTRA_CPPFLAGS)
  ldflags-y  += $(EXTRA_LDFLAGS)
59721d4eb   Masahiro Yamada   kbuild: warn if a...
7
8
  ifneq ($(always),)
  $(warning 'always' is deprecated. Please use 'always-y' instead)
5f2fb52fa   Masahiro Yamada   kbuild: rename ho...
9
  always-y   += $(always)
59721d4eb   Masahiro Yamada   kbuild: warn if a...
10
11
12
13
14
15
16
17
18
  endif
  ifneq ($(hostprogs-y),)
  $(warning 'hostprogs-y' is deprecated. Please use 'hostprogs' instead)
  hostprogs  += $(hostprogs-y)
  endif
  ifneq ($(hostprogs-m),)
  $(warning 'hostprogs-m' is deprecated. Please use 'hostprogs' instead)
  hostprogs  += $(hostprogs-m)
  endif
f77bf0142   Sam Ravnborg   kbuild: introduce...
19

8fdc3fbbd   Cao jin   kbuild: comments ...
20
  # flags that take effect in current and sub directories
4e13d47c5   Masahiro Yamada   kbuild: remove KB...
21
22
  KBUILD_AFLAGS += $(subdir-asflags-y)
  KBUILD_CFLAGS += $(subdir-ccflags-y)
720097d89   Sam Ravnborg   kbuild: introduce...
23

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
24
25
26
27
28
  # Figure out what we need to build from the various variables
  # ===========================================================================
  
  # When an object is listed to be built compiled-in and modular,
  # only build the compiled-in version
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
30
31
32
  obj-m := $(filter-out $(obj-y),$(obj-m))
  
  # Libraries are always collected in one lib file.
  # Filter out objects already built-in
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
33
  lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
0a8820e7f   Masahiro Yamada   kbuild: refactor ...
34
35
36
  # Subdirectories we need to descend into
  subdir-ym := $(sort $(subdir-y) $(subdir-m) \
  			$(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
b2c885549   Masahiro Yamada   kbuild: update mo...
37
38
39
40
41
42
43
44
45
46
47
48
49
  # Handle objects in subdirs:
  # - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
  #   foo/modules.order
  # - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
  #
  # Generate modules.order to determine modorder. Unfortunately, we don't have
  # information about ordering between -y and -m subdirs. Just put -y's first.
  
  ifdef need-modorder
  obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
  else
  obj-m := $(filter-out %/, $(obj-m))
  endif
56d589361   Masahiro Yamada   kbuild: do not cr...
50
  ifdef need-builtin
f49821ee3   Nicholas Piggin   kbuild: rename bu...
51
  obj-y		:= $(patsubst %/, %/built-in.a, $(obj-y))
56d589361   Masahiro Yamada   kbuild: do not cr...
52
53
54
  else
  obj-y		:= $(filter-out %/, $(obj-y))
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
55

33e84f2e7   Masahiro Yamada   kbuild: treat an ...
56
57
58
  # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
  multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-))), $(m))))
  multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)) $($(m:.o=-))), $(m))))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
  multi-used   := $(multi-used-y) $(multi-used-m)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
60

f98fe47ce   Masahiro Yamada   kbuild: link $(re...
61
62
  # Replace multi-part objects by their individual parts,
  # including built-in.a from subdirectories
33e84f2e7   Masahiro Yamada   kbuild: treat an ...
63
64
  real-obj-y := $(foreach m, $(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
  real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)) $($(m:.o=-))),$($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m)),$(m)))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65

5f2fb52fa   Masahiro Yamada   kbuild: rename ho...
66
  always-y += $(always-m)
faabed295   Masahiro Yamada   kbuild: introduce...
67
68
69
70
71
72
73
74
75
76
  # hostprogs-always-y += foo
  # ... is a shorthand for
  # hostprogs += foo
  # always-y  += foo
  hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
  always-y += $(hostprogs-always-y) $(hostprogs-always-m)
  
  # userprogs-always-y is likewise.
  userprogs += $(userprogs-always-y) $(userprogs-always-m)
  always-y += $(userprogs-always-y) $(userprogs-always-m)
7e7962dd1   Masahiro Yamada   kbuild: handle dt...
77
78
79
80
  # DTB
  # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
  extra-y				+= $(dtb-y)
  extra-$(CONFIG_OF_ALL_DTBS)	+= $(dtb-)
4f0e3a57d   Rob Herring   kbuild: Add suppo...
81
82
83
84
  ifneq ($(CHECK_DTBS),)
  extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y))
  extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
85
86
87
  # Add subdir path
  
  extra-y		:= $(addprefix $(obj)/,$(extra-y))
5f2fb52fa   Masahiro Yamada   kbuild: rename ho...
88
  always-y	:= $(addprefix $(obj)/,$(always-y))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
89
  targets		:= $(addprefix $(obj)/,$(targets))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
91
  obj-m		:= $(addprefix $(obj)/,$(obj-m))
  lib-y		:= $(addprefix $(obj)/,$(lib-y))
f5f336812   Masahiro Yamada   kbuild: rename re...
92
93
  real-obj-y	:= $(addprefix $(obj)/,$(real-obj-y))
  real-obj-m	:= $(addprefix $(obj)/,$(real-obj-m))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
94
  multi-used-m	:= $(addprefix $(obj)/,$(multi-used-m))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95
  subdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
96

c0152e9a6   Masahiro Yamada   kbuild: move modn...
97
  # Finds the multi-part object the current object will be linked into.
1664a3779   Masahiro Yamada   kbuild: pass KBUI...
98
99
100
  # If the object belongs to two or more multi-part objects, list them all.
  modname-multi = $(sort $(foreach m,$(multi-used),\
  		$(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=))))
c0152e9a6   Masahiro Yamada   kbuild: move modn...
101

1664a3779   Masahiro Yamada   kbuild: pass KBUI...
102
103
104
105
  __modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
  
  modname = $(subst $(space),:,$(__modname))
  modfile = $(addprefix $(obj)/,$(__modname))
c0152e9a6   Masahiro Yamada   kbuild: move modn...
106

54b8ae66a   Masahiro Yamada   kbuild: change *F...
107
108
  # target with $(obj)/ and its suffix stripped
  target-stem = $(basename $(patsubst $(obj)/%,%,$@))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
109
  # These flags are needed for modversions and compiling, so we define them here
8fdc3fbbd   Cao jin   kbuild: comments ...
110
  # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
111
  # end up in (or would, if it gets compiled in)
110784e04   Sami Tolvanen   FROMLIST: init: l...
112
113
  name-fix-token = $(subst $(comma),_,$(subst -,_,$1))
  name-fix = $(call stringify,$(call name-fix-token,$1))
b42841b7b   Michal Marek   kbuild: Get rid o...
114
  basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
110784e04   Sami Tolvanen   FROMLIST: init: l...
115
116
  modname_flags  = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \
  		 -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname))
1664a3779   Masahiro Yamada   kbuild: pass KBUI...
117
  modfile_flags  = -DKBUILD_MODFILE=$(call stringify,$(modfile))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
118

15d5761ad   Masahiro Yamada   kbuild: introduce...
119
120
121
122
123
124
125
126
  _c_flags       = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
                       $(filter-out $(ccflags-remove-y), \
                           $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
                       $(CFLAGS_$(target-stem).o))
  _a_flags       = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
                       $(filter-out $(asflags-remove-y), \
                           $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
                       $(AFLAGS_$(target-stem).o))
54b8ae66a   Masahiro Yamada   kbuild: change *F...
127
  _cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
128

2521f2c22   Peter Oberparleiter   gcov: add gcov pr...
129
130
131
132
133
134
135
136
137
138
  #
  # Enable gcov profiling flags for a file, directory or for all files depending
  # on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
  # (in this order)
  #
  ifeq ($(CONFIG_GCOV_KERNEL),y)
  _c_flags += $(if $(patsubst n%,, \
  		$(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
  		$(CFLAGS_GCOV))
  endif
0b24becc8   Andrey Ryabinin   kasan: add kernel...
139
140
141
142
143
144
145
  #
  # Enable address sanitizer flags for kernel except some files or directories
  # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
  #
  ifeq ($(CONFIG_KASAN),y)
  _c_flags += $(if $(patsubst n%,, \
  		$(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
0e410e158   Andrey Konovalov   kasan: don't emit...
146
  		$(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
0b24becc8   Andrey Ryabinin   kasan: add kernel...
147
  endif
c6d308534   Andrey Ryabinin   UBSAN: run-time u...
148
149
150
151
152
  ifeq ($(CONFIG_UBSAN),y)
  _c_flags += $(if $(patsubst n%,, \
  		$(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
  		$(CFLAGS_UBSAN))
  endif
5c9a8750a   Dmitry Vyukov   kernel: add kcov ...
153
154
  ifeq ($(CONFIG_KCOV),y)
  _c_flags += $(if $(patsubst n%,, \
a4691deab   Vegard Nossum   kcov: allow more ...
155
  	$(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
5c9a8750a   Dmitry Vyukov   kernel: add kcov ...
156
157
  	$(CFLAGS_KCOV))
  endif
dfd402a4c   Marco Elver   kcsan: Add Kernel...
158
159
160
161
162
163
164
165
166
  #
  # Enable KCSAN flags except some files or directories we don't want to check
  # (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE)
  #
  ifeq ($(CONFIG_KCSAN),y)
  _c_flags += $(if $(patsubst n%,, \
  	$(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \
  	$(CFLAGS_KCSAN))
  endif
5c9a8750a   Dmitry Vyukov   kernel: add kcov ...
167

cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
168
169
  # $(srctree)/$(src) for including checkin headers from generated source files
  # $(objtree)/$(obj) for including generated headers from checkin source files
58156ba44   Masahiro Yamada   kbuild: skip 'add...
170
  ifeq ($(KBUILD_EXTMOD),)
051f278e9   Masahiro Yamada   kbuild: replace K...
171
  ifdef building_out_of_srctree
cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
172
173
174
  _c_flags   += -I $(srctree)/$(src) -I $(objtree)/$(obj)
  _a_flags   += -I $(srctree)/$(src) -I $(objtree)/$(obj)
  _cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
175
  endif
58156ba44   Masahiro Yamada   kbuild: skip 'add...
176
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
177

eb27ea5ce   Masahiro Yamada   kbuild: move modk...
178
179
180
181
182
183
  part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
  quiet_modtag = $(if $(part-of-module),[M],   )
  
  modkern_cflags =                                          \
  	$(if $(part-of-module),                           \
  		$(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
1664a3779   Masahiro Yamada   kbuild: pass KBUI...
184
  		$(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
eb27ea5ce   Masahiro Yamada   kbuild: move modk...
185
186
187
188
  
  modkern_aflags = $(if $(part-of-module),				\
  			$(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE),	\
  			$(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL))
30a772977   Masahiro Yamada   kbuild: use -MMD ...
189
  c_flags        = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
a95b37e20   Masahiro Yamada   kbuild: get <linu...
190
  		 -include $(srctree)/include/linux/compiler_types.h       \
cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
191
  		 $(_c_flags) $(modkern_cflags)                           \
b42841b7b   Michal Marek   kbuild: Get rid o...
192
  		 $(basename_flags) $(modname_flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
193

30a772977   Masahiro Yamada   kbuild: use -MMD ...
194
  a_flags        = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
195
  		 $(_a_flags) $(modkern_aflags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
196

30a772977   Masahiro Yamada   kbuild: use -MMD ...
197
  cpp_flags      = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
198
  		 $(_cpp_flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199

d503ac531   Masahiro Yamada   kbuild: rename LD...
200
  ld_flags       = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
201

50f9ddaf6   Masahiro Yamada   of: search script...
202
  DTC_INCLUDE    := $(srctree)/scripts/dtc/include-prefixes
30a772977   Masahiro Yamada   kbuild: use -MMD ...
203
  dtc_cpp_flags  = -Wp,-MMD,$(depfile).pre.tmp -nostdinc                    \
50f9ddaf6   Masahiro Yamada   of: search script...
204
  		 $(addprefix -I,$(DTC_INCLUDE))                          \
e570d7c15   Stephen Warren   kbuild: limit dtc...
205
  		 -undef -D__DTS__
6dd43b98c   Sami Tolvanen   FROMLIST: kbuild:...
206
207
208
209
210
211
212
213
214
215
216
  # Objtool arguments are also needed for modfinal with LTO, so we define
  # then here to avoid duplication.
  objtool_args =								\
  	$(if $(CONFIG_UNWINDER_ORC),orc generate,check)			\
  	$(if $(part-of-module), --module,)				\
  	$(if $(CONFIG_FRAME_POINTER),, --no-fp)				\
  	$(if $(or $(CONFIG_GCOV_KERNEL),$(CONFIG_LTO_CLANG)), 		\
  		--no-unreachable,)					\
  	$(if $(CONFIG_RETPOLINE), --retpoline,)				\
  	$(if $(CONFIG_X86_SMAP), --uaccess,)				\
  	$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount,)
c8589d1e9   Masahiro Yamada   kbuild: handle mu...
217
218
219
220
221
222
223
224
  # Useful for describing the dependency of composite objects
  # Usage:
  #   $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
  define multi_depend
  $(foreach m, $(notdir $1), \
  	$(eval $(obj)/$m: \
  	$(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))
  endef
dee9c0b57   Masahiro Yamada   dt-bindings: copy...
225
226
  quiet_cmd_copy = COPY    $@
        cmd_copy = cp $< $@
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
227
228
229
230
231
  # Shipped files
  # ===========================================================================
  
  quiet_cmd_shipped = SHIPPED $@
  cmd_shipped = cat $< > $@
991d76c95   Arnaud Lacombe   kbuild: simplify ...
232
  $(obj)/%: $(src)/%_shipped
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233
234
235
236
  	$(call cmd,shipped)
  
  # Commands useful for building a boot image
  # ===========================================================================
38385f8f0   Masahiro Yamada   kbuild: trivial -...
237
  #
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
238
239
240
241
242
  #	Use as following:
  #
  #	target: source(s) FORCE
  #		$(if_changed,ld/objcopy/gzip)
  #
836caba77   Sam Ravnborg   kbuild: kill back...
243
  #	and add target to extra-y so that we know we have to
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
244
245
246
247
248
249
  #	read in the saved command line
  
  # Linking
  # ---------------------------------------------------------------------------
  
  quiet_cmd_ld = LD      $@
afa974b77   Masahiro Yamada   kbuild: add real-...
250
        cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
251

898f5a009   Masahiro Yamada   kbuild: move arch...
252
253
254
255
  # Archive
  # ---------------------------------------------------------------------------
  
  quiet_cmd_ar = AR      $@
13dc8c029   Masahiro Yamada   kbuild: remove ar...
256
        cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
898f5a009   Masahiro Yamada   kbuild: move arch...
257

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
258
259
260
261
262
263
264
265
266
267
  # Objcopy
  # ---------------------------------------------------------------------------
  
  quiet_cmd_objcopy = OBJCOPY $@
  cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
  
  # Gzip
  # ---------------------------------------------------------------------------
  
  quiet_cmd_gzip = GZIP    $@
e4a42c82e   Denis Efremov   kbuild: fix broke...
268
        cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269

aab94339c   Dirk Brandewie   of: Add support f...
270
271
  # DTC
  # ---------------------------------------------------------------------------
47b5470fd   Elliot Berman   FROMLIST: kbuild:...
272
273
274
275
276
277
278
279
280
  ifeq ("$(origin DTC)", "command line")
  PHONY += $(DTC)
  dtc-option = $(call try-run, $(DTC) $1 -v,$1)
  else
  # Just add the flag. DTC is compiled later as a prerequisite, so there's no dtc
  # to test the flag against. This is okay because we're not testing flags which
  # aren't supported by in-kernel dtc to begin with.
  dtc-option = $1
  endif
6b22b3d16   Rob Herring   kbuild: Allow usi...
281
  DTC ?= $(objtree)/scripts/dtc/dtc
47b5470fd   Elliot Berman   FROMLIST: kbuild:...
282
  DTC_FLAGS += $(call dtc-option,-Wno-interrupt_provider)
aab94339c   Dirk Brandewie   of: Add support f...
283

bc553986a   Rob Herring   dtc: turn off dtc...
284
  # Disable noisy checks by default
e27128db6   Masahiro Yamada   kbuild: rename KB...
285
  ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
47b5470fd   Elliot Berman   FROMLIST: kbuild:...
286
287
288
289
290
291
292
293
  DTC_FLAGS += $(call dtc-option,-Wno-unit_address_vs_reg) \
  	$(call dtc-option,-Wno-unit_address_format) \
  	$(call dtc-option,-Wno-avoid_unnecessary_addr_size) \
  	$(call dtc-option,-Wno-alias_paths) \
  	$(call dtc-option,-Wno-graph_child_address) \
  	$(call dtc-option,-Wno-simple_bus_reg) \
  	$(call dtc-option,-Wno-unique_unit_address) \
  	$(call dtc-option,-Wno-pci_device_reg)
bc553986a   Rob Herring   dtc: turn off dtc...
294
  endif
e27128db6   Masahiro Yamada   kbuild: rename KB...
295
  ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
47b5470fd   Elliot Berman   FROMLIST: kbuild:...
296
297
298
  DTC_FLAGS += $(call dtc-option,-Wnode_name_chars_strict) \
  	$(call dtc-option,-Wproperty_name_chars_strict) \
  	$(call dtc-option,-Winterrupt_provider)
bc553986a   Rob Herring   dtc: turn off dtc...
299
  endif
331f74167   Frank Rowand   of: per-file dtc ...
300
  DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
aab94339c   Dirk Brandewie   of: Add support f...
301
  # Generate an assembly file to wrap the output of the device tree compiler
1c00a47e4   James Hogan   Makefile.lib: ali...
302
  quiet_cmd_dt_S_dtb= DTB     $@
aab94339c   Dirk Brandewie   of: Add support f...
303
  cmd_dt_S_dtb=						\
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
304
  {							\
aab94339c   Dirk Brandewie   of: Add support f...
305
306
307
  	echo '\#include <asm-generic/vmlinux.lds.h>'; 	\
  	echo '.section .dtb.init.rodata,"a"';		\
  	echo '.balign STRUCT_ALIGNMENT';		\
55fe6da9e   James Hogan   kbuild: Handle bu...
308
309
  	echo '.global __dtb_$(subst -,_,$(*F))_begin';	\
  	echo '__dtb_$(subst -,_,$(*F))_begin:';		\
aab94339c   Dirk Brandewie   of: Add support f...
310
  	echo '.incbin "$<" ';				\
55fe6da9e   James Hogan   kbuild: Handle bu...
311
312
  	echo '__dtb_$(subst -,_,$(*F))_end:';		\
  	echo '.global __dtb_$(subst -,_,$(*F))_end';	\
aab94339c   Dirk Brandewie   of: Add support f...
313
  	echo '.balign STRUCT_ALIGNMENT'; 		\
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
314
  } > $@
aab94339c   Dirk Brandewie   of: Add support f...
315

a7f924190   Masahiro Yamada   kbuild: add %.dtb...
316
317
  $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
  	$(call if_changed,dt_S_dtb)
aab94339c   Dirk Brandewie   of: Add support f...
318
319
  
  quiet_cmd_dtc = DTC     $@
dd7699e37   Masahiro Yamada   Revert "kbuild: C...
320
  cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
78046fabe   Masahiro Yamada   kbuild: determine...
321
  	$(DTC) -O $(patsubst .%,%,$(suffix $@)) -o $@ -b 0 \
50f9ddaf6   Masahiro Yamada   of: search script...
322
  		$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
b0a4d8b3c   Ian Campbell   kbuild: make sure...
323
324
  		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
  	cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
325

b8fc5b215   Rob Herring   kbuild: add dtc a...
326
  $(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
78046fabe   Masahiro Yamada   kbuild: determine...
327
  	$(call if_changed_dep,dtc)
4f0e3a57d   Rob Herring   kbuild: Add suppo...
328
329
330
  
  DT_CHECKER ?= dt-validate
  DT_BINDING_DIR := Documentation/devicetree/bindings
2ba06cd85   Rob Herring   kbuild: Always va...
331
  # DT_TMP_SCHEMA may be overridden from Documentation/devicetree/bindings/Makefile
b8a49399f   Andrei Ziureaev   dt-bindings: Use ...
332
  DT_TMP_SCHEMA ?= $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
4f0e3a57d   Rob Herring   kbuild: Add suppo...
333
334
  
  quiet_cmd_dtb_check =	CHECK   $@
fd63fab48   Masahiro Yamada   kbuild: remove un...
335
        cmd_dtb_check =	$(DT_CHECKER) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@
4f0e3a57d   Rob Herring   kbuild: Add suppo...
336

7a0496056   Masahiro Yamada   kbuild: fix DT bi...
337
  define rule_dtc
78046fabe   Masahiro Yamada   kbuild: determine...
338
  	$(call cmd_and_fixdep,dtc)
f5688663d   Masahiro Yamada   kbuild: clean up ...
339
  	$(call cmd,dtb_check)
4f0e3a57d   Rob Herring   kbuild: Add suppo...
340
341
342
  endef
  
  $(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
3d4b22386   Masahiro Yamada   kbuild: fix DT bi...
343
  	$(call if_changed_rule,dtc,yaml)
90b335fbb   Stephen Warren   kbuild: centraliz...
344

b0a4d8b3c   Ian Campbell   kbuild: make sure...
345
  dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
22435f383   Stephen Warren   kbuild: create a ...
346

bc22c17e1   Alain Knaff   bzip2/lzma: libra...
347
348
  # Bzip2
  # ---------------------------------------------------------------------------
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
349
350
  # Bzip2 and LZMA do not include size in file... so we have to fake that;
  # append the size as a 32-bit littleendian number as gzip does.
4a2ff67c8   Michael Tokarev   kbuild: fix bzIma...
351
  size_append = printf $(shell						\
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
352
  dec_size=0;								\
afa974b77   Masahiro Yamada   kbuild: add real-...
353
  for F in $(real-prereqs); do					\
a670b0b4a   Michael Forney   kbuild: Use ls(1)...
354
  	fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F);	\
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
355
356
  	dec_size=$$(expr $$dec_size + $$fsize);				\
  done;									\
1373411ae   Jonathan Nieder   kbuild: really fi...
357
358
359
360
361
362
363
364
  printf "%08x
  " $$dec_size |						\
  	sed 's/\(..\)/\1 /g' | {					\
  		read ch0 ch1 ch2 ch3;					\
  		for ch in $$ch3 $$ch2 $$ch1 $$ch0; do			\
  			printf '%s%03o' '\\' $$((0x$$ch)); 		\
  		done;							\
  	}								\
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
365
366
367
  )
  
  quiet_cmd_bzip2 = BZIP2   $@
e4a42c82e   Denis Efremov   kbuild: fix broke...
368
        cmd_bzip2 = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
bc22c17e1   Alain Knaff   bzip2/lzma: libra...
369
370
371
372
373
  
  # Lzma
  # ---------------------------------------------------------------------------
  
  quiet_cmd_lzma = LZMA    $@
8dfb61dcb   Denis Efremov   kbuild: add varia...
374
        cmd_lzma = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
7dd65feb6   Albin Tonnerre   lib: add support ...
375

2d74b2c62   Wu Zhangjin   scripts/Makefile....
376
  quiet_cmd_lzo = LZO     $@
e4a42c82e   Denis Efremov   kbuild: fix broke...
377
        cmd_lzo = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
d61931d89   Borislav Petkov   x86: Add optimize...
378

e76e1fdfa   Kyungsik Lee   lib: add support ...
379
  quiet_cmd_lz4 = LZ4     $@
76a0d3929   Alistair Delva   ANDROID: GKI: scr...
380
        cmd_lz4 = { cat $(real-prereqs) | \
f6e33f3b1   zhang sanshan   MA-11400 [Android...
381
                    $(LZ4) -12 --favor-decSpeed stdin stdout; \
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
382
                    $(size_append); } > $@
e76e1fdfa   Kyungsik Lee   lib: add support ...
383

e33936451   Stephen Warren   Kbuild: centraliz...
384
385
386
387
388
389
390
391
392
393
394
395
396
397
  # U-Boot mkimage
  # ---------------------------------------------------------------------------
  
  MKIMAGE := $(srctree)/scripts/mkuboot.sh
  
  # SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
  # the number of overrides in arch makefiles
  UIMAGE_ARCH ?= $(SRCARCH)
  UIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
  UIMAGE_OPTS-y ?=
  UIMAGE_TYPE ?= kernel
  UIMAGE_LOADADDR ?= arch_must_set_this
  UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
  UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
e33936451   Stephen Warren   Kbuild: centraliz...
398

786ac51a4   Masahiro Yamada   kbuild: remove UI...
399
  quiet_cmd_uimage = UIMAGE  $@
858805b33   Masahiro Yamada   kbuild: add $(BAS...
400
        cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
e33936451   Stephen Warren   Kbuild: centraliz...
401
402
403
  			-C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
  			-T $(UIMAGE_TYPE) \
  			-a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
786ac51a4   Masahiro Yamada   kbuild: remove UI...
404
  			-n $(UIMAGE_NAME) -d $< $@
e33936451   Stephen Warren   Kbuild: centraliz...
405

24fa0402a   Lasse Collin   decompressors: ad...
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
  # XZ
  # ---------------------------------------------------------------------------
  # Use xzkern to compress the kernel image and xzmisc to compress other things.
  #
  # xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
  # of the kernel decompressor. A BCJ filter is used if it is available for
  # the target architecture. xzkern also appends uncompressed size of the data
  # using size_append. The .xz format has the size information available at
  # the end of the file too, but it's in more complex format and it's good to
  # avoid changing the part of the boot code that reads the uncompressed size.
  # Note that the bytes added by size_append will make the xz tool think that
  # the file is corrupt. This is expected.
  #
  # xzmisc doesn't use size_append, so it can be used to create normal .xz
  # files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
  # big dictionary would increase the memory usage too much in the multi-call
  # decompression mode. A BCJ filter isn't used either.
  quiet_cmd_xzkern = XZKERN  $@
b956c7a6d   Harald Seiler   kbuild: fix compr...
424
        cmd_xzkern = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
425
                       $(size_append); } > $@
24fa0402a   Lasse Collin   decompressors: ad...
426
427
  
  quiet_cmd_xzmisc = XZMISC  $@
8dfb61dcb   Denis Efremov   kbuild: add varia...
428
        cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
429

48f7ddf78   Nick Terrell   init: Add support...
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
  # ZSTD
  # ---------------------------------------------------------------------------
  # Appends the uncompressed size of the data using size_append. The .zst
  # format has the size information available at the beginning of the file too,
  # but it's in a more complex format and it's good to avoid changing the part
  # of the boot code that reads the uncompressed size.
  #
  # Note that the bytes added by size_append will make the zstd tool think that
  # the file is corrupt. This is expected.
  #
  # zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of
  # 128 MB. zstd22 is used for kernel compression because it is decompressed in a
  # single pass, so zstd doesn't need to allocate a window buffer. When streaming
  # decompression is used, like initramfs decompression, zstd22 should likely not
  # be used because it would require zstd to allocate a 128 MB buffer.
  
  quiet_cmd_zstd = ZSTD    $@
        cmd_zstd = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@
  
  quiet_cmd_zstd22 = ZSTD22  $@
        cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
451
452
453
454
  # ASM offsets
  # ---------------------------------------------------------------------------
  
  # Default sed regexp - multiline due to syntax constraints
cf0c3e68a   Jeroen Hofstee   kbuild: fix asm-o...
455
456
457
  #
  # Use [:space:] because LLVM's integrated assembler inserts <tab> around
  # the .ascii directive whereas GCC keeps the <space> as-is.
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
458
  define sed-offsets
cf0c3e68a   Jeroen Hofstee   kbuild: fix asm-o...
459
460
  	's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
  	/^->/{s:->#\(.*\):/* \1 */:; \
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
461
  	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
cf0c3e68a   Jeroen Hofstee   kbuild: fix asm-o...
462
  	s:->::; p;}'
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
463
464
465
466
467
  endef
  
  # Use filechk to avoid rebuilds when a header changes, but the resulting file
  # does not
  define filechk_offsets
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
468
469
470
471
472
473
474
475
  	 echo "#ifndef $2"; \
  	 echo "#define $2"; \
  	 echo "/*"; \
  	 echo " * DO NOT MODIFY."; \
  	 echo " *"; \
  	 echo " * This file was generated by Kbuild"; \
  	 echo " */"; \
  	 echo ""; \
43fee2b23   Masahiro Yamada   kbuild: do not re...
476
  	 sed -ne $(sed-offsets) < $<; \
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
477
  	 echo ""; \
ad7740863   Masahiro Yamada   kbuild: change fi...
478
  	 echo "#endif"
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
479
  endef