Blame view

scripts/Makefile.lib 14.7 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)))
8fdc3fbbd   Cao jin   kbuild: comments ...
21
22
23
24
  # Determine modorder.
  # Unfortunately, we don't have information about ordering between -y
  # and -m subdirs.  Just put -y's first.
  modorder	:= $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m:.o=.ko))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
25
26
27
  
  # Handle objects in subdirs
  # ---------------------------------------------------------------------------
f49821ee3   Nicholas Piggin   kbuild: rename bu...
28
  # o if we encounter foo/ in $(obj-y), replace it by foo/built-in.a
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
29
  #   and add the directory to the list of dirs to descend into: $(subdir-y)
38385f8f0   Masahiro Yamada   kbuild: trivial -...
30
  # o if we encounter foo/ in $(obj-m), remove it from $(obj-m)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
31
  #   and add the directory to the list of dirs to descend into: $(subdir-m)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
32
33
34
35
  __subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
  subdir-y	+= $(__subdir-y)
  __subdir-m	:= $(patsubst %/,%,$(filter %/, $(obj-m)))
  subdir-m	+= $(__subdir-m)
f49821ee3   Nicholas Piggin   kbuild: rename bu...
36
  obj-y		:= $(patsubst %/, %/built-in.a, $(obj-y))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
37
38
39
  obj-m		:= $(filter-out %/, $(obj-m))
  
  # Subdirectories we need to descend into
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
40
  subdir-ym	:= $(sort $(subdir-y) $(subdir-m))
33e84f2e7   Masahiro Yamada   kbuild: treat an ...
41
42
43
  # 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
44
  multi-used   := $(multi-used-y) $(multi-used-m)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
45

f5fb97652   Sam Ravnborg   kbuild: fix direc...
46
47
  # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
  # tell kbuild to descend
f49821ee3   Nicholas Piggin   kbuild: rename bu...
48
  subdir-obj-y := $(filter %/built-in.a, $(obj-y))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
49

f98fe47ce   Masahiro Yamada   kbuild: link $(re...
50
51
  # Replace multi-part objects by their individual parts,
  # including built-in.a from subdirectories
33e84f2e7   Masahiro Yamada   kbuild: treat an ...
52
53
  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
54

7e7962dd1   Masahiro Yamada   kbuild: handle dt...
55
56
57
58
  # 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...
59
60
61
62
  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
63
64
65
66
67
  # Add subdir path
  
  extra-y		:= $(addprefix $(obj)/,$(extra-y))
  always		:= $(addprefix $(obj)/,$(always))
  targets		:= $(addprefix $(obj)/,$(targets))
551559e13   Tejun Heo   kbuild: implement...
68
  modorder	:= $(addprefix $(obj)/,$(modorder))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
69
70
71
  obj-m		:= $(addprefix $(obj)/,$(obj-m))
  lib-y		:= $(addprefix $(obj)/,$(lib-y))
  subdir-obj-y	:= $(addprefix $(obj)/,$(subdir-obj-y))
f5f336812   Masahiro Yamada   kbuild: rename re...
72
73
  real-obj-y	:= $(addprefix $(obj)/,$(real-obj-y))
  real-obj-m	:= $(addprefix $(obj)/,$(real-obj-m))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
74
  multi-used-m	:= $(addprefix $(obj)/,$(multi-used-m))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
75
  subdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
76

c0152e9a6   Masahiro Yamada   kbuild: move modn...
77
78
79
80
81
82
83
  # Finds the multi-part object the current object will be linked into.
  # If the object belongs to two or more multi-part objects, all of them are
  # concatenated with a colon separator.
  modname-multi = $(subst $(space),:,$(sort $(foreach m,$(multi-used),\
  		$(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=)))))
  
  modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
54b8ae66a   Masahiro Yamada   kbuild: change *F...
84
85
  # target with $(obj)/ and its suffix stripped
  target-stem = $(basename $(patsubst $(obj)/%,%,$@))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
86
  # These flags are needed for modversions and compiling, so we define them here
8fdc3fbbd   Cao jin   kbuild: comments ...
87
  # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
88
  # end up in (or would, if it gets compiled in)
b42841b7b   Michal Marek   kbuild: Get rid o...
89
90
  name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
  basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
aeacb019b   Masahiro Yamada   kbuild: define KB...
91
  modname_flags  = -DKBUILD_MODNAME=$(call name-fix,$(modname))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
92

4e13d47c5   Masahiro Yamada   kbuild: remove KB...
93
  orig_c_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
54b8ae66a   Masahiro Yamada   kbuild: change *F...
94
95
                   $(ccflags-y) $(CFLAGS_$(target-stem).o)
  _c_flags       = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), $(orig_c_flags))
4e13d47c5   Masahiro Yamada   kbuild: remove KB...
96
  orig_a_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
54b8ae66a   Masahiro Yamada   kbuild: change *F...
97
98
99
                   $(asflags-y) $(AFLAGS_$(target-stem).o)
  _a_flags       = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), $(orig_a_flags))
  _cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
100

2521f2c22   Peter Oberparleiter   gcov: add gcov pr...
101
102
103
104
105
106
107
108
109
110
  #
  # 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...
111
112
113
114
115
116
117
  #
  # 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...
118
  		$(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
0b24becc8   Andrey Ryabinin   kasan: add kernel...
119
  endif
c6d308534   Andrey Ryabinin   UBSAN: run-time u...
120
121
122
123
124
  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 ...
125
126
  ifeq ($(CONFIG_KCOV),y)
  _c_flags += $(if $(patsubst n%,, \
a4691deab   Vegard Nossum   kcov: allow more ...
127
  	$(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
5c9a8750a   Dmitry Vyukov   kernel: add kcov ...
128
129
  	$(CFLAGS_KCOV))
  endif
cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
130
131
  # $(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...
132
  ifeq ($(KBUILD_EXTMOD),)
051f278e9   Masahiro Yamada   kbuild: replace K...
133
  ifdef building_out_of_srctree
cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
134
135
136
  _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
137
  endif
58156ba44   Masahiro Yamada   kbuild: skip 'add...
138
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
139

eb27ea5ce   Masahiro Yamada   kbuild: move modk...
140
141
142
143
144
145
146
147
148
149
150
  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), \
  		$(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL))
  
  modkern_aflags = $(if $(part-of-module),				\
  			$(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE),	\
  			$(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL))
d8672b40d   Sam Ravnborg   kbuild: expand -I...
151
  c_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
a95b37e20   Masahiro Yamada   kbuild: get <linu...
152
  		 -include $(srctree)/include/linux/compiler_types.h       \
cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
153
  		 $(_c_flags) $(modkern_cflags)                           \
b42841b7b   Michal Marek   kbuild: Get rid o...
154
  		 $(basename_flags) $(modname_flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
155

d8672b40d   Sam Ravnborg   kbuild: expand -I...
156
  a_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
157
  		 $(_a_flags) $(modkern_aflags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
158

d8672b40d   Sam Ravnborg   kbuild: expand -I...
159
  cpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
cdd750bfb   Masahiro Yamada   kbuild: remove 'a...
160
  		 $(_cpp_flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
161

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

50f9ddaf6   Masahiro Yamada   of: search script...
164
  DTC_INCLUDE    := $(srctree)/scripts/dtc/include-prefixes
b0a4d8b3c   Ian Campbell   kbuild: make sure...
165
  dtc_cpp_flags  = -Wp,-MD,$(depfile).pre.tmp -nostdinc                    \
50f9ddaf6   Masahiro Yamada   of: search script...
166
  		 $(addprefix -I,$(DTC_INCLUDE))                          \
e570d7c15   Stephen Warren   kbuild: limit dtc...
167
  		 -undef -D__DTS__
c8589d1e9   Masahiro Yamada   kbuild: handle mu...
168
169
170
171
172
173
174
175
  # 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
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
176
177
178
179
180
  # Shipped files
  # ===========================================================================
  
  quiet_cmd_shipped = SHIPPED $@
  cmd_shipped = cat $< > $@
991d76c95   Arnaud Lacombe   kbuild: simplify ...
181
  $(obj)/%: $(src)/%_shipped
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
182
183
184
185
  	$(call cmd,shipped)
  
  # Commands useful for building a boot image
  # ===========================================================================
38385f8f0   Masahiro Yamada   kbuild: trivial -...
186
  #
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
188
189
190
191
  #	Use as following:
  #
  #	target: source(s) FORCE
  #		$(if_changed,ld/objcopy/gzip)
  #
836caba77   Sam Ravnborg   kbuild: kill back...
192
  #	and add target to extra-y so that we know we have to
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
193
194
195
196
197
198
  #	read in the saved command line
  
  # Linking
  # ---------------------------------------------------------------------------
  
  quiet_cmd_ld = LD      $@
afa974b77   Masahiro Yamada   kbuild: add real-...
199
        cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
200

898f5a009   Masahiro Yamada   kbuild: move arch...
201
202
203
204
  # Archive
  # ---------------------------------------------------------------------------
  
  quiet_cmd_ar = AR      $@
13dc8c029   Masahiro Yamada   kbuild: remove ar...
205
        cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
898f5a009   Masahiro Yamada   kbuild: move arch...
206

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
207
208
209
210
211
212
213
214
215
216
  # Objcopy
  # ---------------------------------------------------------------------------
  
  quiet_cmd_objcopy = OBJCOPY $@
  cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
  
  # Gzip
  # ---------------------------------------------------------------------------
  
  quiet_cmd_gzip = GZIP    $@
c98b6ebd9   Denis Efremov   kbuild: fix broke...
217
        cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
218

aab94339c   Dirk Brandewie   of: Add support f...
219
220
  # DTC
  # ---------------------------------------------------------------------------
6b22b3d16   Rob Herring   kbuild: Allow usi...
221
  DTC ?= $(objtree)/scripts/dtc/dtc
aab94339c   Dirk Brandewie   of: Add support f...
222

bc553986a   Rob Herring   dtc: turn off dtc...
223
  # Disable noisy checks by default
e27128db6   Masahiro Yamada   kbuild: rename KB...
224
  ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
8654cb8d0   Rob Herring   dtc: update warni...
225
  DTC_FLAGS += -Wno-unit_address_vs_reg \
8654cb8d0   Rob Herring   dtc: update warni...
226
  	-Wno-unit_address_format \
4fd98e374   Rob Herring   scripts: turn off...
227
228
  	-Wno-avoid_unnecessary_addr_size \
  	-Wno-alias_paths \
74656b682   Rob Herring   kbuild: disable n...
229
  	-Wno-graph_child_address \
70523a3ce   Rob Herring   kbuild: disable d...
230
  	-Wno-simple_bus_reg \
74656b682   Rob Herring   kbuild: disable n...
231
  	-Wno-unique_unit_address \
8654cb8d0   Rob Herring   dtc: update warni...
232
  	-Wno-pci_device_reg
bc553986a   Rob Herring   dtc: turn off dtc...
233
  endif
e27128db6   Masahiro Yamada   kbuild: rename KB...
234
  ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
8654cb8d0   Rob Herring   dtc: update warni...
235
236
  DTC_FLAGS += -Wnode_name_chars_strict \
  	-Wproperty_name_chars_strict
bc553986a   Rob Herring   dtc: turn off dtc...
237
  endif
331f74167   Frank Rowand   of: per-file dtc ...
238
  DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
aab94339c   Dirk Brandewie   of: Add support f...
239
  # Generate an assembly file to wrap the output of the device tree compiler
1c00a47e4   James Hogan   Makefile.lib: ali...
240
  quiet_cmd_dt_S_dtb= DTB     $@
aab94339c   Dirk Brandewie   of: Add support f...
241
  cmd_dt_S_dtb=						\
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
242
  {							\
aab94339c   Dirk Brandewie   of: Add support f...
243
244
245
  	echo '\#include <asm-generic/vmlinux.lds.h>'; 	\
  	echo '.section .dtb.init.rodata,"a"';		\
  	echo '.balign STRUCT_ALIGNMENT';		\
55fe6da9e   James Hogan   kbuild: Handle bu...
246
247
  	echo '.global __dtb_$(subst -,_,$(*F))_begin';	\
  	echo '__dtb_$(subst -,_,$(*F))_begin:';		\
aab94339c   Dirk Brandewie   of: Add support f...
248
  	echo '.incbin "$<" ';				\
55fe6da9e   James Hogan   kbuild: Handle bu...
249
250
  	echo '__dtb_$(subst -,_,$(*F))_end:';		\
  	echo '.global __dtb_$(subst -,_,$(*F))_end';	\
aab94339c   Dirk Brandewie   of: Add support f...
251
  	echo '.balign STRUCT_ALIGNMENT'; 		\
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
252
  } > $@
aab94339c   Dirk Brandewie   of: Add support f...
253

a7f924190   Masahiro Yamada   kbuild: add %.dtb...
254
255
  $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
  	$(call if_changed,dt_S_dtb)
aab94339c   Dirk Brandewie   of: Add support f...
256
257
  
  quiet_cmd_dtc = DTC     $@
77479b38e   Nathan Rossi   kbuild: Create di...
258
  cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
37c8a5faf   Rob Herring   kbuild: consolida...
259
  	$(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
4f0e3a57d   Rob Herring   kbuild: Add suppo...
260
  	$(DTC) -O $(2) -o $@ -b 0 \
50f9ddaf6   Masahiro Yamada   of: search script...
261
  		$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
b0a4d8b3c   Ian Campbell   kbuild: make sure...
262
263
  		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
  	cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
264

b8fc5b215   Rob Herring   kbuild: add dtc a...
265
  $(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
4f0e3a57d   Rob Herring   kbuild: Add suppo...
266
267
268
269
270
271
272
  	$(call if_changed_dep,dtc,dtb)
  
  DT_CHECKER ?= dt-validate
  DT_BINDING_DIR := Documentation/devicetree/bindings
  DT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.yaml
  
  quiet_cmd_dtb_check =	CHECK   $@
05aeca7cb   Rob Herring   dt-bindings: Pass...
273
        cmd_dtb_check =	$(DT_CHECKER) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ ;
4f0e3a57d   Rob Herring   kbuild: Add suppo...
274

f5cfa4750   Masahiro Yamada   kbuild: fix DT bi...
275
  define rule_dtc
f5688663d   Masahiro Yamada   kbuild: clean up ...
276
277
  	$(call cmd_and_fixdep,dtc,yaml)
  	$(call cmd,dtb_check)
4f0e3a57d   Rob Herring   kbuild: Add suppo...
278
279
280
  endef
  
  $(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
8f4cd6f0e   Masahiro Yamada   kbuild: fix DT bi...
281
  	$(call if_changed_rule,dtc,yaml)
90b335fbb   Stephen Warren   kbuild: centraliz...
282

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

bc22c17e1   Alain Knaff   bzip2/lzma: libra...
285
286
  # Bzip2
  # ---------------------------------------------------------------------------
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
287
288
  # 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...
289
  size_append = printf $(shell						\
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
290
  dec_size=0;								\
afa974b77   Masahiro Yamada   kbuild: add real-...
291
  for F in $(real-prereqs); do					\
a670b0b4a   Michael Forney   kbuild: Use ls(1)...
292
  	fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F);	\
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
293
294
  	dec_size=$$(expr $$dec_size + $$fsize);				\
  done;									\
1373411ae   Jonathan Nieder   kbuild: really fi...
295
296
297
298
299
300
301
302
  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...
303
304
305
  )
  
  quiet_cmd_bzip2 = BZIP2   $@
c98b6ebd9   Denis Efremov   kbuild: fix broke...
306
        cmd_bzip2 = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
bc22c17e1   Alain Knaff   bzip2/lzma: libra...
307
308
309
310
311
  
  # Lzma
  # ---------------------------------------------------------------------------
  
  quiet_cmd_lzma = LZMA    $@
37432a83f   Denis Efremov   kbuild: add varia...
312
        cmd_lzma = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
7dd65feb6   Albin Tonnerre   lib: add support ...
313

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

e76e1fdfa   Kyungsik Lee   lib: add support ...
317
  quiet_cmd_lz4 = LZ4     $@
37432a83f   Denis Efremov   kbuild: add varia...
318
        cmd_lz4 = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
319
                    $(size_append); } > $@
e76e1fdfa   Kyungsik Lee   lib: add support ...
320

e33936451   Stephen Warren   Kbuild: centraliz...
321
322
323
324
325
326
327
328
329
330
331
332
333
334
  # 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...
335

786ac51a4   Masahiro Yamada   kbuild: remove UI...
336
  quiet_cmd_uimage = UIMAGE  $@
858805b33   Masahiro Yamada   kbuild: add $(BAS...
337
        cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
e33936451   Stephen Warren   Kbuild: centraliz...
338
339
340
  			-C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
  			-T $(UIMAGE_TYPE) \
  			-a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
786ac51a4   Masahiro Yamada   kbuild: remove UI...
341
  			-n $(UIMAGE_NAME) -d $< $@
e33936451   Stephen Warren   Kbuild: centraliz...
342

24fa0402a   Lasse Collin   decompressors: ad...
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
  # 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...
361
        cmd_xzkern = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
b79c6aa6a   Masahiro Yamada   kbuild: remove un...
362
                       $(size_append); } > $@
24fa0402a   Lasse Collin   decompressors: ad...
363
364
  
  quiet_cmd_xzmisc = XZMISC  $@
37432a83f   Denis Efremov   kbuild: add varia...
365
        cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
366
367
368
369
370
  
  # ASM offsets
  # ---------------------------------------------------------------------------
  
  # Default sed regexp - multiline due to syntax constraints
cf0c3e68a   Jeroen Hofstee   kbuild: fix asm-o...
371
372
373
  #
  # 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...
374
  define sed-offsets
cf0c3e68a   Jeroen Hofstee   kbuild: fix asm-o...
375
376
  	's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
  	/^->/{s:->#\(.*\):/* \1 */:; \
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
377
  	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
cf0c3e68a   Jeroen Hofstee   kbuild: fix asm-o...
378
  	s:->::; p;}'
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
379
380
381
382
383
  endef
  
  # Use filechk to avoid rebuilds when a header changes, but the resulting file
  # does not
  define filechk_offsets
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
384
385
386
387
388
389
390
391
  	 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...
392
  	 sed -ne $(sed-offsets) < $<; \
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
393
  	 echo ""; \
ad7740863   Masahiro Yamada   kbuild: change fi...
394
  	 echo "#endif"
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
395
  endef