Blame view

scripts/Makefile.lib 18 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)
8fdc3fbbd   Cao jin   kbuild: comments ...
7
  # flags that take effect in current and sub directories
4e13d47c5   Masahiro Yamada   kbuild: remove KB...
8
9
  KBUILD_AFLAGS += $(subdir-asflags-y)
  KBUILD_CFLAGS += $(subdir-ccflags-y)
720097d89   Sam Ravnborg   kbuild: introduce...
10

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
11
12
13
14
15
  # 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
16
17
18
19
  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
20
  lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
0a8820e7f   Masahiro Yamada   kbuild: refactor ...
21
22
23
  # 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...
24
25
26
27
28
29
30
31
32
33
34
35
36
  # 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...
37
  ifdef need-builtin
f49821ee3   Nicholas Piggin   kbuild: rename bu...
38
  obj-y		:= $(patsubst %/, %/built-in.a, $(obj-y))
56d589361   Masahiro Yamada   kbuild: do not cr...
39
40
41
  else
  obj-y		:= $(filter-out %/, $(obj-y))
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42

44f87191d   Masahiro Yamada   kbuild: parameter...
43
44
45
46
47
48
  # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
  suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
  # List composite targets that are constructed by combining other targets
  multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m)))
  # List primitive targets that are compiled from source files
  real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
33e84f2e7   Masahiro Yamada   kbuild: treat an ...
49
  # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
44f87191d   Masahiro Yamada   kbuild: parameter...
50
51
  multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
  multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
a6601e01c   Masahiro Yamada   kbuild: rename mu...
52
  multi-obj-ym := $(multi-obj-y) $(multi-obj-m)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
53

f98fe47ce   Masahiro Yamada   kbuild: link $(re...
54
55
  # Replace multi-part objects by their individual parts,
  # including built-in.a from subdirectories
44f87191d   Masahiro Yamada   kbuild: parameter...
56
57
  real-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
  real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
58

5f2fb52fa   Masahiro Yamada   kbuild: rename ho...
59
  always-y += $(always-m)
faabed295   Masahiro Yamada   kbuild: introduce...
60
61
62
63
64
65
66
67
68
69
  # 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...
70
71
  # DTB
  # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
9ca29e415   Viresh Kumar   kbuild: Simplify ...
72
  dtb-$(CONFIG_OF_ALL_DTBS)       += $(dtb-)
bcf0c6642   Masahiro Yamada   kbuild: refactor ...
73
74
75
76
77
78
  # Composite DTB (i.e. DTB constructed by overlay)
  multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs)
  # Primitive DTB compiled from *.dts
  real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs)
  # Base DTB that overlay is applied onto (each first word of $(*-dtbs) expansion)
  base-dtb-y := $(foreach m, $(multi-dtb-y), $(firstword $(call suffix-search, $m, .dtb, -dtbs)))
15d16d6da   Rob Herring   kbuild: Add gener...
79

2047ace96   Masahiro Yamada   kbuild: use alway...
80
  always-y			+= $(dtb-y)
7e7962dd1   Masahiro Yamada   kbuild: handle dt...
81

4f0e3a57d   Rob Herring   kbuild: Add suppo...
82
  ifneq ($(CHECK_DTBS),)
bcf0c6642   Masahiro Yamada   kbuild: refactor ...
83
84
  always-y += $(patsubst %.dtb,%.dt.yaml, $(real-dtb-y))
  always-y += $(patsubst %.dtbo,%.dt.yaml, $(real-dtb-y))
4f0e3a57d   Rob Herring   kbuild: Add suppo...
85
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
87
88
  # Add subdir path
  
  extra-y		:= $(addprefix $(obj)/,$(extra-y))
5f2fb52fa   Masahiro Yamada   kbuild: rename ho...
89
  always-y	:= $(addprefix $(obj)/,$(always-y))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
90
  targets		:= $(addprefix $(obj)/,$(targets))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
91
92
  obj-m		:= $(addprefix $(obj)/,$(obj-m))
  lib-y		:= $(addprefix $(obj)/,$(lib-y))
f5f336812   Masahiro Yamada   kbuild: rename re...
93
94
  real-obj-y	:= $(addprefix $(obj)/,$(real-obj-y))
  real-obj-m	:= $(addprefix $(obj)/,$(real-obj-m))
a6601e01c   Masahiro Yamada   kbuild: rename mu...
95
  multi-obj-m	:= $(addprefix $(obj)/, $(multi-obj-m))
bcf0c6642   Masahiro Yamada   kbuild: refactor ...
96
97
  multi-dtb-y	:= $(addprefix $(obj)/, $(multi-dtb-y))
  real-dtb-y	:= $(addprefix $(obj)/, $(real-dtb-y))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
98
  subdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
99

c0152e9a6   Masahiro Yamada   kbuild: move modn...
100
  # Finds the multi-part object the current object will be linked into.
1664a3779   Masahiro Yamada   kbuild: pass KBUI...
101
  # If the object belongs to two or more multi-part objects, list them all.
a6601e01c   Masahiro Yamada   kbuild: rename mu...
102
  modname-multi = $(sort $(foreach m,$(multi-obj-ym),\
d4452837f   Masahiro Yamada   kbuild: refactor ...
103
  		$(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=))))
c0152e9a6   Masahiro Yamada   kbuild: move modn...
104

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

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

15d5761ad   Masahiro Yamada   kbuild: introduce...
122
123
124
125
126
127
128
129
  _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...
130
  _cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
131

2521f2c22   Peter Oberparleiter   gcov: add gcov pr...
132
133
134
135
136
137
138
139
140
141
  #
  # 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...
142
143
144
145
146
  #
  # 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)
0fea6e9af   Andrey Konovalov   kasan, arm64: exp...
147
  ifneq ($(CONFIG_KASAN_HW_TAGS),y)
0b24becc8   Andrey Ryabinin   kasan: add kernel...
148
149
  _c_flags += $(if $(patsubst n%,, \
  		$(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
0e410e158   Andrey Konovalov   kasan: don't emit...
150
  		$(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
0b24becc8   Andrey Ryabinin   kasan: add kernel...
151
  endif
0fea6e9af   Andrey Konovalov   kasan, arm64: exp...
152
  endif
0b24becc8   Andrey Ryabinin   kasan: add kernel...
153

c6d308534   Andrey Ryabinin   UBSAN: run-time u...
154
155
156
157
158
  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 ...
159
160
  ifeq ($(CONFIG_KCOV),y)
  _c_flags += $(if $(patsubst n%,, \
a4691deab   Vegard Nossum   kcov: allow more ...
161
  	$(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
5c9a8750a   Dmitry Vyukov   kernel: add kcov ...
162
163
  	$(CFLAGS_KCOV))
  endif
dfd402a4c   Marco Elver   kcsan: Add Kernel...
164
165
166
167
168
169
170
171
172
  #
  # 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 ...
173

cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
174
175
  # $(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...
176
  ifeq ($(KBUILD_EXTMOD),)
051f278e9   Masahiro Yamada   kbuild: replace K...
177
  ifdef building_out_of_srctree
cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
178
179
180
  _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
181
  endif
58156ba44   Masahiro Yamada   kbuild: skip 'add...
182
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
183

eb27ea5ce   Masahiro Yamada   kbuild: move modk...
184
185
186
187
188
189
  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...
190
  		$(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
eb27ea5ce   Masahiro Yamada   kbuild: move modk...
191
192
193
194
  
  modkern_aflags = $(if $(part-of-module),				\
  			$(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE),	\
  			$(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL))
30a772977   Masahiro Yamada   kbuild: use -MMD ...
195
  c_flags        = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
a95b37e20   Masahiro Yamada   kbuild: get <linu...
196
  		 -include $(srctree)/include/linux/compiler_types.h       \
cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
197
  		 $(_c_flags) $(modkern_cflags)                           \
b42841b7b   Michal Marek   kbuild: Get rid o...
198
  		 $(basename_flags) $(modname_flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
199

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

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

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

50f9ddaf6   Masahiro Yamada   of: search script...
208
  DTC_INCLUDE    := $(srctree)/scripts/dtc/include-prefixes
30a772977   Masahiro Yamada   kbuild: use -MMD ...
209
  dtc_cpp_flags  = -Wp,-MMD,$(depfile).pre.tmp -nostdinc                    \
50f9ddaf6   Masahiro Yamada   of: search script...
210
  		 $(addprefix -I,$(DTC_INCLUDE))                          \
e570d7c15   Stephen Warren   kbuild: limit dtc...
211
  		 -undef -D__DTS__
850ded46c   Sami Tolvanen   kbuild: Fix TRIM_...
212
213
214
215
216
217
  ifeq ($(CONFIG_LTO_CLANG),y)
  # With CONFIG_LTO_CLANG, .o files in modules might be LLVM bitcode, so we
  # need to run LTO to compile them into native code (.lto.o) before further
  # processing.
  mod-prelink-ext := .lto
  endif
c8589d1e9   Masahiro Yamada   kbuild: handle mu...
218
219
220
221
222
223
224
225
  # 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...
226
227
  quiet_cmd_copy = COPY    $@
        cmd_copy = cp $< $@
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
228
229
  # Shipped files
  # ===========================================================================
3787b7da5   Masahiro Yamada   kbuild: add comme...
230
231
232
  # 'cp' preserves permissions. If you use it to copy a file in read-only srctree,
  # the copy would be read-only as well, leading to an error when executing the
  # rule next time. Use 'cat' instead in order to generate a writable file.
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
233
234
235
  
  quiet_cmd_shipped = SHIPPED $@
  cmd_shipped = cat $< > $@
991d76c95   Arnaud Lacombe   kbuild: simplify ...
236
  $(obj)/%: $(src)/%_shipped
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
237
238
239
240
  	$(call cmd,shipped)
  
  # Commands useful for building a boot image
  # ===========================================================================
38385f8f0   Masahiro Yamada   kbuild: trivial -...
241
  #
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
242
243
244
245
246
  #	Use as following:
  #
  #	target: source(s) FORCE
  #		$(if_changed,ld/objcopy/gzip)
  #
2047ace96   Masahiro Yamada   kbuild: use alway...
247
  #	and add target to 'targets' so that we know we have to
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
248
249
250
251
252
253
  #	read in the saved command line
  
  # Linking
  # ---------------------------------------------------------------------------
  
  quiet_cmd_ld = LD      $@
afa974b77   Masahiro Yamada   kbuild: add real-...
254
        cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
255

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

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

aab94339c   Dirk Brandewie   of: Add support f...
274
275
  # DTC
  # ---------------------------------------------------------------------------
6b22b3d16   Rob Herring   kbuild: Allow usi...
276
  DTC ?= $(objtree)/scripts/dtc/dtc
3eb619b2f   Rob Herring   scripts/dtc: Upda...
277
  DTC_FLAGS += -Wno-interrupt_provider
aab94339c   Dirk Brandewie   of: Add support f...
278

bc553986a   Rob Herring   dtc: turn off dtc...
279
  # Disable noisy checks by default
e27128db6   Masahiro Yamada   kbuild: rename KB...
280
  ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
8654cb8d0   Rob Herring   dtc: update warni...
281
  DTC_FLAGS += -Wno-unit_address_vs_reg \
8654cb8d0   Rob Herring   dtc: update warni...
282
  	-Wno-unit_address_format \
4fd98e374   Rob Herring   scripts: turn off...
283
284
  	-Wno-avoid_unnecessary_addr_size \
  	-Wno-alias_paths \
74656b682   Rob Herring   kbuild: disable n...
285
  	-Wno-graph_child_address \
70523a3ce   Rob Herring   kbuild: disable d...
286
  	-Wno-simple_bus_reg \
1ee7943c3   Rob Herring   kbuild: Enable dt...
287
  	-Wno-unique_unit_address
bc553986a   Rob Herring   dtc: turn off dtc...
288
  endif
e27128db6   Masahiro Yamada   kbuild: rename KB...
289
  ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
8654cb8d0   Rob Herring   dtc: update warni...
290
  DTC_FLAGS += -Wnode_name_chars_strict \
3eb619b2f   Rob Herring   scripts/dtc: Upda...
291
292
  	-Wproperty_name_chars_strict \
  	-Winterrupt_provider
bc553986a   Rob Herring   dtc: turn off dtc...
293
  endif
331f74167   Frank Rowand   of: per-file dtc ...
294
  DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
bcf0c6642   Masahiro Yamada   kbuild: refactor ...
295
296
  # Set -@ if the target is a base DTB that overlay is applied onto
  DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
aab94339c   Dirk Brandewie   of: Add support f...
297
  # Generate an assembly file to wrap the output of the device tree compiler
1c00a47e4   James Hogan   Makefile.lib: ali...
298
  quiet_cmd_dt_S_dtb= DTB     $@
aab94339c   Dirk Brandewie   of: Add support f...
299
  cmd_dt_S_dtb=						\
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
300
  {							\
aab94339c   Dirk Brandewie   of: Add support f...
301
302
303
  	echo '\#include <asm-generic/vmlinux.lds.h>'; 	\
  	echo '.section .dtb.init.rodata,"a"';		\
  	echo '.balign STRUCT_ALIGNMENT';		\
55fe6da9e   James Hogan   kbuild: Handle bu...
304
305
  	echo '.global __dtb_$(subst -,_,$(*F))_begin';	\
  	echo '__dtb_$(subst -,_,$(*F))_begin:';		\
aab94339c   Dirk Brandewie   of: Add support f...
306
  	echo '.incbin "$<" ';				\
55fe6da9e   James Hogan   kbuild: Handle bu...
307
308
  	echo '__dtb_$(subst -,_,$(*F))_end:';		\
  	echo '.global __dtb_$(subst -,_,$(*F))_end';	\
aab94339c   Dirk Brandewie   of: Add support f...
309
  	echo '.balign STRUCT_ALIGNMENT'; 		\
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
310
  } > $@
aab94339c   Dirk Brandewie   of: Add support f...
311

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

b8fc5b215   Rob Herring   kbuild: add dtc a...
322
  $(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
78046fabe   Masahiro Yamada   kbuild: determine...
323
  	$(call if_changed_dep,dtc)
4f0e3a57d   Rob Herring   kbuild: Add suppo...
324

ce88c9c79   Viresh Kumar   kbuild: Add suppo...
325
326
  $(obj)/%.dtbo: $(src)/%.dts $(DTC) FORCE
  	$(call if_changed_dep,dtc)
15d16d6da   Rob Herring   kbuild: Add gener...
327
328
  quiet_cmd_fdtoverlay = DTOVL   $@
        cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(real-prereqs)
bcf0c6642   Masahiro Yamada   kbuild: refactor ...
329
  $(multi-dtb-y): FORCE
15d16d6da   Rob Herring   kbuild: Add gener...
330
  	$(call if_changed,fdtoverlay)
bcf0c6642   Masahiro Yamada   kbuild: refactor ...
331
  $(call multi_depend, $(multi-dtb-y), .dtb, -dtbs)
15d16d6da   Rob Herring   kbuild: Add gener...
332

4f0e3a57d   Rob Herring   kbuild: Add suppo...
333
  DT_CHECKER ?= dt-validate
c59773d20   Rob Herring   kbuild: Enable DT...
334
  DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),,-m)
4f0e3a57d   Rob Herring   kbuild: Add suppo...
335
  DT_BINDING_DIR := Documentation/devicetree/bindings
2ba06cd85   Rob Herring   kbuild: Always va...
336
  # DT_TMP_SCHEMA may be overridden from Documentation/devicetree/bindings/Makefile
b8a49399f   Andrei Ziureaev   dt-bindings: Use ...
337
  DT_TMP_SCHEMA ?= $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
4f0e3a57d   Rob Herring   kbuild: Add suppo...
338
339
  
  quiet_cmd_dtb_check =	CHECK   $@
c59773d20   Rob Herring   kbuild: Enable DT...
340
        cmd_dtb_check =	$(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@
4f0e3a57d   Rob Herring   kbuild: Add suppo...
341

7a0496056   Masahiro Yamada   kbuild: fix DT bi...
342
  define rule_dtc
78046fabe   Masahiro Yamada   kbuild: determine...
343
  	$(call cmd_and_fixdep,dtc)
f5688663d   Masahiro Yamada   kbuild: clean up ...
344
  	$(call cmd,dtb_check)
4f0e3a57d   Rob Herring   kbuild: Add suppo...
345
346
347
  endef
  
  $(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
285a65f1a   Masahiro Yamada   kbuild: remove me...
348
  	$(call if_changed_rule,dtc)
90b335fbb   Stephen Warren   kbuild: centraliz...
349

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

bc22c17e1   Alain Knaff   bzip2/lzma: libra...
352
353
  # Bzip2
  # ---------------------------------------------------------------------------
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
354
355
  # 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...
356
  size_append = printf $(shell						\
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
357
  dec_size=0;								\
afa974b77   Masahiro Yamada   kbuild: add real-...
358
  for F in $(real-prereqs); do					\
a670b0b4a   Michael Forney   kbuild: Use ls(1)...
359
  	fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F);	\
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
360
361
  	dec_size=$$(expr $$dec_size + $$fsize);				\
  done;									\
1373411ae   Jonathan Nieder   kbuild: really fi...
362
363
364
365
366
367
368
369
  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...
370
371
372
  )
  
  quiet_cmd_bzip2 = BZIP2   $@
e4a42c82e   Denis Efremov   kbuild: fix broke...
373
        cmd_bzip2 = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
bc22c17e1   Alain Knaff   bzip2/lzma: libra...
374
375
376
377
378
  
  # Lzma
  # ---------------------------------------------------------------------------
  
  quiet_cmd_lzma = LZMA    $@
8dfb61dcb   Denis Efremov   kbuild: add varia...
379
        cmd_lzma = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
7dd65feb6   Albin Tonnerre   lib: add support ...
380

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

e76e1fdfa   Kyungsik Lee   lib: add support ...
384
  quiet_cmd_lz4 = LZ4     $@
8dfb61dcb   Denis Efremov   kbuild: add varia...
385
        cmd_lz4 = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
386
                    $(size_append); } > $@
e76e1fdfa   Kyungsik Lee   lib: add support ...
387

e33936451   Stephen Warren   Kbuild: centraliz...
388
389
390
391
392
393
394
395
396
397
398
399
400
401
  # 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...
402

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

24fa0402a   Lasse Collin   decompressors: ad...
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
  # 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...
428
        cmd_xzkern = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
429
                       $(size_append); } > $@
24fa0402a   Lasse Collin   decompressors: ad...
430
431
  
  quiet_cmd_xzmisc = XZMISC  $@
8dfb61dcb   Denis Efremov   kbuild: add varia...
432
        cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
433

48f7ddf78   Nick Terrell   init: Add support...
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
  # 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...
455
456
457
458
  # ASM offsets
  # ---------------------------------------------------------------------------
  
  # Default sed regexp - multiline due to syntax constraints
cf0c3e68a   Jeroen Hofstee   kbuild: fix asm-o...
459
460
461
  #
  # 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...
462
  define sed-offsets
cf0c3e68a   Jeroen Hofstee   kbuild: fix asm-o...
463
464
  	's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
  	/^->/{s:->#\(.*\):/* \1 */:; \
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
465
  	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
cf0c3e68a   Jeroen Hofstee   kbuild: fix asm-o...
466
  	s:->::; p;}'
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
467
468
469
470
471
  endef
  
  # Use filechk to avoid rebuilds when a header changes, but the resulting file
  # does not
  define filechk_offsets
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
472
473
474
475
476
477
478
479
  	 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...
480
  	 sed -ne $(sed-offsets) < $<; \
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
481
  	 echo ""; \
ad7740863   Masahiro Yamada   kbuild: change fi...
482
  	 echo "#endif"
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
483
  endef