xref: /linux/scripts/Makefile.lib (revision ecd42fba5765bba5955e3e1f80265295c0f5c32d)
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
4844f87191SMasahiro Yamada# Expand $(foo-objs) $(foo-y) etc. by replacing their individuals
4944f87191SMasahiro Yamadasuffix-search = $(strip $(foreach s, $3, $($(1:%$(strip $2)=%$s))))
5044f87191SMasahiro Yamada# List composite targets that are constructed by combining other targets
5144f87191SMasahiro Yamadamulti-search = $(sort $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $m)))
5244f87191SMasahiro Yamada# List primitive targets that are compiled from source files
5344f87191SMasahiro Yamadareal-search = $(foreach m, $1, $(if $(call suffix-search, $m, $2, $3 -), $(call suffix-search, $m, $2, $3), $m))
5444f87191SMasahiro Yamada
5533e84f2eSMasahiro Yamada# If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
5644f87191SMasahiro Yamadamulti-obj-y := $(call multi-search, $(obj-y), .o, -objs -y)
5744f87191SMasahiro Yamadamulti-obj-m := $(call multi-search, $(obj-m), .o, -objs -y -m)
58a6601e01SMasahiro Yamadamulti-obj-ym := $(multi-obj-y) $(multi-obj-m)
591da177e4SLinus Torvalds
60f98fe47cSMasahiro Yamada# Replace multi-part objects by their individual parts,
61f98fe47cSMasahiro Yamada# including built-in.a from subdirectories
6244f87191SMasahiro Yamadareal-obj-y := $(call real-search, $(obj-y), .o, -objs -y)
6344f87191SMasahiro Yamadareal-obj-m := $(call real-search, $(obj-m), .o, -objs -y -m)
641da177e4SLinus Torvalds
655f2fb52fSMasahiro Yamadaalways-y += $(always-m)
665f2fb52fSMasahiro Yamada
67faabed29SMasahiro Yamada# hostprogs-always-y += foo
68faabed29SMasahiro Yamada# ... is a shorthand for
69faabed29SMasahiro Yamada# hostprogs += foo
70faabed29SMasahiro Yamada# always-y  += foo
71faabed29SMasahiro Yamadahostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
72faabed29SMasahiro Yamadaalways-y += $(hostprogs-always-y) $(hostprogs-always-m)
73faabed29SMasahiro Yamada
74faabed29SMasahiro Yamada# userprogs-always-y is likewise.
75faabed29SMasahiro Yamadauserprogs += $(userprogs-always-y) $(userprogs-always-m)
76faabed29SMasahiro Yamadaalways-y += $(userprogs-always-y) $(userprogs-always-m)
77faabed29SMasahiro Yamada
787e7962ddSMasahiro Yamada# DTB
797e7962ddSMasahiro Yamada# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
809ca29e41SViresh Kumardtb-$(CONFIG_OF_ALL_DTBS)       += $(dtb-)
819ca29e41SViresh Kumar
82bcf0c664SMasahiro Yamada# Composite DTB (i.e. DTB constructed by overlay)
83bcf0c664SMasahiro Yamadamulti-dtb-y := $(call multi-search, $(dtb-y), .dtb, -dtbs)
84bcf0c664SMasahiro Yamada# Primitive DTB compiled from *.dts
85bcf0c664SMasahiro Yamadareal-dtb-y := $(call real-search, $(dtb-y), .dtb, -dtbs)
86bcf0c664SMasahiro Yamada# Base DTB that overlay is applied onto (each first word of $(*-dtbs) expansion)
87bcf0c664SMasahiro Yamadabase-dtb-y := $(foreach m, $(multi-dtb-y), $(firstword $(call suffix-search, $m, .dtb, -dtbs)))
8815d16d6dSRob Herring
892047ace9SMasahiro Yamadaalways-y			+= $(dtb-y)
907e7962ddSMasahiro Yamada
911da177e4SLinus Torvalds# Add subdir path
921da177e4SLinus Torvalds
935750121aSMasahiro Yamadaifneq ($(obj),.)
941da177e4SLinus Torvaldsextra-y		:= $(addprefix $(obj)/,$(extra-y))
955f2fb52fSMasahiro Yamadaalways-y	:= $(addprefix $(obj)/,$(always-y))
961da177e4SLinus Torvaldstargets		:= $(addprefix $(obj)/,$(targets))
971da177e4SLinus Torvaldsobj-m		:= $(addprefix $(obj)/,$(obj-m))
981da177e4SLinus Torvaldslib-y		:= $(addprefix $(obj)/,$(lib-y))
99f5f33681SMasahiro Yamadareal-obj-y	:= $(addprefix $(obj)/,$(real-obj-y))
100f5f33681SMasahiro Yamadareal-obj-m	:= $(addprefix $(obj)/,$(real-obj-m))
101a6601e01SMasahiro Yamadamulti-obj-m	:= $(addprefix $(obj)/, $(multi-obj-m))
102bcf0c664SMasahiro Yamadamulti-dtb-y	:= $(addprefix $(obj)/, $(multi-dtb-y))
103bcf0c664SMasahiro Yamadareal-dtb-y	:= $(addprefix $(obj)/, $(real-dtb-y))
1041da177e4SLinus Torvaldssubdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
1055750121aSMasahiro Yamadaendif
1061da177e4SLinus Torvalds
107c0152e9aSMasahiro Yamada# Finds the multi-part object the current object will be linked into.
1081664a377SMasahiro Yamada# If the object belongs to two or more multi-part objects, list them all.
109a6601e01SMasahiro Yamadamodname-multi = $(sort $(foreach m,$(multi-obj-ym),\
110d4452837SMasahiro Yamada		$(if $(filter $*.o, $(call suffix-search, $m, .o, -objs -y -m)),$(m:.o=))))
111c0152e9aSMasahiro Yamada
1125c816641SMasahiro Yamada__modname = $(or $(modname-multi),$(basetarget))
1131664a377SMasahiro Yamada
1141664a377SMasahiro Yamadamodname = $(subst $(space),:,$(__modname))
1151664a377SMasahiro Yamadamodfile = $(addprefix $(obj)/,$(__modname))
116c0152e9aSMasahiro Yamada
11754b8ae66SMasahiro Yamada# target with $(obj)/ and its suffix stripped
11854b8ae66SMasahiro Yamadatarget-stem = $(basename $(patsubst $(obj)/%,%,$@))
11954b8ae66SMasahiro Yamada
1201da177e4SLinus Torvalds# These flags are needed for modversions and compiling, so we define them here
1218fdc3fbbSCao jin# $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
1221da177e4SLinus Torvalds# end up in (or would, if it gets compiled in)
123a8cccdd9SSami Tolvanenname-fix-token = $(subst $(comma),_,$(subst -,_,$1))
124a8cccdd9SSami Tolvanenname-fix = $(call stringify,$(call name-fix-token,$1))
125b42841b7SMichal Marekbasename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
126a8cccdd9SSami Tolvanenmodname_flags  = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \
127a8cccdd9SSami Tolvanen		 -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname))
1281664a377SMasahiro Yamadamodfile_flags  = -DKBUILD_MODFILE=$(call stringify,$(modfile))
1291da177e4SLinus Torvalds
13015d5761aSMasahiro Yamada_c_flags       = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
13115d5761aSMasahiro Yamada                     $(filter-out $(ccflags-remove-y), \
13215d5761aSMasahiro Yamada                         $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
13315d5761aSMasahiro Yamada                     $(CFLAGS_$(target-stem).o))
1342f7ab126SMiguel Ojeda_rust_flags    = $(filter-out $(RUSTFLAGS_REMOVE_$(target-stem).o), \
1352f7ab126SMiguel Ojeda                     $(filter-out $(rustflags-remove-y), \
1362f7ab126SMiguel Ojeda                         $(KBUILD_RUSTFLAGS) $(rustflags-y)) \
1372f7ab126SMiguel Ojeda                     $(RUSTFLAGS_$(target-stem).o))
13815d5761aSMasahiro Yamada_a_flags       = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
13915d5761aSMasahiro Yamada                     $(filter-out $(asflags-remove-y), \
14015d5761aSMasahiro Yamada                         $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
14115d5761aSMasahiro Yamada                     $(AFLAGS_$(target-stem).o))
14254b8ae66SMasahiro Yamada_cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
1431da177e4SLinus Torvalds
1442521f2c2SPeter Oberparleiter#
1452521f2c2SPeter Oberparleiter# Enable gcov profiling flags for a file, directory or for all files depending
1462521f2c2SPeter Oberparleiter# on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
1472521f2c2SPeter Oberparleiter# (in this order)
1482521f2c2SPeter Oberparleiter#
1492521f2c2SPeter Oberparleiterifeq ($(CONFIG_GCOV_KERNEL),y)
1502521f2c2SPeter Oberparleiter_c_flags += $(if $(patsubst n%,, \
1512521f2c2SPeter Oberparleiter		$(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
1522521f2c2SPeter Oberparleiter		$(CFLAGS_GCOV))
1532521f2c2SPeter Oberparleiterendif
1542521f2c2SPeter Oberparleiter
1550b24beccSAndrey Ryabinin#
1560b24beccSAndrey Ryabinin# Enable address sanitizer flags for kernel except some files or directories
1570b24beccSAndrey Ryabinin# we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
1580b24beccSAndrey Ryabinin#
1590b24beccSAndrey Ryabininifeq ($(CONFIG_KASAN),y)
1600fea6e9aSAndrey Konovalovifneq ($(CONFIG_KASAN_HW_TAGS),y)
1610b24beccSAndrey Ryabinin_c_flags += $(if $(patsubst n%,, \
1620b24beccSAndrey Ryabinin		$(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
1630e410e15SAndrey Konovalov		$(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
1640b24beccSAndrey Ryabininendif
1650fea6e9aSAndrey Konovalovendif
1660b24beccSAndrey Ryabinin
167f80be457SAlexander Potapenkoifeq ($(CONFIG_KMSAN),y)
168f80be457SAlexander Potapenko_c_flags += $(if $(patsubst n%,, \
169f80be457SAlexander Potapenko		$(KMSAN_SANITIZE_$(basetarget).o)$(KMSAN_SANITIZE)y), \
170f80be457SAlexander Potapenko		$(CFLAGS_KMSAN))
171f80be457SAlexander Potapenko_c_flags += $(if $(patsubst n%,, \
172f80be457SAlexander Potapenko		$(KMSAN_ENABLE_CHECKS_$(basetarget).o)$(KMSAN_ENABLE_CHECKS)y), \
173f80be457SAlexander Potapenko		, -mllvm -msan-disable-checks=1)
174f80be457SAlexander Potapenkoendif
175f80be457SAlexander Potapenko
176c6d30853SAndrey Ryabininifeq ($(CONFIG_UBSAN),y)
177c6d30853SAndrey Ryabinin_c_flags += $(if $(patsubst n%,, \
178c6d30853SAndrey Ryabinin		$(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
179c6d30853SAndrey Ryabinin		$(CFLAGS_UBSAN))
180c6d30853SAndrey Ryabininendif
181c6d30853SAndrey Ryabinin
1825c9a8750SDmitry Vyukovifeq ($(CONFIG_KCOV),y)
1835c9a8750SDmitry Vyukov_c_flags += $(if $(patsubst n%,, \
184a4691deaSVegard Nossum	$(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
1855c9a8750SDmitry Vyukov	$(CFLAGS_KCOV))
1865c9a8750SDmitry Vyukovendif
1875c9a8750SDmitry Vyukov
188dfd402a4SMarco Elver#
189dfd402a4SMarco Elver# Enable KCSAN flags except some files or directories we don't want to check
190dfd402a4SMarco Elver# (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE)
191dfd402a4SMarco Elver#
192dfd402a4SMarco Elverifeq ($(CONFIG_KCSAN),y)
193dfd402a4SMarco Elver_c_flags += $(if $(patsubst n%,, \
194dfd402a4SMarco Elver	$(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \
195dfd402a4SMarco Elver	$(CFLAGS_KCSAN))
19648c9e28eSMarco Elver# Some uninstrumented files provide implied barriers required to avoid false
19748c9e28eSMarco Elver# positives: set KCSAN_INSTRUMENT_BARRIERS for barrier instrumentation only.
19848c9e28eSMarco Elver_c_flags += $(if $(patsubst n%,, \
19948c9e28eSMarco Elver	$(KCSAN_INSTRUMENT_BARRIERS_$(basetarget).o)$(KCSAN_INSTRUMENT_BARRIERS)n), \
20048c9e28eSMarco Elver	-D__KCSAN_INSTRUMENT_BARRIERS__)
201dfd402a4SMarco Elverendif
202dfd402a4SMarco Elver
203cdd750bfSMasahiro Yamada# $(srctree)/$(src) for including checkin headers from generated source files
204cdd750bfSMasahiro Yamada# $(objtree)/$(obj) for including generated headers from checkin source files
20558156ba4SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),)
206051f278eSMasahiro Yamadaifdef building_out_of_srctree
207cdd750bfSMasahiro Yamada_c_flags   += -I $(srctree)/$(src) -I $(objtree)/$(obj)
208cdd750bfSMasahiro Yamada_a_flags   += -I $(srctree)/$(src) -I $(objtree)/$(obj)
209cdd750bfSMasahiro Yamada_cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
2101da177e4SLinus Torvaldsendif
21158156ba4SMasahiro Yamadaendif
2121da177e4SLinus Torvalds
213eb27ea5cSMasahiro Yamadapart-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
214eb27ea5cSMasahiro Yamadaquiet_modtag = $(if $(part-of-module),[M],   )
215eb27ea5cSMasahiro Yamada
216eb27ea5cSMasahiro Yamadamodkern_cflags =                                          \
217eb27ea5cSMasahiro Yamada	$(if $(part-of-module),                           \
218eb27ea5cSMasahiro Yamada		$(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
2191664a377SMasahiro Yamada		$(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
220eb27ea5cSMasahiro Yamada
2212f7ab126SMiguel Ojedamodkern_rustflags =                                              \
2222f7ab126SMiguel Ojeda	$(if $(part-of-module),                                   \
2232f7ab126SMiguel Ojeda		$(KBUILD_RUSTFLAGS_MODULE) $(RUSTFLAGS_MODULE), \
2242f7ab126SMiguel Ojeda		$(KBUILD_RUSTFLAGS_KERNEL) $(RUSTFLAGS_KERNEL))
2252f7ab126SMiguel Ojeda
226eb27ea5cSMasahiro Yamadamodkern_aflags = $(if $(part-of-module),				\
227eb27ea5cSMasahiro Yamada			$(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE),	\
228eb27ea5cSMasahiro Yamada			$(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL))
229eb27ea5cSMasahiro Yamada
23030a77297SMasahiro Yamadac_flags        = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
231a95b37e2SMasahiro Yamada		 -include $(srctree)/include/linux/compiler_types.h       \
232cdd750bfSMasahiro Yamada		 $(_c_flags) $(modkern_cflags)                           \
233b42841b7SMichal Marek		 $(basename_flags) $(modname_flags)
2341da177e4SLinus Torvalds
2352f7ab126SMiguel Ojedarust_flags     = $(_rust_flags) $(modkern_rustflags) @$(objtree)/include/generated/rustc_cfg
2362f7ab126SMiguel Ojeda
23730a77297SMasahiro Yamadaa_flags        = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
238cdd750bfSMasahiro Yamada		 $(_a_flags) $(modkern_aflags)
2391da177e4SLinus Torvalds
24030a77297SMasahiro Yamadacpp_flags      = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
241cdd750bfSMasahiro Yamada		 $(_cpp_flags)
2421da177e4SLinus Torvalds
243d503ac53SMasahiro Yamadald_flags       = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
2441da177e4SLinus Torvalds
24550f9ddafSMasahiro YamadaDTC_INCLUDE    := $(srctree)/scripts/dtc/include-prefixes
24650f9ddafSMasahiro Yamada
24730a77297SMasahiro Yamadadtc_cpp_flags  = -Wp,-MMD,$(depfile).pre.tmp -nostdinc                    \
24850f9ddafSMasahiro Yamada		 $(addprefix -I,$(DTC_INCLUDE))                          \
249e570d7c1SStephen Warren		 -undef -D__DTS__
250e570d7c1SStephen Warren
251b42d2306SMasahiro Yamadaifdef CONFIG_OBJTOOL
252b42d2306SMasahiro Yamada
253b42d2306SMasahiro Yamadaobjtool := $(objtree)/tools/objtool/objtool
254b42d2306SMasahiro Yamada
2559ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_HAVE_JUMP_LABEL_HACK)		+= --hacks=jump_label
2569ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_HAVE_NOINSTR_HACK)		+= --hacks=noinstr
2570c0a6d89SPeter Zijlstraobjtool-args-$(CONFIG_CALL_DEPTH_TRACKING)		+= --hacks=skylake
2589ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_X86_KERNEL_IBT)			+= --ibt
259931ab636SPeter Zijlstraobjtool-args-$(CONFIG_FINEIBT)				+= --cfi
2609ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL)	+= --mcount
261280981d6SSathvika Vasireddyifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
262280981d6SSathvika Vasireddyobjtool-args-$(CONFIG_HAVE_OBJTOOL_NOP_MCOUNT)		+= --mnop
263280981d6SSathvika Vasireddyendif
2649ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_UNWINDER_ORC)			+= --orc
2659ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_RETPOLINE)			+= --retpoline
2669ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_RETHUNK)				+= --rethunk
2679ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_SLS)				+= --sls
2689ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_STACK_VALIDATION)			+= --stackval
2699ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE)		+= --static-call
2709ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION)		+= --uaccess
2719ec6ab6eSMasahiro Yamadaobjtool-args-$(CONFIG_GCOV_KERNEL)			+= --no-unreachable
272b341b20dSPeter Zijlstraobjtool-args-$(CONFIG_PREFIX_SYMBOLS)			+= --prefix=$(CONFIG_FUNCTION_PADDING_BYTES)
2739ec6ab6eSMasahiro Yamada
2749ec6ab6eSMasahiro Yamadaobjtool-args = $(objtool-args-y)					\
275b42d2306SMasahiro Yamada	$(if $(delay-objtool), --link)					\
2769ec6ab6eSMasahiro Yamada	$(if $(part-of-module), --module)
277b42d2306SMasahiro Yamada
278b42d2306SMasahiro Yamadadelay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
279b42d2306SMasahiro Yamada
2809ec6ab6eSMasahiro Yamadacmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@)
281b42d2306SMasahiro Yamadacmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
282b42d2306SMasahiro Yamada
283b42d2306SMasahiro Yamadaendif # CONFIG_OBJTOOL
284b42d2306SMasahiro Yamada
285c8589d1eSMasahiro Yamada# Useful for describing the dependency of composite objects
286c8589d1eSMasahiro Yamada# Usage:
287c8589d1eSMasahiro Yamada#   $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
288c8589d1eSMasahiro Yamadadefine multi_depend
289f97cf399SMasahiro Yamada$(foreach m, $1, \
290f97cf399SMasahiro Yamada	$(eval $m: \
291f97cf399SMasahiro Yamada	$(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3))))
292c8589d1eSMasahiro Yamadaendef
293c8589d1eSMasahiro Yamada
294a5575df5SMasahiro Yamada# Copy a file
2951da177e4SLinus Torvalds# ===========================================================================
2963787b7daSMasahiro Yamada# 'cp' preserves permissions. If you use it to copy a file in read-only srctree,
2973787b7daSMasahiro Yamada# the copy would be read-only as well, leading to an error when executing the
2983787b7daSMasahiro Yamada# rule next time. Use 'cat' instead in order to generate a writable file.
299a5575df5SMasahiro Yamadaquiet_cmd_copy = COPY    $@
300a5575df5SMasahiro Yamada      cmd_copy = cat $< > $@
3011da177e4SLinus Torvalds
302991d76c9SArnaud Lacombe$(obj)/%: $(src)/%_shipped
303a5575df5SMasahiro Yamada	$(call cmd,copy)
3041da177e4SLinus Torvalds
3051da177e4SLinus Torvalds# Commands useful for building a boot image
3061da177e4SLinus Torvalds# ===========================================================================
3071da177e4SLinus Torvalds#
3081da177e4SLinus Torvalds#	Use as following:
3091da177e4SLinus Torvalds#
3101da177e4SLinus Torvalds#	target: source(s) FORCE
3111da177e4SLinus Torvalds#		$(if_changed,ld/objcopy/gzip)
3121da177e4SLinus Torvalds#
3132047ace9SMasahiro Yamada#	and add target to 'targets' so that we know we have to
3141da177e4SLinus Torvalds#	read in the saved command line
3151da177e4SLinus Torvalds
3161da177e4SLinus Torvalds# Linking
3171da177e4SLinus Torvalds# ---------------------------------------------------------------------------
3181da177e4SLinus Torvalds
3191da177e4SLinus Torvaldsquiet_cmd_ld = LD      $@
320afa974b7SMasahiro Yamada      cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
3211da177e4SLinus Torvalds
322898f5a00SMasahiro Yamada# Archive
323898f5a00SMasahiro Yamada# ---------------------------------------------------------------------------
324898f5a00SMasahiro Yamada
325898f5a00SMasahiro Yamadaquiet_cmd_ar = AR      $@
32613dc8c02SMasahiro Yamada      cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
327898f5a00SMasahiro Yamada
3281da177e4SLinus Torvalds# Objcopy
3291da177e4SLinus Torvalds# ---------------------------------------------------------------------------
3301da177e4SLinus Torvalds
3311da177e4SLinus Torvaldsquiet_cmd_objcopy = OBJCOPY $@
3321da177e4SLinus Torvaldscmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
3331da177e4SLinus Torvalds
3341da177e4SLinus Torvalds# Gzip
3351da177e4SLinus Torvalds# ---------------------------------------------------------------------------
3361da177e4SLinus Torvalds
3371da177e4SLinus Torvaldsquiet_cmd_gzip = GZIP    $@
338e4a42c82SDenis Efremov      cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
3391da177e4SLinus Torvalds
340aab94339SDirk Brandewie# DTC
341aab94339SDirk Brandewie# ---------------------------------------------------------------------------
3426b22b3d1SRob HerringDTC ?= $(objtree)/scripts/dtc/dtc
343ae5a16c8SAlexandre TorgueDTC_FLAGS += -Wno-interrupt_provider \
344ae5a16c8SAlexandre Torgue	-Wno-unique_unit_address
345aab94339SDirk Brandewie
346bc553986SRob Herring# Disable noisy checks by default
347e27128dbSMasahiro Yamadaifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
3488654cb8dSRob HerringDTC_FLAGS += -Wno-unit_address_vs_reg \
3494fd98e37SRob Herring	-Wno-avoid_unnecessary_addr_size \
3504fd98e37SRob Herring	-Wno-alias_paths \
35174656b68SRob Herring	-Wno-graph_child_address \
352ae5a16c8SAlexandre Torgue	-Wno-simple_bus_reg
353ae5a16c8SAlexandre Torgueelse
354ae5a16c8SAlexandre TorgueDTC_FLAGS += \
355ae5a16c8SAlexandre Torgue        -Wunique_unit_address_if_enabled
356bc553986SRob Herringendif
357bc553986SRob Herring
358e27128dbSMasahiro Yamadaifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
3598654cb8dSRob HerringDTC_FLAGS += -Wnode_name_chars_strict \
3603eb619b2SRob Herring	-Wproperty_name_chars_strict \
361ae5a16c8SAlexandre Torgue	-Winterrupt_provider \
362ae5a16c8SAlexandre Torgue	-Wunique_unit_address
363aab94339SDirk Brandewieendif
364aab94339SDirk Brandewie
365331f7416SFrank RowandDTC_FLAGS += $(DTC_FLAGS_$(basetarget))
366331f7416SFrank Rowand
367bcf0c664SMasahiro Yamada# Set -@ if the target is a base DTB that overlay is applied onto
368bcf0c664SMasahiro YamadaDTC_FLAGS += $(if $(filter $(patsubst $(obj)/%,%,$@), $(base-dtb-y)), -@)
369bcf0c664SMasahiro Yamada
370aab94339SDirk Brandewie# Generate an assembly file to wrap the output of the device tree compiler
371*ecd42fbaSMasahiro Yamadaquiet_cmd_wrap_S_dtb = WRAP    $@
372*ecd42fbaSMasahiro Yamada      cmd_wrap_S_dtb = {								\
373*ecd42fbaSMasahiro Yamada		symbase=__$(patsubst .%,%,$(suffix $<))_$(subst -,_,$(notdir $*));	\
374aab94339SDirk Brandewie		echo '\#include <asm-generic/vmlinux.lds.h>';				\
375aab94339SDirk Brandewie		echo '.section .dtb.init.rodata,"a"';					\
376aab94339SDirk Brandewie		echo '.balign STRUCT_ALIGNMENT';					\
377*ecd42fbaSMasahiro Yamada		echo ".global $${symbase}_begin";					\
378*ecd42fbaSMasahiro Yamada		echo "$${symbase}_begin:";						\
379aab94339SDirk Brandewie		echo '.incbin "$<" ';							\
380*ecd42fbaSMasahiro Yamada		echo ".global $${symbase}_end";						\
381*ecd42fbaSMasahiro Yamada		echo "$${symbase}_end:";						\
382aab94339SDirk Brandewie		echo '.balign STRUCT_ALIGNMENT';					\
383b79c6aa6SMasahiro Yamada	} > $@
384aab94339SDirk Brandewie
385a7f92419SMasahiro Yamada$(obj)/%.dtb.S: $(obj)/%.dtb FORCE
386*ecd42fbaSMasahiro Yamada	$(call if_changed,wrap_S_dtb)
387941214a5SAndrew Davis
388941214a5SAndrew Davis$(obj)/%.dtbo.S: $(obj)/%.dtbo FORCE
389*ecd42fbaSMasahiro Yamada	$(call if_changed,wrap_S_dtb)
390941214a5SAndrew Davis
391aab94339SDirk Brandewiequiet_cmd_dtc = DTC     $@
392dd7699e3SMasahiro Yamadacmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
39364bfc994SMasahiro Yamada	$(DTC) -o $@ -b 0 \
39450f9ddafSMasahiro Yamada		$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
395b0a4d8b3SIan Campbell		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
396b0a4d8b3SIan Campbell	cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
3971da177e4SLinus Torvalds
39815d16d6dSRob Herringquiet_cmd_fdtoverlay = DTOVL   $@
39915d16d6dSRob Herring      cmd_fdtoverlay = $(objtree)/scripts/dtc/fdtoverlay -o $@ -i $(real-prereqs)
40015d16d6dSRob Herring
401bcf0c664SMasahiro Yamada$(multi-dtb-y): FORCE
40215d16d6dSRob Herring	$(call if_changed,fdtoverlay)
403bcf0c664SMasahiro Yamada$(call multi_depend, $(multi-dtb-y), .dtb, -dtbs)
40415d16d6dSRob Herring
405ef8795f3SRob Herringifneq ($(CHECK_DTBS)$(CHECK_DT_BINDING),)
4064f0e3a57SRob HerringDT_CHECKER ?= dt-validate
4072783a7f5SRob HerringDT_CHECKER_FLAGS ?= $(if $(DT_SCHEMA_FILES),-l $(DT_SCHEMA_FILES),-m)
4084f0e3a57SRob HerringDT_BINDING_DIR := Documentation/devicetree/bindings
4092783a7f5SRob HerringDT_TMP_SCHEMA := $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
4104f0e3a57SRob Herring
411d7c6ea02SDmitry Baryshkovquiet_cmd_dtb =	DTC_CHK $@
412d7c6ea02SDmitry Baryshkov      cmd_dtb =	$(cmd_dtc) ; $(DT_CHECKER) $(DT_CHECKER_FLAGS) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@ || true
413d7c6ea02SDmitry Baryshkovelse
414d7c6ea02SDmitry Baryshkovquiet_cmd_dtb = $(quiet_cmd_dtc)
415d7c6ea02SDmitry Baryshkov      cmd_dtb = $(cmd_dtc)
416ef8795f3SRob Herringendif
4174f0e3a57SRob Herring
418ef8795f3SRob Herring$(obj)/%.dtb: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
419d7c6ea02SDmitry Baryshkov	$(call if_changed_dep,dtb)
42090b335fbSStephen Warren
421ef8795f3SRob Herring$(obj)/%.dtbo: $(src)/%.dts $(DTC) FORCE
422ef8795f3SRob Herring	$(call if_changed_dep,dtc)
423ef8795f3SRob Herring
424363547d2SAndrew Davis$(obj)/%.dtbo: $(src)/%.dtso $(DTC) FORCE
425363547d2SAndrew Davis	$(call if_changed_dep,dtc)
426363547d2SAndrew Davis
427b0a4d8b3SIan Campbelldtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
42822435f38SStephen Warren
429bc22c17eSAlain Knaff# Bzip2
430bc22c17eSAlain Knaff# ---------------------------------------------------------------------------
431bc22c17eSAlain Knaff
432d3dd3b5aSH. Peter Anvin# Bzip2 and LZMA do not include size in file... so we have to fake that;
433d3dd3b5aSH. Peter Anvin# append the size as a 32-bit littleendian number as gzip does.
4344a2ff67cSMichael Tokarevsize_append = printf $(shell						\
435d3dd3b5aSH. Peter Anvindec_size=0;								\
436afa974b7SMasahiro Yamadafor F in $(real-prereqs); do					\
437a670b0b4SMichael Forney	fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F);	\
438d3dd3b5aSH. Peter Anvin	dec_size=$$(expr $$dec_size + $$fsize);				\
439d3dd3b5aSH. Peter Anvindone;									\
4401373411aSJonathan Niederprintf "%08x\n" $$dec_size |						\
4411373411aSJonathan Nieder	sed 's/\(..\)/\1 /g' | {					\
4421373411aSJonathan Nieder		read ch0 ch1 ch2 ch3;					\
4431373411aSJonathan Nieder		for ch in $$ch3 $$ch2 $$ch1 $$ch0; do			\
4441373411aSJonathan Nieder			printf '%s%03o' '\\' $$((0x$$ch)); 		\
4451373411aSJonathan Nieder		done;							\
4461373411aSJonathan Nieder	}								\
447d3dd3b5aSH. Peter Anvin)
448bc22c17eSAlain Knaff
449c4d7f40bSMasahiro Yamadaquiet_cmd_file_size = GEN     $@
450c4d7f40bSMasahiro Yamada      cmd_file_size = $(size_append) > $@
451c4d7f40bSMasahiro Yamada
452bc22c17eSAlain Knaffquiet_cmd_bzip2 = BZIP2   $@
4537ce7e984SMasahiro Yamada      cmd_bzip2 = cat $(real-prereqs) | $(KBZIP2) -9 > $@
4547ce7e984SMasahiro Yamada
4557ce7e984SMasahiro Yamadaquiet_cmd_bzip2_with_size = BZIP2   $@
4567ce7e984SMasahiro Yamada      cmd_bzip2_with_size = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
457bc22c17eSAlain Knaff
458bc22c17eSAlain Knaff# Lzma
459bc22c17eSAlain Knaff# ---------------------------------------------------------------------------
460bc22c17eSAlain Knaff
461bc22c17eSAlain Knaffquiet_cmd_lzma = LZMA    $@
4627ce7e984SMasahiro Yamada      cmd_lzma = cat $(real-prereqs) | $(LZMA) -9 > $@
4637ce7e984SMasahiro Yamada
4647ce7e984SMasahiro Yamadaquiet_cmd_lzma_with_size = LZMA    $@
4657ce7e984SMasahiro Yamada      cmd_lzma_with_size = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
4667dd65febSAlbin Tonnerre
4677dd65febSAlbin Tonnerrequiet_cmd_lzo = LZO     $@
4687ce7e984SMasahiro Yamada      cmd_lzo = cat $(real-prereqs) | $(KLZOP) -9 > $@
4697ce7e984SMasahiro Yamada
4707ce7e984SMasahiro Yamadaquiet_cmd_lzo_with_size = LZO     $@
4717ce7e984SMasahiro Yamada      cmd_lzo_with_size = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
472d61931d8SBorislav Petkov
473e76e1fdfSKyungsik Leequiet_cmd_lz4 = LZ4     $@
4747ce7e984SMasahiro Yamada      cmd_lz4 = cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout > $@
4757ce7e984SMasahiro Yamada
4767ce7e984SMasahiro Yamadaquiet_cmd_lz4_with_size = LZ4     $@
4777ce7e984SMasahiro Yamada      cmd_lz4_with_size = { cat $(real-prereqs) | $(LZ4) -l -c1 stdin stdout; \
478b79c6aa6SMasahiro Yamada                  $(size_append); } > $@
479e76e1fdfSKyungsik Lee
480e3393645SStephen Warren# U-Boot mkimage
481e3393645SStephen Warren# ---------------------------------------------------------------------------
482e3393645SStephen Warren
483e3393645SStephen WarrenMKIMAGE := $(srctree)/scripts/mkuboot.sh
484e3393645SStephen Warren
485e3393645SStephen Warren# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
486e3393645SStephen Warren# the number of overrides in arch makefiles
487e3393645SStephen WarrenUIMAGE_ARCH ?= $(SRCARCH)
4885c816641SMasahiro YamadaUIMAGE_COMPRESSION ?= $(or $(2),none)
489e3393645SStephen WarrenUIMAGE_OPTS-y ?=
490e3393645SStephen WarrenUIMAGE_TYPE ?= kernel
491e3393645SStephen WarrenUIMAGE_LOADADDR ?= arch_must_set_this
492e3393645SStephen WarrenUIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
493e3393645SStephen WarrenUIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
494e3393645SStephen Warren
495786ac51aSMasahiro Yamadaquiet_cmd_uimage = UIMAGE  $@
496858805b3SMasahiro Yamada      cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
497e3393645SStephen Warren			-C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
498e3393645SStephen Warren			-T $(UIMAGE_TYPE) \
499e3393645SStephen Warren			-a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
500786ac51aSMasahiro Yamada			-n $(UIMAGE_NAME) -d $< $@
501e3393645SStephen Warren
50224fa0402SLasse Collin# XZ
50324fa0402SLasse Collin# ---------------------------------------------------------------------------
50424fa0402SLasse Collin# Use xzkern to compress the kernel image and xzmisc to compress other things.
50524fa0402SLasse Collin#
50624fa0402SLasse Collin# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
50724fa0402SLasse Collin# of the kernel decompressor. A BCJ filter is used if it is available for
50824fa0402SLasse Collin# the target architecture. xzkern also appends uncompressed size of the data
50924fa0402SLasse Collin# using size_append. The .xz format has the size information available at
51024fa0402SLasse Collin# the end of the file too, but it's in more complex format and it's good to
51124fa0402SLasse Collin# avoid changing the part of the boot code that reads the uncompressed size.
51224fa0402SLasse Collin# Note that the bytes added by size_append will make the xz tool think that
51324fa0402SLasse Collin# the file is corrupt. This is expected.
51424fa0402SLasse Collin#
51524fa0402SLasse Collin# xzmisc doesn't use size_append, so it can be used to create normal .xz
51624fa0402SLasse Collin# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
51724fa0402SLasse Collin# big dictionary would increase the memory usage too much in the multi-call
51824fa0402SLasse Collin# decompression mode. A BCJ filter isn't used either.
51924fa0402SLasse Collinquiet_cmd_xzkern = XZKERN  $@
5207ce7e984SMasahiro Yamada      cmd_xzkern = cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh > $@
5217ce7e984SMasahiro Yamada
5227ce7e984SMasahiro Yamadaquiet_cmd_xzkern_with_size = XZKERN  $@
5237ce7e984SMasahiro Yamada      cmd_xzkern_with_size = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
524b79c6aa6SMasahiro Yamada                     $(size_append); } > $@
52524fa0402SLasse Collin
52624fa0402SLasse Collinquiet_cmd_xzmisc = XZMISC  $@
5278dfb61dcSDenis Efremov      cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
528ebf003f0SMatthias Kaehlcke
52948f7ddf7SNick Terrell# ZSTD
53048f7ddf7SNick Terrell# ---------------------------------------------------------------------------
53148f7ddf7SNick Terrell# Appends the uncompressed size of the data using size_append. The .zst
53248f7ddf7SNick Terrell# format has the size information available at the beginning of the file too,
53348f7ddf7SNick Terrell# but it's in a more complex format and it's good to avoid changing the part
53448f7ddf7SNick Terrell# of the boot code that reads the uncompressed size.
53548f7ddf7SNick Terrell#
53648f7ddf7SNick Terrell# Note that the bytes added by size_append will make the zstd tool think that
53748f7ddf7SNick Terrell# the file is corrupt. This is expected.
53848f7ddf7SNick Terrell#
53948f7ddf7SNick Terrell# zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of
54048f7ddf7SNick Terrell# 128 MB. zstd22 is used for kernel compression because it is decompressed in a
54148f7ddf7SNick Terrell# single pass, so zstd doesn't need to allocate a window buffer. When streaming
54248f7ddf7SNick Terrell# decompression is used, like initramfs decompression, zstd22 should likely not
54348f7ddf7SNick Terrell# be used because it would require zstd to allocate a 128 MB buffer.
54448f7ddf7SNick Terrell
54548f7ddf7SNick Terrellquiet_cmd_zstd = ZSTD    $@
54664d8aaa4SMasahiro Yamada      cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@
54748f7ddf7SNick Terrell
54848f7ddf7SNick Terrellquiet_cmd_zstd22 = ZSTD22  $@
5497ce7e984SMasahiro Yamada      cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@
5507ce7e984SMasahiro Yamada
5517ce7e984SMasahiro Yamadaquiet_cmd_zstd22_with_size = ZSTD22  $@
5527ce7e984SMasahiro Yamada      cmd_zstd22_with_size = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
55348f7ddf7SNick Terrell
554ebf003f0SMatthias Kaehlcke# ASM offsets
555ebf003f0SMatthias Kaehlcke# ---------------------------------------------------------------------------
556ebf003f0SMatthias Kaehlcke
557ebf003f0SMatthias Kaehlcke# Default sed regexp - multiline due to syntax constraints
558cf0c3e68SJeroen Hofstee#
559cf0c3e68SJeroen Hofstee# Use [:space:] because LLVM's integrated assembler inserts <tab> around
560cf0c3e68SJeroen Hofstee# the .ascii directive whereas GCC keeps the <space> as-is.
561ebf003f0SMatthias Kaehlckedefine sed-offsets
562cf0c3e68SJeroen Hofstee	's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
563cf0c3e68SJeroen Hofstee	/^->/{s:->#\(.*\):/* \1 */:; \
564ebf003f0SMatthias Kaehlcke	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
565cf0c3e68SJeroen Hofstee	s:->::; p;}'
566ebf003f0SMatthias Kaehlckeendef
567ebf003f0SMatthias Kaehlcke
568ebf003f0SMatthias Kaehlcke# Use filechk to avoid rebuilds when a header changes, but the resulting file
569ebf003f0SMatthias Kaehlcke# does not
570ebf003f0SMatthias Kaehlckedefine filechk_offsets
571ebf003f0SMatthias Kaehlcke	 echo "#ifndef $2"; \
572ebf003f0SMatthias Kaehlcke	 echo "#define $2"; \
573ebf003f0SMatthias Kaehlcke	 echo "/*"; \
574ebf003f0SMatthias Kaehlcke	 echo " * DO NOT MODIFY."; \
575ebf003f0SMatthias Kaehlcke	 echo " *"; \
576ebf003f0SMatthias Kaehlcke	 echo " * This file was generated by Kbuild"; \
577ebf003f0SMatthias Kaehlcke	 echo " */"; \
578ebf003f0SMatthias Kaehlcke	 echo ""; \
57943fee2b2SMasahiro Yamada	 sed -ne $(sed-offsets) < $<; \
580ebf003f0SMatthias Kaehlcke	 echo ""; \
581ad774086SMasahiro Yamada	 echo "#endif"
582ebf003f0SMatthias Kaehlckeendef
583