Debian Codegraph @

Makefile

raw symbols ◀ ▶ SCIP
Source reconstructed at patch state 3 of 4 — not the installed (fully patched) source.
4 Debian patches touch this file
1 # SPDX-License-Identifier: GPL-2.0
2 VERSION = 7
3 PATCHLEVEL = 0
4 SUBLEVEL = 12
5 EXTRAVERSION =
6 NAME = Baby Opossum Posse
7
8 # *DOCUMENTATION*
9 # To see a list of typical targets execute "make help"
10 # More info can be located in ./README
11 # Comments in this file are targeted only to the developer, do not
12 # expect to learn how to build the kernel reading this file.
13
14 ifeq ($(filter output-sync,$(.FEATURES)),)
15 $(error GNU Make >= 4.0 is required. Your Make version is $(MAKE_VERSION))
16 endif
17
18 $(if $(filter __%, $(MAKECMDGOALS)), \
19 $(error targets prefixed with '__' are only for internal use))
20
21 # That's our default target when none is given on the command line
22 PHONY := __all
23 __all:
24
25 # We are using a recursive build, so we need to do a little thinking
26 # to get the ordering right.
27 #
28 # Most importantly: sub-Makefiles should only ever modify files in
29 # their own directory. If in some directory we have a dependency on
30 # a file in another dir (which doesn't happen often, but it's often
31 # unavoidable when linking the built-in.a targets which finally
32 # turn into vmlinux), we will call a sub make in that other dir, and
33 # after that we are sure that everything which is in that other dir
34 # is now up to date.
35 #
36 # The only cases where we need to modify files which have global
37 # effects are thus separated out and done before the recursive
38 # descending is started. They are now explicitly listed as the
39 # prepare rule.
40
41 this-makefile := $(lastword $(MAKEFILE_LIST))
42 abs_srctree := $(realpath $(dir $(this-makefile)))
43 abs_output := $(CURDIR)
44
45 ifneq ($(sub_make_done),1)
46
47 # Do not use make's built-in rules and variables
48 # (this increases performance and avoids hard-to-debug behaviour)
49 MAKEFLAGS += -rR
50
51 # Avoid funny character set dependencies
52 unexport LC_ALL
53 LC_COLLATE=C
54 LC_NUMERIC=C
55 export LC_COLLATE LC_NUMERIC
56
57 # Avoid interference with shell env settings
58 unexport GREP_OPTIONS
59
60 # Beautify output
61 # ---------------------------------------------------------------------------
62 #
63 # Most of build commands in Kbuild start with "cmd_". You can optionally define
64 # "quiet_cmd_*". If defined, the short log is printed. Otherwise, no log from
65 # that command is printed by default.
66 #
67 # e.g.)
68 # quiet_cmd_depmod = DEPMOD $(MODLIB)
69 # cmd_depmod = $(srctree)/scripts/depmod.sh $(DEPMOD) $(KERNELRELEASE)
70 #
71 # A simple variant is to prefix commands with $(Q) - that's useful
72 # for commands that shall be hidden in non-verbose mode.
73 #
74 # $(Q)$(MAKE) $(build)=scripts/basic
75 #
76 # If KBUILD_VERBOSE contains 1, the whole command is echoed.
77 # If KBUILD_VERBOSE contains 2, the reason for rebuilding is printed.
78 #
79 # To put more focus on warnings, be less verbose as default
80 # Use 'make V=1' to see the full commands
81
82 ifeq ("$(origin V)", "command line")
83 KBUILD_VERBOSE = $(V)
84 endif
85
86 quiet = quiet_
87 Q = @
88
89 ifneq ($(findstring 1, $(KBUILD_VERBOSE)),)
90 quiet =
91 Q =
92 endif
93
94 # If the user is running make -s (silent mode), suppress echoing of
95 # commands
96 ifneq ($(findstring s,$(firstword -$(MAKEFLAGS))),)
97 quiet=silent_
98 override KBUILD_VERBOSE :=
99 endif
100
101 export quiet Q KBUILD_VERBOSE
102
103 # Call a source code checker (by default, "sparse") as part of the
104 # C compilation.
105 #
106 # Use 'make C=1' to enable checking of only re-compiled files.
107 # Use 'make C=2' to enable checking of *all* source files, regardless
108 # of whether they are re-compiled or not.
109 #
110 # See the file "Documentation/dev-tools/sparse.rst" for more details,
111 # including where to get the "sparse" utility.
112
113 ifeq ("$(origin C)", "command line")
114 KBUILD_CHECKSRC = $(C)
115 endif
116 ifndef KBUILD_CHECKSRC
117 KBUILD_CHECKSRC = 0
118 endif
119
120 export KBUILD_CHECKSRC
121
122 # Enable "clippy" (a linter) as part of the Rust compilation.
123 #
124 # Use 'make CLIPPY=1' to enable it.
125 ifeq ("$(origin CLIPPY)", "command line")
126 KBUILD_CLIPPY := $(CLIPPY)
127 endif
128
129 export KBUILD_CLIPPY
130
131 # Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the
132 # directory of external module to build. Setting M= takes precedence.
133 ifeq ("$(origin M)", "command line")
134 KBUILD_EXTMOD := $(M)
135 endif
136
137 ifeq ("$(origin MO)", "command line")
138 KBUILD_EXTMOD_OUTPUT := $(MO)
139 endif
140
141 # Old syntax make ... SUBDIRS=$PWD should be rejected to avoid mishaps
142 # (see Debian bugs #982334, #987575)
143 ifndef KBUILD_EXTMOD
144 ifdef SUBDIRS
145 $(warning =============== ERROR ==============)
146 $(warning 'SUBDIRS' was removed in Linux 5.3)
147 $(warning Use 'M=' or 'KBUILD_EXTMOD=' instead)
148 $(warning ====================================)
149 $(error .)
150 endif
151 endif
152
153 $(if $(word 2, $(KBUILD_EXTMOD)), \
154 $(error building multiple external modules is not supported))
155
156 $(foreach x, % :, $(if $(findstring $x, $(KBUILD_EXTMOD)), \
157 $(error module directory path cannot contain '$x')))
158
159 # Remove trailing slashes
160 ifneq ($(filter %/, $(KBUILD_EXTMOD)),)
161 KBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD).)
162 endif
163
164 export KBUILD_EXTMOD
165
166 ifeq ("$(origin W)", "command line")
167 KBUILD_EXTRA_WARN := $(W)
168 endif
169
170 export KBUILD_EXTRA_WARN
171
172 # Kbuild will save output files in the current working directory.
173 # This does not need to match to the root of the kernel source tree.
174 #
175 # For example, you can do this:
176 #
177 # cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile
178 #
179 # If you want to save output files in a different location, there are
180 # two syntaxes to specify it.
181 #
182 # 1) O=
183 # Use "make O=dir/to/store/output/files/"
184 #
185 # 2) Set KBUILD_OUTPUT
186 # Set the environment variable KBUILD_OUTPUT to point to the output directory.
187 # export KBUILD_OUTPUT=dir/to/store/output/files/; make
188 #
189 # The O= assignment takes precedence over the KBUILD_OUTPUT environment
190 # variable.
191
192 ifeq ("$(origin O)", "command line")
193 KBUILD_OUTPUT := $(O)
194 endif
195
196 ifdef KBUILD_EXTMOD
197 ifdef KBUILD_OUTPUT
198 objtree := $(realpath $(KBUILD_OUTPUT))
199 $(if $(objtree),,$(error specified kernel directory "$(KBUILD_OUTPUT)" does not exist))
200 else
201 objtree := $(abs_srctree)
202 endif
203 # If Make is invoked from the kernel directory (either kernel
204 # source directory or kernel build directory), external modules
205 # are built in $(KBUILD_EXTMOD) for backward compatibility,
206 # otherwise, built in the current directory.
207 output := $(or $(KBUILD_EXTMOD_OUTPUT),$(if $(filter $(CURDIR),$(objtree) $(abs_srctree)),$(KBUILD_EXTMOD)))
208 # KBUILD_EXTMOD might be a relative path. Remember its absolute path before
209 # Make changes the working directory.
210 srcroot := $(realpath $(KBUILD_EXTMOD))
211 $(if $(srcroot),,$(error specified external module directory "$(KBUILD_EXTMOD)" does not exist))
212 else
213 objtree := .
214 output := $(KBUILD_OUTPUT)
215 endif
216
217 export objtree srcroot
218
219 # Do we want to change the working directory?
220 ifneq ($(output),)
221 # $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first.
222 $(shell mkdir -p "$(output)")
223 # $(realpath ...) resolves symlinks
224 abs_output := $(realpath $(output))
225 $(if $(abs_output),,$(error failed to create output directory "$(output)"))
226 endif
227
228 ifneq ($(words $(subst :, ,$(abs_srctree))), 1)
229 $(error source directory cannot contain spaces or colons)
230 endif
231
232 export sub_make_done := 1
233
234 endif # sub_make_done
235
236 ifeq ($(abs_output),$(CURDIR))
237 # Suppress "Entering directory ..." if we are at the final work directory.
238 no-print-directory := --no-print-directory
239 else
240 # Recursion to show "Entering directory ..."
241 need-sub-make := 1
242 endif
243
244 ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),)
245 # If --no-print-directory is unset, recurse once again to set it.
246 # You may end up recursing into __sub-make twice. This is needed due to the
247 # behavior change in GNU Make 4.4.1.
248 need-sub-make := 1
249 endif
250
251 ifeq ($(need-sub-make),1)
252
253 PHONY += $(MAKECMDGOALS) __sub-make
254
255 $(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
256 @:
257
258 # Invoke a second make in the output directory, passing relevant variables
259 __sub-make:
260 $(Q)$(MAKE) $(no-print-directory) -C $(abs_output) \
261 -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
262
263 else # need-sub-make
264
265 # We process the rest of the Makefile if this is the final invocation of make
266
267 ifndef KBUILD_EXTMOD
268 srcroot := $(abs_srctree)
269 endif
270
271 ifeq ($(srcroot),$(CURDIR))
272 building_out_of_srctree :=
273 else
274 export building_out_of_srctree := 1
275 endif
276
277 ifdef KBUILD_ABS_SRCTREE
278 # Do nothing. Use the absolute path.
279 else ifeq ($(srcroot),$(CURDIR))
280 # Building in the source.
281 srcroot := .
282 else ifeq ($(srcroot)/,$(dir $(CURDIR)))
283 # Building in a subdirectory of the source.
284 srcroot := ..
285 endif
286
287 export srctree := $(if $(KBUILD_EXTMOD),$(abs_srctree),$(srcroot))
288
289 ifdef building_out_of_srctree
290 export VPATH := $(srcroot)
291 else
292 VPATH :=
293 endif
294
295 # To make sure we do not include .config for any of the *config targets
296 # catch them early, and hand them over to scripts/kconfig/Makefile
297 # It is allowed to specify more targets when calling make, including
298 # mixing *config targets and build targets.
299 # For example 'make oldconfig all'.
300 # Detect when mixed targets is specified, and make a second invocation
301 # of make so .config is not included in this case either (for *config).
302
303 version_h := include/generated/uapi/linux/version.h
304
305 clean-targets := %clean mrproper cleandocs
306 no-dot-config-targets := $(clean-targets) \
307 cscope gtags TAGS tags help% %docs check% coccicheck \
308 $(version_h) headers headers_% archheaders archscripts \
309 %asm-generic kernelversion %src-pkg dt_binding_check \
310 outputmakefile rustavailable rustfmt rustfmtcheck \
311 run-command
312 no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \
313 image_name
314 single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %/
315
316 config-build :=
317 mixed-build :=
318 need-config := 1
319 may-sync-config := 1
320 single-build :=
321
322 ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
323 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
324 need-config :=
325 endif
326 endif
327
328 ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
329 ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
330 may-sync-config :=
331 endif
332 endif
333
334 need-compiler := $(may-sync-config)
335
336 ifneq ($(KBUILD_EXTMOD),)
337 may-sync-config :=
338 endif
339
340 ifeq ($(KBUILD_EXTMOD),)
341 ifneq ($(filter %config,$(MAKECMDGOALS)),)
342 config-build := 1
343 ifneq ($(words $(MAKECMDGOALS)),1)
344 mixed-build := 1
345 endif
346 endif
347 endif
348
349 # We cannot build single targets and the others at the same time
350 ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),)
351 single-build := 1
352 ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),)
353 mixed-build := 1
354 endif
355 endif
356
357 # For "make -j clean all", "make -j mrproper defconfig all", etc.
358 ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
359 ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
360 mixed-build := 1
361 endif
362 endif
363
364 # install and modules_install need also be processed one by one
365 ifneq ($(filter install,$(MAKECMDGOALS)),)
366 ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
367 mixed-build := 1
368 endif
369 endif
370
371 ifdef mixed-build
372 # ===========================================================================
373 # We're called with mixed targets (*config and build targets).
374 # Handle them one by one.
375
376 PHONY += $(MAKECMDGOALS) __build_one_by_one
377
378 $(MAKECMDGOALS): __build_one_by_one
379 @:
380
381 __build_one_by_one:
382 $(Q)set -e; \
383 for i in $(MAKECMDGOALS); do \
384 $(MAKE) -f $(srctree)/Makefile $$i; \
385 done
386
387 else # !mixed-build
388
389 include $(srctree)/scripts/Kbuild.include
390
391 # Read KERNELRELEASE from include/config/kernel.release (if it exists)
392 KERNELRELEASE = $(call read-file, $(objtree)/include/config/kernel.release)
393 KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
394 export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
395
396 include $(srctree)/scripts/subarch.include
397
398 # Cross compiling and selecting different set of gcc/bin-utils
399 # ---------------------------------------------------------------------------
400 #
401 # When performing cross compilation for other architectures ARCH shall be set
402 # to the target architecture. (See arch/* for the possibilities).
403 # ARCH can be set during invocation of make:
404 # make ARCH=arm64
405 # Another way is to have ARCH set in the environment.
406 # The default ARCH is the host where make is executed.
407
408 # CROSS_COMPILE specify the prefix used for all executables used
409 # during compilation. Only gcc and related bin-utils executables
410 # are prefixed with $(CROSS_COMPILE).
411 # CROSS_COMPILE can be set on the command line
412 # make CROSS_COMPILE=aarch64-linux-gnu-
413 # Alternatively CROSS_COMPILE can be set in the environment.
414 # Default value for CROSS_COMPILE is not to prefix executables
415 # Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
416 ARCH ?= $(SUBARCH)
417
418 KCONFIG_CONFIG ?= .config
419 export KCONFIG_CONFIG
420
421 # SHELL used by kbuild
422 CONFIG_SHELL := sh
423
424 HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
425 HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
426 HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
427
428 ifneq ($(LLVM),)
429 ifneq ($(filter %/,$(LLVM)),)
430 LLVM_PREFIX := $(LLVM)
431 else ifneq ($(filter -%,$(LLVM)),)
432 LLVM_SUFFIX := $(LLVM)
433 else ifneq ($(LLVM),1)
434 $(error Invalid value for LLVM, see Documentation/kbuild/llvm.rst)
435 endif
436
437 HOSTCC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
438 HOSTCXX = $(LLVM_PREFIX)clang++$(LLVM_SUFFIX)
439 else
440 HOSTCC = gcc
441 HOSTCXX = g++
442 endif
443 HOSTRUSTC = rustc
444 HOSTPKG_CONFIG = pkg-config
445
446 # the KERNELDOC macro needs to be exported, as scripts/Makefile.build
447 # has a logic to call it
448 KERNELDOC = $(srctree)/tools/docs/kernel-doc
449 export KERNELDOC
450
451 KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
452 -O2 -fomit-frame-pointer -std=gnu11
453 KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
454 KBUILD_USERLDFLAGS := $(USERLDFLAGS)
455
456 # These flags apply to all Rust code in the tree, including the kernel and
457 # host programs.
458 export rust_common_flags := --edition=2021 \
459 -Zbinary_dep_depinfo=y \
460 -Astable_features \
461 -Aunused_features \
462 -Dnon_ascii_idents \
463 -Dunsafe_op_in_unsafe_fn \
464 -Wmissing_docs \
465 -Wrust_2018_idioms \
466 -Wunreachable_pub \
467 -Wclippy::all \
468 -Wclippy::as_ptr_cast_mut \
469 -Wclippy::as_underscore \
470 -Wclippy::cast_lossless \
471 -Aclippy::collapsible_if \
472 -Aclippy::collapsible_match \
473 -Wclippy::ignored_unit_patterns \
474 -Wclippy::mut_mut \
475 -Wclippy::needless_bitwise_bool \
476 -Aclippy::needless_lifetimes \
477 -Wclippy::no_mangle_with_rust_abi \
478 -Wclippy::ptr_as_ptr \
479 -Wclippy::ptr_cast_constness \
480 -Wclippy::ref_as_ptr \
481 -Wclippy::undocumented_unsafe_blocks \
482 -Aclippy::uninlined_format_args \
483 -Wclippy::unnecessary_safety_comment \
484 -Wclippy::unnecessary_safety_doc \
485 -Wrustdoc::missing_crate_level_docs \
486 -Wrustdoc::unescaped_backticks
487
488 KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \
489 $(HOSTCFLAGS) -I $(srctree)/scripts/include
490 KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \
491 -I $(srctree)/scripts/include
492 KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \
493 -Zallow-features= $(HOSTRUSTFLAGS)
494 KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
495 KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
496 KBUILD_PROCMACROLDFLAGS := $(or $(PROCMACROLDFLAGS),$(KBUILD_HOSTLDFLAGS))
497
498 # Make variables (CC, etc...)
499 CPP = $(CC) -E
500 ifneq ($(LLVM),)
501 CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
502 LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
503 AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
504 NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX)
505 OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
506 OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
507 READELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
508 STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
509 else
510 CC = $(CROSS_COMPILE)gcc
511 LD = $(CROSS_COMPILE)ld
512 AR = $(CROSS_COMPILE)ar
513 NM = $(CROSS_COMPILE)nm
514 OBJCOPY = $(CROSS_COMPILE)objcopy
515 OBJDUMP = $(CROSS_COMPILE)objdump
516 READELF = $(CROSS_COMPILE)readelf
517 STRIP = $(CROSS_COMPILE)strip
518 endif
519 RUSTC = rustc
520 RUSTDOC = rustdoc
521 RUSTFMT = rustfmt
522 CLIPPY_DRIVER = clippy-driver
523 BINDGEN = bindgen
524 PAHOLE = pahole
525 RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
526 LEX = flex
527 YACC = bison
528 AWK = awk
529 INSTALLKERNEL := installkernel
530 PERL = perl
531 PYTHON3 = python3
532 CHECK = sparse
533 BASH = bash
534 KGZIP = gzip
535 KBZIP2 = bzip2
536 KLZOP = lzop
537 LZMA = lzma
538 LZ4 = lz4
539 XZ = xz
540 ZSTD = zstd
541 TAR = tar
542
543 CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
544 -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
545 NOSTDINC_FLAGS :=
546 CFLAGS_MODULE =
547 RUSTFLAGS_MODULE =
548 AFLAGS_MODULE =
549 LDFLAGS_MODULE =
550 CFLAGS_KERNEL =
551 RUSTFLAGS_KERNEL =
552 AFLAGS_KERNEL =
553 LDFLAGS_vmlinux =
554
555 -include $(objtree)/.kernelvariables
556
557 # Architecture as present in compile.h
558 UTS_MACHINE := $(ARCH)
559 SRCARCH := $(ARCH)
560
561 # Additional ARCH settings for x86
562 ifeq ($(ARCH),i386)
563 SRCARCH := x86
564 endif
565 ifeq ($(ARCH),x86_64)
566 SRCARCH := x86
567 endif
568
569 # Additional ARCH settings for sparc
570 ifeq ($(ARCH),sparc64)
571 SRCARCH := sparc
572 endif
573
574 # Additional ARCH settings for parisc
575 ifeq ($(ARCH),parisc64)
576 SRCARCH := parisc
577 endif
578
579 # Additional ARCH settings for sh
580 ifeq ($(ARCH),sh64)
581 SRCARCH := sh
582 endif
583
584 # Use USERINCLUDE when you must reference the UAPI directories only.
585 USERINCLUDE := \
586 -I$(srctree)/arch/$(SRCARCH)/include/uapi \
587 -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
588 -I$(srctree)/include/uapi \
589 -I$(objtree)/include/generated/uapi \
590 -include $(srctree)/include/linux/compiler-version.h \
591 -include $(srctree)/include/linux/kconfig.h
592
593 # Use LINUXINCLUDE when you must reference the include/ directory.
594 # Needed to be compatible with the O= option
595 LINUXINCLUDE := \
596 -I$(srctree)/arch/$(SRCARCH)/include \
597 -I$(objtree)/arch/$(SRCARCH)/include/generated \
598 -I$(srctree)/include \
599 -I$(objtree)/include \
600 $(USERINCLUDE)
601
602 KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
603
604 KBUILD_CFLAGS :=
605 KBUILD_CFLAGS += -std=gnu11
606 KBUILD_CFLAGS += -fshort-wchar
607 KBUILD_CFLAGS += -funsigned-char
608 KBUILD_CFLAGS += -fno-common
609 KBUILD_CFLAGS += -fno-PIE
610 KBUILD_CFLAGS += -fno-strict-aliasing
611
612 KBUILD_CPPFLAGS := -D__KERNEL__
613 KBUILD_RUSTFLAGS := $(rust_common_flags) \
614 -Cpanic=abort -Cembed-bitcode=n -Clto=n \
615 -Cforce-unwind-tables=n -Ccodegen-units=1 \
616 -Csymbol-mangling-version=v0 \
617 -Crelocation-model=static \
618 -Zfunction-sections=n \
619 -Wclippy::float_arithmetic
620
621 KBUILD_AFLAGS_KERNEL :=
622 KBUILD_CFLAGS_KERNEL :=
623 KBUILD_RUSTFLAGS_KERNEL :=
624 KBUILD_AFLAGS_MODULE := -DMODULE
625 KBUILD_CFLAGS_MODULE := -DMODULE
626 KBUILD_RUSTFLAGS_MODULE := --cfg MODULE
627 KBUILD_LDFLAGS_MODULE :=
628 KBUILD_LDFLAGS :=
629 CLANG_FLAGS :=
630
631 ifeq ($(KBUILD_CLIPPY),1)
632 RUSTC_OR_CLIPPY_QUIET := CLIPPY
633 RUSTC_OR_CLIPPY = $(CLIPPY_DRIVER)
634 else
635 RUSTC_OR_CLIPPY_QUIET := RUSTC
636 RUSTC_OR_CLIPPY = $(RUSTC)
637 endif
638
639 # Allows the usage of unstable features in stable compilers.
640 export RUSTC_BOOTSTRAP := 1
641
642 # Allows finding `.clippy.toml` in out-of-srctree builds.
643 export CLIPPY_CONF_DIR := $(srctree)
644
645 export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG
646 export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN
647 export HOSTRUSTC KBUILD_HOSTRUSTFLAGS
648 export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
649 export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
650 export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD TAR
651 export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS KBUILD_PROCMACROLDFLAGS LDFLAGS_MODULE
652 export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS
653
654 export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
655 export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
656 export KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE
657 export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
658 export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE
659 export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL
660
661 # Files to ignore in find ... statements
662
663 export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \
664 -name CVS -o -name .pc -o -name .hg -o -name .git \) \
665 -prune -o
666
667 # ===========================================================================
668 # Rules shared between *config targets and build targets
669
670 # Basic helpers built in scripts/basic/
671 PHONY += scripts_basic
672 scripts_basic: KBUILD_HOSTCFLAGS := $(KBUILD_HOSTCFLAGS)
673 scripts_basic: KBUILD_HOSTLDFLAGS := $(KBUILD_HOSTLDFLAGS)
674 scripts_basic:
675 $(Q)$(MAKE) $(build)=scripts/basic
676
677 PHONY += outputmakefile
678 ifdef building_out_of_srctree
679 # Before starting out-of-tree build, make sure the source tree is clean.
680 # outputmakefile generates a Makefile in the output directory, if using a
681 # separate output directory. This allows convenient use of make in the
682 # output directory.
683 # At the same time when output Makefile generated, generate .gitignore to
684 # ignore whole output directory
685
686 ifdef KBUILD_EXTMOD
687 print_env_for_makefile = \
688 echo "export KBUILD_OUTPUT = $(objtree)"; \
689 echo "export KBUILD_EXTMOD = $(realpath $(srcroot))" ; \
690 echo "export KBUILD_EXTMOD_OUTPUT = $(CURDIR)"
691 else
692 print_env_for_makefile = \
693 echo "export KBUILD_OUTPUT = $(CURDIR)"
694 endif
695
696 quiet_cmd_makefile = GEN Makefile
697 cmd_makefile = { \
698 echo "\# Automatically generated by $(abs_srctree)/Makefile: don't edit"; \
699 $(print_env_for_makefile); \
700 echo "include $(abs_srctree)/Makefile"; \
701 } > Makefile
702
703 outputmakefile:
704 ifeq ($(KBUILD_EXTMOD),)
705 @if [ -f $(srctree)/.config -o \
706 -d $(srctree)/include/config -o \
707 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
708 echo >&2 "***"; \
709 echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
710 echo >&2 "*** in $(abs_srctree)";\
711 echo >&2 "***"; \
712 false; \
713 fi
714 else
715 @if [ -f $(srcroot)/modules.order ]; then \
716 echo >&2 "***"; \
717 echo >&2 "*** The external module source tree is not clean."; \
718 echo >&2 "*** Please run 'make -C $(abs_srctree) M=$(realpath $(srcroot)) clean'"; \
719 echo >&2 "***"; \
720 false; \
721 fi
722 endif
723 $(Q)ln -fsn $(srcroot) source
724 $(call cmd,makefile)
725 $(Q)test -e .gitignore || \
726 { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
727 endif
728
729 # The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
730 # Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
731 # CC_VERSION_TEXT, RUSTC_VERSION_TEXT and PAHOLE_VERSION are referenced from
732 # Kconfig (so they need export), and from include/config/auto.conf.cmd to
733 # detect the version changes between builds.
734 CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
735 RUSTC_VERSION_TEXT = $(subst $(pound),,$(shell $(RUSTC) --version 2>/dev/null))
736 PAHOLE_VERSION = $(shell $(srctree)/scripts/pahole-version.sh $(PAHOLE))
737
738 ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
739 include $(srctree)/scripts/Makefile.clang
740 endif
741
742 # Include this also for config targets because some architectures need
743 # cc-cross-prefix to determine CROSS_COMPILE.
744 ifdef need-compiler
745 include $(srctree)/scripts/Makefile.compiler
746 endif
747
748 ifdef config-build
749 # ===========================================================================
750 # *config targets only - make sure prerequisites are updated, and descend
751 # in scripts/kconfig to make the *config target
752
753 # Read arch-specific Makefile to set KBUILD_DEFCONFIG as needed.
754 # KBUILD_DEFCONFIG may point out an alternative default configuration
755 # used for 'make defconfig'
756 include $(srctree)/arch/$(SRCARCH)/Makefile
757 export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT RUSTC_VERSION_TEXT PAHOLE_VERSION
758
759 config: outputmakefile scripts_basic FORCE
760 $(Q)$(MAKE) $(build)=scripts/kconfig $@
761
762 %config: outputmakefile scripts_basic FORCE
763 $(Q)$(MAKE) $(build)=scripts/kconfig $@
764
765 else #!config-build
766 # ===========================================================================
767 # Build targets only - this includes vmlinux, arch-specific targets, clean
768 # targets and others. In general all targets except *config targets.
769
770 # If building an external module we do not care about the all: rule
771 # but instead __all depend on modules
772 PHONY += all
773 ifeq ($(KBUILD_EXTMOD),)
774 __all: all
775 else
776 __all: modules
777 endif
778
779 targets :=
780
781 # Decide whether to build built-in, modular, or both.
782 # Normally, just do built-in.
783
784 KBUILD_MODULES :=
785 KBUILD_BUILTIN := y
786
787 # If we have only "make modules", don't compile built-in objects.
788 ifeq ($(MAKECMDGOALS),modules)
789 KBUILD_BUILTIN :=
790 endif
791
792 # If we have "make <whatever> modules", compile modules
793 # in addition to whatever we do anyway.
794 # Just "make" or "make all" shall build modules as well
795
796 ifneq ($(filter all modules nsdeps compile_commands.json clang-%,$(MAKECMDGOALS)),)
797 KBUILD_MODULES := y
798 endif
799
800 ifeq ($(MAKECMDGOALS),)
801 KBUILD_MODULES := y
802 endif
803
804 export KBUILD_MODULES KBUILD_BUILTIN
805
806 ifdef need-config
807 include $(objtree)/include/config/auto.conf
808 endif
809
810 ifeq ($(KBUILD_EXTMOD),)
811 # Objects we will link into vmlinux / subdirs we need to visit
812 core-y :=
813 drivers-y :=
814 libs-y := lib/
815 endif # KBUILD_EXTMOD
816
817 # The all: target is the default when no target is given on the
818 # command line.
819 # This allow a user to issue only 'make' to build a kernel including modules
820 # Defaults to vmlinux, but the arch makefile usually adds further targets
821 all: vmlinux
822
823 CFLAGS_GCOV := -fprofile-arcs -ftest-coverage
824 ifdef CONFIG_CC_IS_GCC
825 CFLAGS_GCOV += -fno-tree-loop-im
826 endif
827 export CFLAGS_GCOV
828
829 # The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
830 ifdef CONFIG_FUNCTION_TRACER
831 CC_FLAGS_FTRACE := -pg
832 endif
833
834 ifdef CONFIG_TRACEPOINTS
835 # To check for unused tracepoints (tracepoints that are defined but never
836 # called), run with:
837 #
838 # make UT=1
839 #
840 # Each unused tracepoints can take up to 5KB of memory in the running kernel.
841 # It is best to remove any that are not used.
842 #
843 # This command line option will be removed when all current unused
844 # tracepoints are removed.
845
846 ifeq ("$(origin UT)", "command line")
847 WARN_ON_UNUSED_TRACEPOINTS := $(UT)
848 endif
849 endif # CONFIG_TRACEPOINTS
850
851 export WARN_ON_UNUSED_TRACEPOINTS
852
853 include $(srctree)/arch/$(SRCARCH)/Makefile
854
855 ifdef need-config
856 ifdef may-sync-config
857 # Read in dependencies to all Kconfig* files, make sure to run syncconfig if
858 # changes are detected. This should be included after arch/$(SRCARCH)/Makefile
859 # because some architectures define CROSS_COMPILE there.
860 include include/config/auto.conf.cmd
861
862 $(KCONFIG_CONFIG):
863 @echo >&2 '***'
864 @echo >&2 '*** Configuration file "$@" not found!'
865 @echo >&2 '***'
866 @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or'
867 @echo >&2 '*** "make menuconfig" or "make xconfig").'
868 @echo >&2 '***'
869 @/bin/false
870
871 # The actual configuration files used during the build are stored in
872 # include/generated/ and include/config/. Update them if .config is newer than
873 # include/config/auto.conf (which mirrors .config).
874 #
875 # This exploits the 'multi-target pattern rule' trick.
876 # The syncconfig should be executed only once to make all the targets.
877 # (Note: use the grouped target '&:' when we bump to GNU Make 4.3)
878 #
879 # Do not use $(call cmd,...) here. That would suppress prompts from syncconfig,
880 # so you cannot notice that Kconfig is waiting for the user input.
881 %/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h %/generated/rustc_cfg: $(KCONFIG_CONFIG)
882 $(Q)$(kecho) " SYNC $@"
883 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
884 else # !may-sync-config
885 # External modules and some install targets need include/generated/autoconf.h
886 # and include/config/auto.conf but do not care if they are up-to-date.
887 # Use auto.conf to show the error message
888
889 checked-configs := $(addprefix $(objtree)/, include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf)
890 missing-configs := $(filter-out $(wildcard $(checked-configs)), $(checked-configs))
891
892 ifdef missing-configs
893 PHONY += $(objtree)/include/config/auto.conf
894
895 $(objtree)/include/config/auto.conf:
896 @echo >&2 '***'
897 @echo >&2 '*** ERROR: Kernel configuration is invalid. The following files are missing:'
898 @printf >&2 '*** - %s\n' $(missing-configs)
899 @echo >&2 '*** Run "make oldconfig && make prepare" on kernel source to fix it.'
900 @echo >&2 '***'
901 @/bin/false
902 endif
903
904 endif # may-sync-config
905 endif # need-config
906
907 KBUILD_CFLAGS += -fno-delete-null-pointer-checks
908
909 ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
910 KBUILD_CFLAGS += -O2
911 KBUILD_RUSTFLAGS += -Copt-level=2
912 else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
913 KBUILD_CFLAGS += -Os
914 KBUILD_RUSTFLAGS += -Copt-level=s
915 endif
916
917 # Always set `debug-assertions` and `overflow-checks` because their default
918 # depends on `opt-level` and `debug-assertions`, respectively.
919 KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n)
920 KBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n)
921
922 # Tell gcc to never replace conditional load with a non-conditional one
923 ifdef CONFIG_CC_IS_GCC
924 # gcc-10 renamed --param=allow-store-data-races=0 to
925 # -fno-allow-store-data-races.
926 KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
927 KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races)
928 endif
929
930 ifdef CONFIG_READABLE_ASM
931 # Disable optimizations that make assembler listings hard to read.
932 # reorder blocks reorders the control in the function
933 # ipa clone creates specialized cloned functions
934 # partial inlining inlines only parts of functions
935 KBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining
936 endif
937
938 stackp-flags-y := -fno-stack-protector
939 stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector
940 stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
941
942 KBUILD_CFLAGS += $(stackp-flags-y)
943
944 ifdef CONFIG_FRAME_POINTER
945 KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
946 KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y
947 else
948 # Some targets (ARM with Thumb2, for example), can't be built with frame
949 # pointers. For those, we don't have FUNCTION_TRACER automatically
950 # select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is
951 # incompatible with -fomit-frame-pointer with current GCC, so we don't use
952 # -fomit-frame-pointer with FUNCTION_TRACER.
953 # In the Rust target specification, "frame-pointer" is set explicitly
954 # to "may-omit".
955 ifndef CONFIG_FUNCTION_TRACER
956 KBUILD_CFLAGS += -fomit-frame-pointer
957 endif
958 endif
959
960 # Initialize all stack variables with a 0xAA pattern.
961 ifdef CONFIG_INIT_STACK_ALL_PATTERN
962 KBUILD_CFLAGS += -ftrivial-auto-var-init=pattern
963 endif
964
965 # Initialize all stack variables with a zero value.
966 ifdef CONFIG_INIT_STACK_ALL_ZERO
967 KBUILD_CFLAGS += -ftrivial-auto-var-init=zero
968 ifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER
969 # https://github.com/llvm/llvm-project/issues/44842
970 CC_AUTO_VAR_INIT_ZERO_ENABLER := -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
971 export CC_AUTO_VAR_INIT_ZERO_ENABLER
972 KBUILD_CFLAGS += $(CC_AUTO_VAR_INIT_ZERO_ENABLER)
973 endif
974 endif
975
976 ifdef CONFIG_CC_IS_CLANG
977 ifdef CONFIG_CC_HAS_COUNTED_BY_PTR
978 KBUILD_CFLAGS += -fexperimental-late-parse-attributes
979 endif
980 endif
981
982 # Explicitly clear padding bits during variable initialization
983 KBUILD_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all)
984
985 # While VLAs have been removed, GCC produces unreachable stack probes
986 # for the randomize_kstack_offset feature. Disable it for all compilers.
987 KBUILD_CFLAGS += $(call cc-option, -fno-stack-clash-protection)
988
989 # Get details on warnings generated due to GCC value tracking.
990 KBUILD_CFLAGS += $(call cc-option, -fdiagnostics-show-context=2)
991
992 # Clear used registers at func exit (to reduce data lifetime and ROP gadgets).
993 ifdef CONFIG_ZERO_CALL_USED_REGS
994 KBUILD_CFLAGS += -fzero-call-used-regs=used-gpr
995 endif
996
997 ifdef CONFIG_FUNCTION_TRACER
998 ifdef CONFIG_FTRACE_MCOUNT_USE_CC
999 CC_FLAGS_FTRACE += -mrecord-mcount
1000 ifdef CONFIG_HAVE_NOP_MCOUNT
1001 ifeq ($(call cc-option-yn, -mnop-mcount),y)
1002 CC_FLAGS_FTRACE += -mnop-mcount
1003 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
1004 endif
1005 endif
1006 endif
1007 ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
1008 ifdef CONFIG_HAVE_OBJTOOL_NOP_MCOUNT
1009 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
1010 endif
1011 endif
1012 ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
1013 ifdef CONFIG_HAVE_C_RECORDMCOUNT
1014 BUILD_C_RECORDMCOUNT := y
1015 export BUILD_C_RECORDMCOUNT
1016 endif
1017 endif
1018 ifdef CONFIG_HAVE_FENTRY
1019 # s390-linux-gnu-gcc did not support -mfentry until gcc-9.
1020 ifeq ($(call cc-option-yn, -mfentry),y)
1021 CC_FLAGS_FTRACE += -mfentry
1022 CC_FLAGS_USING += -DCC_USING_FENTRY
1023 endif
1024 endif
1025 export CC_FLAGS_FTRACE
1026 KBUILD_CFLAGS += $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING)
1027 KBUILD_AFLAGS += $(CC_FLAGS_USING)
1028 endif
1029
1030 # We trigger additional mismatches with less inlining
1031 ifdef CONFIG_DEBUG_SECTION_MISMATCH
1032 KBUILD_CFLAGS += -fno-inline-functions-called-once
1033 endif
1034
1035 # `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0).
1036 ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
1037 KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
1038 KBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y
1039 LDFLAGS_vmlinux += --gc-sections
1040 endif
1041
1042 ifdef CONFIG_SHADOW_CALL_STACK
1043 ifndef CONFIG_DYNAMIC_SCS
1044 CC_FLAGS_SCS := -fsanitize=shadow-call-stack
1045 KBUILD_CFLAGS += $(CC_FLAGS_SCS)
1046 KBUILD_RUSTFLAGS += -Zsanitizer=shadow-call-stack
1047 endif
1048 export CC_FLAGS_SCS
1049 endif
1050
1051 ifdef CONFIG_LTO_CLANG
1052 ifdef CONFIG_LTO_CLANG_THIN
1053 CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit
1054 else
1055 CC_FLAGS_LTO := -flto
1056 endif
1057 CC_FLAGS_LTO += -fvisibility=hidden
1058
1059 # Limit inlining across translation units to reduce binary size
1060 KBUILD_LDFLAGS += -mllvm -import-instr-limit=5
1061 endif
1062
1063 ifdef CONFIG_LTO
1064 KBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO)
1065 KBUILD_AFLAGS += -fno-lto
1066 export CC_FLAGS_LTO
1067 endif
1068
1069 ifdef CONFIG_CFI
1070 CC_FLAGS_CFI := -fsanitize=kcfi
1071 ifdef CONFIG_CFI_ICALL_NORMALIZE_INTEGERS
1072 CC_FLAGS_CFI += -fsanitize-cfi-icall-experimental-normalize-integers
1073 endif
1074 ifdef CONFIG_FINEIBT_BHI
1075 CC_FLAGS_CFI += -fsanitize-kcfi-arity
1076 endif
1077 ifdef CONFIG_RUST
1078 # Always pass -Zsanitizer-cfi-normalize-integers as CONFIG_RUST selects
1079 # CONFIG_CFI_ICALL_NORMALIZE_INTEGERS.
1080 RUSTC_FLAGS_CFI := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers
1081 KBUILD_RUSTFLAGS += $(RUSTC_FLAGS_CFI)
1082 export RUSTC_FLAGS_CFI
1083 endif
1084 KBUILD_CFLAGS += $(CC_FLAGS_CFI)
1085 export CC_FLAGS_CFI
1086 endif
1087
1088 # Architectures can define flags to add/remove for floating-point support
1089 CC_FLAGS_FPU += -D_LINUX_FPU_COMPILATION_UNIT
1090 export CC_FLAGS_FPU
1091 export CC_FLAGS_NO_FPU
1092
1093 ifneq ($(CONFIG_FUNCTION_ALIGNMENT),0)
1094 # Set the minimal function alignment. Use the newer GCC option
1095 # -fmin-function-alignment if it is available, or fall back to -falign-funtions.
1096 # See also CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT.
1097 ifdef CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT
1098 KBUILD_CFLAGS += -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT)
1099 else
1100 KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT)
1101 endif
1102 endif
1103
1104 # arch Makefile may override CC so keep this after arch Makefile is included
1105 NOSTDINC_FLAGS += -nostdinc
1106
1107 # To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE,
1108 # the kernel uses only C99 flexible arrays for dynamically sized trailing
1109 # arrays. Enforce this for everything that may examine structure sizes and
1110 # perform bounds checking.
1111 KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
1112
1113 # Allow including a tagged struct or union anonymously in another struct/union.
1114 KBUILD_CFLAGS += -fms-extensions
1115
1116 # disable invalid "can't wrap" optimizations for signed / pointers
1117 KBUILD_CFLAGS += -fno-strict-overflow
1118
1119 # Make sure -fstack-check isn't enabled (like gentoo apparently did)
1120 KBUILD_CFLAGS += -fno-stack-check
1121
1122 # conserve stack if available
1123 ifdef CONFIG_CC_IS_GCC
1124 KBUILD_CFLAGS += -fconserve-stack
1125 endif
1126
1127 # Ensure compilers do not transform certain loops into calls to wcslen()
1128 KBUILD_CFLAGS += -fno-builtin-wcslen
1129
1130 # change __FILE__ to the relative path to the source directory
1131 ifdef building_out_of_srctree
1132 KBUILD_CPPFLAGS += -fmacro-prefix-map=$(srcroot)/=
1133 ifeq ($(call rustc-option-yn, --remap-path-scope=macro),y)
1134 KBUILD_RUSTFLAGS += --remap-path-prefix=$(srcroot)/= --remap-path-scope=macro
1135 endif
1136 endif
1137
1138 # include additional Makefiles when needed
1139 include-y := scripts/Makefile.warn
1140 include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug
1141 include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf
1142 include-$(CONFIG_KASAN) += scripts/Makefile.kasan
1143 include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan
1144 include-$(CONFIG_KMSAN) += scripts/Makefile.kmsan
1145 include-$(CONFIG_UBSAN) += scripts/Makefile.ubsan
1146 include-$(CONFIG_KCOV) += scripts/Makefile.kcov
1147 include-$(CONFIG_RANDSTRUCT) += scripts/Makefile.randstruct
1148 include-$(CONFIG_KSTACK_ERASE) += scripts/Makefile.kstack_erase
1149 include-$(CONFIG_AUTOFDO_CLANG) += scripts/Makefile.autofdo
1150 include-$(CONFIG_PROPELLER_CLANG) += scripts/Makefile.propeller
1151 include-$(CONFIG_WARN_CONTEXT_ANALYSIS) += scripts/Makefile.context-analysis
1152 include-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins
1153
1154 include $(addprefix $(srctree)/, $(include-y))
1155
1156 # scripts/Makefile.gcc-plugins is intentionally included last.
1157 # Do not add $(call cc-option,...) below this line. When you build the kernel
1158 # from the clean source tree, the GCC plugins do not exist at this point.
1159
1160 # Add user supplied CPPFLAGS, AFLAGS, CFLAGS and RUSTFLAGS as the last assignments
1161 KBUILD_CPPFLAGS += $(KCPPFLAGS)
1162 KBUILD_AFLAGS += $(KAFLAGS)
1163 KBUILD_CFLAGS += $(KCFLAGS)
1164 KBUILD_RUSTFLAGS += $(KRUSTFLAGS)
1165
1166 KBUILD_LDFLAGS_MODULE += --build-id=sha1
1167 LDFLAGS_vmlinux += --build-id=sha1
1168
1169 KBUILD_LDFLAGS += -z noexecstack
1170 ifeq ($(CONFIG_LD_IS_BFD),y)
1171 KBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments)
1172 endif
1173
1174 ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
1175 LDFLAGS_vmlinux += -X
1176 endif
1177
1178 ifeq ($(CONFIG_RELR),y)
1179 # ld.lld before 15 did not support -z pack-relative-relocs.
1180 LDFLAGS_vmlinux += $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs)
1181 endif
1182
1183 # We never want expected sections to be placed heuristically by the
1184 # linker. All sections should be explicitly named in the linker script.
1185 ifdef CONFIG_LD_ORPHAN_WARN
1186 LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
1187 endif
1188
1189 ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),)
1190 LDFLAGS_vmlinux += --emit-relocs --discard-none
1191 endif
1192
1193 # Align the architecture of userspace programs with the kernel
1194 USERFLAGS_FROM_KERNEL := --target=%
1195
1196 ifdef CONFIG_ARCH_USERFLAGS
1197 KBUILD_USERCFLAGS += $(CONFIG_ARCH_USERFLAGS)
1198 KBUILD_USERLDFLAGS += $(CONFIG_ARCH_USERFLAGS)
1199 else
1200 # If not overridden also inherit the bit size
1201 USERFLAGS_FROM_KERNEL += -m32 -m64
1202 endif
1203
1204 KBUILD_USERCFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
1205 KBUILD_USERLDFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
1206
1207 # userspace programs are linked via the compiler, use the correct linker
1208 ifdef CONFIG_CC_IS_CLANG
1209 KBUILD_USERLDFLAGS += --ld-path=$(LD)
1210 endif
1211
1212 # make the checker run with the right architecture
1213 CHECKFLAGS += --arch=$(ARCH)
1214
1215 # insure the checker run with the right endianness
1216 CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
1217
1218 # the checker needs the correct machine size
1219 CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
1220
1221 # Validate the checker is available and functional
1222 ifneq ($(KBUILD_CHECKSRC), 0)
1223 ifneq ($(shell $(srctree)/scripts/checker-valid.sh $(CHECK) $(CHECKFLAGS)), 1)
1224 $(warning C=$(KBUILD_CHECKSRC) specified, but $(CHECK) is not available or not up to date)
1225 KBUILD_CHECKSRC = 0
1226 endif
1227 endif
1228
1229 # Default kernel image to build when no specific target is given.
1230 # KBUILD_IMAGE may be overruled on the command line or
1231 # set in the environment
1232 # Also any assignments in arch/$(ARCH)/Makefile take precedence over
1233 # this default value
1234 export KBUILD_IMAGE ?= vmlinux
1235
1236 #
1237 # INSTALL_PATH specifies where to place the updated kernel and system map
1238 # images. Default is /boot, but you can set it to other values
1239 export INSTALL_PATH ?= /boot
1240
1241 #
1242 # INSTALL_DTBS_PATH specifies a prefix for relocations required by build roots.
1243 # Like INSTALL_MOD_PATH, it isn't defined in the Makefile, but can be passed as
1244 # an argument if needed. Otherwise it defaults to the kernel install path
1245 #
1246 export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE)
1247
1248 #
1249 # INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
1250 # relocations required by build roots. This is not defined in the
1251 # makefile but the argument can be passed to make if needed.
1252 #
1253
1254 MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
1255 export MODLIB
1256
1257 PHONY += prepare0
1258
1259 ifeq ($(KBUILD_EXTMOD),)
1260
1261 build-dir := .
1262 clean-dirs := $(sort . Documentation \
1263 $(patsubst %/,%,$(filter %/, $(core-) \
1264 $(drivers-) $(libs-))))
1265
1266 export ARCH_CORE := $(core-y)
1267 export ARCH_LIB := $(filter %/, $(libs-y))
1268 export ARCH_DRIVERS := $(drivers-y) $(drivers-m)
1269 # Externally visible symbols (used by link-vmlinux.sh)
1270
1271 KBUILD_VMLINUX_OBJS := built-in.a $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
1272 KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
1273
1274 export KBUILD_VMLINUX_LIBS
1275 export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
1276
1277 ifdef CONFIG_TRIM_UNUSED_KSYMS
1278 # For the kernel to actually contain only the needed exported symbols,
1279 # we have to build modules as well to determine what those symbols are.
1280 KBUILD_MODULES := y
1281 endif
1282
1283 # '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14
1284 quiet_cmd_ar_vmlinux.a = AR $@
1285 cmd_ar_vmlinux.a = \
1286 rm -f $@; \
1287 $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \
1288 $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt)
1289
1290 targets += vmlinux.a
1291 vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
1292 $(call if_changed,ar_vmlinux.a)
1293
1294 PHONY += vmlinux_o
1295 vmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS)
1296 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_o
1297
1298 vmlinux.o modules.builtin.modinfo modules.builtin: vmlinux_o
1299 @:
1300
1301 PHONY += vmlinux
1302 # LDFLAGS_vmlinux in the top Makefile defines linker flags for the top vmlinux,
1303 # not for decompressors. LDFLAGS_vmlinux in arch/*/boot/compressed/Makefile is
1304 # unrelated; the decompressors just happen to have the same base name,
1305 # arch/*/boot/compressed/vmlinux.
1306 # Export LDFLAGS_vmlinux only to scripts/Makefile.vmlinux.
1307 #
1308 # _LDFLAGS_vmlinux is a workaround for the 'private export' bug:
1309 # https://savannah.gnu.org/bugs/?61463
1310 # For Make > 4.4, the following simple code will work:
1311 # vmlinux: private export LDFLAGS_vmlinux := $(LDFLAGS_vmlinux)
1312 vmlinux: private _LDFLAGS_vmlinux := $(LDFLAGS_vmlinux)
1313 vmlinux: export LDFLAGS_vmlinux = $(_LDFLAGS_vmlinux)
1314 vmlinux: vmlinux.o $(KBUILD_LDS) modpost
1315 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux
1316
1317 # The actual objects are generated when descending,
1318 # make sure no implicit rule kicks in
1319 $(sort $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)): . ;
1320
1321 ifeq ($(origin KERNELRELEASE),file)
1322 filechk_kernel.release = $(srctree)/scripts/setlocalversion $(srctree)
1323 else
1324 filechk_kernel.release = echo $(KERNELRELEASE)
1325 endif
1326
1327 # Store (new) KERNELRELEASE string in include/config/kernel.release
1328 include/config/kernel.release: FORCE
1329 $(call filechk,kernel.release)
1330
1331 # Additional helpers built in scripts/
1332 # Carefully list dependencies so we do not try to build scripts twice
1333 # in parallel
1334 PHONY += scripts
1335 scripts: scripts_basic scripts_dtc
1336 $(Q)$(MAKE) $(build)=$(@)
1337
1338 # Things we need to do before we recursively start building the kernel
1339 # or the modules are listed in "prepare".
1340 # A multi level approach is used. prepareN is processed before prepareN-1.
1341 # archprepare is used in arch Makefiles and when processed asm symlink,
1342 # version.h and scripts_basic is processed / created.
1343
1344 PHONY += prepare archprepare
1345
1346 archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \
1347 asm-generic $(version_h) include/generated/utsrelease.h \
1348 include/generated/compile.h include/generated/autoconf.h \
1349 include/generated/rustc_cfg include/generated/package.h remove-stale-files
1350
1351 prepare0: archprepare
1352 $(Q)$(MAKE) $(build)=scripts/mod
1353 $(Q)$(MAKE) $(build)=. prepare
1354
1355 # All the preparing..
1356 prepare: prepare0
1357 ifdef CONFIG_RUST
1358 +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh
1359 $(Q)$(MAKE) $(build)=rust
1360 endif
1361
1362 PHONY += remove-stale-files
1363 remove-stale-files:
1364 $(Q)$(srctree)/scripts/remove-stale-files
1365
1366 # Support for using generic headers in asm-generic
1367 asm-generic := -f $(srctree)/scripts/Makefile.asm-headers obj
1368
1369 PHONY += asm-generic uapi-asm-generic
1370 asm-generic: uapi-asm-generic
1371 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \
1372 generic=include/asm-generic
1373 uapi-asm-generic:
1374 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \
1375 generic=include/uapi/asm-generic
1376
1377 # Generate some files
1378 # ---------------------------------------------------------------------------
1379
1380 # KERNELRELEASE can change from a few different places, meaning version.h
1381 # needs to be updated, so this check is forced on all builds
1382
1383 uts_len := 64
1384 define filechk_utsrelease.h
1385 if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
1386 echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
1387 exit 1; \
1388 fi; \
1389 echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"
1390 endef
1391
1392 define filechk_version.h
1393 if [ $(SUBLEVEL) -gt 255 ]; then \
1394 echo \#define LINUX_VERSION_CODE $(shell \
1395 expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + 255); \
1396 else \
1397 echo \#define LINUX_VERSION_CODE $(shell \
1398 expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \
1399 fi; \
1400 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \
1401 ((c) > 255 ? 255 : (c)))'; \
1402 echo \#define LINUX_VERSION_MAJOR $(VERSION); \
1403 echo \#define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL); \
1404 echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL)
1405 endef
1406
1407 ifneq ($(DISTRIBUTION_OFFICIAL_BUILD),)
1408 define filechk_package.h
1409 echo \#define LINUX_PACKAGE_ID \" $(DISTRIBUTOR) $(DISTRIBUTION_VERSION)\"
1410 endef
1411 else
1412 define filechk_package.h
1413 echo \#define LINUX_PACKAGE_ID \"\"
1414 endef
1415 endif
1416
1417 $(version_h): private PATCHLEVEL := $(or $(PATCHLEVEL), 0)
1418 $(version_h): private SUBLEVEL := $(or $(SUBLEVEL), 0)
1419 $(version_h): FORCE
1420 $(call filechk,version.h)
1421
1422 include/generated/utsrelease.h: include/config/kernel.release FORCE
1423 $(call filechk,utsrelease.h)
1424
1425 filechk_compile.h = $(srctree)/scripts/mkcompile_h \
1426 "$(UTS_MACHINE)" "$(CONFIG_CC_VERSION_TEXT)" "$(LD)"
1427
1428 include/generated/compile.h: FORCE
1429 $(call filechk,compile.h)
1430
1431 include/generated/package.h: $(srctree)/Makefile FORCE
1432 $(call filechk,package.h)
1433
1434 PHONY += headerdep
1435 headerdep:
1436 $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \
1437 $(srctree)/scripts/headerdep.pl -I$(srctree)/include
1438
1439 # ---------------------------------------------------------------------------
1440 # Kernel headers
1441
1442 #Default location for installed headers
1443 export INSTALL_HDR_PATH = $(objtree)/usr
1444
1445 quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include
1446 cmd_headers_install = \
1447 mkdir -p $(INSTALL_HDR_PATH); \
1448 rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
1449 usr/include $(INSTALL_HDR_PATH)
1450
1451 PHONY += headers_install
1452 headers_install: headers
1453 $(call cmd,headers_install)
1454
1455 PHONY += archheaders archscripts
1456
1457 hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
1458
1459 PHONY += headers
1460 headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders
1461 ifdef HEADER_ARCH
1462 $(Q)$(MAKE) -f $(srctree)/Makefile HEADER_ARCH= SRCARCH=$(HEADER_ARCH) headers
1463 else
1464 $(Q)$(MAKE) $(hdr-inst)=include/uapi
1465 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi
1466 endif
1467
1468 ifdef CONFIG_HEADERS_INSTALL
1469 prepare: headers
1470 endif
1471
1472 PHONY += usr_gen_init_cpio
1473 usr_gen_init_cpio: scripts_basic
1474 $(Q)$(MAKE) $(build)=usr usr/gen_init_cpio
1475
1476 PHONY += scripts_unifdef
1477 scripts_unifdef: scripts_basic
1478 $(Q)$(MAKE) $(build)=scripts scripts/unifdef
1479
1480 PHONY += scripts_gen_packed_field_checks
1481 scripts_gen_packed_field_checks: scripts_basic
1482 $(Q)$(MAKE) $(build)=scripts scripts/gen_packed_field_checks
1483
1484 # ---------------------------------------------------------------------------
1485 # Install
1486
1487 # Many distributions have the custom install script, /sbin/installkernel.
1488 # If DKMS is installed, 'make install' will eventually recurse back
1489 # to this Makefile to build and install external modules.
1490 # Cancel sub_make_done so that options such as M=, V=, etc. are parsed.
1491
1492 quiet_cmd_install = INSTALL $(INSTALL_PATH)
1493 cmd_install = unset sub_make_done; $(srctree)/scripts/install.sh
1494
1495 # ---------------------------------------------------------------------------
1496 # vDSO install
1497
1498 PHONY += vdso_install
1499 vdso_install: export INSTALL_FILES = $(vdso-install-y)
1500 vdso_install:
1501 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vdsoinst
1502
1503 # ---------------------------------------------------------------------------
1504 # Tools
1505
1506 ifdef CONFIG_OBJTOOL
1507 prepare: tools/objtool
1508 endif
1509
1510 ifdef CONFIG_BPF
1511 ifdef CONFIG_DEBUG_INFO_BTF
1512 prepare: tools/bpf/resolve_btfids
1513 endif
1514 endif
1515
1516 # The tools build system is not a part of Kbuild and tends to introduce
1517 # its own unique issues. If you need to integrate a new tool into Kbuild,
1518 # please consider locating that tool outside the tools/ tree and using the
1519 # standard Kbuild "hostprogs" syntax instead of adding a new tools/* entry
1520 # here. See Documentation/kbuild/makefiles.rst for details.
1521
1522 PHONY += resolve_btfids_clean
1523
1524 resolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids
1525
1526 # tools/bpf/resolve_btfids directory might not exist
1527 # in output directory, skip its clean in that case
1528 resolve_btfids_clean:
1529 ifneq ($(wildcard $(resolve_btfids_O)),)
1530 $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean
1531 endif
1532
1533 PHONY += objtool_clean objtool_mrproper
1534
1535 objtool_O = $(abspath $(objtree))/tools/objtool
1536
1537 objtool_clean objtool_mrproper:
1538 ifneq ($(wildcard $(objtool_O)),)
1539 $(Q)$(MAKE) -sC $(abs_srctree)/tools/objtool O=$(objtool_O) srctree=$(abs_srctree) $(patsubst objtool_%,%,$@)
1540 endif
1541
1542 tools/: FORCE
1543 $(Q)mkdir -p $(objtree)/tools
1544 $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
1545
1546 tools/%: FORCE
1547 $(Q)mkdir -p $(objtree)/tools
1548 $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
1549
1550 # ---------------------------------------------------------------------------
1551 # Kernel selftest
1552
1553 PHONY += kselftest
1554 kselftest: headers
1555 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests
1556
1557 kselftest-%: headers FORCE
1558 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
1559
1560 PHONY += kselftest-merge
1561 kselftest-merge:
1562 $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!))
1563 $(Q)find $(srctree)/tools/testing/selftests -name config -o -name config.$(UTS_MACHINE) | \
1564 xargs $(srctree)/scripts/kconfig/merge_config.sh -y -m $(objtree)/.config
1565 $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
1566
1567 # ---------------------------------------------------------------------------
1568 # Devicetree files
1569
1570 ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)
1571 dtstree := arch/$(SRCARCH)/boot/dts
1572 endif
1573
1574 dtbindingtree := Documentation/devicetree/bindings
1575
1576 %.yaml: dtbs_prepare
1577 $(Q)$(MAKE) $(build)=$(dtbindingtree) \
1578 $(dtbindingtree)/$(patsubst %.yaml,%.example.dtb,$@) dt_binding_check_one
1579
1580 ifneq ($(dtstree),)
1581
1582 %.dtb: dtbs_prepare
1583 $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
1584
1585 %.dtbo: dtbs_prepare
1586 $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
1587
1588 PHONY += dtbs dtbs_prepare dtbs_install dtbs_check
1589 dtbs: dtbs_prepare
1590 $(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1
1591
1592 # include/config/kernel.release is actually needed when installing DTBs because
1593 # INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make
1594 # dtbs_install depend on it as dtbs_install may run as root.
1595 dtbs_prepare: include/config/kernel.release scripts_dtc
1596
1597 ifneq ($(filter dtbs_check %.yaml, $(MAKECMDGOALS)),)
1598 export CHECK_DTBS=y
1599 endif
1600
1601 ifneq ($(CHECK_DTBS),)
1602 dtbs_prepare: dt_binding_schemas
1603 endif
1604
1605 dtbs_check: dtbs
1606
1607 dtbs_install:
1608 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree)
1609
1610 ifdef CONFIG_OF_EARLY_FLATTREE
1611 all: dtbs
1612 endif
1613
1614 ifdef CONFIG_GENERIC_BUILTIN_DTB
1615 vmlinux: dtbs
1616 endif
1617
1618 endif
1619
1620 PHONY += scripts_dtc
1621 scripts_dtc: scripts_basic
1622 $(Q)$(MAKE) $(build)=scripts/dtc
1623
1624 ifneq ($(filter dt_binding_check, $(MAKECMDGOALS)),)
1625 export CHECK_DTBS=y
1626 endif
1627
1628 PHONY += dt_binding_check dt_binding_schemas
1629 dt_binding_check: dt_binding_schemas scripts_dtc
1630 $(Q)$(MAKE) $(build)=$(dtbindingtree) $@
1631
1632 dt_binding_schemas:
1633 $(Q)$(MAKE) $(build)=$(dtbindingtree)
1634
1635 PHONY += dt_compatible_check
1636 dt_compatible_check: dt_binding_schemas
1637 $(Q)$(MAKE) $(build)=$(dtbindingtree) $@
1638
1639 # ---------------------------------------------------------------------------
1640 # Modules
1641
1642 ifdef CONFIG_MODULES
1643
1644 # By default, build modules as well
1645
1646 all: modules
1647
1648 # When we're building modules with modversions, we need to consider
1649 # the built-in objects during the descend as well, in order to
1650 # make sure the checksums are up to date before we record them.
1651 ifdef CONFIG_MODVERSIONS
1652 KBUILD_BUILTIN := y
1653 endif
1654
1655 # Build modules
1656 #
1657
1658 # *.ko are usually independent of vmlinux, but CONFIG_DEBUG_INFO_BTF_MODULES
1659 # is an exception.
1660 ifdef CONFIG_DEBUG_INFO_BTF_MODULES
1661 KBUILD_BUILTIN := y
1662 modules: vmlinux
1663 endif
1664
1665 modules: modules_prepare
1666
1667 # Target to prepare building external modules
1668 modules_prepare: prepare
1669 $(Q)$(MAKE) $(build)=scripts scripts/module.lds
1670
1671 endif # CONFIG_MODULES
1672
1673 ###
1674 # Cleaning is done on three levels.
1675 # make clean Delete most generated files
1676 # Leave enough to build external modules
1677 # make mrproper Delete the current configuration, and all generated files
1678 # make distclean Remove editor backup files, patch leftover files and the like
1679
1680 # Directories & files removed with 'make clean'
1681 CLEAN_FILES += vmlinux.symvers modules-only.symvers \
1682 modules.builtin modules.builtin.modinfo modules.nsdeps \
1683 modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \
1684 compile_commands.json rust/test \
1685 rust-project.json .vmlinux.objs .vmlinux.export.c \
1686 .builtin-dtbs-list .builtin-dtbs.S
1687
1688 # Directories & files removed with 'make mrproper'
1689 MRPROPER_FILES += include/config include/generated \
1690 arch/$(SRCARCH)/include/generated .objdiff \
1691 debian snap tar-install PKGBUILD pacman \
1692 .config .config.old .version \
1693 Module.symvers \
1694 certs/signing_key.pem \
1695 certs/x509.genkey \
1696 vmlinux-gdb.py \
1697 rpmbuild \
1698 rust/libmacros.so rust/libmacros.dylib \
1699 rust/libpin_init_internal.so rust/libpin_init_internal.dylib
1700
1701 # clean - Delete most, but leave enough to build external modules
1702 #
1703 clean: private rm-files := $(CLEAN_FILES)
1704
1705 PHONY += archclean vmlinuxclean
1706
1707 vmlinuxclean:
1708 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
1709 $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
1710
1711 clean: archclean vmlinuxclean resolve_btfids_clean objtool_clean
1712
1713 # mrproper - Delete all generated files, including .config
1714 #
1715 mrproper: private rm-files := $(MRPROPER_FILES)
1716 mrproper-dirs := $(addprefix _mrproper_,scripts)
1717
1718 PHONY += $(mrproper-dirs) mrproper
1719 $(mrproper-dirs):
1720 $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
1721
1722 mrproper: clean objtool_mrproper $(mrproper-dirs)
1723 $(call cmd,rmfiles)
1724 @find . $(RCS_FIND_IGNORE) \
1725 \( -name '*.rmeta' \) \
1726 -type f -print | xargs rm -f
1727
1728 # distclean
1729 #
1730 PHONY += distclean
1731
1732 distclean: mrproper
1733 @find . $(RCS_FIND_IGNORE) \
1734 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
1735 -o -name '*.bak' -o -name '#*#' -o -name '*%' \
1736 -o -name 'core' -o -name tags -o -name TAGS -o -name 'cscope*' \
1737 -o -name GPATH -o -name GRTAGS -o -name GSYMS -o -name GTAGS \) \
1738 -type f -print | xargs rm -f
1739
1740
1741 # Packaging of the kernel to various formats
1742 # ---------------------------------------------------------------------------
1743
1744 modules-cpio-pkg: usr_gen_init_cpio
1745
1746 %src-pkg: FORCE
1747 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
1748 %pkg: include/config/kernel.release FORCE
1749 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
1750
1751 # Brief documentation of the typical targets used
1752 # ---------------------------------------------------------------------------
1753
1754 boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig)
1755 boards := $(sort $(notdir $(boards)))
1756 board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
1757 board-dirs := $(sort $(notdir $(board-dirs:/=)))
1758
1759 PHONY += help
1760 help:
1761 @echo 'Cleaning targets:'
1762 @echo ' clean - Remove most generated files but keep the config and'
1763 @echo ' enough build support to build external modules'
1764 @echo ' mrproper - Remove all generated files + config + various backup files'
1765 @echo ' distclean - mrproper + remove editor backup and patch files'
1766 @echo ''
1767 @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
1768 @echo ''
1769 @echo 'Other generic targets:'
1770 @echo ' all - Build all targets marked with [*]'
1771 @echo '* vmlinux - Build the bare kernel'
1772 @echo '* modules - Build all modules'
1773 @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
1774 @echo ' vdso_install - Install unstripped vdso to INSTALL_MOD_PATH (default: /)'
1775 @echo ' dir/ - Build all files in dir and below'
1776 @echo ' dir/file.[ois] - Build specified target only'
1777 @echo ' dir/file.ll - Build the LLVM assembly file'
1778 @echo ' (requires compiler support for LLVM assembly generation)'
1779 @echo ' dir/file.lst - Build specified mixed source/assembly target only'
1780 @echo ' (requires a recent binutils and recent build (System.map))'
1781 @echo ' dir/file.ko - Build module including final link'
1782 @echo ' modules_prepare - Set up for building external modules'
1783 @echo ' tags/TAGS - Generate tags file for editors'
1784 @echo ' cscope - Generate cscope index'
1785 @echo ' gtags - Generate GNU GLOBAL index'
1786 @echo ' kernelrelease - Output the release version string (use with make -s)'
1787 @echo ' kernelversion - Output the version stored in Makefile (use with make -s)'
1788 @echo ' image_name - Output the image name (use with make -s)'
1789 @echo ' headers - Build ready-to-install UAPI headers in usr/include'
1790 @echo ' headers_install - Install sanitised kernel UAPI headers to INSTALL_HDR_PATH'; \
1791 echo ' (default: $(INSTALL_HDR_PATH))'; \
1792 echo ''
1793 @echo 'Static analysers:'
1794 @echo ' checkstack - Generate a list of stack hogs and consider all functions'
1795 @echo ' with a stack size larger than MINSTACKSIZE (default: 100)'
1796 @echo ' versioncheck - Sanity check on version.h usage'
1797 @echo ' includecheck - Check for duplicate included header files'
1798 @echo ' headerdep - Detect inclusion cycles in headers'
1799 @echo ' coccicheck - Check with Coccinelle'
1800 @echo ' clang-analyzer - Check with clang static analyzer'
1801 @echo ' clang-tidy - Check with clang-tidy'
1802 @echo ''
1803 @echo 'Tools:'
1804 @echo ' nsdeps - Generate missing symbol namespace dependencies'
1805 @echo ''
1806 @echo 'Kernel selftest:'
1807 @echo ' kselftest - Build and run kernel selftest'
1808 @echo ' Build, install, and boot kernel before'
1809 @echo ' running kselftest on it'
1810 @echo ' Run as root for full coverage'
1811 @echo ' kselftest-all - Build kernel selftest'
1812 @echo ' kselftest-install - Build and install kernel selftest'
1813 @echo ' kselftest-clean - Remove all generated kselftest files'
1814 @echo ' kselftest-merge - Merge all the config dependencies of'
1815 @echo ' kselftest to existing .config.'
1816 @echo ''
1817 @echo 'Rust targets:'
1818 @echo ' rustavailable - Checks whether the Rust toolchain is'
1819 @echo ' available and, if not, explains why.'
1820 @echo ' rustfmt - Reformat all the Rust code in the kernel'
1821 @echo ' rustfmtcheck - Checks if all the Rust code in the kernel'
1822 @echo ' is formatted, printing a diff otherwise.'
1823 @echo ' rustdoc - Generate Rust documentation'
1824 @echo ' (requires kernel .config)'
1825 @echo ' rusttest - Runs the Rust tests'
1826 @echo ' (requires kernel .config; downloads external repos)'
1827 @echo ' rust-analyzer - Generate rust-project.json rust-analyzer support file'
1828 @echo ' (requires kernel .config)'
1829 @echo ' dir/file.[os] - Build specified target only'
1830 @echo ' dir/file.rsi - Build macro expanded source, similar to C preprocessing.'
1831 @echo ' Run with RUSTFMT=n to skip reformatting if needed.'
1832 @echo ' The output is not intended to be compilable.'
1833 @echo ' dir/file.ll - Build the LLVM assembly file'
1834 @echo ''
1835 @$(if $(dtstree), \
1836 echo 'Devicetree:'; \
1837 echo '* dtbs - Build device tree blobs for enabled boards'; \
1838 echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \
1839 echo ' dt_binding_check - Validate device tree binding documents and examples'; \
1840 echo ' dt_binding_schemas - Build processed device tree binding schemas'; \
1841 echo ' dtbs_check - Validate device tree source files';\
1842 echo '')
1843
1844 @echo 'Userspace tools targets:'
1845 @echo ' use "make tools/help"'
1846 @echo ' or "cd tools; make help"'
1847 @echo ''
1848 @echo 'Kernel packaging:'
1849 @$(MAKE) -f $(srctree)/scripts/Makefile.package help
1850 @echo ''
1851 @echo 'Documentation targets:'
1852 @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
1853 @echo ''
1854 @echo 'Architecture-specific targets ($(SRCARCH)):'
1855 @$(or $(archhelp),\
1856 echo ' No architecture-specific help defined for $(SRCARCH)')
1857 @echo ''
1858 @$(if $(boards), \
1859 $(foreach b, $(boards), \
1860 printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
1861 echo '')
1862 @$(if $(board-dirs), \
1863 $(foreach b, $(board-dirs), \
1864 printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
1865 printf " %-16s - Show all of the above\\n" help-boards; \
1866 echo '')
1867
1868 @echo ' make V=n [targets] 1: verbose build'
1869 @echo ' 2: give reason for rebuild of target'
1870 @echo ' V=1 and V=2 can be combined with V=12'
1871 @echo ' make O=dir [targets] Locate all output files in "dir", including .config'
1872 @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK'
1873 @echo ' (sparse by default)'
1874 @echo ' make C=2 [targets] Force check of all c source with $$CHECK'
1875 @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections'
1876 @echo ' make W=n [targets] Enable extra build checks, n=1,2,3,c,e where'
1877 @echo ' 1: warnings which may be relevant and do not occur too often'
1878 @echo ' 2: warnings which occur quite often but may still be relevant'
1879 @echo ' 3: more obscure warnings, can most likely be ignored'
1880 @echo ' c: extra checks in the configuration stage (Kconfig)'
1881 @echo ' e: warnings are being treated as errors'
1882 @echo ' Multiple levels can be combined with W=12 or W=123'
1883 @echo ' make UT=1 [targets] Warn if a tracepoint is defined but not used.'
1884 @echo ' [ This will be removed when all current unused tracepoints are eliminated. ]'
1885 @$(if $(dtstree), \
1886 echo ' make CHECK_DTBS=1 [targets] Check all generated dtb files against schema'; \
1887 echo ' This can be applied both to "dtbs" and to individual "foo.dtb" targets' ; \
1888 )
1889 @echo ''
1890 @echo 'Execute "make" or "make all" to build all targets marked with [*] '
1891 @echo 'For further info see the ./README file'
1892
1893
1894 help-board-dirs := $(addprefix help-,$(board-dirs))
1895
1896 help-boards: $(help-board-dirs)
1897
1898 boards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)))
1899
1900 $(help-board-dirs): help-%:
1901 @echo 'Architecture-specific targets ($(SRCARCH) $*):'
1902 @$(if $(boards-per-dir), \
1903 $(foreach b, $(boards-per-dir), \
1904 printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
1905 echo '')
1906
1907
1908 # Documentation targets
1909 # ---------------------------------------------------------------------------
1910 DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \
1911 linkcheckdocs dochelp refcheckdocs texinfodocs infodocs mandocs \
1912 htmldocs-redirects
1913
1914 PHONY += $(DOC_TARGETS)
1915 $(DOC_TARGETS):
1916 $(Q)$(MAKE) $(build)=Documentation $@
1917
1918
1919 # Rust targets
1920 # ---------------------------------------------------------------------------
1921
1922 # "Is Rust available?" target
1923 PHONY += rustavailable
1924 rustavailable:
1925 +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh && echo "Rust is available!"
1926
1927 # Documentation target
1928 #
1929 # Using the singular to avoid running afoul of `no-dot-config-targets`.
1930 PHONY += rustdoc
1931 rustdoc: prepare
1932 $(Q)$(MAKE) $(build)=rust $@
1933
1934 # Testing target
1935 PHONY += rusttest
1936 rusttest: prepare
1937 $(Q)$(MAKE) $(build)=rust $@
1938
1939 # Formatting targets
1940 #
1941 # Generated files as well as vendored crates are skipped.
1942 PHONY += rustfmt rustfmtcheck
1943
1944 rustfmt:
1945 $(Q)find $(srctree) $(RCS_FIND_IGNORE) \
1946 \( \
1947 -path $(srctree)/rust/proc-macro2 \
1948 -o -path $(srctree)/rust/quote \
1949 -o -path $(srctree)/rust/syn \
1950 \) -prune -o \
1951 -type f -a -name '*.rs' -a ! -name '*generated*' -print \
1952 | xargs $(RUSTFMT) $(rustfmt_flags)
1953
1954 rustfmtcheck: rustfmt_flags = --check
1955 rustfmtcheck: rustfmt
1956
1957 # Misc
1958 # ---------------------------------------------------------------------------
1959
1960 PHONY += misc-check
1961 misc-check:
1962 $(Q)$(srctree)/scripts/misc-check
1963
1964 all: misc-check
1965
1966 PHONY += scripts_gdb
1967 scripts_gdb: prepare0
1968 $(Q)$(MAKE) $(build)=scripts/gdb
1969 $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
1970
1971 ifdef CONFIG_GDB_SCRIPTS
1972 all: scripts_gdb
1973 endif
1974
1975 else # KBUILD_EXTMOD
1976
1977 filechk_kernel.release = echo $(KERNELRELEASE)
1978
1979 ###
1980 # External module support.
1981 # When building external modules the kernel used as basis is considered
1982 # read-only, and no consistency checks are made and the make
1983 # system is not used on the basis kernel. If updates are required
1984 # in the basis kernel ordinary make commands (without M=...) must be used.
1985
1986 # We are always building only modules.
1987 KBUILD_BUILTIN :=
1988 KBUILD_MODULES := y
1989
1990 build-dir := .
1991
1992 clean-dirs := .
1993 clean: private rm-files := Module.symvers modules.nsdeps compile_commands.json
1994
1995 PHONY += prepare
1996 # now expand this into a simple variable to reduce the cost of shell evaluations
1997 prepare: CC_VERSION_TEXT := $(CC_VERSION_TEXT)
1998 prepare: PAHOLE_VERSION := $(PAHOLE_VERSION)
1999 prepare:
2000 @if [ -z "$(DEBIAN_KERNEL_NO_CC_VERSION_CHECK)" ] && [ "$(CC_VERSION_TEXT)" != "$(CONFIG_CC_VERSION_TEXT)" ]; then \
2001 echo >&2 "warning: the compiler differs from the one used to build the kernel"; \
2002 echo >&2 " The kernel was built by: $(CONFIG_CC_VERSION_TEXT)"; \
2003 echo >&2 " You are using: $(CC_VERSION_TEXT)"; \
2004 fi
2005 @if [ "$(PAHOLE_VERSION)" != "$(CONFIG_PAHOLE_VERSION)" ]; then \
2006 echo >&2 "warning: pahole version differs from the one used to build the kernel"; \
2007 echo >&2 " The kernel was built with: $(CONFIG_PAHOLE_VERSION)"; \
2008 echo >&2 " You are using: $(PAHOLE_VERSION)"; \
2009 fi
2010
2011 PHONY += help
2012 help:
2013 @echo ' Building external modules.'
2014 @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target'
2015 @echo ''
2016 @echo ' modules - default target, build the module(s)'
2017 @echo ' modules_install - install the module'
2018 @echo ' clean - remove generated files in module directory only'
2019 @echo ' rust-analyzer - generate rust-project.json rust-analyzer support file'
2020 @echo ''
2021
2022 ifndef CONFIG_MODULES
2023 modules modules_install: __external_modules_error
2024 __external_modules_error:
2025 @echo >&2 '***'
2026 @echo >&2 '*** The present kernel disabled CONFIG_MODULES.'
2027 @echo >&2 '*** You cannot build or install external modules.'
2028 @echo >&2 '***'
2029 @false
2030 endif
2031
2032 endif # KBUILD_EXTMOD
2033
2034 # ---------------------------------------------------------------------------
2035 # Modules
2036
2037 PHONY += modules modules_install modules_sign modules_prepare
2038
2039 modules_install:
2040 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst \
2041 sign-only=$(if $(filter modules_install,$(MAKECMDGOALS)),,y)
2042
2043 ifeq ($(CONFIG_MODULE_SIG),y)
2044 # modules_sign is a subset of modules_install.
2045 # 'make modules_install modules_sign' is equivalent to 'make modules_install'.
2046 modules_sign: modules_install
2047 @:
2048 else
2049 modules_sign:
2050 @echo >&2 '***'
2051 @echo >&2 '*** CONFIG_MODULE_SIG is disabled. You cannot sign modules.'
2052 @echo >&2 '***'
2053 @false
2054 endif
2055
2056 ifdef CONFIG_MODULES
2057
2058 modules.order: $(build-dir)
2059 @:
2060
2061 # KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
2062 # This is solely useful to speed up test compiles.
2063 modules: modpost
2064 ifneq ($(KBUILD_MODPOST_NOFINAL),1)
2065 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
2066 endif
2067
2068 PHONY += modules_check
2069 modules_check: modules.order
2070 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
2071
2072 else # CONFIG_MODULES
2073
2074 modules:
2075 @:
2076
2077 KBUILD_MODULES :=
2078
2079 endif # CONFIG_MODULES
2080
2081 PHONY += modpost
2082 modpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \
2083 $(if $(KBUILD_MODULES), modules_check)
2084 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
2085
2086 # Single targets
2087 # ---------------------------------------------------------------------------
2088 # To build individual files in subdirectories, you can do like this:
2089 #
2090 # make foo/bar/baz.s
2091 #
2092 # The supported suffixes for single-target are listed in 'single-targets'
2093 #
2094 # To build only under specific subdirectories, you can do like this:
2095 #
2096 # make foo/bar/baz/
2097
2098 ifdef single-build
2099
2100 # .ko is special because modpost is needed
2101 single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
2102 single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
2103 $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
2104
2105 $(single-ko): single_modules
2106 @:
2107 $(single-no-ko): $(build-dir)
2108 @:
2109
2110 # Remove modules.order when done because it is not the real one.
2111 PHONY += single_modules
2112 single_modules: $(single-no-ko) modules_prepare
2113 $(Q){ $(foreach m, $(single-ko), echo $(m:%.ko=%.o);) } > modules.order
2114 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
2115 ifneq ($(KBUILD_MODPOST_NOFINAL),1)
2116 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
2117 endif
2118 $(Q)rm -f modules.order
2119
2120 single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
2121
2122 KBUILD_MODULES := y
2123
2124 endif
2125
2126 prepare: outputmakefile
2127
2128 # Preset locale variables to speed up the build process. Limit locale
2129 # tweaks to this spot to avoid wrong language settings when running
2130 # make menuconfig etc.
2131 # Error messages still appears in the original language
2132 PHONY += $(build-dir)
2133 $(build-dir): prepare
2134 $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals)
2135
2136 clean-dirs := $(addprefix _clean_, $(clean-dirs))
2137 PHONY += $(clean-dirs) clean
2138 $(clean-dirs):
2139 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
2140
2141 clean: $(clean-dirs)
2142 $(call cmd,rmfiles)
2143 @find . $(RCS_FIND_IGNORE) \
2144 \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \
2145 -o -name '*.ko.*' \
2146 -o -name '*.dtb' -o -name '*.dtbo' \
2147 -o -name '*.dtb.S' -o -name '*.dtbo.S' \
2148 -o -name '*.dt.yaml' -o -name 'dtbs-list' \
2149 -o -name '*.dwo' -o -name '*.lst' \
2150 -o -name '*.su' -o -name '*.mod' \
2151 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
2152 -o -name '*.lex.c' -o -name '*.tab.[ch]' \
2153 -o -name '*.asn1.[ch]' \
2154 -o -name '*.symtypes' -o -name 'modules.order' \
2155 -o -name '*.c.[012]*.*' \
2156 -o -name '*.ll' \
2157 -o -name '*.gcno' \
2158 \) -type f -print \
2159 -o -name '.tmp_*' -print \
2160 | xargs rm -rf
2161
2162 # Generate tags for editors
2163 # ---------------------------------------------------------------------------
2164 quiet_cmd_tags = GEN $@
2165 cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@
2166
2167 tags TAGS cscope gtags: FORCE
2168 $(call cmd,tags)
2169
2170 # Generate rust-project.json (a file that describes the structure of non-Cargo
2171 # Rust projects) for rust-analyzer (an implementation of the Language Server
2172 # Protocol).
2173 PHONY += rust-analyzer
2174 rust-analyzer:
2175 +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh
2176 ifdef KBUILD_EXTMOD
2177 # FIXME: external modules must not descend into a sub-directory of the kernel
2178 $(Q)$(MAKE) $(build)=$(objtree)/rust src=$(srctree)/rust $@
2179 else
2180 $(Q)$(MAKE) $(build)=rust $@
2181 endif
2182
2183 # Script to generate missing namespace dependencies
2184 # ---------------------------------------------------------------------------
2185
2186 PHONY += nsdeps
2187 nsdeps: export KBUILD_NSDEPS=1
2188 nsdeps: modules
2189 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps
2190
2191 # Clang Tooling
2192 # ---------------------------------------------------------------------------
2193
2194 quiet_cmd_gen_compile_commands = GEN $@
2195 cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
2196
2197 compile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \
2198 $(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \
2199 $(if $(CONFIG_MODULES), modules.order) FORCE
2200 $(call if_changed,gen_compile_commands)
2201
2202 targets += compile_commands.json
2203
2204 PHONY += clang-tidy clang-analyzer
2205
2206 ifdef CONFIG_CC_IS_CLANG
2207 quiet_cmd_clang_tools = CHECK $<
2208 cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $<
2209
2210 clang-tidy clang-analyzer: compile_commands.json
2211 $(call cmd,clang_tools)
2212 else
2213 clang-tidy clang-analyzer:
2214 @echo "$@ requires CC=clang" >&2
2215 @false
2216 endif
2217
2218 # Scripts to check various things for consistency
2219 # ---------------------------------------------------------------------------
2220
2221 PHONY += includecheck versioncheck coccicheck
2222
2223 includecheck:
2224 find $(srctree)/* $(RCS_FIND_IGNORE) \
2225 -name '*.[hcS]' -type f -print | sort \
2226 | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
2227
2228 versioncheck:
2229 find $(srctree)/* $(RCS_FIND_IGNORE) \
2230 -name '*.[hcS]' -type f -print | sort \
2231 | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
2232
2233 coccicheck:
2234 $(Q)$(BASH) $(srctree)/scripts/$@
2235
2236 PHONY += checkstack kernelrelease kernelversion image_name
2237
2238 # UML needs a little special treatment here. It wants to use the host
2239 # toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone
2240 # else wants $(ARCH), including people doing cross-builds, which means
2241 # that $(SUBARCH) doesn't work here.
2242 ifeq ($(ARCH), um)
2243 CHECKSTACK_ARCH := $(SUBARCH)
2244 else
2245 CHECKSTACK_ARCH := $(ARCH)
2246 endif
2247 MINSTACKSIZE ?= 100
2248 checkstack:
2249 $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
2250 $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH) $(MINSTACKSIZE)
2251
2252 kernelrelease:
2253 @$(filechk_kernel.release)
2254
2255 kernelversion:
2256 @echo $(KERNELVERSION)
2257
2258 image_name:
2259 @echo $(KBUILD_IMAGE)
2260
2261 PHONY += run-command
2262 run-command:
2263 $(Q)$(KBUILD_RUN_COMMAND)
2264
2265 quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
2266 cmd_rmfiles = rm -rf $(rm-files)
2267
2268 # read saved command lines for existing targets
2269 existing-targets := $(wildcard $(sort $(targets)))
2270
2271 -include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
2272
2273 endif # config-build
2274 endif # mixed-build
2275 endif # need-sub-make
2276
2277 PHONY += FORCE
2278 FORCE:
2279
2280 # Declare the contents of the PHONY variable as phony. We keep that
2281 # information in a variable so we can use it in if_changed and friends.
2282 .PHONY: $(PHONY)