xref: /linux/scripts/Makefile.lib (revision 223390b1c4d266c3b684b99d0a1980c49ebccf0d)
1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0
2f77bf014SSam Ravnborg# Backward compatibility
3f77bf014SSam Ravnborgasflags-y  += $(EXTRA_AFLAGS)
4f77bf014SSam Ravnborgccflags-y  += $(EXTRA_CFLAGS)
5f77bf014SSam Ravnborgcppflags-y += $(EXTRA_CPPFLAGS)
6f77bf014SSam Ravnborgldflags-y  += $(EXTRA_LDFLAGS)
7f77bf014SSam Ravnborg
88fdc3fbbSCao jin# flags that take effect in current and sub directories
94e13d47cSMasahiro YamadaKBUILD_AFLAGS += $(subdir-asflags-y)
104e13d47cSMasahiro YamadaKBUILD_CFLAGS += $(subdir-ccflags-y)
112f7ab126SMiguel OjedaKBUILD_RUSTFLAGS += $(subdir-rustflags-y)
12720097d8SSam Ravnborg
131da177e4SLinus Torvalds# Figure out what we need to build from the various variables
141da177e4SLinus Torvalds# ===========================================================================
151da177e4SLinus Torvalds
161da177e4SLinus Torvalds# When an object is listed to be built compiled-in and modular,
171da177e4SLinus Torvalds# only build the compiled-in version
181da177e4SLinus Torvaldsobj-m := $(filter-out $(obj-y),$(obj-m))
191da177e4SLinus Torvalds
201da177e4SLinus Torvalds# Libraries are always collected in one lib file.
211da177e4SLinus Torvalds# Filter out objects already built-in
221da177e4SLinus Torvaldslib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
231da177e4SLinus Torvalds
240a8820e7SMasahiro Yamada# Subdirectories we need to descend into
250a8820e7SMasahiro Yamadasubdir-ym := $(sort $(subdir-y) $(subdir-m) \
260a8820e7SMasahiro Yamada			$(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
270a8820e7SMasahiro Yamada
28b2c88554SMasahiro Yamada# Handle objects in subdirs:
29b2c88554SMasahiro Yamada# - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
30b2c88554SMasahiro Yamada#   foo/modules.order
31b2c88554SMasahiro Yamada# - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
32b2c88554SMasahiro Yamada#
33b2c88554SMasahiro Yamada# Generate modules.order to determine modorder. Unfortunately, we don't have
34b2c88554SMasahiro Yamada# information about ordering between -y and -m subdirs. Just put -y's first.
35b2c88554SMasahiro Yamada
36b2c88554SMasahiro Yamadaifdef need-modorder
37b2c88554SMasahiro Yamadaobj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
38b2c88554SMasahiro Yamadaelse
39b2c88554SMasahiro Yamadaobj-m := $(filter-out %/, $(obj-m))
40b2c88554SMasahiro Yamadaendif
41b2c88554SMasahiro Yamada
4256d58936SMasahiro Yamadaifdef need-builtin
43f49821eeSNicholas Pigginobj-y		:= $(patsubst %/, %/built-in.a, $(obj-y))
4456d58936SMasahiro Yamadaelse
4556d58936SMasahiro Yamadaobj-y		:= $(filter-out %/, $(obj-y))
4656d58936SMasahiro Yamadaendif
471da177e4SLinus Torvalds
4824507871SMasahiro Yamadaifdef need-dtbslist
4924507871SMasahiro Yamadadtb-y		+= $(addsuffix /dtbs-list, $(subdir-ym))
5024507871SMasahiro Yamadaalways-y	+= dtbs-list
5124507871SMasahiro Yamadaendif
5224507871SMasahiro Yamada
5344f87191SMasahiro Yamada# Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
5444f87191SMasahiro Yamadasuffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
5544f87191SMasahiro Yamada# List composite targets that are constructed by combining other targets
5644f87191SMasahiro Yamadamulti-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m)))
5744f87191SMasahiro Yamada# List primitive targets that are compiled from source files
5844f87191SMasahiro Yamadareal-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
5944f87191SMasahiro Yamada
6033e84f2eSMasahiro Yamada# If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
6144f87191SMasahiro Yamadamulti-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
6244f87191SMasahiro Yamadamulti-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
63a6601e01SMasahiro Yamadamulti-obj-ym := $(multi-obj-y) $(multi-obj-m)
641da177e4SLinus Torvalds
65f98fe47cSMasahiro Yamada# Replace multi-part objects by their individual parts,
66f98fe47cSMasahiro Yamada# including built-in.a from subdirectories
6744f87191SMasahiro Yamadareal-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
6844f87191SMasahiro Yamadareal-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
691da177e4SLinus Torvalds
705f2fb52fSMasahiro Yamadaalways-y += $(always-m)
715f2fb52fSMasahiro Yamada
72faabed29SMasahiro Yamada# hostprogs-always-y += foo
73faabed29SMasahiro Yamada# ... is a shorthand for
74faabed29SMasahiro Yamada# hostprogs += foo
75faabed29SMasahiro Yamada# always-y  += foo
76faabed29SMasahiro Yamadahostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
77faabed29SMasahiro Yamadaalways-y += $(hostprogs-always-y) $(hostprogs-always-m)
78faabed29SMasahiro Yamada
79faabed29SMasahiro Yamada# userprogs-always-y is likewise.
80faabed29SMasahiro Yamadauserprogs += $(userprogs-always-y) $(userprogs-always-m)
81faabed29SMasahiro Yamadaalways-y += $(userprogs-always-y) $(userprogs-always-m)
82faabed29SMasahiro Yamada
837e7962ddSMasahiro Yamada# DTB
847e7962ddSMasahiro Yamada# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
859ca29e41SViresh Kumardtb-$(CONFIG_OF_ALL_DTBS)       += $(dtb-)
869ca29e41SViresh Kumar
87bcf0c664SMasahiro Yamada# Composite DTB (i.e. DTB constructed by overlay)
88bcf0c664SMasahiro Yamadamulti-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs)
89bcf0c664SMasahiro Yamada# Primitive DTB compiled from *.dts
90bcf0c664SMasahiro Yamadareal-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs)
91cbe826b0SMasahiro Yamada# Base DTB that overlay is applied onto
92cbe826b0SMasahiro Yamadabase-dtb-y := $(filter %.dtb, $(call real-search, $(multi-dtb-y), .dtb, -dtbs))
9315d16d6dSRob Herring
942047ace9SMasahiro Yamadaalways-y			+= $(dtb-y)
957e7962ddSMasahiro Yamada
961da177e4SLinus Torvalds# Add subdir path
971da177e4SLinus Torvalds
985750121aSMasahiro Yamadaifneq ($(obj),.)
991da177e4SLinus Torvaldsextra-y		:= $(addprefix $(obj)/,$(extra-y))
1005f2fb52fSMasahiro Yamadaalways-y	:= $(addprefix $(obj)/,$(always-y))
1011da177e4SLinus Torvaldstargets		:= $(addprefix $(obj)/,$(targets))
1021da177e4SLinus Torvaldsobj-m		:= $(addprefix $(obj)/,$(obj-m))
1031da177e4SLinus Torvaldslib-y		:= $(addprefix $(obj)/,$(lib-y))
104f5f33681SMasahiro Yamadareal-obj-y	:= $(addprefix $(obj)/,$(real-obj-y))
105f5f33681SMasahiro Yamadareal-obj-m	:= $(addprefix $(obj)/,$(real-obj-m))
106a6601e01SMasahiro Yamadamulti-obj-m	:= $(addprefix $(obj)/, $(multi-obj-m))
10724507871SMasahiro Yamadadtb-y		:= $(addprefix $(obj)/, $(dtb-y))
108bcf0c664SMasahiro Yamadamulti-dtb-y	:= $(addprefix $(obj)/, $(multi-dtb-y))
109bcf0c664SMasahiro Yamadareal-dtb-y	:= $(addprefix $(obj)/, $(real-dtb-y))
1101da177e4SLinus Torvaldssubdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
1115750121aSMasahiro Yamadaendif
1121da177e4SLinus Torvalds
113c0152e9aSMasahiro Yamada# Finds the multi-part object the current object will be linked into.
1141664a377SMasahiro Yamada# If the object belongs to two or more multi-part objects, list them all.
115a6601e01SMasahiro Yamadamodname-multi = $(sort $(foreach m,$(multi-obj-ym),\
116d4452837SMasahiro Yamada		$(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=))))
117c0152e9aSMasahiro Yamada
1185c816641SMasahiro Yamada__modname = $(or $(modname-multi),$(basetarget))
1191664a377SMasahiro Yamada
1201664a377SMasahiro Yamadamodname = $(subst $(space),:,$(__modname))
1211664a377SMasahiro Yamadamodfile = $(addprefix $(obj)/,$(__modname))
122c0152e9aSMasahiro Yamada
12354b8ae66SMasahiro Yamada# target with $(obj)/ and its suffix stripped
12454b8ae66SMasahiro Yamadatarget-stem = $(basename $(patsubst $(obj)/%,%,$@))
12554b8ae66SMasahiro Yamada
1261da177e4SLinus Torvalds# These flags are needed for modversions and compiling, so we define them here
1278fdc3fbbSCao jin# $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
1281da177e4SLinus Torvalds# end up in (or would, if it gets compiled in)
129a8cccdd9SSami Tolvanenname-fix-token = $(subst $(comma),_,$(subst -,_,$1))
130a8cccdd9SSami Tolvanenname-fix = $(call stringify,$(call name-fix-token,$1))
131b42841b7SMichal Marekbasename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
132a8cccdd9SSami Tolvanenmodname_flags  = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \
133a8cccdd9SSami Tolvanen		 -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname))
1341664a377SMasahiro Yamadamodfile_flags  = -DKBUILD_MODFILE=$(call stringify,$(modfile))
1351da177e4SLinus Torvalds
13615d5761aSMasahiro Yamada_c_flags       = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
13715d5761aSMasahiro Yamada                     $(filter-out $(ccflags-remove-y), \
13815d5761aSMasahiro Yamada                         $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
13915d5761aSMasahiro Yamada                     $(CFLAGS_$(target-stem).o))
1402f7ab126SMiguel Ojeda_rust_flags    = $(filter-out $(RUSTFLAGS_REMOVE_$(target-stem).o), \
1412f7ab126SMiguel Ojeda                     $(filter-out $(rustflags-remove-y), \
1422f7ab126SMiguel Ojeda                         $(KBUILD_RUSTFLAGS) $(rustflags-y)) \
1432f7ab126SMiguel Ojeda                     $(RUSTFLAGS_$(target-stem).o))
14415d5761aSMasahiro Yamada_a_flags       = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
14515d5761aSMasahiro Yamada                     $(filter-out $(asflags-remove-y), \
14615d5761aSMasahiro Yamada                         $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
14715d5761aSMasahiro Yamada                     $(AFLAGS_$(target-stem).o))
14854b8ae66SMasahiro Yamada_cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
1491da177e4SLinus Torvalds
1502521f2c2SPeter Oberparleiter#
1512521f2c2SPeter Oberparleiter# Enable gcov profiling flags for a file, directory or for all files depending
1522521f2c2SPeter Oberparleiter# on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
1532521f2c2SPeter Oberparleiter# (in this order)
1542521f2c2SPeter Oberparleiter#
1552521f2c2SPeter Oberparleiterifeq ($(CONFIG_GCOV_KERNEL),y)
1562521f2c2SPeter Oberparleiter_c_flags += $(if $(patsubst n%,, \
157bf48d9b7SMasahiro Yamada		$(GCOV_PROFILE_$(target-stem).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
1582521f2c2SPeter Oberparleiter		$(CFLAGS_GCOV))
1592521f2c2SPeter Oberparleiterendif
1602521f2c2SPeter Oberparleiter
1610b24beccSAndrey Ryabinin#
1620b24beccSAndrey Ryabinin# Enable address sanitizer flags for kernel except some files or directories
1630b24beccSAndrey Ryabinin# we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
1640b24beccSAndrey Ryabinin#
1650b24beccSAndrey Ryabininifeq ($(CONFIG_KASAN),y)
1660fea6e9aSAndrey Konovalovifneq ($(CONFIG_KASAN_HW_TAGS),y)
1670b24beccSAndrey Ryabinin_c_flags += $(if $(patsubst n%,, \
168bf48d9b7SMasahiro Yamada		$(KASAN_SANITIZE_$(target-stem).o)$(KASAN_SANITIZE)y), \
1690e410e15SAndrey Konovalov		$(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
1700b24beccSAndrey Ryabininendif
1710fea6e9aSAndrey Konovalovendif
1720b24beccSAndrey Ryabinin
173f80be457SAlexander Potapenkoifeq ($(CONFIG_KMSAN),y)
174f80be457SAlexander Potapenko_c_flags += $(if $(patsubst n%,, \
175bf48d9b7SMasahiro Yamada		$(KMSAN_SANITIZE_$(target-stem).o)$(KMSAN_SANITIZE)y), \
176f80be457SAlexander Potapenko		$(CFLAGS_KMSAN))
177f80be457SAlexander Potapenko_c_flags += $(if $(patsubst n%,, \
178bf48d9b7SMasahiro Yamada		$(KMSAN_ENABLE_CHECKS_$(target-stem).o)$(KMSAN_ENABLE_CHECKS)y), \
179f80be457SAlexander Potapenko		, -mllvm -msan-disable-checks=1)
180f80be457SAlexander Potapenkoendif
181f80be457SAlexander Potapenko
182c6d30853SAndrey Ryabininifeq ($(CONFIG_UBSAN),y)
183c6d30853SAndrey Ryabinin_c_flags += $(if $(patsubst n%,, \
184bf48d9b7SMasahiro Yamada		$(UBSAN_SANITIZE_$(target-stem).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
185c6d30853SAndrey Ryabinin		$(CFLAGS_UBSAN))
186c6d30853SAndrey Ryabininendif
187c6d30853SAndrey Ryabinin
1885c9a8750SDmitry Vyukovifeq ($(CONFIG_KCOV),y)
1895c9a8750SDmitry Vyukov_c_flags += $(if $(patsubst n%,, \
190bf48d9b7SMasahiro Yamada	$(KCOV_INSTRUMENT_$(target-stem).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
1915c9a8750SDmitry Vyukov	$(CFLAGS_KCOV))
1925c9a8750SDmitry Vyukovendif
1935c9a8750SDmitry Vyukov
194dfd402a4SMarco Elver#
195dfd402a4SMarco Elver# Enable KCSAN flags except some files or directories we don't want to check
196dfd402a4SMarco Elver# (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE)
197dfd402a4SMarco Elver#
198dfd402a4SMarco Elverifeq ($(CONFIG_KCSAN),y)
199dfd402a4SMarco Elver_c_flags += $(if $(patsubst n%,, \
200bf48d9b7SMasahiro Yamada	$(KCSAN_SANITIZE_$(target-stem).o)$(KCSAN_SANITIZE)y), \
201dfd402a4SMarco Elver	$(CFLAGS_KCSAN))
20248c9e28eSMarco Elver# Some uninstrumented files provide implied barriers required to avoid false
20348c9e28eSMarco Elver# positives: set KCSAN_INSTRUMENT_BARRIERS for barrier instrumentation only.
20448c9e28eSMarco Elver_c_flags += $(if $(patsubst n%,, \
205bf48d9b7SMasahiro Yamada	$(KCSAN_INSTRUMENT_BARRIERS_$(target-stem).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \
20648c9e28eSMarco Elver	-D__KCSAN_INSTRUMENT_BARRIERS__)
207dfd402a4SMarco Elverendif
208dfd402a4SMarco Elver
209cdd750bfSMasahiro Yamada# $(srctree)/$(src) for including checkin headers from generated source files
210cdd750bfSMasahiro Yamada# $(objtree)/$(obj) for including generated headers from checkin source files
21158156ba4SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
212051f278eSMasahiro Yamadaifdef building_out_of_srctree
213cdd750bfSMasahiro Yamada_c_flags   += -I $(srctree)/$(src) -I $(objtree)/$(obj)
214cdd750bfSMasahiro Yamada_a_flags   += -I $(srctree)/$(src) -I $(objtree)/$(obj)
215cdd750bfSMasahiro Yamada_cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
2161da177e4SLinus Torvaldsendif
21758156ba4SMasahiro Yamadaendif
2181da177e4SLinus Torvalds
219eb27ea5cSMasahiro Yamadapart-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
220eb27ea5cSMasahiro Yamadaquiet_modtag = $(if $(part-of-module),[M],   )
221eb27ea5cSMasahiro Yamada
222eb27ea5cSMasahiro Yamadamodkern_cflags =                                          \
223eb27ea5cSMasahiro Yamada	$(if $(part-of-module),                           \
224eb27ea5cSMasahiro Yamada		$(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
2251664a377SMasahiro Yamada		$(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
226eb27ea5cSMasahiro Yamada
2272f7ab126SMiguel Ojedamodkern_rustflags =                                              \
2282f7ab126SMiguel Ojeda	$(if $(part-of-module),                                   \
2292f7ab126SMiguel Ojeda		$(KBUILD_RUSTFLAGS_MODULE) $(RUSTFLAGS_MODULE), \
2302f7ab126SMiguel Ojeda		$(KBUILD_RUSTFLAGS_KERNEL) $(RUSTFLAGS_KERNEL))
2312f7ab126SMiguel Ojeda
232eb27ea5cSMasahiro Yamadamodkern_aflags = $(if $(part-of-module),				\
233eb27ea5cSMasahiro Yamada			$(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE),	\
234eb27ea5cSMasahiro Yamada			$(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL))
235eb27ea5cSMasahiro Yamada
23630a77297SMasahiro Yamadac_flags        = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
237a95b37e2SMasahiro Yamada		 -include $(srctree)/include/linux/compiler_types.h       \
238cdd750bfSMasahiro Yamada		 $(_c_flags) $(modkern_cflags)                           \
239b42841b7SMichal Marek		 $(basename_flags) $(modname_flags)
2401da177e4SLinus Torvalds
2412f7ab126SMiguel Ojedarust_flags     = $(_rust_flags) $(modkern_rustflags) @$(objtree)/include/generated/rustc_cfg
2422f7ab126SMiguel Ojeda
24330a77297SMasahiro Yamadaa_flags        = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
244cdd750bfSMasahiro Yamada		 $(_a_flags) $(modkern_aflags)
2451da177e4SLinus Torvalds
24630a77297SMasahiro Yamadacpp_flags      = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
247cdd750bfSMasahiro Yamada		 $(_cpp_flags)
2481da177e4SLinus Torvalds
249d503ac53SMasahiro Yamadald_flags       = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
2501da177e4SLinus Torvalds
25150f9ddafSMasahiro YamadaDTC_INCLUDE    := $(srctree)/scripts/dtc/include-prefixes
25250f9ddafSMasahiro Yamada
25330a77297SMasahiro Yamadadtc_cpp_flags  = -Wp,-MMD,$(depfile).pre.tmp -nostdinc                    \
25450f9ddafSMasahiro Yamada		 $(addprefix -I,$(DTC_INCLUDE))                          \
255e570d7c1SStephen Warren		 -undef -D__DTS__
256e570d7c1SStephen Warren
257b42d2306SMasahiro Yamadaifdef CONFIG_OBJTOOL
258b42d2306SMasahiro Yamada
259b42d2306SMasahiro Yamadaobjtool := $(objtree)/tools/objtool/objtool
260b42d2306SMasahiro Yamada
2619ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK)		+= --hacks=jump_label
2629ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_HAVE_NOINSTR_HACK)		+= --hacks=noinstr
2630c0a6d89SPeter Zijlstraobjtool-args-$(CONFIG_CALL_DEPTH_TRACKING)		+= --hacks=skylake
2649ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_X86_KERNEL_IBT)			+= --ibt
265931ab636SPeter Zijlstraobjtool-args-$(CONFIG_FINEIBT)				+= --cfi
2669ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL)	+= --mcount
267280981d6SSathvika Vasireddyifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
268280981d6SSathvika Vasireddyobjtool-args-$(CONFIG_HAVE_OBJTOOL_NOP_MCOUNT)		+= --mnop
269280981d6SSathvika Vasireddyendif
2709ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_UNWINDER_ORC)			+= --orc
2719ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_RETPOLINE)			+= --retpoline
2729ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_RETHUNK)				+= --rethunk
2739ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_SLS)				+= --sls
2749ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_STACK_VALIDATION)			+= --stackval
2759ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE)		+= --static-call
2769ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION)		+= --uaccess
2779ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_GCOV_KERNEL)			+= --no-unreachable
278b341b20dSPeter Zijlstraobjtool-args-$(CONFIG_PREFIX_SYMBOLS)			+= --prefix=$(CONFIG_FUNCTION_PADDING_BYTES)
2799ec6ab6eSMasahiro Yamada
2809ec6ab6eSMasahiro Yamadaobjtool-args = $(objtool-args-y)					\
281b42d2306SMasahiro Yamada	$(if $(delay-objtool), --link)					\
2829ec6ab6eSMasahiro Yamada	$(if $(part-of-module), --module)
283b42d2306SMasahiro Yamada
284b42d2306SMasahiro Yamadadelay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
285b42d2306SMasahiro Yamada
2869ec6ab6eSMasahiro Yamadacmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@)
287b42d2306SMasahiro Yamadacmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
288b42d2306SMasahiro Yamada
289b42d2306SMasahiro Yamadaendif # CONFIG_OBJTOOL
290b42d2306SMasahiro Yamada
291c8589d1eSMasahiro Yamada# Useful for describing the dependency of composite objects
292c8589d1eSMasahiro Yamada# Usage:
293c8589d1eSMasahiro Yamada#   $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
294c8589d1eSMasahiro Yamadadefine multi_depend
295f97cf399SMasahiro Yamada$(foreach m, $1, \
296f97cf399SMasahiro Yamada	$(eval $m: \
297f97cf399SMasahiro Yamada	$(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3))))
298c8589d1eSMasahiro Yamadaendef
299c8589d1eSMasahiro Yamada
300a5575df5SMasahiro Yamada# Copy a file
3011da177e4SLinus Torvalds# ===========================================================================
3023787b7daSMasahiro Yamada# 'cp' preserves permissions. If you use it to copy a file in read-only srctree,
3033787b7daSMasahiro Yamada# the copy would be read-only as well, leading to an error when executing the
3043787b7daSMasahiro Yamada# rule next time. Use 'cat' instead in order to generate a writable file.
305a5575df5SMasahiro Yamadaquiet_cmd_copy = COPY    $@
306a5575df5SMasahiro Yamada      cmd_copy = cat $< > $@
3071da177e4SLinus Torvalds
308991d76c9SArnaud Lacombe$(obj)/%: $(src)/%_shipped
309a5575df5SMasahiro Yamada	$(call cmd,copy)
3101da177e4SLinus Torvalds
3111da177e4SLinus Torvalds# Commands useful for building a boot image
3121da177e4SLinus Torvalds# ===========================================================================
3131da177e4SLinus Torvalds#
3141da177e4SLinus Torvalds#	Use as following:
3151da177e4SLinus Torvalds#
3161da177e4SLinus Torvalds#	target: source(s) FORCE
3171da177e4SLinus Torvalds#		$(if_changed,ld/objcopy/gzip)
3181da177e4SLinus Torvalds#
3192047ace9SMasahiro Yamada#	and add target to 'targets' so that we know we have to
3201da177e4SLinus Torvalds#	read in the saved command line
3211da177e4SLinus Torvalds
3221da177e4SLinus Torvalds# Linking
3231da177e4SLinus Torvalds# ---------------------------------------------------------------------------
3241da177e4SLinus Torvalds
3251da177e4SLinus Torvaldsquiet_cmd_ld = LD      $@
326afa974b7SMasahiro Yamada      cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
3271da177e4SLinus Torvalds
328898f5a00SMasahiro Yamada# Archive
329898f5a00SMasahiro Yamada# ---------------------------------------------------------------------------
330898f5a00SMasahiro Yamada
331898f5a00SMasahiro Yamadaquiet_cmd_ar = AR      $@
33213dc8c02SMasahiro Yamada      cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
333898f5a00SMasahiro Yamada
3341da177e4SLinus Torvalds# Objcopy
3351da177e4SLinus Torvalds# ---------------------------------------------------------------------------
3361da177e4SLinus Torvalds
3371da177e4SLinus Torvaldsquiet_cmd_objcopy = OBJCOPY $@
3381da177e4SLinus Torvaldscmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
3391da177e4SLinus Torvalds
3401da177e4SLinus Torvalds# Gzip
3411da177e4SLinus Torvalds# ---------------------------------------------------------------------------
3421da177e4SLinus Torvalds
3431da177e4SLinus Torvaldsquiet_cmd_gzip = GZIP    $@
344e4a42c82SDenis Efremov      cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
3451da177e4SLinus Torvalds
346aab94339SDirk Brandewie# DTC
347aab94339SDirk Brandewie# ---------------------------------------------------------------------------
3486b22b3d1SRob HerringDTC ?= $(objtree)/scripts/dtc/dtc
349ae5a16c8SAlexandre TorgueDTC_FLAGS += -Wno-interrupt_provider \
350ae5a16c8SAlexandre Torgue	-Wno-unique_unit_address
351aab94339SDirk Brandewie
352bc553986SRob Herring# Disable noisy checks by default
353e27128dbSMasahiro Yamadaifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
3548654cb8dSRob HerringDTC_FLAGS += -Wno-unit_address_vs_reg \
3554fd98e37SRob Herring	-Wno-avoid_unnecessary_addr_size \
3564fd98e37SRob Herring	-Wno-alias_paths \
35774656b68SRob Herring	-Wno-graph_child_address \
358ae5a16c8SAlexandre Torgue	-Wno-simple_bus_reg
359ae5a16c8SAlexandre Torgueelse
360ae5a16c8SAlexandre TorgueDTC_FLAGS += \
361ae5a16c8SAlexandre Torgue        -Wunique_unit_address_if_enabled
362bc553986SRob Herringendif
363bc553986SRob Herring
364e27128dbSMasahiro Yamadaifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
3658654cb8dSRob HerringDTC_FLAGS += -Wnode_name_chars_strict \
3663eb619b2SRob Herring	-Wproperty_name_chars_strict \
367ae5a16c8SAlexandre Torgue	-Winterrupt_provider \
368ae5a16c8SAlexandre Torgue	-Wunique_unit_address
369aab94339SDirk Brandewieendif
370aab94339SDirk Brandewie
371*223390b1SMasahiro YamadaDTC_FLAGS += $(DTC_FLAGS_$(target-stem))
372331f7416SFrank Rowand
373bcf0c664SMasahiro Yamada# Set -@ if the target is a base DTB that overlay is applied onto
374bcf0c664SMasahiro YamadaDTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
375bcf0c664SMasahiro Yamada
376aab94339SDirk Brandewie# Generate an assembly file to wrap the output of the device tree compiler
377ecd42fbaSMasahiro Yamadaquiet_cmd_wrap_S_dtb = WRAP    $@
378ecd42fbaSMasahiro Yamada      cmd_wrap_S_dtb = {								\
379ecd42fbaSMasahiro Yamada		symbase=__$(patsubst .%,%,$(suffix $<))_$(subst -,_,$(notdir $*));	\
380aab94339SDirk Brandewie		echo '\#include <asm-generic/vmlinux.lds.h>';				\
381aab94339SDirk Brandewie		echo '.section .dtb.init.rodata,"a"';					\
382aab94339SDirk Brandewie		echo '.balign STRUCT_ALIGNMENT';					\
383ecd42fbaSMasahiro Yamada		echo ".global $${symbase}_begin";					\
384ecd42fbaSMasahiro Yamada		echo "$${symbase}_begin:";						\
385aab94339SDirk Brandewie		echo '.incbin "$<" ';							\
386ecd42fbaSMasahiro Yamada		echo ".global $${symbase}_end";						\
387ecd42fbaSMasahiro Yamada		echo "$${symbase}_end:";						\
388aab94339SDirk Brandewie		echo '.balign STRUCT_ALIGNMENT';					\
389b79c6aa6SMasahiro Yamada	} > $@
390aab94339SDirk Brandewie
391a7f92419SMasahiro Yamada$(obj)/%.dtb.S: $(obj)/%.dtb FORCE
392ecd42fbaSMasahiro Yamada	$(call if_changed,wrap_S_dtb)
393941214a5SAndrew Davis
394941214a5SAndrew Davis$(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE
395ecd42fbaSMasahiro Yamada	$(call if_changed,wrap_S_dtb)
396941214a5SAndrew Davis
397aab94339SDirk Brandewiequiet_cmd_dtc = DTC     $@
398dd7699e3SMasahiro Yamadacmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
39964bfc994SMasahiro Yamada	$(DTC) -o $@ -b 0 \
40050f9ddafSMasahiro Yamada		$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
401b0a4d8b3SIan Campbell		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
402b0a4d8b3SIan Campbell	cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
4031da177e4SLinus Torvalds
40415d16d6dSRob Herringquiet_cmd_fdtoverlay = DTOVL   $@
40515d16d6dSRob Herring      cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(real-prereqs)
40615d16d6dSRob Herring
407bcf0c664SMasahiro Yamada$(multi-dtb-y): FORCE
40815d16d6dSRob Herring	$(call if_changed,fdtoverlay)
409bcf0c664SMasahiro Yamada$(call multi_depend, $(multi-dtb-y), .dtb, -dtbs)
41015d16d6dSRob Herring
411ef8795f3SRob Herringifneq ($(CHECK_DTBS)$(CHECK_DT_BINDING),)
4124f0e3a57SRob HerringDT_CHECKER ?= dt-validate
4132783a7f5SRob HerringDT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m)
4144f0e3a57SRob HerringDT_BINDING_DIR := Documentation/devicetree/bindings
4152783a7f5SRob HerringDT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
4164f0e3a57SRob Herring
417d7c6ea02SDmitry Baryshkovquiet_cmd_dtb =	DTC_CHK $@
418d7c6ea02SDmitry Baryshkov      cmd_dtb =	$(cmd_dtc) ; $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ || true
419d7c6ea02SDmitry Baryshkovelse
420d7c6ea02SDmitry Baryshkovquiet_cmd_dtb = $(quiet_cmd_dtc)
421d7c6ea02SDmitry Baryshkov      cmd_dtb = $(cmd_dtc)
422ef8795f3SRob Herringendif
4234f0e3a57SRob Herring
424ef8795f3SRob Herring$(obj)/%.dtb: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
425d7c6ea02SDmitry Baryshkov	$(call if_changed_dep,dtb)
42690b335fbSStephen Warren
427363547d2SAndrew Davis$(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE
428363547d2SAndrew Davis	$(call if_changed_dep,dtc)
429363547d2SAndrew Davis
430b0a4d8b3SIan Campbelldtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
43122435f38SStephen Warren
432bc22c17eSAlain Knaff# Bzip2
433bc22c17eSAlain Knaff# ---------------------------------------------------------------------------
434bc22c17eSAlain Knaff
435d3dd3b5aSH. Peter Anvin# Bzip2 and LZMA do not include size in file... so we have to fake that;
436d3dd3b5aSH. Peter Anvin# append the size as a 32-bit littleendian number as gzip does.
4374a2ff67cSMichael Tokarevsize_append = printf $(shell						\
438d3dd3b5aSH. Peter Anvindec_size=0;								\
439afa974b7SMasahiro Yamadafor F in $(real-prereqs); do					\
440a670b0b4SMichael Forney	fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F);	\
441d3dd3b5aSH. Peter Anvin	dec_size=$$(expr $$dec_size + $$fsize);				\
442d3dd3b5aSH. Peter Anvindone;									\
4431373411aSJonathan Niederprintf "%08x\n" $$dec_size |						\
4441373411aSJonathan Nieder	sed 's/\(..\)/\1 /g' | {					\
4451373411aSJonathan Nieder		read ch0 ch1 ch2 ch3;					\
4461373411aSJonathan Nieder		for ch in $$ch3 $$ch2 $$ch1 $$ch0; do			\
4471373411aSJonathan Nieder			printf '%s%03o' '\\' $$((0x$$ch)); 		\
4481373411aSJonathan Nieder		done;							\
4491373411aSJonathan Nieder	}								\
450d3dd3b5aSH. Peter Anvin)
451bc22c17eSAlain Knaff
452c4d7f40bSMasahiro Yamadaquiet_cmd_file_size = GEN     $@
453c4d7f40bSMasahiro Yamada      cmd_file_size = $(size_append) > $@
454c4d7f40bSMasahiro Yamada
455bc22c17eSAlain Knaffquiet_cmd_bzip2 = BZIP2   $@
4567ce7e984SMasahiro Yamada      cmd_bzip2 = cat $(real-prereqs) | $(KBZIP2) -9 > $@
4577ce7e984SMasahiro Yamada
4587ce7e984SMasahiro Yamadaquiet_cmd_bzip2_with_size = BZIP2   $@
4597ce7e984SMasahiro Yamada      cmd_bzip2_with_size = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
460bc22c17eSAlain Knaff
461bc22c17eSAlain Knaff# Lzma
462bc22c17eSAlain Knaff# ---------------------------------------------------------------------------
463bc22c17eSAlain Knaff
464bc22c17eSAlain Knaffquiet_cmd_lzma = LZMA    $@
4657ce7e984SMasahiro Yamada      cmd_lzma = cat $(real-prereqs) | $(LZMA) -9 > $@
4667ce7e984SMasahiro Yamada
4677ce7e984SMasahiro Yamadaquiet_cmd_lzma_with_size = LZMA    $@
4687ce7e984SMasahiro Yamada      cmd_lzma_with_size = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
4697dd65febSAlbin Tonnerre
4707dd65febSAlbin Tonnerrequiet_cmd_lzo = LZO     $@
4717ce7e984SMasahiro Yamada      cmd_lzo = cat $(real-prereqs) | $(KLZOP) -9 > $@
4727ce7e984SMasahiro Yamada
4737ce7e984SMasahiro Yamadaquiet_cmd_lzo_with_size = LZO     $@
4747ce7e984SMasahiro Yamada      cmd_lzo_with_size = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
475d61931d8SBorislav Petkov
476e76e1fdfSKyungsik Leequiet_cmd_lz4 = LZ4     $@
4777ce7e984SMasahiro Yamada      cmd_lz4 = cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout > $@
4787ce7e984SMasahiro Yamada
4797ce7e984SMasahiro Yamadaquiet_cmd_lz4_with_size = LZ4     $@
4807ce7e984SMasahiro Yamada      cmd_lz4_with_size = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \
481b79c6aa6SMasahiro Yamada                  $(size_append); } > $@
482e76e1fdfSKyungsik Lee
483e3393645SStephen Warren# U-Boot mkimage
484e3393645SStephen Warren# ---------------------------------------------------------------------------
485e3393645SStephen Warren
486e3393645SStephen WarrenMKIMAGE := $(srctree)/scripts/mkuboot.sh
487e3393645SStephen Warren
488e3393645SStephen Warren# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
489e3393645SStephen Warren# the number of overrides in arch makefiles
490e3393645SStephen WarrenUIMAGE_ARCH ?= $(SRCARCH)
4915c816641SMasahiro YamadaUIMAGE_COMPRESSION ?= $(or $(2),none)
492e3393645SStephen WarrenUIMAGE_OPTS-y ?=
493e3393645SStephen WarrenUIMAGE_TYPE ?= kernel
494e3393645SStephen WarrenUIMAGE_LOADADDR ?= arch_must_set_this
495e3393645SStephen WarrenUIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
49676020731SSimon GlassUIMAGE_NAME ?= Linux-$(KERNELRELEASE)
497e3393645SStephen Warren
498786ac51aSMasahiro Yamadaquiet_cmd_uimage = UIMAGE  $@
499858805b3SMasahiro Yamada      cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
500e3393645SStephen Warren			-C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
501e3393645SStephen Warren			-T $(UIMAGE_TYPE) \
502e3393645SStephen Warren			-a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
50376020731SSimon Glass			-n '$(UIMAGE_NAME)' -d $< $@
504e3393645SStephen Warren
50524fa0402SLasse Collin# XZ
50624fa0402SLasse Collin# ---------------------------------------------------------------------------
50724fa0402SLasse Collin# Use xzkern to compress the kernel image and xzmisc to compress other things.
50824fa0402SLasse Collin#
50924fa0402SLasse Collin# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
51024fa0402SLasse Collin# of the kernel decompressor. A BCJ filter is used if it is available for
51124fa0402SLasse Collin# the target architecture. xzkern also appends uncompressed size of the data
51224fa0402SLasse Collin# using size_append. The .xz format has the size information available at
51324fa0402SLasse Collin# the end of the file too, but it's in more complex format and it's good to
51424fa0402SLasse Collin# avoid changing the part of the boot code that reads the uncompressed size.
51524fa0402SLasse Collin# Note that the bytes added by size_append will make the xz tool think that
51624fa0402SLasse Collin# the file is corrupt. This is expected.
51724fa0402SLasse Collin#
51824fa0402SLasse Collin# xzmisc doesn't use size_append, so it can be used to create normal .xz
51924fa0402SLasse Collin# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
52024fa0402SLasse Collin# big dictionary would increase the memory usage too much in the multi-call
52124fa0402SLasse Collin# decompression mode. A BCJ filter isn't used either.
52224fa0402SLasse Collinquiet_cmd_xzkern = XZKERN  $@
5237ce7e984SMasahiro Yamada      cmd_xzkern = cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh > $@
5247ce7e984SMasahiro Yamada
5257ce7e984SMasahiro Yamadaquiet_cmd_xzkern_with_size = XZKERN  $@
5267ce7e984SMasahiro Yamada      cmd_xzkern_with_size = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
527b79c6aa6SMasahiro Yamada                     $(size_append); } > $@
52824fa0402SLasse Collin
52924fa0402SLasse Collinquiet_cmd_xzmisc = XZMISC  $@
5308dfb61dcSDenis Efremov      cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
531ebf003f0SMatthias Kaehlcke
53248f7ddf7SNick Terrell# ZSTD
53348f7ddf7SNick Terrell# ---------------------------------------------------------------------------
53448f7ddf7SNick Terrell# Appends the uncompressed size of the data using size_append. The .zst
53548f7ddf7SNick Terrell# format has the size information available at the beginning of the file too,
53648f7ddf7SNick Terrell# but it's in a more complex format and it's good to avoid changing the part
53748f7ddf7SNick Terrell# of the boot code that reads the uncompressed size.
53848f7ddf7SNick Terrell#
53948f7ddf7SNick Terrell# Note that the bytes added by size_append will make the zstd tool think that
54048f7ddf7SNick Terrell# the file is corrupt. This is expected.
54148f7ddf7SNick Terrell#
54248f7ddf7SNick Terrell# zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of
54348f7ddf7SNick Terrell# 128 MB. zstd22 is used for kernel compression because it is decompressed in a
54448f7ddf7SNick Terrell# single pass, so zstd doesn't need to allocate a window buffer. When streaming
54548f7ddf7SNick Terrell# decompression is used, like initramfs decompression, zstd22 should likely not
54648f7ddf7SNick Terrell# be used because it would require zstd to allocate a 128 MB buffer.
54748f7ddf7SNick Terrell
54848f7ddf7SNick Terrellquiet_cmd_zstd = ZSTD    $@
54964d8aaa4SMasahiro Yamada      cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@
55048f7ddf7SNick Terrell
55148f7ddf7SNick Terrellquiet_cmd_zstd22 = ZSTD22  $@
5527ce7e984SMasahiro Yamada      cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@
5537ce7e984SMasahiro Yamada
5547ce7e984SMasahiro Yamadaquiet_cmd_zstd22_with_size = ZSTD22  $@
5557ce7e984SMasahiro Yamada      cmd_zstd22_with_size = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
55648f7ddf7SNick Terrell
557ebf003f0SMatthias Kaehlcke# ASM offsets
558ebf003f0SMatthias Kaehlcke# ---------------------------------------------------------------------------
559ebf003f0SMatthias Kaehlcke
560ebf003f0SMatthias Kaehlcke# Default sed regexp - multiline due to syntax constraints
561cf0c3e68SJeroen Hofstee#
562cf0c3e68SJeroen Hofstee# Use [:space:] because LLVM's integrated assembler inserts <tab> around
563cf0c3e68SJeroen Hofstee# the .ascii directive whereas GCC keeps the <space> as-is.
564ebf003f0SMatthias Kaehlckedefine sed-offsets
565cf0c3e68SJeroen Hofstee	's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
566cf0c3e68SJeroen Hofstee	/^->/{s:->#\(.*\):/* \1 */:; \
567ebf003f0SMatthias Kaehlcke	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
568cf0c3e68SJeroen Hofstee	s:->::; p;}'
569ebf003f0SMatthias Kaehlckeendef
570ebf003f0SMatthias Kaehlcke
571ebf003f0SMatthias Kaehlcke# Use filechk to avoid rebuilds when a header changes, but the resulting file
572ebf003f0SMatthias Kaehlcke# does not
573ebf003f0SMatthias Kaehlckedefine filechk_offsets
574ebf003f0SMatthias Kaehlcke	 echo "#ifndef $2"; \
575ebf003f0SMatthias Kaehlcke	 echo "#define $2"; \
576ebf003f0SMatthias Kaehlcke	 echo "/*"; \
577ebf003f0SMatthias Kaehlcke	 echo " * DO NOT MODIFY."; \
578ebf003f0SMatthias Kaehlcke	 echo " *"; \
579ebf003f0SMatthias Kaehlcke	 echo " * This file was generated by Kbuild"; \
580ebf003f0SMatthias Kaehlcke	 echo " */"; \
581ebf003f0SMatthias Kaehlcke	 echo ""; \
58243fee2b2SMasahiro Yamada	 sed -ne $(sed-offsets) < $<; \
583ebf003f0SMatthias Kaehlcke	 echo ""; \
584ad774086SMasahiro Yamada	 echo "#endif"
585ebf003f0SMatthias Kaehlckeendef
586