• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: GPL-2.0
2# Backward compatibility
3asflags-y  += $(EXTRA_AFLAGS)
4ccflags-y  += $(EXTRA_CFLAGS)
5cppflags-y += $(EXTRA_CPPFLAGS)
6ldflags-y  += $(EXTRA_LDFLAGS)
7ifneq ($(always),)
8$(warning 'always' is deprecated. Please use 'always-y' instead)
9always-y   += $(always)
10endif
11ifneq ($(hostprogs-y),)
12$(warning 'hostprogs-y' is deprecated. Please use 'hostprogs' instead)
13hostprogs  += $(hostprogs-y)
14endif
15ifneq ($(hostprogs-m),)
16$(warning 'hostprogs-m' is deprecated. Please use 'hostprogs' instead)
17hostprogs  += $(hostprogs-m)
18endif
19
20# flags that take effect in current and sub directories
21KBUILD_AFLAGS += $(subdir-asflags-y)
22KBUILD_CFLAGS += $(subdir-ccflags-y)
23
24# Figure out what we need to build from the various variables
25# ===========================================================================
26
27# When an object is listed to be built compiled-in and modular,
28# only build the compiled-in version
29obj-m := $(filter-out $(obj-y),$(obj-m))
30
31# Libraries are always collected in one lib file.
32# Filter out objects already built-in
33lib-y := $(filter-out $(obj-y), $(sort $(lib-y) $(lib-m)))
34
35# Subdirectories we need to descend into
36subdir-ym := $(sort $(subdir-y) $(subdir-m) \
37			$(patsubst %/,%, $(filter %/, $(obj-y) $(obj-m))))
38
39# Handle objects in subdirs:
40# - If we encounter foo/ in $(obj-y), replace it by foo/built-in.a and
41#   foo/modules.order
42# - If we encounter foo/ in $(obj-m), replace it by foo/modules.order
43#
44# Generate modules.order to determine modorder. Unfortunately, we don't have
45# information about ordering between -y and -m subdirs. Just put -y's first.
46
47ifdef need-modorder
48obj-m := $(patsubst %/,%/modules.order, $(filter %/, $(obj-y)) $(obj-m))
49else
50obj-m := $(filter-out %/, $(obj-m))
51endif
52
53ifdef need-builtin
54obj-y		:= $(patsubst %/, %/built-in.a, $(obj-y))
55else
56obj-y		:= $(filter-out %/, $(obj-y))
57endif
58
59# Expand $(foo-objs) $(foo-y) by calling $(call suffix-search,foo.o,-objs -y)
60suffix-search = $(foreach s,$(2),$($(1:.o=$s)))
61# If $(foo-objs), $(foo-y), $(foo-m), or $(foo-) exists, foo.o is a composite object
62# Do this recursively to find nested composite objects.
63# foo-y may contain foo.o bar.o . For backwards compatibility, don't treat this
64# foo.o as a nested object
65multi-search = $(sort $(foreach m,$(1),$(if $(strip $(call suffix-search,$(m),$(2) -)),\
66	$(if $(filter $(m),$(strip $(call suffix-search,$(m),$(2) -))),,\
67	$(m) $(call multi-search,$(call suffix-search,$(m),$(2)),$(2))))))
68multi-used-y := $(call multi-search,$(obj-y),-objs -y)
69multi-used-m := $(call multi-search,$(obj-m),-objs -y -m)
70multi-used   := $(multi-used-y) $(multi-used-m)
71
72# Replace multi-part objects by their individual parts,
73# including built-in.a from subdirectories
74# Recursively search for real files. For backwards compatibility,
75# foo-y may contain foo.o bar.o . foo.o in this context is a real object, and
76# shouldn't be recursed into.
77real-search = $(foreach m,$(1), $(if $(strip $(call suffix-search,$(m),$(2) -)), \
78	$(filter $(m),$(call suffix-search,$(m),$(2))) $(call real-search,$(filter-out $(m),$(call suffix-search,$(m),$(2))),$(2)),\
79	$(m)))
80real-obj-y := $(call real-search, $(obj-y),-objs -y)
81real-obj-m := $(call real-search, $(obj-m),-objs -y -m)
82
83always-y += $(always-m)
84
85# hostprogs-always-y += foo
86# ... is a shorthand for
87# hostprogs += foo
88# always-y  += foo
89hostprogs += $(hostprogs-always-y) $(hostprogs-always-m)
90always-y += $(hostprogs-always-y) $(hostprogs-always-m)
91
92# userprogs-always-y is likewise.
93userprogs += $(userprogs-always-y) $(userprogs-always-m)
94always-y += $(userprogs-always-y) $(userprogs-always-m)
95
96# DTB
97# If CONFIG_OF_ALL_DTBS is enabled, all DT blobs are built
98extra-y				+= $(dtb-y)
99extra-$(CONFIG_OF_ALL_DTBS)	+= $(dtb-)
100
101ifneq ($(CHECK_DTBS),)
102extra-y += $(patsubst %.dtb,%.dt.yaml, $(dtb-y))
103extra-$(CONFIG_OF_ALL_DTBS) += $(patsubst %.dtb,%.dt.yaml, $(dtb-))
104endif
105
106# Add subdir path
107
108extra-y		:= $(addprefix $(obj)/,$(extra-y))
109always-y	:= $(addprefix $(obj)/,$(always-y))
110targets		:= $(addprefix $(obj)/,$(targets))
111obj-m		:= $(addprefix $(obj)/,$(obj-m))
112lib-y		:= $(addprefix $(obj)/,$(lib-y))
113real-obj-y	:= $(addprefix $(obj)/,$(real-obj-y))
114real-obj-m	:= $(addprefix $(obj)/,$(real-obj-m))
115multi-used-m	:= $(addprefix $(obj)/,$(multi-used-m))
116subdir-ym	:= $(addprefix $(obj)/,$(subdir-ym))
117
118# Finds the multi-part object the current object will be linked into.
119# If the object belongs to two or more multi-part objects, list them all.
120modname-multi = $(sort $(foreach m,$(multi-used),\
121		$(if $(filter $*.o, $($(m:.o=-objs)) $($(m:.o=-y)) $($(m:.o=-m))),$(m:.o=))))
122
123__modname = $(if $(modname-multi),$(modname-multi),$(basetarget))
124
125modname = $(subst $(space),:,$(__modname))
126modfile = $(addprefix $(obj)/,$(__modname))
127
128# target with $(obj)/ and its suffix stripped
129target-stem = $(basename $(patsubst $(obj)/%,%,$@))
130
131# These flags are needed for modversions and compiling, so we define them here
132# $(modname_flags) defines KBUILD_MODNAME as the name of the module it will
133# end up in (or would, if it gets compiled in)
134name-fix-token = $(subst $(comma),_,$(subst -,_,$1))
135name-fix = $(call stringify,$(call name-fix-token,$1))
136basename_flags = -DKBUILD_BASENAME=$(call name-fix,$(basetarget))
137modname_flags  = -DKBUILD_MODNAME=$(call name-fix,$(modname)) \
138		 -D__KBUILD_MODNAME=kmod_$(call name-fix-token,$(modname))
139modfile_flags  = -DKBUILD_MODFILE=$(call stringify,$(modfile))
140
141_c_flags       = $(filter-out $(CFLAGS_REMOVE_$(target-stem).o), \
142                     $(filter-out $(ccflags-remove-y), \
143                         $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) $(ccflags-y)) \
144                     $(CFLAGS_$(target-stem).o))
145_a_flags       = $(filter-out $(AFLAGS_REMOVE_$(target-stem).o), \
146                     $(filter-out $(asflags-remove-y), \
147                         $(KBUILD_CPPFLAGS) $(KBUILD_AFLAGS) $(asflags-y)) \
148                     $(AFLAGS_$(target-stem).o))
149_cpp_flags     = $(KBUILD_CPPFLAGS) $(cppflags-y) $(CPPFLAGS_$(target-stem).lds)
150
151#
152# Enable gcov profiling flags for a file, directory or for all files depending
153# on variables GCOV_PROFILE_obj.o, GCOV_PROFILE and CONFIG_GCOV_PROFILE_ALL
154# (in this order)
155#
156ifeq ($(CONFIG_GCOV_KERNEL),y)
157_c_flags += $(if $(patsubst n%,, \
158		$(GCOV_PROFILE_$(basetarget).o)$(GCOV_PROFILE)$(CONFIG_GCOV_PROFILE_ALL)), \
159		$(CFLAGS_GCOV))
160endif
161
162#
163# Enable address sanitizer flags for kernel except some files or directories
164# we don't want to check (depends on variables KASAN_SANITIZE_obj.o, KASAN_SANITIZE)
165#
166ifeq ($(CONFIG_KASAN),y)
167ifneq ($(CONFIG_KASAN_HW_TAGS),y)
168_c_flags += $(if $(patsubst n%,, \
169		$(KASAN_SANITIZE_$(basetarget).o)$(KASAN_SANITIZE)y), \
170		$(CFLAGS_KASAN), $(CFLAGS_KASAN_NOSANITIZE))
171endif
172endif
173
174ifeq ($(CONFIG_UBSAN),y)
175_c_flags += $(if $(patsubst n%,, \
176		$(UBSAN_SANITIZE_$(basetarget).o)$(UBSAN_SANITIZE)$(CONFIG_UBSAN_SANITIZE_ALL)), \
177		$(CFLAGS_UBSAN))
178endif
179
180ifeq ($(CONFIG_KCOV),y)
181_c_flags += $(if $(patsubst n%,, \
182	$(KCOV_INSTRUMENT_$(basetarget).o)$(KCOV_INSTRUMENT)$(CONFIG_KCOV_INSTRUMENT_ALL)), \
183	$(CFLAGS_KCOV))
184endif
185
186#
187# Enable KCSAN flags except some files or directories we don't want to check
188# (depends on variables KCSAN_SANITIZE_obj.o, KCSAN_SANITIZE)
189#
190ifeq ($(CONFIG_KCSAN),y)
191_c_flags += $(if $(patsubst n%,, \
192	$(KCSAN_SANITIZE_$(basetarget).o)$(KCSAN_SANITIZE)y), \
193	$(CFLAGS_KCSAN))
194endif
195
196# $(srctree)/$(src) for including checkin headers from generated source files
197# $(objtree)/$(obj) for including generated headers from checkin source files
198ifeq ($(KBUILD_EXTMOD),)
199ifdef building_out_of_srctree
200_c_flags   += -I $(srctree)/$(src) -I $(objtree)/$(obj)
201_a_flags   += -I $(srctree)/$(src) -I $(objtree)/$(obj)
202_cpp_flags += -I $(srctree)/$(src) -I $(objtree)/$(obj)
203endif
204endif
205
206part-of-module = $(if $(filter $(basename $@).o, $(real-obj-m)),y)
207quiet_modtag = $(if $(part-of-module),[M],   )
208
209modkern_cflags =                                          \
210	$(if $(part-of-module),                           \
211		$(KBUILD_CFLAGS_MODULE) $(CFLAGS_MODULE), \
212		$(KBUILD_CFLAGS_KERNEL) $(CFLAGS_KERNEL) $(modfile_flags))
213
214modkern_aflags = $(if $(part-of-module),				\
215			$(KBUILD_AFLAGS_MODULE) $(AFLAGS_MODULE),	\
216			$(KBUILD_AFLAGS_KERNEL) $(AFLAGS_KERNEL))
217
218c_flags        = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
219		 -include $(srctree)/include/linux/compiler_types.h       \
220		 $(_c_flags) $(modkern_cflags)                           \
221		 $(basename_flags) $(modname_flags)
222
223a_flags        = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
224		 $(_a_flags) $(modkern_aflags)
225
226cpp_flags      = -Wp,-MMD,$(depfile) $(NOSTDINC_FLAGS) $(LINUXINCLUDE)     \
227		 $(_cpp_flags)
228
229ld_flags       = $(KBUILD_LDFLAGS) $(ldflags-y) $(LDFLAGS_$(@F))
230
231DTC_INCLUDE    := $(srctree)/scripts/dtc/include-prefixes
232
233dtc_cpp_flags  = -Wp,-MMD,$(depfile).pre.tmp -nostdinc                    \
234		 $(addprefix -I,$(DTC_INCLUDE))                          \
235		 -undef -D__DTS__
236
237# Objtool arguments are also needed for modfinal with LTO, so we define
238# then here to avoid duplication.
239objtool_args =								\
240	$(if $(CONFIG_UNWINDER_ORC),orc generate,check)			\
241	$(if $(part-of-module), --module,)				\
242	$(if $(CONFIG_FRAME_POINTER),, --no-fp)				\
243	$(if $(or $(CONFIG_GCOV_KERNEL),$(CONFIG_LTO_CLANG)), 		\
244		--no-unreachable,)					\
245	$(if $(CONFIG_RETPOLINE), --retpoline,)				\
246	$(if $(CONFIG_RETHUNK), --rethunk,)				\
247	$(if $(CONFIG_X86_SMAP), --uaccess,)				\
248	$(if $(CONFIG_SLS), --sls,)					\
249	$(if $(CONFIG_FTRACE_MCOUNT_USE_OBJTOOL), --mcount,)
250
251# Useful for describing the dependency of composite objects
252# Usage:
253#   $(call multi_depend, multi_used_targets, suffix_to_remove, suffix_to_add)
254define multi_depend
255$(foreach m, $(notdir $1), \
256	$(eval $(obj)/$m: \
257	$(addprefix $(obj)/, $(foreach s, $3, $($(m:%$(strip $2)=%$(s)))))))
258endef
259
260quiet_cmd_copy = COPY    $@
261      cmd_copy = cp $< $@
262
263# Shipped files
264# ===========================================================================
265
266quiet_cmd_shipped = SHIPPED $@
267cmd_shipped = cat $< > $@
268
269$(obj)/%: $(src)/%_shipped
270	$(call cmd,shipped)
271
272# Commands useful for building a boot image
273# ===========================================================================
274#
275#	Use as following:
276#
277#	target: source(s) FORCE
278#		$(if_changed,ld/objcopy/gzip)
279#
280#	and add target to extra-y so that we know we have to
281#	read in the saved command line
282
283# Linking
284# ---------------------------------------------------------------------------
285
286quiet_cmd_ld = LD      $@
287      cmd_ld = $(LD) $(ld_flags) $(real-prereqs) -o $@
288
289# Archive
290# ---------------------------------------------------------------------------
291
292quiet_cmd_ar = AR      $@
293      cmd_ar = rm -f $@; $(AR) cDPrsT $@ $(real-prereqs)
294
295# Objcopy
296# ---------------------------------------------------------------------------
297
298quiet_cmd_objcopy = OBJCOPY $@
299cmd_objcopy = $(OBJCOPY) $(OBJCOPYFLAGS) $(OBJCOPYFLAGS_$(@F)) $< $@
300
301# Gzip
302# ---------------------------------------------------------------------------
303
304quiet_cmd_gzip = GZIP    $@
305      cmd_gzip = cat $(real-prereqs) | $(KGZIP) -n -f -9 > $@
306
307# DTC
308# ---------------------------------------------------------------------------
309ifeq ("$(origin DTC)", "command line")
310PHONY += $(DTC)
311dtc-option = $(call try-run, $(DTC) $1 -v,$1)
312else
313# Just add the flag. DTC is compiled later as a prerequisite, so there's no dtc
314# to test the flag against. This is okay because we're not testing flags which
315# aren't supported by in-kernel dtc to begin with.
316dtc-option = $1
317endif
318
319DTC ?= $(objtree)/scripts/dtc/dtc
320DTC_FLAGS += $(call dtc-option,-Wno-interrupt_provider)
321
322# Disable noisy checks by default
323ifeq ($(findstring 1,$(KBUILD_EXTRA_WARN)),)
324DTC_FLAGS += $(call dtc-option,-Wno-unit_address_vs_reg) \
325	$(call dtc-option,-Wno-unit_address_format) \
326	$(call dtc-option,-Wno-avoid_unnecessary_addr_size) \
327	$(call dtc-option,-Wno-alias_paths) \
328	$(call dtc-option,-Wno-graph_child_address) \
329	$(call dtc-option,-Wno-simple_bus_reg) \
330	$(call dtc-option,-Wno-unique_unit_address) \
331	$(call dtc-option,-Wno-pci_device_reg)
332endif
333
334ifneq ($(findstring 2,$(KBUILD_EXTRA_WARN)),)
335DTC_FLAGS += $(call dtc-option,-Wnode_name_chars_strict) \
336	$(call dtc-option,-Wproperty_name_chars_strict) \
337	$(call dtc-option,-Winterrupt_provider)
338endif
339
340DTC_FLAGS += $(DTC_FLAGS_$(basetarget))
341
342# Generate an assembly file to wrap the output of the device tree compiler
343quiet_cmd_dt_S_dtb= DTB     $@
344cmd_dt_S_dtb=						\
345{							\
346	echo '\#include <asm-generic/vmlinux.lds.h>'; 	\
347	echo '.section .dtb.init.rodata,"a"';		\
348	echo '.balign STRUCT_ALIGNMENT';		\
349	echo '.global __dtb_$(subst -,_,$(*F))_begin';	\
350	echo '__dtb_$(subst -,_,$(*F))_begin:';		\
351	echo '.incbin "$<" ';				\
352	echo '__dtb_$(subst -,_,$(*F))_end:';		\
353	echo '.global __dtb_$(subst -,_,$(*F))_end';	\
354	echo '.balign STRUCT_ALIGNMENT'; 		\
355} > $@
356
357$(obj)/%.dtb.S: $(obj)/%.dtb FORCE
358	$(call if_changed,dt_S_dtb)
359
360quiet_cmd_dtc = DTC     $@
361cmd_dtc = $(HOSTCC) -E $(dtc_cpp_flags) -x assembler-with-cpp -o $(dtc-tmp) $< ; \
362	$(DTC) -O $(patsubst .%,%,$(suffix $@)) -o $@ -b 0 \
363		$(addprefix -i,$(dir $<) $(DTC_INCLUDE)) $(DTC_FLAGS) \
364		-d $(depfile).dtc.tmp $(dtc-tmp) ; \
365	cat $(depfile).pre.tmp $(depfile).dtc.tmp > $(depfile)
366
367$(obj)/%.dtb: $(src)/%.dts $(DTC) FORCE
368	$(call if_changed_dep,dtc)
369
370DT_CHECKER ?= dt-validate
371DT_BINDING_DIR := Documentation/devicetree/bindings
372# DT_TMP_SCHEMA may be overridden from Documentation/devicetree/bindings/Makefile
373DT_TMP_SCHEMA ?= $(objtree)/$(DT_BINDING_DIR)/processed-schema.json
374
375quiet_cmd_dtb_check =	CHECK   $@
376      cmd_dtb_check =	$(DT_CHECKER) -u $(srctree)/$(DT_BINDING_DIR) -p $(DT_TMP_SCHEMA) $@
377
378define rule_dtc
379	$(call cmd_and_fixdep,dtc)
380	$(call cmd,dtb_check)
381endef
382
383$(obj)/%.dt.yaml: $(src)/%.dts $(DTC) $(DT_TMP_SCHEMA) FORCE
384	$(call if_changed_rule,dtc,yaml)
385
386dtc-tmp = $(subst $(comma),_,$(dot-target).dts.tmp)
387
388# Bzip2
389# ---------------------------------------------------------------------------
390
391# Bzip2 and LZMA do not include size in file... so we have to fake that;
392# append the size as a 32-bit littleendian number as gzip does.
393size_append = printf $(shell						\
394dec_size=0;								\
395for F in $(real-prereqs); do					\
396	fsize=$$($(CONFIG_SHELL) $(srctree)/scripts/file-size.sh $$F);	\
397	dec_size=$$(expr $$dec_size + $$fsize);				\
398done;									\
399printf "%08x\n" $$dec_size |						\
400	sed 's/\(..\)/\1 /g' | {					\
401		read ch0 ch1 ch2 ch3;					\
402		for ch in $$ch3 $$ch2 $$ch1 $$ch0; do			\
403			printf '%s%03o' '\\' $$((0x$$ch)); 		\
404		done;							\
405	}								\
406)
407
408quiet_cmd_bzip2 = BZIP2   $@
409      cmd_bzip2 = { cat $(real-prereqs) | $(KBZIP2) -9; $(size_append); } > $@
410
411# Lzma
412# ---------------------------------------------------------------------------
413
414quiet_cmd_lzma = LZMA    $@
415      cmd_lzma = { cat $(real-prereqs) | $(LZMA) -9; $(size_append); } > $@
416
417quiet_cmd_lzo = LZO     $@
418      cmd_lzo = { cat $(real-prereqs) | $(KLZOP) -9; $(size_append); } > $@
419
420quiet_cmd_lz4 = LZ4     $@
421      cmd_lz4 = { cat $(real-prereqs) | \
422                  $(LZ4) -l -12 --favor-decSpeed stdin stdout; \
423                  $(size_append); } > $@
424
425# U-Boot mkimage
426# ---------------------------------------------------------------------------
427
428MKIMAGE := $(srctree)/scripts/mkuboot.sh
429
430# SRCARCH just happens to match slightly more than ARCH (on sparc), so reduces
431# the number of overrides in arch makefiles
432UIMAGE_ARCH ?= $(SRCARCH)
433UIMAGE_COMPRESSION ?= $(if $(2),$(2),none)
434UIMAGE_OPTS-y ?=
435UIMAGE_TYPE ?= kernel
436UIMAGE_LOADADDR ?= arch_must_set_this
437UIMAGE_ENTRYADDR ?= $(UIMAGE_LOADADDR)
438UIMAGE_NAME ?= 'Linux-$(KERNELRELEASE)'
439
440quiet_cmd_uimage = UIMAGE  $@
441      cmd_uimage = $(BASH) $(MKIMAGE) -A $(UIMAGE_ARCH) -O linux \
442			-C $(UIMAGE_COMPRESSION) $(UIMAGE_OPTS-y) \
443			-T $(UIMAGE_TYPE) \
444			-a $(UIMAGE_LOADADDR) -e $(UIMAGE_ENTRYADDR) \
445			-n $(UIMAGE_NAME) -d $< $@
446
447# XZ
448# ---------------------------------------------------------------------------
449# Use xzkern to compress the kernel image and xzmisc to compress other things.
450#
451# xzkern uses a big LZMA2 dictionary since it doesn't increase memory usage
452# of the kernel decompressor. A BCJ filter is used if it is available for
453# the target architecture. xzkern also appends uncompressed size of the data
454# using size_append. The .xz format has the size information available at
455# the end of the file too, but it's in more complex format and it's good to
456# avoid changing the part of the boot code that reads the uncompressed size.
457# Note that the bytes added by size_append will make the xz tool think that
458# the file is corrupt. This is expected.
459#
460# xzmisc doesn't use size_append, so it can be used to create normal .xz
461# files. xzmisc uses smaller LZMA2 dictionary than xzkern, because a very
462# big dictionary would increase the memory usage too much in the multi-call
463# decompression mode. A BCJ filter isn't used either.
464quiet_cmd_xzkern = XZKERN  $@
465      cmd_xzkern = { cat $(real-prereqs) | sh $(srctree)/scripts/xz_wrap.sh; \
466                     $(size_append); } > $@
467
468quiet_cmd_xzmisc = XZMISC  $@
469      cmd_xzmisc = cat $(real-prereqs) | $(XZ) --check=crc32 --lzma2=dict=1MiB > $@
470
471# ZSTD
472# ---------------------------------------------------------------------------
473# Appends the uncompressed size of the data using size_append. The .zst
474# format has the size information available at the beginning of the file too,
475# but it's in a more complex format and it's good to avoid changing the part
476# of the boot code that reads the uncompressed size.
477#
478# Note that the bytes added by size_append will make the zstd tool think that
479# the file is corrupt. This is expected.
480#
481# zstd uses a maximum window size of 8 MB. zstd22 uses a maximum window size of
482# 128 MB. zstd22 is used for kernel compression because it is decompressed in a
483# single pass, so zstd doesn't need to allocate a window buffer. When streaming
484# decompression is used, like initramfs decompression, zstd22 should likely not
485# be used because it would require zstd to allocate a 128 MB buffer.
486
487quiet_cmd_zstd = ZSTD    $@
488      cmd_zstd = { cat $(real-prereqs) | $(ZSTD) -19; $(size_append); } > $@
489
490quiet_cmd_zstd22 = ZSTD22  $@
491      cmd_zstd22 = { cat $(real-prereqs) | $(ZSTD) -22 --ultra; $(size_append); } > $@
492
493# ASM offsets
494# ---------------------------------------------------------------------------
495
496# Default sed regexp - multiline due to syntax constraints
497#
498# Use [:space:] because LLVM's integrated assembler inserts <tab> around
499# the .ascii directive whereas GCC keeps the <space> as-is.
500define sed-offsets
501	's:^[[:space:]]*\.ascii[[:space:]]*"\(.*\)".*:\1:; \
502	/^->/{s:->#\(.*\):/* \1 */:; \
503	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
504	s:->::; p;}'
505endef
506
507# Use filechk to avoid rebuilds when a header changes, but the resulting file
508# does not
509define filechk_offsets
510	 echo "#ifndef $2"; \
511	 echo "#define $2"; \
512	 echo "/*"; \
513	 echo " * DO NOT MODIFY."; \
514	 echo " *"; \
515	 echo " * This file was generated by Kbuild"; \
516	 echo " */"; \
517	 echo ""; \
518	 sed -ne $(sed-offsets) < $<; \
519	 echo ""; \
520	 echo "#endif"
521endef
522