Blame view

scripts/Makefile.lib 14.6 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))
8fdc3fbbd   Cao jin   kbuild: comments ...
41
  # if $(foo-objs), $(foo-y), or $(foo-m) exists, foo.o is a composite object
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
42
  multi-used-y := $(sort $(foreach m,$(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))), $(m))))
cf4f21938   Michal Marek   kbuild: Allow to ...
43
  multi-used-m := $(sort $(foreach m,$(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))), $(m))))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
44
45
  multi-used   := $(multi-used-y) $(multi-used-m)
  single-used-m := $(sort $(filter-out $(multi-used-m),$(obj-m)))
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
52
  # Replace multi-part objects by their individual parts,
  # including built-in.a from subdirectories
  real-obj-y := $(foreach m, $(obj-y), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y))),$($(m:.o=-objs)) $($(m:.o=-y)),$(m)))
f5f336812   Masahiro Yamada   kbuild: rename re...
53
  real-obj-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$($(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-)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
59
60
61
62
63
  # Add subdir path
  
  extra-y		:= $(addprefix $(obj)/,$(extra-y))
  always		:= $(addprefix $(obj)/,$(always))
  targets		:= $(addprefix $(obj)/,$(targets))
551559e13   Tejun Heo   kbuild: implement...
64
  modorder	:= $(addprefix $(obj)/,$(modorder))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
65
66
67
  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...
68
69
  real-obj-y	:= $(addprefix $(obj)/,$(real-obj-y))
  real-obj-m	:= $(addprefix $(obj)/,$(real-obj-m))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
70
  single-used-m	:= $(addprefix $(obj)/,$(single-used-m))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
71
  multi-used-m	:= $(addprefix $(obj)/,$(multi-used-m))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
72
  subdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
73

c0152e9a6   Masahiro Yamada   kbuild: move modn...
74
75
76
77
78
79
80
  # 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))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
81
  # These flags are needed for modversions and compiling, so we define them here
8fdc3fbbd   Cao jin   kbuild: comments ...
82
  # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
83
  # end up in (or would, if it gets compiled in)
b42841b7b   Michal Marek   kbuild: Get rid o...
84
85
  name-fix = $(squote)$(quote)$(subst $(comma),_,$(subst -,_,$1))$(quote)$(squote)
  basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
aeacb019b   Masahiro Yamada   kbuild: define KB...
86
  modname_flags  = -DKBUILD_MODNAME=$(call name-fix,$(modname))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
87

4e13d47c5   Masahiro Yamada   kbuild: remove KB...
88
  orig_c_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) \
d8672b40d   Sam Ravnborg   kbuild: expand -I...
89
                   $(ccflags-y) $(CFLAGS_$(basetarget).o)
656ee82cc   Steven Rostedt   kbuild: create ne...
90
  _c_flags       = $(filter-out $(CFLAGS_REMOVE_$(basetarget).o), $(orig_c_flags))
4e13d47c5   Masahiro Yamada   kbuild: remove KB...
91
  orig_a_flags   = $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) \
d8672b40d   Sam Ravnborg   kbuild: expand -I...
92
                   $(asflags-y) $(AFLAGS_$(basetarget).o)
a7e137eb9   Heiko Carstens   kbuild: add AFLAG...
93
  _a_flags       = $(filter-out $(AFLAGS_REMOVE_$(basetarget).o), $(orig_a_flags))
f77bf0142   Sam Ravnborg   kbuild: introduce...
94
  _cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(@F))
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
95

2521f2c22   Peter Oberparleiter   gcov: add gcov pr...
96
97
98
99
100
101
102
103
104
105
  #
  # 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...
106
107
108
109
110
111
112
  #
  # 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...
113
  		$(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
0b24becc8   Andrey Ryabinin   kasan: add kernel...
114
  endif
c6d308534   Andrey Ryabinin   UBSAN: run-time u...
115
116
117
118
119
  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 ...
120
121
  ifeq ($(CONFIG_KCOV),y)
  _c_flags += $(if $(patsubst n%,, \
a4691deab   Vegard Nossum   kcov: allow more ...
122
  	$(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
5c9a8750a   Dmitry Vyukov   kernel: add kcov ...
123
124
  	$(CFLAGS_KCOV))
  endif
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
125
126
127
128
129
130
131
132
  # If building the kernel in a separate objtree expand all occurrences
  # of -Idir to -I$(srctree)/dir except for absolute paths (starting with '/').
  
  ifeq ($(KBUILD_SRC),)
  __c_flags	= $(_c_flags)
  __a_flags	= $(_a_flags)
  __cpp_flags     = $(_cpp_flags)
  else
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
133
134
135
136
  # -I$(obj) locates generated .h files
  # $(call addtree,-I$(obj)) locates .h files in srctree, from generated .c files
  #   and locates generated .h files
  # FIXME: Replace both with specific CFLAGS* statements in the makefiles
4607ebf04   Allan, Bruce W   kbuild: external ...
137
  __c_flags	= $(if $(obj),$(call addtree,-I$(src)) -I$(obj)) \
db547ef19   Arnd Bergmann   Kbuild: don't add...
138
139
140
  		  $(call flags,_c_flags)
  __a_flags	= $(call flags,_a_flags)
  __cpp_flags     = $(call flags,_cpp_flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
141
  endif
d8672b40d   Sam Ravnborg   kbuild: expand -I...
142
  c_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
a95b37e20   Masahiro Yamada   kbuild: get <linu...
143
  		 -include $(srctree)/include/linux/compiler_types.h       \
d8672b40d   Sam Ravnborg   kbuild: expand -I...
144
  		 $(__c_flags) $(modkern_cflags)                           \
b42841b7b   Michal Marek   kbuild: Get rid o...
145
  		 $(basename_flags) $(modname_flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
146

d8672b40d   Sam Ravnborg   kbuild: expand -I...
147
  a_flags        = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
148
  		 $(__a_flags) $(modkern_aflags)
d8672b40d   Sam Ravnborg   kbuild: expand -I...
149
150
  cpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
  		 $(__cpp_flags)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
151

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

50f9ddaf6   Masahiro Yamada   of: search script...
154
  DTC_INCLUDE    := $(srctree)/scripts/dtc/include-prefixes
b0a4d8b3c   Ian Campbell   kbuild: make sure...
155
  dtc_cpp_flags  = -Wp,-MD,$(depfile).pre.tmp -nostdinc                    \
50f9ddaf6   Masahiro Yamada   of: search script...
156
  		 $(addprefix -I,$(DTC_INCLUDE))                          \
e570d7c15   Stephen Warren   kbuild: limit dtc...
157
  		 -undef -D__DTS__
c8589d1e9   Masahiro Yamada   kbuild: handle mu...
158
159
160
161
162
163
164
165
  # 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
7373f4f83   Arnaud Lacombe   kbuild: add impli...
166
167
  # LEX
  # ---------------------------------------------------------------------------
7373f4f83   Arnaud Lacombe   kbuild: add impli...
168
  quiet_cmd_flex = LEX     $@
eea199b44   Masahiro Yamada   kbuild: remove un...
169
        cmd_flex = $(LEX) -o$@ -L $<
7373f4f83   Arnaud Lacombe   kbuild: add impli...
170

833e62245   Masahiro Yamada   genksyms: generat...
171
  $(obj)/%.lex.c: $(src)/%.l FORCE
033dba2ec   Masahiro Yamada   kbuild: prepare t...
172
  	$(call if_changed,flex)
7373f4f83   Arnaud Lacombe   kbuild: add impli...
173
174
175
  
  # YACC
  # ---------------------------------------------------------------------------
7373f4f83   Arnaud Lacombe   kbuild: add impli...
176
  quiet_cmd_bison = YACC    $@
eea199b44   Masahiro Yamada   kbuild: remove un...
177
        cmd_bison = $(YACC) -o$@ -t -l $<
7373f4f83   Arnaud Lacombe   kbuild: add impli...
178

833e62245   Masahiro Yamada   genksyms: generat...
179
  $(obj)/%.tab.c: $(src)/%.y FORCE
033dba2ec   Masahiro Yamada   kbuild: prepare t...
180
  	$(call if_changed,bison)
7373f4f83   Arnaud Lacombe   kbuild: add impli...
181
182
  
  quiet_cmd_bison_h = YACC    $@
d59fbbd09   Masahiro Yamada   kbuild: replace h...
183
        cmd_bison_h = $(YACC) -o/dev/null --defines=$@ -t -l $<
7373f4f83   Arnaud Lacombe   kbuild: add impli...
184

833e62245   Masahiro Yamada   genksyms: generat...
185
  $(obj)/%.tab.h: $(src)/%.y FORCE
033dba2ec   Masahiro Yamada   kbuild: prepare t...
186
  	$(call if_changed,bison_h)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
187
188
189
190
191
  # Shipped files
  # ===========================================================================
  
  quiet_cmd_shipped = SHIPPED $@
  cmd_shipped = cat $< > $@
991d76c95   Arnaud Lacombe   kbuild: simplify ...
192
  $(obj)/%: $(src)/%_shipped
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
193
194
195
196
  	$(call cmd,shipped)
  
  # Commands useful for building a boot image
  # ===========================================================================
38385f8f0   Masahiro Yamada   kbuild: trivial -...
197
  #
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
198
199
200
201
202
  #	Use as following:
  #
  #	target: source(s) FORCE
  #		$(if_changed,ld/objcopy/gzip)
  #
836caba77   Sam Ravnborg   kbuild: kill back...
203
  #	and add target to extra-y so that we know we have to
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
204
205
206
207
208
209
  #	read in the saved command line
  
  # Linking
  # ---------------------------------------------------------------------------
  
  quiet_cmd_ld = LD      $@
2fb9279f2   Masahiro Yamada   kbuild: change ld...
210
  cmd_ld = $(LD) $(ld_flags) $(filter-out FORCE,$^) -o $@
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
211
212
213
214
215
216
217
218
219
220
221
  
  # Objcopy
  # ---------------------------------------------------------------------------
  
  quiet_cmd_objcopy = OBJCOPY $@
  cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
  
  # Gzip
  # ---------------------------------------------------------------------------
  
  quiet_cmd_gzip = GZIP    $@
6ae9ecb86   Michal Marek   kbuild: Call gzip...
222
  cmd_gzip = (cat $(filter-out FORCE,$^) | gzip -n -f -9 > $@) || \
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
223
  	(rm -f $@ ; false)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
224

aab94339c   Dirk Brandewie   of: Add support f...
225
226
  # DTC
  # ---------------------------------------------------------------------------
6b22b3d16   Rob Herring   kbuild: Allow usi...
227
  DTC ?= $(objtree)/scripts/dtc/dtc
aab94339c   Dirk Brandewie   of: Add support f...
228

bc553986a   Rob Herring   dtc: turn off dtc...
229
  # Disable noisy checks by default
f759625ad   Masahiro Yamada   kbuild: fix W= op...
230
  ifeq ($(findstring 1,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
8654cb8d0   Rob Herring   dtc: update warni...
231
  DTC_FLAGS += -Wno-unit_address_vs_reg \
8654cb8d0   Rob Herring   dtc: update warni...
232
  	-Wno-unit_address_format \
4fd98e374   Rob Herring   scripts: turn off...
233
234
  	-Wno-avoid_unnecessary_addr_size \
  	-Wno-alias_paths \
74656b682   Rob Herring   kbuild: disable n...
235
236
237
  	-Wno-graph_child_address \
  	-Wno-graph_port \
  	-Wno-unique_unit_address \
8654cb8d0   Rob Herring   dtc: update warni...
238
  	-Wno-pci_device_reg
bc553986a   Rob Herring   dtc: turn off dtc...
239
  endif
f759625ad   Masahiro Yamada   kbuild: fix W= op...
240
  ifneq ($(findstring 2,$(KBUILD_ENABLE_EXTRA_GCC_CHECKS)),)
8654cb8d0   Rob Herring   dtc: update warni...
241
242
  DTC_FLAGS += -Wnode_name_chars_strict \
  	-Wproperty_name_chars_strict
bc553986a   Rob Herring   dtc: turn off dtc...
243
  endif
331f74167   Frank Rowand   of: per-file dtc ...
244
  DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
aab94339c   Dirk Brandewie   of: Add support f...
245
  # Generate an assembly file to wrap the output of the device tree compiler
1c00a47e4   James Hogan   Makefile.lib: ali...
246
  quiet_cmd_dt_S_dtb= DTB     $@
aab94339c   Dirk Brandewie   of: Add support f...
247
248
249
250
251
  cmd_dt_S_dtb=						\
  (							\
  	echo '\#include <asm-generic/vmlinux.lds.h>'; 	\
  	echo '.section .dtb.init.rodata,"a"';		\
  	echo '.balign STRUCT_ALIGNMENT';		\
55fe6da9e   James Hogan   kbuild: Handle bu...
252
253
  	echo '.global __dtb_$(subst -,_,$(*F))_begin';	\
  	echo '__dtb_$(subst -,_,$(*F))_begin:';		\
aab94339c   Dirk Brandewie   of: Add support f...
254
  	echo '.incbin "$<" ';				\
55fe6da9e   James Hogan   kbuild: Handle bu...
255
256
  	echo '__dtb_$(subst -,_,$(*F))_end:';		\
  	echo '.global __dtb_$(subst -,_,$(*F))_end';	\
aab94339c   Dirk Brandewie   of: Add support f...
257
258
  	echo '.balign STRUCT_ALIGNMENT'; 		\
  ) > $@
a7f924190   Masahiro Yamada   kbuild: add %.dtb...
259
260
  $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
  	$(call if_changed,dt_S_dtb)
aab94339c   Dirk Brandewie   of: Add support f...
261
262
  
  quiet_cmd_dtc = DTC     $@
77479b38e   Nathan Rossi   kbuild: Create di...
263
264
  cmd_dtc = mkdir -p $(dir ${dtc-tmp}) ; \
  	$(CPP) $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
6b22b3d16   Rob Herring   kbuild: Allow usi...
265
  	$(DTC) -O dtb -o $@ -b 0 \
50f9ddaf6   Masahiro Yamada   of: search script...
266
  		$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
b0a4d8b3c   Ian Campbell   kbuild: make sure...
267
268
  		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
  	cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
269

b8fc5b215   Rob Herring   kbuild: add dtc a...
270
  $(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
90b335fbb   Stephen Warren   kbuild: centraliz...
271
  	$(call if_changed_dep,dtc)
b0a4d8b3c   Ian Campbell   kbuild: make sure...
272
  dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
22435f383   Stephen Warren   kbuild: create a ...
273

bc22c17e1   Alain Knaff   bzip2/lzma: libra...
274
275
  # Bzip2
  # ---------------------------------------------------------------------------
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
276
277
  # 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...
278
  size_append = printf $(shell						\
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
279
280
  dec_size=0;								\
  for F in $1; do								\
a670b0b4a   Michael Forney   kbuild: Use ls(1)...
281
  	fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F);	\
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
282
283
  	dec_size=$$(expr $$dec_size + $$fsize);				\
  done;									\
1373411ae   Jonathan Nieder   kbuild: really fi...
284
285
286
287
288
289
290
291
  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...
292
293
294
295
296
297
  )
  
  quiet_cmd_bzip2 = BZIP2   $@
  cmd_bzip2 = (cat $(filter-out FORCE,$^) | \
  	bzip2 -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
  	(rm -f $@ ; false)
bc22c17e1   Alain Knaff   bzip2/lzma: libra...
298
299
300
301
302
  
  # Lzma
  # ---------------------------------------------------------------------------
  
  quiet_cmd_lzma = LZMA    $@
d3dd3b5a2   H. Peter Anvin   kbuild: allow com...
303
304
305
  cmd_lzma = (cat $(filter-out FORCE,$^) | \
  	lzma -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
  	(rm -f $@ ; false)
7dd65feb6   Albin Tonnerre   lib: add support ...
306

2d74b2c62   Wu Zhangjin   scripts/Makefile....
307
  quiet_cmd_lzo = LZO     $@
7dd65feb6   Albin Tonnerre   lib: add support ...
308
309
310
  cmd_lzo = (cat $(filter-out FORCE,$^) | \
  	lzop -9 && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
  	(rm -f $@ ; false)
d61931d89   Borislav Petkov   x86: Add optimize...
311

e76e1fdfa   Kyungsik Lee   lib: add support ...
312
313
314
315
  quiet_cmd_lz4 = LZ4     $@
  cmd_lz4 = (cat $(filter-out FORCE,$^) | \
  	lz4c -l -c1 stdin stdout && $(call size_append, $(filter-out FORCE,$^))) > $@ || \
  	(rm -f $@ ; false)
e33936451   Stephen Warren   Kbuild: centraliz...
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
  # 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)'
  UIMAGE_IN ?= $<
  UIMAGE_OUT ?= $@
  
  quiet_cmd_uimage = UIMAGE  $(UIMAGE_OUT)
        cmd_uimage = $(CONFIG_SHELL) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
  			-C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
  			-T $(UIMAGE_TYPE) \
  			-a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
  			-n $(UIMAGE_NAME) -d $(UIMAGE_IN) $(UIMAGE_OUT)
24fa0402a   Lasse Collin   decompressors: ad...
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
  # 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  $@
  cmd_xzkern = (cat $(filter-out FORCE,$^) | \
  	sh $(srctree)/scripts/xz_wrap.sh && \
  	$(call size_append, $(filter-out FORCE,$^))) > $@ || \
  	(rm -f $@ ; false)
  
  quiet_cmd_xzmisc = XZMISC  $@
  cmd_xzmisc = (cat $(filter-out FORCE,$^) | \
  	xz --check=crc32 --lzma2=dict=1MiB) > $@ || \
  	(rm -f $@ ; false)
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
384
385
386
387
388
389
390
391
392
  endef
  
  # Use filechk to avoid rebuilds when a header changes, but the resulting file
  # does not
  define filechk_offsets
  	(set -e; \
  	 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...
393
  	 sed -ne $(sed-offsets) < $<; \
ebf003f0c   Matthias Kaehlcke   kbuild: Consolida...
394
395
396
  	 echo ""; \
  	 echo "#endif" )
  endef