Makefile.lib 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502
  1. # SPDX-License-Identifier: GPL-2.0
  2. # Backward compatibility
  3. asflags-y += $(EXTRA_AFLAGS)
  4. ccflags-y += $(EXTRA_CFLAGS)
  5. cppflags-y += $(EXTRA_CPPFLAGS)
  6. ldflags-y += $(EXTRA_LDFLAGS)
  7. # flags that take effect in current and sub directories
  8. KBUILD_AFLAGS += $(subdir-asflags-y)
  9. KBUILD_CFLAGS += $(subdir-ccflags-y)
  10. KBUILD_RUSTFLAGS += $(subdir-rustflags-y)
  11. # Figure out what we need to build from the various variables
  12. # ===========================================================================
  13. # When an object is listed to be built compiled-in and modular,
  14. # only build the compiled-in version
  15. obj-m := $(filter-out $(obj-y),$(obj-m))
  16. # Libraries are always collected in one lib file.
  17. # Filter out objects already built-in
  18. lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
  19. # Subdirectories we need to descend into
  20. subdir-ym := $(sort $(subdir-y) $(subdir-m) \
  21. $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
  22. # Handle objects in subdirs:
  23. # - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
  24. # foo/modules.order
  25. # - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
  26. #
  27. # Generate modules.order to determine modorder. Unfortunately, we don't have
  28. # information about ordering between -y and -m subdirs. Just put -y's first.
  29. ifdef need-modorder
  30. obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
  31. else
  32. obj-m := $(filter-out %/, $(obj-m))
  33. endif
  34. ifdef need-builtin
  35. obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
  36. else
  37. obj-y := $(filter-out %/, $(obj-y))
  38. endif
  39. # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
  40. suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
  41. # List composite targets that are constructed by combining other targets
  42. multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m)))
  43. # List primitive targets that are compiled from source files
  44. real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
  45. # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
  46. multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
  47. multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
  48. multi-obj-ym := $(multi-obj-y) $(multi-obj-m)
  49. # Replace multi-part objects by their individual parts,
  50. # including built-in.a from subdirectories
  51. real-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
  52. real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
  53. always-y += $(always-m)
  54. # hostprogs-always-y += foo
  55. # ... is a shorthand for
  56. # hostprogs += foo
  57. # always-y += foo
  58. hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
  59. always-y += $(hostprogs-always-y) $(hostprogs-always-m)
  60. # userprogs-always-y is likewise.
  61. userprogs += $(userprogs-always-y) $(userprogs-always-m)
  62. always-y += $(userprogs-always-y) $(userprogs-always-m)
  63. # Add subdir path
  64. ifneq ($(obj),.)
  65. extra-y := $(addprefix $(obj)/,$(extra-y))
  66. always-y := $(addprefix $(obj)/,$(always-y))
  67. targets := $(addprefix $(obj)/,$(targets))
  68. obj-m := $(addprefix $(obj)/,$(obj-m))
  69. lib-y := $(addprefix $(obj)/,$(lib-y))
  70. real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
  71. real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
  72. multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m))
  73. subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
  74. endif
  75. # Finds the multi-part object the current object will be linked into.
  76. # If the object belongs to two or more multi-part objects, list them all.
  77. modname-multi = $(sort $(foreach m,$(multi-obj-ym),\
  78. $(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=))))
  79. __modname = $(or $(modname-multi),$(basetarget))
  80. modname = $(subst $(space),:,$(__modname))
  81. modfile = $(addprefix $(obj)/,$(__modname))
  82. # target with $(obj)/ and its suffix stripped
  83. target-stem = $(basename $(patsubst $(obj)/%,%,$@))
  84. # These flags are needed for modversions and compiling, so we define them here
  85. # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
  86. # end up in (or would, if it gets compiled in)
  87. name-fix-token = $(subst $(comma),_,$(subst -,_,$1))
  88. name-fix = $(call stringify,$(call name-fix-token,$1))
  89. basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
  90. modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \
  91. -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname))
  92. modfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile))
  93. _c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
  94. $(filter-out $(ccflags-remove-y), \
  95. $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
  96. $(CFLAGS_$(target-stem).o))
  97. _rust_flags = $(filter-out $(RUSTFLAGS_REMOVE_$(target-stem).o), \
  98. $(filter-out $(rustflags-remove-y), \
  99. $(KBUILD_RUSTFLAGS) $(rustflags-y)) \
  100. $(RUSTFLAGS_$(target-stem).o))
  101. _a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
  102. $(filter-out $(asflags-remove-y), \
  103. $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
  104. $(AFLAGS_$(target-stem).o))
  105. _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
  106. #
  107. # Enable gcov profiling flags for a file, directory or for all files depending
  108. # on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
  109. # (in this order)
  110. #
  111. ifeq ($(CONFIG_GCOV_KERNEL),y)
  112. _c_flags += $(if $(patsubst n%,, \
  113. $(GCOV_PROFILE_$(target-stem).o)$(GCOV_PROFILE)$(if $(is-kernel-object),$(CONFIG_GCOV_PROFILE_ALL))), \
  114. $(CFLAGS_GCOV))
  115. endif
  116. #
  117. # Enable address sanitizer flags for kernel except some files or directories
  118. # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
  119. #
  120. ifeq ($(CONFIG_KASAN),y)
  121. ifneq ($(CONFIG_KASAN_HW_TAGS),y)
  122. _c_flags += $(if $(patsubst n%,, \
  123. $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)$(is-kernel-object)), \
  124. $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
  125. _rust_flags += $(if $(patsubst n%,, \
  126. $(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)$(is-kernel-object)), \
  127. $(RUSTFLAGS_KASAN))
  128. endif
  129. endif
  130. ifeq ($(CONFIG_KMSAN),y)
  131. _c_flags += $(if $(patsubst n%,, \
  132. $(KMSAN_SANITIZE_$(target-stem).o)$(KMSAN_SANITIZE)$(is-kernel-object)), \
  133. $(CFLAGS_KMSAN))
  134. _c_flags += $(if $(patsubst n%,, \
  135. $(KMSAN_ENABLE_CHECKS_$(target-stem).o)$(KMSAN_ENABLE_CHECKS)$(is-kernel-object)), \
  136. , -mllvm -msan-disable-checks=1)
  137. endif
  138. ifeq ($(CONFIG_UBSAN),y)
  139. _c_flags += $(if $(patsubst n%,, \
  140. $(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_SANITIZE)$(is-kernel-object)), \
  141. $(CFLAGS_UBSAN))
  142. _c_flags += $(if $(patsubst n%,, \
  143. $(UBSAN_SIGNED_WRAP_$(target-stem).o)$(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_SIGNED_WRAP)$(UBSAN_SANITIZE)$(is-kernel-object)), \
  144. $(CFLAGS_UBSAN_SIGNED_WRAP))
  145. endif
  146. ifeq ($(CONFIG_KCOV),y)
  147. _c_flags += $(if $(patsubst n%,, \
  148. $(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(if $(is-kernel-object),$(CONFIG_KCOV_INSTRUMENT_ALL))), \
  149. $(CFLAGS_KCOV))
  150. endif
  151. #
  152. # Enable KCSAN flags except some files or directories we don't want to check
  153. # (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE)
  154. #
  155. ifeq ($(CONFIG_KCSAN),y)
  156. _c_flags += $(if $(patsubst n%,, \
  157. $(KCSAN_SANITIZE_$(target-stem).o)$(KCSAN_SANITIZE)$(is-kernel-object)), \
  158. $(CFLAGS_KCSAN))
  159. # Some uninstrumented files provide implied barriers required to avoid false
  160. # positives: set KCSAN_INSTRUMENT_BARRIERS for barrier instrumentation only.
  161. _c_flags += $(if $(patsubst n%,, \
  162. $(KCSAN_INSTRUMENT_BARRIERS_$(target-stem).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \
  163. -D__KCSAN_INSTRUMENT_BARRIERS__)
  164. endif
  165. # $(src) for including checkin headers from generated source files
  166. # $(obj) for including generated headers from checkin source files
  167. ifeq ($(KBUILD_EXTMOD),)
  168. ifdef building_out_of_srctree
  169. _c_flags += $(addprefix -I, $(src) $(obj))
  170. _a_flags += $(addprefix -I, $(src) $(obj))
  171. _cpp_flags += $(addprefix -I, $(src) $(obj))
  172. endif
  173. endif
  174. # If $(is-kernel-object) is 'y', this object will be linked to vmlinux or modules
  175. is-kernel-object = $(or $(part-of-builtin),$(part-of-module))
  176. part-of-builtin = $(if $(filter $(basename $@).o, $(real-obj-y) $(lib-y)),y)
  177. part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
  178. quiet_modtag = $(if $(part-of-module),[M], )
  179. modkern_cflags = \
  180. $(if $(part-of-module), \
  181. $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
  182. $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
  183. modkern_rustflags = \
  184. $(if $(part-of-module), \
  185. $(KBUILD_RUSTFLAGS_MODULE) $(RUSTFLAGS_MODULE), \
  186. $(KBUILD_RUSTFLAGS_KERNEL) $(RUSTFLAGS_KERNEL))
  187. modkern_aflags = $(if $(part-of-module), \
  188. $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \
  189. $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL) $(modfile_flags))
  190. c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
  191. -include $(srctree)/include/linux/compiler_types.h \
  192. $(_c_flags) $(modkern_cflags) \
  193. $(basename_flags) $(modname_flags)
  194. rust_flags = $(_rust_flags) $(modkern_rustflags) @$(objtree)/include/generated/rustc_cfg
  195. a_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
  196. $(_a_flags) $(modkern_aflags) $(modname_flags)
  197. cpp_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
  198. $(_cpp_flags)
  199. ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
  200. ifdef CONFIG_OBJTOOL
  201. objtool := $(objtree)/tools/objtool/objtool
  202. objtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK) += --hacks=jump_label
  203. objtool-args-$(CONFIG_HAVE_NOINSTR_HACK) += --hacks=noinstr
  204. objtool-args-$(CONFIG_MITIGATION_CALL_DEPTH_TRACKING) += --hacks=skylake
  205. objtool-args-$(CONFIG_X86_KERNEL_IBT) += --ibt
  206. objtool-args-$(CONFIG_FINEIBT) += --cfi
  207. objtool-args-$(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL) += --mcount
  208. ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
  209. objtool-args-$(CONFIG_HAVE_OBJTOOL_NOP_MCOUNT) += --mnop
  210. endif
  211. objtool-args-$(CONFIG_UNWINDER_ORC) += --orc
  212. objtool-args-$(CONFIG_MITIGATION_RETPOLINE) += --retpoline
  213. objtool-args-$(CONFIG_MITIGATION_RETHUNK) += --rethunk
  214. objtool-args-$(CONFIG_MITIGATION_SLS) += --sls
  215. objtool-args-$(CONFIG_STACK_VALIDATION) += --stackval
  216. objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE) += --static-call
  217. objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION) += --uaccess
  218. objtool-args-$(or $(CONFIG_GCOV_KERNEL),$(CONFIG_KCOV)) += --no-unreachable
  219. objtool-args-$(CONFIG_PREFIX_SYMBOLS) += --prefix=$(CONFIG_FUNCTION_PADDING_BYTES)
  220. objtool-args = $(objtool-args-y) \
  221. $(if $(delay-objtool), --link) \
  222. $(if $(part-of-module), --module)
  223. delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
  224. cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@)
  225. cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
  226. endif # CONFIG_OBJTOOL
  227. # Useful for describing the dependency of composite objects
  228. # Usage:
  229. # $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
  230. define multi_depend
  231. $(foreach m, $1, \
  232. $(eval $m: \
  233. $(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3))))
  234. endef
  235. # Copy a file
  236. # ===========================================================================
  237. # 'cp' preserves permissions. If you use it to copy a file in read-only srctree,
  238. # the copy would be read-only as well, leading to an error when executing the
  239. # rule next time. Use 'cat' instead in order to generate a writable file.
  240. quiet_cmd_copy = COPY $@
  241. cmd_copy = cat $< > $@
  242. $(obj)/%: $(src)/%_shipped
  243. $(call cmd,copy)
  244. # Commands useful for building a boot image
  245. # ===========================================================================
  246. #
  247. # Use as following:
  248. #
  249. # target: source(s) FORCE
  250. # $(if_changed,ld/objcopy/gzip)
  251. #
  252. # and add target to 'targets' so that we know we have to
  253. # read in the saved command line
  254. # Linking
  255. # ---------------------------------------------------------------------------
  256. quiet_cmd_ld = LD $@
  257. cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
  258. # Archive
  259. # ---------------------------------------------------------------------------
  260. quiet_cmd_ar = AR $@
  261. cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
  262. # Objcopy
  263. # ---------------------------------------------------------------------------
  264. quiet_cmd_objcopy = OBJCOPY $@
  265. cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
  266. # Gzip
  267. # ---------------------------------------------------------------------------
  268. quiet_cmd_gzip = GZIP $@
  269. cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
  270. # Bzip2
  271. # ---------------------------------------------------------------------------
  272. # Bzip2 and LZMA do not include size in file... so we have to fake that;
  273. # append the size as a 32-bit littleendian number as gzip does.
  274. size_append = printf $(shell \
  275. dec_size=0; \
  276. for F in $(real-prereqs); do \
  277. fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \
  278. dec_size=$$(expr $$dec_size + $$fsize); \
  279. done; \
  280. printf "%08x\n" $$dec_size | \
  281. sed 's/\(..\)/\1 /g' | { \
  282. read ch0 ch1 ch2 ch3; \
  283. for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \
  284. printf '%s%03o' '\\' $$((0x$$ch)); \
  285. done; \
  286. } \
  287. )
  288. quiet_cmd_file_size = GEN $@
  289. cmd_file_size = $(size_append) > $@
  290. quiet_cmd_bzip2 = BZIP2 $@
  291. cmd_bzip2 = cat $(real-prereqs) | $(KBZIP2) -9 > $@
  292. quiet_cmd_bzip2_with_size = BZIP2 $@
  293. cmd_bzip2_with_size = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
  294. # Lzma
  295. # ---------------------------------------------------------------------------
  296. quiet_cmd_lzma = LZMA $@
  297. cmd_lzma = cat $(real-prereqs) | $(LZMA) -9 > $@
  298. quiet_cmd_lzma_with_size = LZMA $@
  299. cmd_lzma_with_size = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
  300. quiet_cmd_lzo = LZO $@
  301. cmd_lzo = cat $(real-prereqs) | $(KLZOP) -9 > $@
  302. quiet_cmd_lzo_with_size = LZO $@
  303. cmd_lzo_with_size = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
  304. quiet_cmd_lz4 = LZ4 $@
  305. cmd_lz4 = cat $(real-prereqs) | $(LZ4) -l -9 - - > $@
  306. quiet_cmd_lz4_with_size = LZ4 $@
  307. cmd_lz4_with_size = { cat $(real-prereqs) | $(LZ4) -l -9 - -; \
  308. $(size_append); } > $@
  309. # U-Boot mkimage
  310. # ---------------------------------------------------------------------------
  311. MKIMAGE := $(srctree)/scripts/mkuboot.sh
  312. # SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
  313. # the number of overrides in arch makefiles
  314. UIMAGE_ARCH ?= $(SRCARCH)
  315. UIMAGE_COMPRESSION ?= $(or $(2),none)
  316. UIMAGE_OPTS-y ?=
  317. UIMAGE_TYPE ?= kernel
  318. UIMAGE_LOADADDR ?= arch_must_set_this
  319. UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
  320. UIMAGE_NAME ?= Linux-$(KERNELRELEASE)
  321. quiet_cmd_uimage = UIMAGE $@
  322. cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
  323. -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
  324. -T $(UIMAGE_TYPE) \
  325. -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
  326. -n '$(UIMAGE_NAME)' -d $< $@
  327. # Flat Image Tree (FIT)
  328. # This allows for packaging of a kernel and all devicetrees files, using
  329. # compression.
  330. # ---------------------------------------------------------------------------
  331. MAKE_FIT := $(srctree)/scripts/make_fit.py
  332. # Use this to override the compression algorithm
  333. FIT_COMPRESSION ?= gzip
  334. quiet_cmd_fit = FIT $@
  335. cmd_fit = $(MAKE_FIT) -o $@ --arch $(UIMAGE_ARCH) --os linux \
  336. --name '$(UIMAGE_NAME)' \
  337. $(if $(findstring 1,$(KBUILD_VERBOSE)),-v) \
  338. $(if $(FIT_DECOMPOSE_DTBS),--decompose-dtbs) \
  339. --compress $(FIT_COMPRESSION) -k $< @$(word 2,$^)
  340. # XZ
  341. # ---------------------------------------------------------------------------
  342. # Use xzkern or xzkern_with_size to compress the kernel image and xzmisc to
  343. # compress other things.
  344. #
  345. # xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
  346. # of the kernel decompressor. A BCJ filter is used if it is available for
  347. # the target architecture.
  348. #
  349. # xzkern_with_size also appends uncompressed size of the data using
  350. # size_append. The .xz format has the size information available at the end
  351. # of the file too, but it's in more complex format and it's good to avoid
  352. # changing the part of the boot code that reads the uncompressed size.
  353. # Note that the bytes added by size_append will make the xz tool think that
  354. # the file is corrupt. This is expected.
  355. #
  356. # xzmisc doesn't use size_append, so it can be used to create normal .xz
  357. # files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
  358. # big dictionary would increase the memory usage too much in the multi-call
  359. # decompression mode. A BCJ filter isn't used either.
  360. quiet_cmd_xzkern = XZKERN $@
  361. cmd_xzkern = cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh > $@
  362. quiet_cmd_xzkern_with_size = XZKERN $@
  363. cmd_xzkern_with_size = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
  364. $(size_append); } > $@
  365. quiet_cmd_xzmisc = XZMISC $@
  366. cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
  367. # ZSTD
  368. # ---------------------------------------------------------------------------
  369. # Appends the uncompressed size of the data using size_append. The .zst
  370. # format has the size information available at the beginning of the file too,
  371. # but it's in a more complex format and it's good to avoid changing the part
  372. # of the boot code that reads the uncompressed size.
  373. #
  374. # Note that the bytes added by size_append will make the zstd tool think that
  375. # the file is corrupt. This is expected.
  376. #
  377. # zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of
  378. # 128 MB. zstd22 is used for kernel compression because it is decompressed in a
  379. # single pass, so zstd doesn't need to allocate a window buffer. When streaming
  380. # decompression is used, like initramfs decompression, zstd22 should likely not
  381. # be used because it would require zstd to allocate a 128 MB buffer.
  382. quiet_cmd_zstd = ZSTD $@
  383. cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@
  384. quiet_cmd_zstd22 = ZSTD22 $@
  385. cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@
  386. quiet_cmd_zstd22_with_size = ZSTD22 $@
  387. cmd_zstd22_with_size = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
  388. # ASM offsets
  389. # ---------------------------------------------------------------------------
  390. # Default sed regexp - multiline due to syntax constraints
  391. #
  392. # Use [:space:] because LLVM's integrated assembler inserts <tab> around
  393. # the .ascii directive whereas GCC keeps the <space> as-is.
  394. define sed-offsets
  395. 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
  396. /^->/{s:->#\(.*\):/* \1 */:; \
  397. s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
  398. s:->::; p;}'
  399. endef
  400. # Use filechk to avoid rebuilds when a header changes, but the resulting file
  401. # does not
  402. define filechk_offsets
  403. echo "#ifndef $2"; \
  404. echo "#define $2"; \
  405. echo "/*"; \
  406. echo " * DO NOT MODIFY."; \
  407. echo " *"; \
  408. echo " * This file was generated by Kbuild"; \
  409. echo " */"; \
  410. echo ""; \
  411. sed -ne $(sed-offsets) < $<; \
  412. echo ""; \
  413. echo "#endif"
  414. endef