xref: /linux/scripts/Makefile.lib (revision 8630c59e99363c4b655788fd01134aef9bcd9264)
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=kmod_$(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_HAVE_JUMP_LABEL_HACK)		+= --hacks=jump_label
177objtool-args-$(CONFIG_HAVE_NOINSTR_HACK)		+= --hacks=noinstr
178objtool-args-$(CONFIG_MITIGATION_CALL_DEPTH_TRACKING)	+= --hacks=skylake
179objtool-args-$(CONFIG_X86_KERNEL_IBT)			+= --ibt
180objtool-args-$(CONFIG_FINEIBT)				+= --cfi
181objtool-args-$(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL)	+= --mcount
182ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
183objtool-args-$(CONFIG_HAVE_OBJTOOL_NOP_MCOUNT)		+= --mnop
184endif
185objtool-args-$(CONFIG_UNWINDER_ORC)			+= --orc
186objtool-args-$(CONFIG_MITIGATION_RETPOLINE)		+= --retpoline
187objtool-args-$(CONFIG_MITIGATION_RETHUNK)		+= --rethunk
188objtool-args-$(CONFIG_MITIGATION_SLS)			+= --sls
189objtool-args-$(CONFIG_STACK_VALIDATION)			+= --stackval
190objtool-args-$(CONFIG_HAVE_STATIC_CALL_INLINE)		+= --static-call
191objtool-args-$(CONFIG_HAVE_UACCESS_VALIDATION)		+= --uaccess
192objtool-args-$(or $(CONFIG_GCOV_KERNEL),$(CONFIG_KCOV))	+= --no-unreachable
193objtool-args-$(CONFIG_PREFIX_SYMBOLS)			+= --prefix=$(CONFIG_FUNCTION_PADDING_BYTES)
194objtool-args-$(CONFIG_OBJTOOL_WERROR)			+= --Werror
195
196objtool-args = $(objtool-args-y)					\
197	$(if $(delay-objtool), --link)					\
198	$(if $(part-of-module), --module)
199
200delay-objtool := $(or $(CONFIG_LTO_CLANG),$(CONFIG_X86_KERNEL_IBT))
201
202cmd_objtool = $(if $(objtool-enabled), ; $(objtool) $(objtool-args) $@)
203cmd_gen_objtooldep = $(if $(objtool-enabled), { echo ; echo '$@: $$(wildcard $(objtool))' ; } >> $(dot-target).cmd)
204
205objtool-enabled := y
206
207endif # CONFIG_OBJTOOL
208
209# Useful for describing the dependency of composite objects
210# Usage:
211#   $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
212define multi_depend
213$(foreach m, $1, \
214	$(eval $m: \
215	$(addprefix $(obj)/, $(call suffix-search, $(patsubst $(obj)/%,%,$m), $2, $3))))
216endef
217
218# Remove ".." and "." from a path, without using "realpath"
219# Usage:
220#   $(call normalize_path,path/to/../file)
221define normalize_path
222$(strip $(eval elements :=) \
223$(foreach elem,$(subst /, ,$1), \
224	$(if $(filter-out .,$(elem)), \
225	     $(if $(filter ..,$(elem)), \
226		  $(eval elements := $(wordlist 2,$(words $(elements)),x $(elements))), \
227		  $(eval elements := $(elements) $(elem))))) \
228$(subst $(space),/,$(elements)))
229endef
230
231# Build commands
232# ===========================================================================
233# These are shared by some Makefile.* files.
234
235ifdef CONFIG_LTO_CLANG
236# Run $(LD) here to convert LLVM IR to ELF in the following cases:
237#  - when this object needs objtool processing, as objtool cannot process LLVM IR
238#  - when this is a single-object module, as modpost cannot process LLVM IR
239cmd_ld_single = $(if $(objtool-enabled)$(is-single-obj-m), ; $(LD) $(ld_flags) -r -o $(tmp-target) $@; mv $(tmp-target) $@)
240endif
241
242quiet_cmd_cc_o_c = CC $(quiet_modtag)  $@
243      cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $< \
244		$(cmd_ld_single) \
245		$(cmd_objtool)
246
247define rule_cc_o_c
248	$(call cmd_and_fixdep,cc_o_c)
249	$(call cmd,checksrc)
250	$(call cmd,checkdoc)
251	$(call cmd,gen_objtooldep)
252	$(call cmd,gen_symversions_c)
253	$(call cmd,record_mcount)
254	$(call cmd,warn_shared_object)
255endef
256
257quiet_cmd_as_o_S = AS $(quiet_modtag)  $@
258      cmd_as_o_S = $(CC) $(a_flags) -c -o $@ $< $(cmd_objtool)
259
260define rule_as_o_S
261	$(call cmd_and_fixdep,as_o_S)
262	$(call cmd,gen_objtooldep)
263	$(call cmd,gen_symversions_S)
264	$(call cmd,warn_shared_object)
265endef
266
267# Copy a file
268# ===========================================================================
269# 'cp' preserves permissions. If you use it to copy a file in read-only srctree,
270# the copy would be read-only as well, leading to an error when executing the
271# rule next time. Use 'cat' instead in order to generate a writable file.
272quiet_cmd_copy = COPY    $@
273      cmd_copy = cat $< > $@
274
275$(obj)/%: $(src)/%_shipped
276	$(call cmd,copy)
277
278# Touch a file
279# ===========================================================================
280quiet_cmd_touch = TOUCH   $(call normalize_path,$@)
281      cmd_touch = touch $@
282
283# Commands useful for building a boot image
284# ===========================================================================
285#
286#	Use as following:
287#
288#	target: source(s) FORCE
289#		$(if_changed,ld/objcopy/gzip)
290#
291#	and add target to 'targets' so that we know we have to
292#	read in the saved command line
293
294# Linking
295# ---------------------------------------------------------------------------
296
297quiet_cmd_ld = LD      $@
298      cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
299
300# Archive
301# ---------------------------------------------------------------------------
302
303quiet_cmd_ar = AR      $@
304      cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
305
306# Objcopy
307# ---------------------------------------------------------------------------
308
309quiet_cmd_objcopy = OBJCOPY $@
310cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
311
312# Gzip
313# ---------------------------------------------------------------------------
314
315quiet_cmd_gzip = GZIP    $@
316      cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
317
318# Bzip2
319# ---------------------------------------------------------------------------
320
321# Bzip2 and LZMA do not include size in file... so we have to fake that;
322# append the size as a 32-bit littleendian number as gzip does.
323size_append = printf $(shell						\
324dec_size=0;								\
325for F in $(real-prereqs); do					\
326	fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F);	\
327	dec_size=$$(expr $$dec_size + $$fsize);				\
328done;									\
329printf "%08x\n" $$dec_size |						\
330	sed 's/\(..\)/\1 /g' | {					\
331		read ch0 ch1 ch2 ch3;					\
332		for ch in $$ch3 $$ch2 $$ch1 $$ch0; do			\
333			printf '%s%03o' '\\' $$((0x$$ch)); 		\
334		done;							\
335	}								\
336)
337
338quiet_cmd_file_size = GEN     $@
339      cmd_file_size = $(size_append) > $@
340
341quiet_cmd_bzip2 = BZIP2   $@
342      cmd_bzip2 = cat $(real-prereqs) | $(KBZIP2) -9 > $@
343
344quiet_cmd_bzip2_with_size = BZIP2   $@
345      cmd_bzip2_with_size = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
346
347# Lzma
348# ---------------------------------------------------------------------------
349
350quiet_cmd_lzma = LZMA    $@
351      cmd_lzma = cat $(real-prereqs) | $(LZMA) -9 > $@
352
353quiet_cmd_lzma_with_size = LZMA    $@
354      cmd_lzma_with_size = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
355
356quiet_cmd_lzo = LZO     $@
357      cmd_lzo = cat $(real-prereqs) | $(KLZOP) -9 > $@
358
359quiet_cmd_lzo_with_size = LZO     $@
360      cmd_lzo_with_size = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
361
362quiet_cmd_lz4 = LZ4     $@
363      cmd_lz4 = cat $(real-prereqs) | $(LZ4) -l -9 - - > $@
364
365quiet_cmd_lz4_with_size = LZ4     $@
366      cmd_lz4_with_size = { cat $(real-prereqs) | $(LZ4) -l -9 - -; \
367                  $(size_append); } > $@
368
369# U-Boot mkimage
370# ---------------------------------------------------------------------------
371
372MKIMAGE := $(srctree)/scripts/mkuboot.sh
373
374# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
375# the number of overrides in arch makefiles
376UIMAGE_ARCH ?= $(SRCARCH)
377UIMAGE_COMPRESSION ?= $(or $(2),none)
378UIMAGE_OPTS-y ?=
379UIMAGE_TYPE ?= kernel
380UIMAGE_LOADADDR ?= arch_must_set_this
381UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
382UIMAGE_NAME ?= Linux-$(KERNELRELEASE)
383
384quiet_cmd_uimage = UIMAGE  $@
385      cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
386			-C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
387			-T $(UIMAGE_TYPE) \
388			-a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
389			-n '$(UIMAGE_NAME)' -d $< $@
390
391# Flat Image Tree (FIT)
392# This allows for packaging of a kernel and all devicetrees files, using
393# compression.
394# ---------------------------------------------------------------------------
395
396MAKE_FIT := $(srctree)/scripts/make_fit.py
397
398# Use this to override the compression algorithm
399FIT_COMPRESSION ?= gzip
400
401quiet_cmd_fit = FIT     $@
402      cmd_fit = $(MAKE_FIT) -o $@ --arch $(UIMAGE_ARCH) --os linux \
403		--name '$(UIMAGE_NAME)' \
404		$(if $(findstring 1,$(KBUILD_VERBOSE)),-v) \
405		$(if $(FIT_DECOMPOSE_DTBS),--decompose-dtbs) \
406		--compress $(FIT_COMPRESSION) -k $< @$(word 2,$^)
407
408# XZ
409# ---------------------------------------------------------------------------
410# Use xzkern or xzkern_with_size to compress the kernel image and xzmisc to
411# compress other things.
412#
413# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
414# of the kernel decompressor. A BCJ filter is used if it is available for
415# the target architecture.
416#
417# xzkern_with_size also appends uncompressed size of the data using
418# size_append. The .xz format has the size information available at the end
419# of the file too, but it's in more complex format and it's good to avoid
420# changing the part of the boot code that reads the uncompressed size.
421# Note that the bytes added by size_append will make the xz tool think that
422# the file is corrupt. This is expected.
423#
424# xzmisc doesn't use size_append, so it can be used to create normal .xz
425# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
426# big dictionary would increase the memory usage too much in the multi-call
427# decompression mode. A BCJ filter isn't used either.
428quiet_cmd_xzkern = XZKERN  $@
429      cmd_xzkern = cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh > $@
430
431quiet_cmd_xzkern_with_size = XZKERN  $@
432      cmd_xzkern_with_size = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
433                     $(size_append); } > $@
434
435quiet_cmd_xzmisc = XZMISC  $@
436      cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
437
438# ZSTD
439# ---------------------------------------------------------------------------
440# Appends the uncompressed size of the data using size_append. The .zst
441# format has the size information available at the beginning of the file too,
442# but it's in a more complex format and it's good to avoid changing the part
443# of the boot code that reads the uncompressed size.
444#
445# Note that the bytes added by size_append will make the zstd tool think that
446# the file is corrupt. This is expected.
447#
448# zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of
449# 128 MB. zstd22 is used for kernel compression because it is decompressed in a
450# single pass, so zstd doesn't need to allocate a window buffer. When streaming
451# decompression is used, like initramfs decompression, zstd22 should likely not
452# be used because it would require zstd to allocate a 128 MB buffer.
453
454quiet_cmd_zstd = ZSTD    $@
455      cmd_zstd = cat $(real-prereqs) | $(ZSTD) -19 > $@
456
457quiet_cmd_zstd22 = ZSTD22  $@
458      cmd_zstd22 = cat $(real-prereqs) | $(ZSTD) -22 --ultra > $@
459
460quiet_cmd_zstd22_with_size = ZSTD22  $@
461      cmd_zstd22_with_size = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
462
463# ASM offsets
464# ---------------------------------------------------------------------------
465
466# Default sed regexp - multiline due to syntax constraints
467#
468# Use [:space:] because LLVM's integrated assembler inserts <tab> around
469# the .ascii directive whereas GCC keeps the <space> as-is.
470define sed-offsets
471	's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
472	/^->/{s:->#\(.*\):/* \1 */:; \
473	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
474	s:->::; p;}'
475endef
476
477# Use filechk to avoid rebuilds when a header changes, but the resulting file
478# does not
479define filechk_offsets
480	 echo "#ifndef $2"; \
481	 echo "#define $2"; \
482	 echo "/*"; \
483	 echo " * DO NOT MODIFY."; \
484	 echo " *"; \
485	 echo " * This file was generated by Kbuild"; \
486	 echo " */"; \
487	 echo ""; \
488	 sed -ne $(sed-offsets) < $<; \
489	 echo ""; \
490	 echo "#endif"
491endef
492