Makefile.lib 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  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. ifneq ($(always),)
  8. $(warning 'always' is deprecated. Please use 'always-y' instead)
  9. always-y += $(always)
  10. endif
  11. ifneq ($(hostprogs-y),)
  12. $(warning 'hostprogs-y' is deprecated. Please use 'hostprogs' instead)
  13. hostprogs += $(hostprogs-y)
  14. endif
  15. ifneq ($(hostprogs-m),)
  16. $(warning 'hostprogs-m' is deprecated. Please use 'hostprogs' instead)
  17. hostprogs += $(hostprogs-m)
  18. endif
  19. # flags that take effect in current and sub directories
  20. KBUILD_AFLAGS += $(subdir-asflags-y)
  21. KBUILD_CFLAGS += $(subdir-ccflags-y)
  22. # Figure out what we need to build from the various variables
  23. # ===========================================================================
  24. # When an object is listed to be built compiled-in and modular,
  25. # only build the compiled-in version
  26. obj-m := $(filter-out $(obj-y),$(obj-m))
  27. # Libraries are always collected in one lib file.
  28. # Filter out objects already built-in
  29. lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
  30. # Subdirectories we need to descend into
  31. subdir-ym := $(sort $(subdir-y) $(subdir-m) \
  32. $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
  33. # Handle objects in subdirs:
  34. # - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
  35. # foo/modules.order
  36. # - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
  37. #
  38. # Generate modules.order to determine modorder. Unfortunately, we don't have
  39. # information about ordering between -y and -m subdirs. Just put -y's first.
  40. ifdef need-modorder
  41. obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
  42. else
  43. obj-m := $(filter-out %/, $(obj-m))
  44. endif
  45. ifdef need-builtin
  46. obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
  47. else
  48. obj-y := $(filter-out %/, $(obj-y))
  49. endif
  50. # Expand $(foo-objs) $(foo-y) by calling $(call suffix-search,foo.o,-objs -y)
  51. suffix-search = $(foreach s,$(2),$($(1:.o=$s)))
  52. # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
  53. # Do this recursively to find nested composite objects.
  54. # foo-y may contain foo.o bar.o . For backwards compatibility, don't treat this
  55. # foo.o as a nested object
  56. multi-search = $(sort $(foreach m,$(1),$(if $(strip $(call suffix-search,$(m),$(2) -)),\
  57. $(if $(filter $(m),$(strip $(call suffix-search,$(m),$(2) -))),,\
  58. $(m) $(call multi-search,$(call suffix-search,$(m),$(2)),$(2))))))
  59. multi-used-y := $(call multi-search,$(obj-y),-objs -y)
  60. multi-used-m := $(call multi-search,$(obj-m),-objs -y -m)
  61. multi-used := $(multi-used-y) $(multi-used-m)
  62. # Replace multi-part objects by their individual parts,
  63. # including built-in.a from subdirectories
  64. # Recursively search for real files. For backwards compatibility,
  65. # foo-y may contain foo.o bar.o . foo.o in this context is a real object, and
  66. # shouldn't be recursed into.
  67. real-search = $(foreach m,$(1), $(if $(strip $(call suffix-search,$(m),$(2) -)), \
  68. $(filter $(m),$(call suffix-search,$(m),$(2))) $(call real-search,$(filter-out $(m),$(call suffix-search,$(m),$(2))),$(2)),\
  69. $(m)))
  70. real-obj-y := $(call real-search, $(obj-y),-objs -y)
  71. real-obj-m := $(call real-search, $(obj-m),-objs -y -m)
  72. always-y += $(always-m)
  73. # hostprogs-always-y += foo
  74. # ... is a shorthand for
  75. # hostprogs += foo
  76. # always-y += foo
  77. hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
  78. always-y += $(hostprogs-always-y) $(hostprogs-always-m)
  79. # userprogs-always-y is likewise.
  80. userprogs += $(userprogs-always-y) $(userprogs-always-m)
  81. always-y += $(userprogs-always-y) $(userprogs-always-m)
  82. # DTB
  83. # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
  84. extra-y += $(dtb-y)
  85. extra-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
  86. ifneq ($(CHECK_DTBS),)
  87. extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y))
  88. extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
  89. endif
  90. # Add subdir path
  91. extra-y := $(addprefix $(obj)/,$(extra-y))
  92. always-y := $(addprefix $(obj)/,$(always-y))
  93. targets := $(addprefix $(obj)/,$(targets))
  94. obj-m := $(addprefix $(obj)/,$(obj-m))
  95. lib-y := $(addprefix $(obj)/,$(lib-y))
  96. real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
  97. real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
  98. multi-used-m := $(addprefix $(obj)/,$(multi-used-m))
  99. subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
  100. # Finds the multi-part object the current object will be linked into.
  101. # If the object belongs to two or more multi-part objects, list them all.
  102. modname-multi = $(sort $(foreach m,$(multi-used),\
  103. $(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=))))
  104. __modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
  105. modname = $(subst $(space),:,$(__modname))
  106. modfile = $(addprefix $(obj)/,$(__modname))
  107. # target with $(obj)/ and its suffix stripped
  108. target-stem = $(basename $(patsubst $(obj)/%,%,$@))
  109. # These flags are needed for modversions and compiling, so we define them here
  110. # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
  111. # end up in (or would, if it gets compiled in)
  112. name-fix-token = $(subst $(comma),_,$(subst -,_,$1))
  113. name-fix = $(call stringify,$(call name-fix-token,$1))
  114. basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
  115. modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \
  116. -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname))
  117. modfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile))
  118. _c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
  119. $(filter-out $(ccflags-remove-y), \
  120. $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
  121. $(CFLAGS_$(target-stem).o))
  122. _a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
  123. $(filter-out $(asflags-remove-y), \
  124. $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
  125. $(AFLAGS_$(target-stem).o))
  126. _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
  127. #
  128. # Enable gcov profiling flags for a file, directory or for all files depending
  129. # on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
  130. # (in this order)
  131. #
  132. ifeq ($(CONFIG_GCOV_KERNEL),y)
  133. _c_flags += $(if $(patsubst n%,, \
  134. $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
  135. $(CFLAGS_GCOV))
  136. endif
  137. #
  138. # Enable address sanitizer flags for kernel except some files or directories
  139. # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
  140. #
  141. ifeq ($(CONFIG_KASAN),y)
  142. ifneq ($(CONFIG_KASAN_HW_TAGS),y)
  143. _c_flags += $(if $(patsubst n%,, \
  144. $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
  145. $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
  146. endif
  147. endif
  148. ifeq ($(CONFIG_UBSAN),y)
  149. _c_flags += $(if $(patsubst n%,, \
  150. $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
  151. $(CFLAGS_UBSAN))
  152. endif
  153. ifeq ($(CONFIG_KCOV),y)
  154. _c_flags += $(if $(patsubst n%,, \
  155. $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
  156. $(CFLAGS_KCOV))
  157. endif
  158. #
  159. # Enable KCSAN flags except some files or directories we don't want to check
  160. # (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE)
  161. #
  162. ifeq ($(CONFIG_KCSAN),y)
  163. _c_flags += $(if $(patsubst n%,, \
  164. $(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \
  165. $(CFLAGS_KCSAN))
  166. endif
  167. # $(srctree)/$(src) for including checkin headers from generated source files
  168. # $(objtree)/$(obj) for including generated headers from checkin source files
  169. ifeq ($(KBUILD_EXTMOD),)
  170. ifdef building_out_of_srctree
  171. _c_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
  172. _a_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
  173. _cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
  174. endif
  175. endif
  176. part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
  177. quiet_modtag = $(if $(part-of-module),[M], )
  178. modkern_cflags = \
  179. $(if $(part-of-module), \
  180. $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
  181. $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
  182. modkern_aflags = $(if $(part-of-module), \
  183. $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \
  184. $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL))
  185. c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
  186. -include $(srctree)/include/linux/compiler_types.h \
  187. $(_c_flags) $(modkern_cflags) \
  188. $(basename_flags) $(modname_flags)
  189. a_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
  190. $(_a_flags) $(modkern_aflags)
  191. cpp_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
  192. $(_cpp_flags)
  193. ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
  194. DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes
  195. dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc \
  196. $(addprefix -I,$(DTC_INCLUDE)) \
  197. -undef -D__DTS__
  198. # Objtool arguments are also needed for modfinal with LTO, so we define
  199. # then here to avoid duplication.
  200. objtool_args = \
  201. $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \
  202. $(if $(part-of-module), --module,) \
  203. $(if $(CONFIG_FRAME_POINTER),, --no-fp) \
  204. $(if $(or $(CONFIG_GCOV_KERNEL),$(CONFIG_LTO_CLANG)), \
  205. --no-unreachable,) \
  206. $(if $(CONFIG_RETPOLINE), --retpoline,) \
  207. $(if $(CONFIG_X86_SMAP), --uaccess,) \
  208. $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount,)
  209. # Useful for describing the dependency of composite objects
  210. # Usage:
  211. # $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
  212. define multi_depend
  213. $(foreach m, $(notdir $1), \
  214. $(eval $(obj)/$m: \
  215. $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))
  216. endef
  217. quiet_cmd_copy = COPY $@
  218. cmd_copy = cp $< $@
  219. # Shipped files
  220. # ===========================================================================
  221. quiet_cmd_shipped = SHIPPED $@
  222. cmd_shipped = cat $< > $@
  223. $(obj)/%: $(src)/%_shipped
  224. $(call cmd,shipped)
  225. # Commands useful for building a boot image
  226. # ===========================================================================
  227. #
  228. # Use as following:
  229. #
  230. # target: source(s) FORCE
  231. # $(if_changed,ld/objcopy/gzip)
  232. #
  233. # and add target to extra-y so that we know we have to
  234. # read in the saved command line
  235. # Linking
  236. # ---------------------------------------------------------------------------
  237. quiet_cmd_ld = LD $@
  238. cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
  239. # Archive
  240. # ---------------------------------------------------------------------------
  241. quiet_cmd_ar = AR $@
  242. cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
  243. # Objcopy
  244. # ---------------------------------------------------------------------------
  245. quiet_cmd_objcopy = OBJCOPY $@
  246. cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
  247. # Gzip
  248. # ---------------------------------------------------------------------------
  249. quiet_cmd_gzip = GZIP $@
  250. cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
  251. # DTC
  252. # ---------------------------------------------------------------------------
  253. ifeq ("$(origin DTC)", "command line")
  254. PHONY += $(DTC)
  255. dtc-option = $(call try-run, $(DTC) $1 -v,$1)
  256. else
  257. # Just add the flag. DTC is compiled later as a prerequisite, so there's no dtc
  258. # to test the flag against. This is okay because we're not testing flags which
  259. # aren't supported by in-kernel dtc to begin with.
  260. dtc-option = $1
  261. endif
  262. DTC ?= $(objtree)/scripts/dtc/dtc
  263. DTC_FLAGS += $(call dtc-option,-Wno-interrupt_provider)
  264. # Disable noisy checks by default
  265. ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
  266. DTC_FLAGS += $(call dtc-option,-Wno-unit_address_vs_reg) \
  267. $(call dtc-option,-Wno-unit_address_format) \
  268. $(call dtc-option,-Wno-avoid_unnecessary_addr_size) \
  269. $(call dtc-option,-Wno-alias_paths) \
  270. $(call dtc-option,-Wno-graph_child_address) \
  271. $(call dtc-option,-Wno-simple_bus_reg) \
  272. $(call dtc-option,-Wno-unique_unit_address) \
  273. $(call dtc-option,-Wno-pci_device_reg)
  274. endif
  275. ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
  276. DTC_FLAGS += $(call dtc-option,-Wnode_name_chars_strict) \
  277. $(call dtc-option,-Wproperty_name_chars_strict) \
  278. $(call dtc-option,-Winterrupt_provider)
  279. endif
  280. DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
  281. # Generate an assembly file to wrap the output of the device tree compiler
  282. quiet_cmd_dt_S_dtb= DTB $@
  283. cmd_dt_S_dtb= \
  284. { \
  285. echo '\#include <asm-generic/vmlinux.lds.h>'; \
  286. echo '.section .dtb.init.rodata,"a"'; \
  287. echo '.balign STRUCT_ALIGNMENT'; \
  288. echo '.global __dtb_$(subst -,_,$(*F))_begin'; \
  289. echo '__dtb_$(subst -,_,$(*F))_begin:'; \
  290. echo '.incbin "$<" '; \
  291. echo '__dtb_$(subst -,_,$(*F))_end:'; \
  292. echo '.global __dtb_$(subst -,_,$(*F))_end'; \
  293. echo '.balign STRUCT_ALIGNMENT'; \
  294. } > $@
  295. $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
  296. $(call if_changed,dt_S_dtb)
  297. quiet_cmd_dtc = DTC $@
  298. cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
  299. $(DTC) -O $(patsubst .%,%,$(suffix $@)) -o $@ -b 0 \
  300. $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
  301. -d $(depfile).dtc.tmp $(dtc-tmp) ; \
  302. cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
  303. $(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
  304. $(call if_changed_dep,dtc)
  305. DT_CHECKER ?= dt-validate
  306. DT_BINDING_DIR := Documentation/devicetree/bindings
  307. # DT_TMP_SCHEMA may be overridden from Documentation/devicetree/bindings/Makefile
  308. DT_TMP_SCHEMA ?= $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
  309. quiet_cmd_dtb_check = CHECK $@
  310. cmd_dtb_check = $(DT_CHECKER) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@
  311. define rule_dtc
  312. $(call cmd_and_fixdep,dtc)
  313. $(call cmd,dtb_check)
  314. endef
  315. $(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
  316. $(call if_changed_rule,dtc,yaml)
  317. dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
  318. # Bzip2
  319. # ---------------------------------------------------------------------------
  320. # Bzip2 and LZMA do not include size in file... so we have to fake that;
  321. # append the size as a 32-bit littleendian number as gzip does.
  322. size_append = printf $(shell \
  323. dec_size=0; \
  324. for F in $(real-prereqs); do \
  325. fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \
  326. dec_size=$$(expr $$dec_size + $$fsize); \
  327. done; \
  328. printf "%08x\n" $$dec_size | \
  329. sed 's/\(..\)/\1 /g' | { \
  330. read ch0 ch1 ch2 ch3; \
  331. for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \
  332. printf '%s%03o' '\\' $$((0x$$ch)); \
  333. done; \
  334. } \
  335. )
  336. quiet_cmd_bzip2 = BZIP2 $@
  337. cmd_bzip2 = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
  338. # Lzma
  339. # ---------------------------------------------------------------------------
  340. quiet_cmd_lzma = LZMA $@
  341. cmd_lzma = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
  342. quiet_cmd_lzo = LZO $@
  343. cmd_lzo = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
  344. quiet_cmd_lz4 = LZ4 $@
  345. cmd_lz4 = { cat $(real-prereqs) | \
  346. $(LZ4) -l -12 --favor-decSpeed stdin stdout; \
  347. $(size_append); } > $@
  348. # U-Boot mkimage
  349. # ---------------------------------------------------------------------------
  350. MKIMAGE := $(srctree)/scripts/mkuboot.sh
  351. # SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
  352. # the number of overrides in arch makefiles
  353. UIMAGE_ARCH ?= $(SRCARCH)
  354. UIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
  355. UIMAGE_OPTS-y ?=
  356. UIMAGE_TYPE ?= kernel
  357. UIMAGE_LOADADDR ?= arch_must_set_this
  358. UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
  359. UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
  360. quiet_cmd_uimage = UIMAGE $@
  361. cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
  362. -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
  363. -T $(UIMAGE_TYPE) \
  364. -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
  365. -n $(UIMAGE_NAME) -d $< $@
  366. # XZ
  367. # ---------------------------------------------------------------------------
  368. # Use xzkern to compress the kernel image and xzmisc to compress other things.
  369. #
  370. # xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
  371. # of the kernel decompressor. A BCJ filter is used if it is available for
  372. # the target architecture. xzkern also appends uncompressed size of the data
  373. # using size_append. The .xz format has the size information available at
  374. # the end of the file too, but it's in more complex format and it's good to
  375. # avoid changing the part of the boot code that reads the uncompressed size.
  376. # Note that the bytes added by size_append will make the xz tool think that
  377. # the file is corrupt. This is expected.
  378. #
  379. # xzmisc doesn't use size_append, so it can be used to create normal .xz
  380. # files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
  381. # big dictionary would increase the memory usage too much in the multi-call
  382. # decompression mode. A BCJ filter isn't used either.
  383. quiet_cmd_xzkern = XZKERN $@
  384. cmd_xzkern = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
  385. $(size_append); } > $@
  386. quiet_cmd_xzmisc = XZMISC $@
  387. cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
  388. # ZSTD
  389. # ---------------------------------------------------------------------------
  390. # Appends the uncompressed size of the data using size_append. The .zst
  391. # format has the size information available at the beginning of the file too,
  392. # but it's in a more complex format and it's good to avoid changing the part
  393. # of the boot code that reads the uncompressed size.
  394. #
  395. # Note that the bytes added by size_append will make the zstd tool think that
  396. # the file is corrupt. This is expected.
  397. #
  398. # zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of
  399. # 128 MB. zstd22 is used for kernel compression because it is decompressed in a
  400. # single pass, so zstd doesn't need to allocate a window buffer. When streaming
  401. # decompression is used, like initramfs decompression, zstd22 should likely not
  402. # be used because it would require zstd to allocate a 128 MB buffer.
  403. quiet_cmd_zstd = ZSTD $@
  404. cmd_zstd = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@
  405. quiet_cmd_zstd22 = ZSTD22 $@
  406. cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
  407. # ASM offsets
  408. # ---------------------------------------------------------------------------
  409. # Default sed regexp - multiline due to syntax constraints
  410. #
  411. # Use [:space:] because LLVM's integrated assembler inserts <tab> around
  412. # the .ascii directive whereas GCC keeps the <space> as-is.
  413. define sed-offsets
  414. 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
  415. /^->/{s:->#\(.*\):/* \1 */:; \
  416. s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
  417. s:->::; p;}'
  418. endef
  419. # Use filechk to avoid rebuilds when a header changes, but the resulting file
  420. # does not
  421. define filechk_offsets
  422. echo "#ifndef $2"; \
  423. echo "#define $2"; \
  424. echo "/*"; \
  425. echo " * DO NOT MODIFY."; \
  426. echo " *"; \
  427. echo " * This file was generated by Kbuild"; \
  428. echo " */"; \
  429. echo ""; \
  430. sed -ne $(sed-offsets) < $<; \
  431. echo ""; \
  432. echo "#endif"
  433. endef