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