b24413180f560 (Greg Kroah-Hartman 2017-11-01 15:07:57 +0100 1) # SPDX-License-Identifier: GPL-2.0
f77bf01425b11 (Sam Ravnborg 2007-10-15 22:25:06 +0200 2) # Backward compatibility
f77bf01425b11 (Sam Ravnborg 2007-10-15 22:25:06 +0200 3) asflags-y += $(EXTRA_AFLAGS)
f77bf01425b11 (Sam Ravnborg 2007-10-15 22:25:06 +0200 4) ccflags-y += $(EXTRA_CFLAGS)
f77bf01425b11 (Sam Ravnborg 2007-10-15 22:25:06 +0200 5) cppflags-y += $(EXTRA_CPPFLAGS)
f77bf01425b11 (Sam Ravnborg 2007-10-15 22:25:06 +0200 6) ldflags-y += $(EXTRA_LDFLAGS)
f77bf01425b11 (Sam Ravnborg 2007-10-15 22:25:06 +0200 7)
8fdc3fbbd5b64 (Cao jin 2017-10-09 11:49:11 +0800 8) # flags that take effect in current and sub directories
4e13d47c5806b (Masahiro Yamada 2017-10-10 20:43:21 +0900 9) KBUILD_AFLAGS += $(subdir-asflags-y)
4e13d47c5806b (Masahiro Yamada 2017-10-10 20:43:21 +0900 10) KBUILD_CFLAGS += $(subdir-ccflags-y)
720097d895956 (Sam Ravnborg 2009-04-19 11:04:26 +0200 11)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 12) # Figure out what we need to build from the various variables
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 13) # ===========================================================================
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 14)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 15) # When an object is listed to be built compiled-in and modular,
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 16) # only build the compiled-in version
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 17) obj-m := $(filter-out $(obj-y),$(obj-m))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 18)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 19) # Libraries are always collected in one lib file.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 20) # Filter out objects already built-in
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 21) lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 22)
0a8820e7f8071 (Masahiro Yamada 2020-06-01 14:56:55 +0900 23) # Subdirectories we need to descend into
0a8820e7f8071 (Masahiro Yamada 2020-06-01 14:56:55 +0900 24) subdir-ym := $(sort $(subdir-y) $(subdir-m) \
0a8820e7f8071 (Masahiro Yamada 2020-06-01 14:56:55 +0900 25) $(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
0a8820e7f8071 (Masahiro Yamada 2020-06-01 14:56:55 +0900 26)
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 27) # Handle objects in subdirs:
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 28) # - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 29) # foo/modules.order
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 30) # - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 31) #
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 32) # Generate modules.order to determine modorder. Unfortunately, we don't have
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 33) # information about ordering between -y and -m subdirs. Just put -y's first.
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 34)
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 35) ifdef need-modorder
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 36) obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 37) else
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 38) obj-m := $(filter-out %/, $(obj-m))
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 39) endif
b2c8855491226 (Masahiro Yamada 2020-06-01 14:57:00 +0900 40)
56d5893615727 (Masahiro Yamada 2019-12-19 01:04:28 +0900 41) ifdef need-builtin
f49821ee32b76 (Nicholas Piggin 2018-02-11 00:25:04 +1000 42) obj-y := $(patsubst %/, %/built-in.a, $(obj-y))
56d5893615727 (Masahiro Yamada 2019-12-19 01:04:28 +0900 43) else
56d5893615727 (Masahiro Yamada 2019-12-19 01:04:28 +0900 44) obj-y := $(filter-out %/, $(obj-y))
56d5893615727 (Masahiro Yamada 2019-12-19 01:04:28 +0900 45) endif
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 46)
44f87191d1055 (Masahiro Yamada 2021-05-03 03:09:55 +0900 47) # Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
44f87191d1055 (Masahiro Yamada 2021-05-03 03:09:55 +0900 48) suffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
44f87191d1055 (Masahiro Yamada 2021-05-03 03:09:55 +0900 49) # List composite targets that are constructed by combining other targets
44f87191d1055 (Masahiro Yamada 2021-05-03 03:09:55 +0900 50) multi-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m)))
44f87191d1055 (Masahiro Yamada 2021-05-03 03:09:55 +0900 51) # List primitive targets that are compiled from source files
44f87191d1055 (Masahiro Yamada 2021-05-03 03:09:55 +0900 52) real-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
44f87191d1055 (Masahiro Yamada 2021-05-03 03:09:55 +0900 53)
33e84f2e79659 (Masahiro Yamada 2019-08-06 15:39:19 +0900 54) # If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
44f87191d1055 (Masahiro Yamada 2021-05-03 03:09:55 +0900 55) multi-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
44f87191d1055 (Masahiro Yamada 2021-05-03 03:09:55 +0900 56) multi-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
a6601e01cd548 (Masahiro Yamada 2021-03-06 15:11:20 +0900 57) multi-obj-ym := $(multi-obj-y) $(multi-obj-m)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 58)
f98fe47ce51de (Masahiro Yamada 2018-03-19 20:26:08 +0900 59) # Replace multi-part objects by their individual parts,
f98fe47ce51de (Masahiro Yamada 2018-03-19 20:26:08 +0900 60) # including built-in.a from subdirectories
44f87191d1055 (Masahiro Yamada 2021-05-03 03:09:55 +0900 61) real-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
44f87191d1055 (Masahiro Yamada 2021-05-03 03:09:55 +0900 62) real-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 63)
5f2fb52fac15a (Masahiro Yamada 2020-02-02 01:49:24 +0900 64) always-y += $(always-m)
5f2fb52fac15a (Masahiro Yamada 2020-02-02 01:49:24 +0900 65)
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 66) # hostprogs-always-y += foo
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 67) # ... is a shorthand for
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 68) # hostprogs += foo
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 69) # always-y += foo
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 70) hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 71) always-y += $(hostprogs-always-y) $(hostprogs-always-m)
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 72)
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 73) # userprogs-always-y is likewise.
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 74) userprogs += $(userprogs-always-y) $(userprogs-always-m)
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 75) always-y += $(userprogs-always-y) $(userprogs-always-m)
faabed295cccc (Masahiro Yamada 2020-08-01 21:27:18 +0900 76)
7e7962dd1a530 (Masahiro Yamada 2017-11-05 14:30:53 +0900 77) # DTB
7e7962dd1a530 (Masahiro Yamada 2017-11-05 14:30:53 +0900 78) # If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
9ca29e41508e9 (Viresh Kumar 2021-03-10 11:05:29 +0530 79) dtb-$(CONFIG_OF_ALL_DTBS) += $(dtb-)
9ca29e41508e9 (Viresh Kumar 2021-03-10 11:05:29 +0530 80)
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 81) # Composite DTB (i.e. DTB constructed by overlay)
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 82) multi-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs)
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 83) # Primitive DTB compiled from *.dts
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 84) real-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs)
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 85) # Base DTB that overlay is applied onto (each first word of $(*-dtbs) expansion)
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 86) base-dtb-y := $(foreach m, $(multi-dtb-y), $(firstword $(call suffix-search, $m, .dtb, -dtbs)))
15d16d6dadf69 (Rob Herring 2021-03-10 11:05:30 +0530 87)
2047ace96679a (Masahiro Yamada 2021-01-20 15:23:51 +0900 88) always-y += $(dtb-y)
7e7962dd1a530 (Masahiro Yamada 2017-11-05 14:30:53 +0900 89)
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 90) ifneq ($(CHECK_DTBS),)
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 91) always-y += $(patsubst %.dtb,%.dt.yaml, $(real-dtb-y))
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 92) always-y += $(patsubst %.dtbo,%.dt.yaml, $(real-dtb-y))
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 93) endif
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 94)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 95) # Add subdir path
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 96)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 97) extra-y := $(addprefix $(obj)/,$(extra-y))
5f2fb52fac15a (Masahiro Yamada 2020-02-02 01:49:24 +0900 98) always-y := $(addprefix $(obj)/,$(always-y))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 99) targets := $(addprefix $(obj)/,$(targets))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 100) obj-m := $(addprefix $(obj)/,$(obj-m))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 101) lib-y := $(addprefix $(obj)/,$(lib-y))
f5f336812c233 (Masahiro Yamada 2018-03-19 20:26:07 +0900 102) real-obj-y := $(addprefix $(obj)/,$(real-obj-y))
f5f336812c233 (Masahiro Yamada 2018-03-19 20:26:07 +0900 103) real-obj-m := $(addprefix $(obj)/,$(real-obj-m))
a6601e01cd548 (Masahiro Yamada 2021-03-06 15:11:20 +0900 104) multi-obj-m := $(addprefix $(obj)/, $(multi-obj-m))
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 105) multi-dtb-y := $(addprefix $(obj)/, $(multi-dtb-y))
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 106) real-dtb-y := $(addprefix $(obj)/, $(real-dtb-y))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 107) subdir-ym := $(addprefix $(obj)/,$(subdir-ym))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 108)
c0152e9a6b448 (Masahiro Yamada 2018-03-19 18:01:27 +0900 109) # Finds the multi-part object the current object will be linked into.
1664a377908ed (Masahiro Yamada 2019-12-19 17:33:28 +0900 110) # If the object belongs to two or more multi-part objects, list them all.
a6601e01cd548 (Masahiro Yamada 2021-03-06 15:11:20 +0900 111) modname-multi = $(sort $(foreach m,$(multi-obj-ym),\
d4452837ffbeb (Masahiro Yamada 2021-05-03 03:09:57 +0900 112) $(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=))))
c0152e9a6b448 (Masahiro Yamada 2018-03-19 18:01:27 +0900 113)
1664a377908ed (Masahiro Yamada 2019-12-19 17:33:28 +0900 114) __modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
1664a377908ed (Masahiro Yamada 2019-12-19 17:33:28 +0900 115)
1664a377908ed (Masahiro Yamada 2019-12-19 17:33:28 +0900 116) modname = $(subst $(space),:,$(__modname))
1664a377908ed (Masahiro Yamada 2019-12-19 17:33:28 +0900 117) modfile = $(addprefix $(obj)/,$(__modname))
c0152e9a6b448 (Masahiro Yamada 2018-03-19 18:01:27 +0900 118)
54b8ae66ae1a3 (Masahiro Yamada 2019-08-30 13:34:01 +0900 119) # target with $(obj)/ and its suffix stripped
54b8ae66ae1a3 (Masahiro Yamada 2019-08-30 13:34:01 +0900 120) target-stem = $(basename $(patsubst $(obj)/%,%,$@))
54b8ae66ae1a3 (Masahiro Yamada 2019-08-30 13:34:01 +0900 121)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 122) # These flags are needed for modversions and compiling, so we define them here
8fdc3fbbd5b64 (Cao jin 2017-10-09 11:49:11 +0800 123) # $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 124) # end up in (or would, if it gets compiled in)
a8cccdd954732 (Sami Tolvanen 2020-12-11 10:46:24 -0800 125) name-fix-token = $(subst $(comma),_,$(subst -,_,$1))
a8cccdd954732 (Sami Tolvanen 2020-12-11 10:46:24 -0800 126) name-fix = $(call stringify,$(call name-fix-token,$1))
b42841b7bb628 (Michal Marek 2016-03-17 16:32:14 +0100 127) basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
a8cccdd954732 (Sami Tolvanen 2020-12-11 10:46:24 -0800 128) modname_flags = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \
a8cccdd954732 (Sami Tolvanen 2020-12-11 10:46:24 -0800 129) -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname))
1664a377908ed (Masahiro Yamada 2019-12-19 17:33:28 +0900 130) modfile_flags = -DKBUILD_MODFILE=$(call stringify,$(modfile))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 131)
15d5761ad31df (Masahiro Yamada 2020-07-07 18:21:16 +0900 132) _c_flags = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
15d5761ad31df (Masahiro Yamada 2020-07-07 18:21:16 +0900 133) $(filter-out $(ccflags-remove-y), \
15d5761ad31df (Masahiro Yamada 2020-07-07 18:21:16 +0900 134) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
15d5761ad31df (Masahiro Yamada 2020-07-07 18:21:16 +0900 135) $(CFLAGS_$(target-stem).o))
15d5761ad31df (Masahiro Yamada 2020-07-07 18:21:16 +0900 136) _a_flags = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
15d5761ad31df (Masahiro Yamada 2020-07-07 18:21:16 +0900 137) $(filter-out $(asflags-remove-y), \
15d5761ad31df (Masahiro Yamada 2020-07-07 18:21:16 +0900 138) $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
15d5761ad31df (Masahiro Yamada 2020-07-07 18:21:16 +0900 139) $(AFLAGS_$(target-stem).o))
54b8ae66ae1a3 (Masahiro Yamada 2019-08-30 13:34:01 +0900 140) _cpp_flags = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 141)
2521f2c228ad7 (Peter Oberparleiter 2009-06-17 16:28:08 -0700 142) #
2521f2c228ad7 (Peter Oberparleiter 2009-06-17 16:28:08 -0700 143) # Enable gcov profiling flags for a file, directory or for all files depending
2521f2c228ad7 (Peter Oberparleiter 2009-06-17 16:28:08 -0700 144) # on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
2521f2c228ad7 (Peter Oberparleiter 2009-06-17 16:28:08 -0700 145) # (in this order)
2521f2c228ad7 (Peter Oberparleiter 2009-06-17 16:28:08 -0700 146) #
2521f2c228ad7 (Peter Oberparleiter 2009-06-17 16:28:08 -0700 147) ifeq ($(CONFIG_GCOV_KERNEL),y)
2521f2c228ad7 (Peter Oberparleiter 2009-06-17 16:28:08 -0700 148) _c_flags += $(if $(patsubst n%,, \
2521f2c228ad7 (Peter Oberparleiter 2009-06-17 16:28:08 -0700 149) $(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
2521f2c228ad7 (Peter Oberparleiter 2009-06-17 16:28:08 -0700 150) $(CFLAGS_GCOV))
2521f2c228ad7 (Peter Oberparleiter 2009-06-17 16:28:08 -0700 151) endif
2521f2c228ad7 (Peter Oberparleiter 2009-06-17 16:28:08 -0700 152)
0b24becc810dc (Andrey Ryabinin 2015-02-13 14:39:17 -0800 153) #
0b24becc810dc (Andrey Ryabinin 2015-02-13 14:39:17 -0800 154) # Enable address sanitizer flags for kernel except some files or directories
0b24becc810dc (Andrey Ryabinin 2015-02-13 14:39:17 -0800 155) # we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
0b24becc810dc (Andrey Ryabinin 2015-02-13 14:39:17 -0800 156) #
0b24becc810dc (Andrey Ryabinin 2015-02-13 14:39:17 -0800 157) ifeq ($(CONFIG_KASAN),y)
0fea6e9af889f (Andrey Konovalov 2020-12-22 12:02:06 -0800 158) ifneq ($(CONFIG_KASAN_HW_TAGS),y)
0b24becc810dc (Andrey Ryabinin 2015-02-13 14:39:17 -0800 159) _c_flags += $(if $(patsubst n%,, \
0b24becc810dc (Andrey Ryabinin 2015-02-13 14:39:17 -0800 160) $(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
0e410e158e5ba (Andrey Konovalov 2018-02-06 15:36:00 -0800 161) $(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
0b24becc810dc (Andrey Ryabinin 2015-02-13 14:39:17 -0800 162) endif
0fea6e9af889f (Andrey Konovalov 2020-12-22 12:02:06 -0800 163) endif
0b24becc810dc (Andrey Ryabinin 2015-02-13 14:39:17 -0800 164)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 165) ifeq ($(CONFIG_UBSAN),y)
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 166) _c_flags += $(if $(patsubst n%,, \
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 167) $(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 168) $(CFLAGS_UBSAN))
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 169) endif
c6d308534aef6 (Andrey Ryabinin 2016-01-20 15:00:55 -0800 170)
5c9a8750a6409 (Dmitry Vyukov 2016-03-22 14:27:30 -0700 171) ifeq ($(CONFIG_KCOV),y)
5c9a8750a6409 (Dmitry Vyukov 2016-03-22 14:27:30 -0700 172) _c_flags += $(if $(patsubst n%,, \
a4691deabf284 (Vegard Nossum 2016-08-02 14:07:30 -0700 173) $(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
5c9a8750a6409 (Dmitry Vyukov 2016-03-22 14:27:30 -0700 174) $(CFLAGS_KCOV))
5c9a8750a6409 (Dmitry Vyukov 2016-03-22 14:27:30 -0700 175) endif
5c9a8750a6409 (Dmitry Vyukov 2016-03-22 14:27:30 -0700 176)
dfd402a4c4baa (Marco Elver 2019-11-14 19:02:54 +0100 177) #
dfd402a4c4baa (Marco Elver 2019-11-14 19:02:54 +0100 178) # Enable KCSAN flags except some files or directories we don't want to check
dfd402a4c4baa (Marco Elver 2019-11-14 19:02:54 +0100 179) # (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE)
dfd402a4c4baa (Marco Elver 2019-11-14 19:02:54 +0100 180) #
dfd402a4c4baa (Marco Elver 2019-11-14 19:02:54 +0100 181) ifeq ($(CONFIG_KCSAN),y)
dfd402a4c4baa (Marco Elver 2019-11-14 19:02:54 +0100 182) _c_flags += $(if $(patsubst n%,, \
dfd402a4c4baa (Marco Elver 2019-11-14 19:02:54 +0100 183) $(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \
dfd402a4c4baa (Marco Elver 2019-11-14 19:02:54 +0100 184) $(CFLAGS_KCSAN))
dfd402a4c4baa (Marco Elver 2019-11-14 19:02:54 +0100 185) endif
5c9a8750a6409 (Dmitry Vyukov 2016-03-22 14:27:30 -0700 186)
cdd750bfb1f76 (Masahiro Yamada 2019-05-13 15:22:17 +0900 187) # $(srctree)/$(src) for including checkin headers from generated source files
cdd750bfb1f76 (Masahiro Yamada 2019-05-13 15:22:17 +0900 188) # $(objtree)/$(obj) for including generated headers from checkin source files
58156ba4468f1 (Masahiro Yamada 2019-01-16 11:56:40 +0900 189) ifeq ($(KBUILD_EXTMOD),)
051f278e9d81b (Masahiro Yamada 2019-07-06 12:07:12 +0900 190) ifdef building_out_of_srctree
cdd750bfb1f76 (Masahiro Yamada 2019-05-13 15:22:17 +0900 191) _c_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
cdd750bfb1f76 (Masahiro Yamada 2019-05-13 15:22:17 +0900 192) _a_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
cdd750bfb1f76 (Masahiro Yamada 2019-05-13 15:22:17 +0900 193) _cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 194) endif
58156ba4468f1 (Masahiro Yamada 2019-01-16 11:56:40 +0900 195) endif
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 196)
eb27ea5ce7f36 (Masahiro Yamada 2019-08-19 17:58:43 +0900 197) part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
eb27ea5ce7f36 (Masahiro Yamada 2019-08-19 17:58:43 +0900 198) quiet_modtag = $(if $(part-of-module),[M], )
eb27ea5ce7f36 (Masahiro Yamada 2019-08-19 17:58:43 +0900 199)
eb27ea5ce7f36 (Masahiro Yamada 2019-08-19 17:58:43 +0900 200) modkern_cflags = \
eb27ea5ce7f36 (Masahiro Yamada 2019-08-19 17:58:43 +0900 201) $(if $(part-of-module), \
eb27ea5ce7f36 (Masahiro Yamada 2019-08-19 17:58:43 +0900 202) $(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
1664a377908ed (Masahiro Yamada 2019-12-19 17:33:28 +0900 203) $(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
eb27ea5ce7f36 (Masahiro Yamada 2019-08-19 17:58:43 +0900 204)
eb27ea5ce7f36 (Masahiro Yamada 2019-08-19 17:58:43 +0900 205) modkern_aflags = $(if $(part-of-module), \
eb27ea5ce7f36 (Masahiro Yamada 2019-08-19 17:58:43 +0900 206) $(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE), \
eb27ea5ce7f36 (Masahiro Yamada 2019-08-19 17:58:43 +0900 207) $(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL))
eb27ea5ce7f36 (Masahiro Yamada 2019-08-19 17:58:43 +0900 208)
30a7729771731 (Masahiro Yamada 2020-04-23 23:23:53 +0900 209) c_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
a95b37e20db9a (Masahiro Yamada 2018-03-27 21:52:50 +0900 210) -include $(srctree)/include/linux/compiler_types.h \
cdd750bfb1f76 (Masahiro Yamada 2019-05-13 15:22:17 +0900 211) $(_c_flags) $(modkern_cflags) \
b42841b7bb628 (Michal Marek 2016-03-17 16:32:14 +0100 212) $(basename_flags) $(modname_flags)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 213)
30a7729771731 (Masahiro Yamada 2020-04-23 23:23:53 +0900 214) a_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
cdd750bfb1f76 (Masahiro Yamada 2019-05-13 15:22:17 +0900 215) $(_a_flags) $(modkern_aflags)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 216)
30a7729771731 (Masahiro Yamada 2020-04-23 23:23:53 +0900 217) cpp_flags = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE) \
cdd750bfb1f76 (Masahiro Yamada 2019-05-13 15:22:17 +0900 218) $(_cpp_flags)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 219)
d503ac531a524 (Masahiro Yamada 2018-08-24 08:20:39 +0900 220) ld_flags = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 221)
50f9ddaf64e13 (Masahiro Yamada 2017-07-25 11:23:36 +0900 222) DTC_INCLUDE := $(srctree)/scripts/dtc/include-prefixes
50f9ddaf64e13 (Masahiro Yamada 2017-07-25 11:23:36 +0900 223)
30a7729771731 (Masahiro Yamada 2020-04-23 23:23:53 +0900 224) dtc_cpp_flags = -Wp,-MMD,$(depfile).pre.tmp -nostdinc \
50f9ddaf64e13 (Masahiro Yamada 2017-07-25 11:23:36 +0900 225) $(addprefix -I,$(DTC_INCLUDE)) \
e570d7c15a73f (Stephen Warren 2013-02-12 15:03:37 -0700 226) -undef -D__DTS__
e570d7c15a73f (Stephen Warren 2013-02-12 15:03:37 -0700 227)
850ded46c6429 (Sami Tolvanen 2021-08-16 11:05:19 -0700 228) ifeq ($(CONFIG_LTO_CLANG),y)
850ded46c6429 (Sami Tolvanen 2021-08-16 11:05:19 -0700 229) # With CONFIG_LTO_CLANG, .o files in modules might be LLVM bitcode, so we
850ded46c6429 (Sami Tolvanen 2021-08-16 11:05:19 -0700 230) # need to run LTO to compile them into native code (.lto.o) before further
850ded46c6429 (Sami Tolvanen 2021-08-16 11:05:19 -0700 231) # processing.
850ded46c6429 (Sami Tolvanen 2021-08-16 11:05:19 -0700 232) mod-prelink-ext := .lto
850ded46c6429 (Sami Tolvanen 2021-08-16 11:05:19 -0700 233) endif
850ded46c6429 (Sami Tolvanen 2021-08-16 11:05:19 -0700 234)
b1a1a1a09b460 (Sami Tolvanen 2020-04-13 16:10:13 -0700 235) # Objtool arguments are also needed for modfinal with LTO, so we define
b1a1a1a09b460 (Sami Tolvanen 2020-04-13 16:10:13 -0700 236) # then here to avoid duplication.
b1a1a1a09b460 (Sami Tolvanen 2020-04-13 16:10:13 -0700 237) objtool_args = \
b1a1a1a09b460 (Sami Tolvanen 2020-04-13 16:10:13 -0700 238) $(if $(CONFIG_UNWINDER_ORC),orc generate,check) \
44815c90210cd (Masahiro Yamada 2021-08-28 18:51:01 +0900 239) $(if $(part-of-module), --module) \
b1a1a1a09b460 (Sami Tolvanen 2020-04-13 16:10:13 -0700 240) $(if $(CONFIG_FRAME_POINTER),, --no-fp) \
44815c90210cd (Masahiro Yamada 2021-08-28 18:51:01 +0900 241) $(if $(CONFIG_GCOV_KERNEL)$(CONFIG_LTO_CLANG), --no-unreachable)\
44815c90210cd (Masahiro Yamada 2021-08-28 18:51:01 +0900 242) $(if $(CONFIG_RETPOLINE), --retpoline) \
44815c90210cd (Masahiro Yamada 2021-08-28 18:51:01 +0900 243) $(if $(CONFIG_X86_SMAP), --uaccess) \
44815c90210cd (Masahiro Yamada 2021-08-28 18:51:01 +0900 244) $(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount)
b1a1a1a09b460 (Sami Tolvanen 2020-04-13 16:10:13 -0700 245)
c8589d1e9e01d (Masahiro Yamada 2014-08-19 16:34:20 +0900 246) # Useful for describing the dependency of composite objects
c8589d1e9e01d (Masahiro Yamada 2014-08-19 16:34:20 +0900 247) # Usage:
c8589d1e9e01d (Masahiro Yamada 2014-08-19 16:34:20 +0900 248) # $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
c8589d1e9e01d (Masahiro Yamada 2014-08-19 16:34:20 +0900 249) define multi_depend
c8589d1e9e01d (Masahiro Yamada 2014-08-19 16:34:20 +0900 250) $(foreach m, $(notdir $1), \
c8589d1e9e01d (Masahiro Yamada 2014-08-19 16:34:20 +0900 251) $(eval $(obj)/$m: \
c8589d1e9e01d (Masahiro Yamada 2014-08-19 16:34:20 +0900 252) $(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))
c8589d1e9e01d (Masahiro Yamada 2014-08-19 16:34:20 +0900 253) endef
c8589d1e9e01d (Masahiro Yamada 2014-08-19 16:34:20 +0900 254)
dee9c0b575948 (Masahiro Yamada 2020-06-26 02:04:33 +0900 255) quiet_cmd_copy = COPY $@
dee9c0b575948 (Masahiro Yamada 2020-06-26 02:04:33 +0900 256) cmd_copy = cp $< $@
dee9c0b575948 (Masahiro Yamada 2020-06-26 02:04:33 +0900 257)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 258) # Shipped files
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 259) # ===========================================================================
3787b7da5d3e2 (Masahiro Yamada 2021-04-24 20:55:53 +0900 260) # 'cp' preserves permissions. If you use it to copy a file in read-only srctree,
3787b7da5d3e2 (Masahiro Yamada 2021-04-24 20:55:53 +0900 261) # the copy would be read-only as well, leading to an error when executing the
3787b7da5d3e2 (Masahiro Yamada 2021-04-24 20:55:53 +0900 262) # rule next time. Use 'cat' instead in order to generate a writable file.
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 263)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 264) quiet_cmd_shipped = SHIPPED $@
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 265) cmd_shipped = cat $< > $@
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 266)
991d76c950f6c (Arnaud Lacombe 2011-06-07 13:09:28 -0400 267) $(obj)/%: $(src)/%_shipped
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 268) $(call cmd,shipped)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 269)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 270) # Commands useful for building a boot image
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 271) # ===========================================================================
38385f8f01803 (Masahiro Yamada 2014-04-28 16:26:18 +0900 272) #
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 273) # Use as following:
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 274) #
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 275) # target: source(s) FORCE
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 276) # $(if_changed,ld/objcopy/gzip)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 277) #
2047ace96679a (Masahiro Yamada 2021-01-20 15:23:51 +0900 278) # and add target to 'targets' so that we know we have to
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 279) # read in the saved command line
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 280)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 281) # Linking
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 282) # ---------------------------------------------------------------------------
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 283)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 284) quiet_cmd_ld = LD $@
afa974b771281 (Masahiro Yamada 2019-01-17 19:02:43 +0900 285) cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 286)
898f5a009f226 (Masahiro Yamada 2019-02-05 16:33:37 +0900 287) # Archive
898f5a009f226 (Masahiro Yamada 2019-02-05 16:33:37 +0900 288) # ---------------------------------------------------------------------------
898f5a009f226 (Masahiro Yamada 2019-02-05 16:33:37 +0900 289)
898f5a009f226 (Masahiro Yamada 2019-02-05 16:33:37 +0900 290) quiet_cmd_ar = AR $@
13dc8c029cabf (Masahiro Yamada 2019-09-21 15:49:54 +0900 291) cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
898f5a009f226 (Masahiro Yamada 2019-02-05 16:33:37 +0900 292)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 293) # Objcopy
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 294) # ---------------------------------------------------------------------------
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 295)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 296) quiet_cmd_objcopy = OBJCOPY $@
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 297) cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 298)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 299) # Gzip
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 300) # ---------------------------------------------------------------------------
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 301)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 302) quiet_cmd_gzip = GZIP $@
e4a42c82e943b (Denis Efremov 2020-06-08 12:59:44 +0300 303) cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 304)
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 305) # DTC
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 306) # ---------------------------------------------------------------------------
6b22b3d1614af (Rob Herring 2016-02-11 16:28:13 -0600 307) DTC ?= $(objtree)/scripts/dtc/dtc
3eb619b2f7d8a (Rob Herring 2020-06-29 12:15:13 -0600 308) DTC_FLAGS += -Wno-interrupt_provider
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 309)
bc553986a2f7c (Rob Herring 2016-03-24 10:52:42 -0500 310) # Disable noisy checks by default
e27128db62834 (Masahiro Yamada 2019-09-01 01:25:55 +0900 311) ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
8654cb8d0371d (Rob Herring 2017-03-21 09:14:20 -0500 312) DTC_FLAGS += -Wno-unit_address_vs_reg \
8654cb8d0371d (Rob Herring 2017-03-21 09:14:20 -0500 313) -Wno-unit_address_format \
4fd98e374fd37 (Rob Herring 2018-02-28 08:09:45 -0600 314) -Wno-avoid_unnecessary_addr_size \
4fd98e374fd37 (Rob Herring 2018-02-28 08:09:45 -0600 315) -Wno-alias_paths \
74656b682902c (Rob Herring 2018-05-07 16:46:47 -0500 316) -Wno-graph_child_address \
70523a3ce5ff9 (Rob Herring 2018-11-28 19:11:50 -0600 317) -Wno-simple_bus_reg \
1ee7943c33431 (Rob Herring 2021-08-20 11:24:20 -0500 318) -Wno-unique_unit_address
bc553986a2f7c (Rob Herring 2016-03-24 10:52:42 -0500 319) endif
bc553986a2f7c (Rob Herring 2016-03-24 10:52:42 -0500 320)
e27128db62834 (Masahiro Yamada 2019-09-01 01:25:55 +0900 321) ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
8654cb8d0371d (Rob Herring 2017-03-21 09:14:20 -0500 322) DTC_FLAGS += -Wnode_name_chars_strict \
3eb619b2f7d8a (Rob Herring 2020-06-29 12:15:13 -0600 323) -Wproperty_name_chars_strict \
3eb619b2f7d8a (Rob Herring 2020-06-29 12:15:13 -0600 324) -Winterrupt_provider
bc553986a2f7c (Rob Herring 2016-03-24 10:52:42 -0500 325) endif
bc553986a2f7c (Rob Herring 2016-03-24 10:52:42 -0500 326)
331f741679564 (Frank Rowand 2017-04-25 17:09:53 -0700 327) DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
331f741679564 (Frank Rowand 2017-04-25 17:09:53 -0700 328)
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 329) # Set -@ if the target is a base DTB that overlay is applied onto
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 330) DTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 331)
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 332) # Generate an assembly file to wrap the output of the device tree compiler
1c00a47e48d1b (James Hogan 2013-06-13 11:53:09 +0100 333) quiet_cmd_dt_S_dtb= DTB $@
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 334) cmd_dt_S_dtb= \
b79c6aa6a1f11 (Masahiro Yamada 2019-01-17 19:02:44 +0900 335) { \
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 336) echo '\#include <asm-generic/vmlinux.lds.h>'; \
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 337) echo '.section .dtb.init.rodata,"a"'; \
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 338) echo '.balign STRUCT_ALIGNMENT'; \
55fe6da9efba1 (James Hogan 2018-03-08 11:02:46 +0000 339) echo '.global __dtb_$(subst -,_,$(*F))_begin'; \
55fe6da9efba1 (James Hogan 2018-03-08 11:02:46 +0000 340) echo '__dtb_$(subst -,_,$(*F))_begin:'; \
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 341) echo '.incbin "$<" '; \
55fe6da9efba1 (James Hogan 2018-03-08 11:02:46 +0000 342) echo '__dtb_$(subst -,_,$(*F))_end:'; \
55fe6da9efba1 (James Hogan 2018-03-08 11:02:46 +0000 343) echo '.global __dtb_$(subst -,_,$(*F))_end'; \
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 344) echo '.balign STRUCT_ALIGNMENT'; \
b79c6aa6a1f11 (Masahiro Yamada 2019-01-17 19:02:44 +0900 345) } > $@
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 346)
a7f9241909247 (Masahiro Yamada 2018-03-23 22:04:34 +0900 347) $(obj)/%.dtb.S: $(obj)/%.dtb FORCE
a7f9241909247 (Masahiro Yamada 2018-03-23 22:04:34 +0900 348) $(call if_changed,dt_S_dtb)
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 349)
aab94339cd85d (Dirk Brandewie 2010-12-22 11:57:26 -0800 350) quiet_cmd_dtc = DTC $@
dd7699e37f289 (Masahiro Yamada 2020-06-23 17:05:49 +0900 351) cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
64bfc99429a5c (Masahiro Yamada 2021-03-10 20:08:24 +0900 352) $(DTC) -o $@ -b 0 \
50f9ddaf64e13 (Masahiro Yamada 2017-07-25 11:23:36 +0900 353) $(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
b0a4d8b3cf199 (Ian Campbell 2013-05-31 11:14:20 +0100 354) -d $(depfile).dtc.tmp $(dtc-tmp) ; \
b0a4d8b3cf199 (Ian Campbell 2013-05-31 11:14:20 +0100 355) cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
^1da177e4c3f4 (Linus Torvalds 2005-04-16 15:20:36 -0700 356)
b8fc5b2157b10 (Rob Herring 2018-02-27 17:49:57 -0600 357) $(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
78046fabe6e78 (Masahiro Yamada 2020-04-27 22:49:30 +0900 358) $(call if_changed_dep,dtc)
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 359)
ce88c9c79455f (Viresh Kumar 2021-01-29 12:54:08 +0530 360) $(obj)/%.dtbo: $(src)/%.dts $(DTC) FORCE
ce88c9c79455f (Viresh Kumar 2021-01-29 12:54:08 +0530 361) $(call if_changed_dep,dtc)
ce88c9c79455f (Viresh Kumar 2021-01-29 12:54:08 +0530 362)
15d16d6dadf69 (Rob Herring 2021-03-10 11:05:30 +0530 363) quiet_cmd_fdtoverlay = DTOVL $@
15d16d6dadf69 (Rob Herring 2021-03-10 11:05:30 +0530 364) cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(real-prereqs)
15d16d6dadf69 (Rob Herring 2021-03-10 11:05:30 +0530 365)
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 366) $(multi-dtb-y): FORCE
15d16d6dadf69 (Rob Herring 2021-03-10 11:05:30 +0530 367) $(call if_changed,fdtoverlay)
bcf0c66428336 (Masahiro Yamada 2021-05-03 03:09:56 +0900 368) $(call multi_depend, $(multi-dtb-y), .dtb, -dtbs)
15d16d6dadf69 (Rob Herring 2021-03-10 11:05:30 +0530 369)
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 370) DT_CHECKER ?= dt-validate
c59773d204cc0 (Rob Herring 2021-03-11 16:36:40 -0700 371) DT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),,-m)
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 372) DT_BINDING_DIR := Documentation/devicetree/bindings
2ba06cd8565b5 (Rob Herring 2020-02-28 18:37:30 -0600 373) # DT_TMP_SCHEMA may be overridden from Documentation/devicetree/bindings/Makefile
b8a49399fb7ab (Andrei Ziureaev 2020-08-13 14:26:11 +0100 374) DT_TMP_SCHEMA ?= $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 375)
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 376) quiet_cmd_dtb_check = CHECK $@
c59773d204cc0 (Rob Herring 2021-03-11 16:36:40 -0700 377) cmd_dtb_check = $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 378)
7a04960560640 (Masahiro Yamada 2020-02-23 04:04:31 +0900 379) define rule_dtc
78046fabe6e78 (Masahiro Yamada 2020-04-27 22:49:30 +0900 380) $(call cmd_and_fixdep,dtc)
f5688663db9b2 (Masahiro Yamada 2018-12-31 13:09:00 +0900 381) $(call cmd,dtb_check)
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 382) endef
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 383)
4f0e3a57d6eb7 (Rob Herring 2018-09-06 13:26:07 -0500 384) $(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
285a65f1a10f8 (Masahiro Yamada 2021-03-11 15:30:54 +0900 385) $(call if_changed_rule,dtc)
90b335fbbc316 (Stephen Warren 2012-11-27 16:29:10 -0700 386)
b0a4d8b3cf199 (Ian Campbell 2013-05-31 11:14:20 +0100 387) dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
22435f38337ef (Stephen Warren 2013-02-05 12:06:28 -0700 388)
bc22c17e12c13 (Alain Knaff 2009-01-04 22:46:16 +0100 389) # Bzip2
bc22c17e12c13 (Alain Knaff 2009-01-04 22:46:16 +0100 390) # ---------------------------------------------------------------------------
bc22c17e12c13 (Alain Knaff 2009-01-04 22:46:16 +0100 391)
d3dd3b5a29bb9 (H. Peter Anvin 2009-05-05 21:17:15 -0700 392) # Bzip2 and LZMA do not include size in file... so we have to fake that;
d3dd3b5a29bb9 (H. Peter Anvin 2009-05-05 21:17:15 -0700 393) # append the size as a 32-bit littleendian number as gzip does.
4a2ff67c88211 (Michael Tokarev 2009-10-13 22:22:46 +0200 394) size_append = printf $(shell \
d3dd3b5a29bb9 (H. Peter Anvin 2009-05-05 21:17:15 -0700 395) dec_size=0; \
afa974b771281 (Masahiro Yamada 2019-01-17 19:02:43 +0900 396) for F in $(real-prereqs); do \
a670b0b4aed12 (Michael Forney 2018-03-18 17:54:02 -0700 397) fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F); \
d3dd3b5a29bb9 (H. Peter Anvin 2009-05-05 21:17:15 -0700 398) dec_size=$$(expr $$dec_size + $$fsize); \
d3dd3b5a29bb9 (H. Peter Anvin 2009-05-05 21:17:15 -0700 399) done; \
1373411ae4cd0 (Jonathan Nieder 2009-12-28 19:38:27 +0000 400) printf "%08x\n" $$dec_size | \
1373411ae4cd0 (Jonathan Nieder 2009-12-28 19:38:27 +0000 401) sed 's/\(..\)/\1 /g' | { \
1373411ae4cd0 (Jonathan Nieder 2009-12-28 19:38:27 +0000 402) read ch0 ch1 ch2 ch3; \
1373411ae4cd0 (Jonathan Nieder 2009-12-28 19:38:27 +0000 403) for ch in $$ch3 $$ch2 $$ch1 $$ch0; do \
1373411ae4cd0 (Jonathan Nieder 2009-12-28 19:38:27 +0000 404) printf '%s%03o' '\\' $$((0x$$ch)); \
1373411ae4cd0 (Jonathan Nieder 2009-12-28 19:38:27 +0000 405) done; \
1373411ae4cd0 (Jonathan Nieder 2009-12-28 19:38:27 +0000 406) } \
d3dd3b5a29bb9 (H. Peter Anvin 2009-05-05 21:17:15 -0700 407) )
d3dd3b5a29bb9 (H. Peter Anvin 2009-05-05 21:17:15 -0700 408)
d3dd3b5a29bb9 (H. Peter Anvin 2009-05-05 21:17:15 -0700 409) quiet_cmd_bzip2 = BZIP2 $@
e4a42c82e943b (Denis Efremov 2020-06-08 12:59:44 +0300 410) cmd_bzip2 = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
bc22c17e12c13 (Alain Knaff 2009-01-04 22:46:16 +0100 411)
bc22c17e12c13 (Alain Knaff 2009-01-04 22:46:16 +0100 412) # Lzma
bc22c17e12c13 (Alain Knaff 2009-01-04 22:46:16 +0100 413) # ---------------------------------------------------------------------------
bc22c17e12c13 (Alain Knaff 2009-01-04 22:46:16 +0100 414)
bc22c17e12c13 (Alain Knaff 2009-01-04 22:46:16 +0100 415) quiet_cmd_lzma = LZMA $@
8dfb61dcbaceb (Denis Efremov 2020-06-05 10:39:55 +0300 416) cmd_lzma = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
7dd65feb6c603 (Albin Tonnerre 2010-01-08 14:42:42 -0800 417)
2d74b2c62cf88 (Wu Zhangjin 2010-03-11 17:42:14 +0800 418) quiet_cmd_lzo = LZO $@
e4a42c82e943b (Denis Efremov 2020-06-08 12:59:44 +0300 419) cmd_lzo = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
d61931d89be50 (Borislav Petkov 2010-03-05 17:34:46 +0100 420)
e76e1fdfa8f8d (Kyungsik Lee 2013-07-08 16:01:46 -0700 421) quiet_cmd_lz4 = LZ4 $@
8dfb61dcbaceb (Denis Efremov 2020-06-05 10:39:55 +0300 422) cmd_lz4 = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \
b79c6aa6a1f11 (Masahiro Yamada 2019-01-17 19:02:44 +0900 423) $(size_append); } > $@
e76e1fdfa8f8d (Kyungsik Lee 2013-07-08 16:01:46 -0700 424)
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 425) # U-Boot mkimage
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 426) # ---------------------------------------------------------------------------
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 427)
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 428) MKIMAGE := $(srctree)/scripts/mkuboot.sh
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 429)
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 430) # SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 431) # the number of overrides in arch makefiles
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 432) UIMAGE_ARCH ?= $(SRCARCH)
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 433) UIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 434) UIMAGE_OPTS-y ?=
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 435) UIMAGE_TYPE ?= kernel
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 436) UIMAGE_LOADADDR ?= arch_must_set_this
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 437) UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 438) UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 439)
786ac51a48465 (Masahiro Yamada 2018-12-31 10:05:01 +0900 440) quiet_cmd_uimage = UIMAGE $@
858805b336be1 (Masahiro Yamada 2019-08-25 22:28:37 +0900 441) cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 442) -C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 443) -T $(UIMAGE_TYPE) \
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 444) -a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
786ac51a48465 (Masahiro Yamada 2018-12-31 10:05:01 +0900 445) -n $(UIMAGE_NAME) -d $< $@
e33936451484b (Stephen Warren 2012-03-16 15:03:55 -0600 446)
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 447) # XZ
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 448) # ---------------------------------------------------------------------------
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 449) # Use xzkern to compress the kernel image and xzmisc to compress other things.
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 450) #
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 451) # xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 452) # of the kernel decompressor. A BCJ filter is used if it is available for
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 453) # the target architecture. xzkern also appends uncompressed size of the data
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 454) # using size_append. The .xz format has the size information available at
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 455) # the end of the file too, but it's in more complex format and it's good to
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 456) # avoid changing the part of the boot code that reads the uncompressed size.
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 457) # Note that the bytes added by size_append will make the xz tool think that
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 458) # the file is corrupt. This is expected.
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 459) #
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 460) # xzmisc doesn't use size_append, so it can be used to create normal .xz
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 461) # files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 462) # big dictionary would increase the memory usage too much in the multi-call
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 463) # decompression mode. A BCJ filter isn't used either.
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 464) quiet_cmd_xzkern = XZKERN $@
b956c7a6df3aa (Harald Seiler 2019-07-09 12:50:50 +0200 465) cmd_xzkern = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
b79c6aa6a1f11 (Masahiro Yamada 2019-01-17 19:02:44 +0900 466) $(size_append); } > $@
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 467)
24fa0402a9b6a (Lasse Collin 2011-01-12 17:01:22 -0800 468) quiet_cmd_xzmisc = XZMISC $@
8dfb61dcbaceb (Denis Efremov 2020-06-05 10:39:55 +0300 469) cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 470)
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 471) # ZSTD
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 472) # ---------------------------------------------------------------------------
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 473) # Appends the uncompressed size of the data using size_append. The .zst
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 474) # format has the size information available at the beginning of the file too,
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 475) # but it's in a more complex format and it's good to avoid changing the part
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 476) # of the boot code that reads the uncompressed size.
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 477) #
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 478) # Note that the bytes added by size_append will make the zstd tool think that
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 479) # the file is corrupt. This is expected.
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 480) #
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 481) # zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 482) # 128 MB. zstd22 is used for kernel compression because it is decompressed in a
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 483) # single pass, so zstd doesn't need to allocate a window buffer. When streaming
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 484) # decompression is used, like initramfs decompression, zstd22 should likely not
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 485) # be used because it would require zstd to allocate a 128 MB buffer.
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 486)
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 487) quiet_cmd_zstd = ZSTD $@
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 488) cmd_zstd = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 489)
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 490) quiet_cmd_zstd22 = ZSTD22 $@
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 491) cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
48f7ddf785af2 (Nick Terrell 2020-07-30 12:08:36 -0700 492)
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 493) # ASM offsets
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 494) # ---------------------------------------------------------------------------
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 495)
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 496) # Default sed regexp - multiline due to syntax constraints
cf0c3e68aa81f (Jeroen Hofstee 2017-04-21 15:21:11 +0900 497) #
cf0c3e68aa81f (Jeroen Hofstee 2017-04-21 15:21:11 +0900 498) # Use [:space:] because LLVM's integrated assembler inserts <tab> around
cf0c3e68aa81f (Jeroen Hofstee 2017-04-21 15:21:11 +0900 499) # the .ascii directive whereas GCC keeps the <space> as-is.
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 500) define sed-offsets
cf0c3e68aa81f (Jeroen Hofstee 2017-04-21 15:21:11 +0900 501) 's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
cf0c3e68aa81f (Jeroen Hofstee 2017-04-21 15:21:11 +0900 502) /^->/{s:->#\(.*\):/* \1 */:; \
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 503) s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
cf0c3e68aa81f (Jeroen Hofstee 2017-04-21 15:21:11 +0900 504) s:->::; p;}'
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 505) endef
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 506)
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 507) # Use filechk to avoid rebuilds when a header changes, but the resulting file
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 508) # does not
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 509) define filechk_offsets
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 510) echo "#ifndef $2"; \
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 511) echo "#define $2"; \
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 512) echo "/*"; \
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 513) echo " * DO NOT MODIFY."; \
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 514) echo " *"; \
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 515) echo " * This file was generated by Kbuild"; \
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 516) echo " */"; \
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 517) echo ""; \
43fee2b238959 (Masahiro Yamada 2018-07-25 14:16:11 +0900 518) sed -ne $(sed-offsets) < $<; \
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 519) echo ""; \
ad774086356da (Masahiro Yamada 2018-12-31 17:24:09 +0900 520) echo "#endif"
ebf003f0cfb37 (Matthias Kaehlcke 2017-04-12 12:43:52 -0700 521) endef