• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# SPDX-License-Identifier: GPL-2.0
2VERSION = 5
3PATCHLEVEL = 10
4SUBLEVEL = 184
5EXTRAVERSION =
6NAME = Dare mighty things
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$(if $(filter __%, $(MAKECMDGOALS)), \
15	$(error targets prefixed with '__' are only for internal use))
16
17# That's our default target when none is given on the command line
18PHONY := __all
19__all:
20
21# We are using a recursive build, so we need to do a little thinking
22# to get the ordering right.
23#
24# Most importantly: sub-Makefiles should only ever modify files in
25# their own directory. If in some directory we have a dependency on
26# a file in another dir (which doesn't happen often, but it's often
27# unavoidable when linking the built-in.a targets which finally
28# turn into vmlinux), we will call a sub make in that other dir, and
29# after that we are sure that everything which is in that other dir
30# is now up to date.
31#
32# The only cases where we need to modify files which have global
33# effects are thus separated out and done before the recursive
34# descending is started. They are now explicitly listed as the
35# prepare rule.
36
37ifneq ($(sub_make_done),1)
38
39# Do not use make's built-in rules and variables
40# (this increases performance and avoids hard-to-debug behaviour)
41MAKEFLAGS += -rR
42
43# Avoid funny character set dependencies
44unexport LC_ALL
45LC_COLLATE=C
46LC_NUMERIC=C
47export LC_COLLATE LC_NUMERIC
48
49# Avoid interference with shell env settings
50unexport GREP_OPTIONS
51
52# Beautify output
53# ---------------------------------------------------------------------------
54#
55# Normally, we echo the whole command before executing it. By making
56# that echo $($(quiet)$(cmd)), we now have the possibility to set
57# $(quiet) to choose other forms of output instead, e.g.
58#
59#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
60#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
61#
62# If $(quiet) is empty, the whole command will be printed.
63# If it is set to "quiet_", only the short version will be printed.
64# If it is set to "silent_", nothing will be printed at all, since
65# the variable $(silent_cmd_cc_o_c) doesn't exist.
66#
67# A simple variant is to prefix commands with $(Q) - that's useful
68# for commands that shall be hidden in non-verbose mode.
69#
70#	$(Q)ln $@ :<
71#
72# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
73# If KBUILD_VERBOSE equals 1 then the above command is displayed.
74# If KBUILD_VERBOSE equals 2 then give the reason why each target is rebuilt.
75#
76# To put more focus on warnings, be less verbose as default
77# Use 'make V=1' to see the full commands
78
79ifeq ("$(origin V)", "command line")
80  KBUILD_VERBOSE = $(V)
81endif
82ifndef KBUILD_VERBOSE
83  KBUILD_VERBOSE = 0
84endif
85
86ifeq ($(KBUILD_VERBOSE),1)
87  quiet =
88  Q =
89else
90  quiet=quiet_
91  Q = @
92endif
93
94# If the user is running make -s (silent mode), suppress echoing of
95# commands
96# make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS.
97
98ifeq ($(filter 3.%,$(MAKE_VERSION)),)
99silence:=$(findstring s,$(firstword -$(MAKEFLAGS)))
100else
101silence:=$(findstring s,$(filter-out --%,$(MAKEFLAGS)))
102endif
103
104ifeq ($(silence),s)
105quiet=silent_
106endif
107
108export quiet Q KBUILD_VERBOSE
109
110# Kbuild will save output files in the current working directory.
111# This does not need to match to the root of the kernel source tree.
112#
113# For example, you can do this:
114#
115#  cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile
116#
117# If you want to save output files in a different location, there are
118# two syntaxes to specify it.
119#
120# 1) O=
121# Use "make O=dir/to/store/output/files/"
122#
123# 2) Set KBUILD_OUTPUT
124# Set the environment variable KBUILD_OUTPUT to point to the output directory.
125# export KBUILD_OUTPUT=dir/to/store/output/files/; make
126#
127# The O= assignment takes precedence over the KBUILD_OUTPUT environment
128# variable.
129
130# Do we want to change the working directory?
131ifeq ("$(origin O)", "command line")
132  KBUILD_OUTPUT := $(O)
133endif
134
135ifneq ($(KBUILD_OUTPUT),)
136# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
137# expand a shell special character '~'. We use a somewhat tedious way here.
138abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
139$(if $(abs_objtree),, \
140     $(error failed to create output directory "$(KBUILD_OUTPUT)"))
141
142# $(realpath ...) resolves symlinks
143abs_objtree := $(realpath $(abs_objtree))
144else
145abs_objtree := $(CURDIR)
146endif # ifneq ($(KBUILD_OUTPUT),)
147
148ifeq ($(abs_objtree),$(CURDIR))
149# Suppress "Entering directory ..." unless we are changing the work directory.
150MAKEFLAGS += --no-print-directory
151else
152need-sub-make := 1
153endif
154
155abs_srctree := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
156
157ifneq ($(words $(subst :, ,$(abs_srctree))), 1)
158$(error source directory cannot contain spaces or colons)
159endif
160
161ifneq ($(abs_srctree),$(abs_objtree))
162# Look for make include files relative to root of kernel src
163#
164# This does not become effective immediately because MAKEFLAGS is re-parsed
165# once after the Makefile is read. We need to invoke sub-make.
166MAKEFLAGS += --include-dir=$(abs_srctree)
167need-sub-make := 1
168endif
169
170this-makefile := $(lastword $(MAKEFILE_LIST))
171
172ifneq ($(filter 3.%,$(MAKE_VERSION)),)
173# 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x
174# We need to invoke sub-make to avoid implicit rules in the top Makefile.
175need-sub-make := 1
176# Cancel implicit rules for this Makefile.
177$(this-makefile): ;
178endif
179
180export abs_srctree abs_objtree
181export sub_make_done := 1
182
183ifeq ($(need-sub-make),1)
184
185PHONY += $(MAKECMDGOALS) __sub-make
186
187$(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
188	@:
189
190# Invoke a second make in the output directory, passing relevant variables
191__sub-make:
192	$(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
193
194endif # need-sub-make
195endif # sub_make_done
196
197# We process the rest of the Makefile if this is the final invocation of make
198ifeq ($(need-sub-make),)
199
200# Do not print "Entering directory ...",
201# but we want to display it when entering to the output directory
202# so that IDEs/editors are able to understand relative filenames.
203MAKEFLAGS += --no-print-directory
204
205# Call a source code checker (by default, "sparse") as part of the
206# C compilation.
207#
208# Use 'make C=1' to enable checking of only re-compiled files.
209# Use 'make C=2' to enable checking of *all* source files, regardless
210# of whether they are re-compiled or not.
211#
212# See the file "Documentation/dev-tools/sparse.rst" for more details,
213# including where to get the "sparse" utility.
214
215ifeq ("$(origin C)", "command line")
216  KBUILD_CHECKSRC = $(C)
217endif
218ifndef KBUILD_CHECKSRC
219  KBUILD_CHECKSRC = 0
220endif
221
222# Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the
223# directory of external module to build. Setting M= takes precedence.
224ifeq ("$(origin M)", "command line")
225  KBUILD_EXTMOD := $(M)
226endif
227
228$(if $(word 2, $(KBUILD_EXTMOD)), \
229	$(error building multiple external modules is not supported))
230
231export KBUILD_CHECKSRC KBUILD_EXTMOD
232
233extmod-prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)
234
235ifeq ($(abs_srctree),$(abs_objtree))
236        # building in the source tree
237        srctree := .
238	building_out_of_srctree :=
239else
240        ifeq ($(abs_srctree)/,$(dir $(abs_objtree)))
241                # building in a subdirectory of the source tree
242                srctree := ..
243        else
244                srctree := $(abs_srctree)
245        endif
246	building_out_of_srctree := 1
247endif
248
249ifneq ($(KBUILD_ABS_SRCTREE),)
250srctree := $(abs_srctree)
251endif
252
253objtree		:= .
254VPATH		:= $(srctree)
255
256export building_out_of_srctree srctree objtree VPATH
257
258# To make sure we do not include .config for any of the *config targets
259# catch them early, and hand them over to scripts/kconfig/Makefile
260# It is allowed to specify more targets when calling make, including
261# mixing *config targets and build targets.
262# For example 'make oldconfig all'.
263# Detect when mixed targets is specified, and make a second invocation
264# of make so .config is not included in this case either (for *config).
265
266version_h := include/generated/uapi/linux/version.h
267old_version_h := include/linux/version.h
268
269clean-targets := %clean mrproper cleandocs
270no-dot-config-targets := $(clean-targets) \
271			 cscope gtags TAGS tags help% %docs check% coccicheck \
272			 $(version_h) headers headers_% archheaders archscripts \
273			 %asm-generic kernelversion %src-pkg dt_binding_check \
274			 outputmakefile
275no-sync-config-targets := $(no-dot-config-targets) %install kernelrelease \
276			  image_name
277single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.s %.symtypes %/
278
279config-build	:=
280mixed-build	:=
281need-config	:= 1
282may-sync-config	:= 1
283single-build	:=
284
285ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
286	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
287		need-config :=
288	endif
289endif
290
291ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
292	ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
293		may-sync-config :=
294	endif
295endif
296
297ifneq ($(KBUILD_EXTMOD),)
298	may-sync-config :=
299endif
300
301ifeq ($(KBUILD_EXTMOD),)
302        ifneq ($(filter %config,$(MAKECMDGOALS)),)
303		config-build := 1
304                ifneq ($(words $(MAKECMDGOALS)),1)
305			mixed-build := 1
306                endif
307        endif
308endif
309
310# We cannot build single targets and the others at the same time
311ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),)
312	single-build := 1
313	ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),)
314		mixed-build := 1
315	endif
316endif
317
318# For "make -j clean all", "make -j mrproper defconfig all", etc.
319ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
320        ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
321		mixed-build := 1
322        endif
323endif
324
325# install and modules_install need also be processed one by one
326ifneq ($(filter install,$(MAKECMDGOALS)),)
327        ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
328		mixed-build := 1
329        endif
330endif
331
332ifdef mixed-build
333# ===========================================================================
334# We're called with mixed targets (*config and build targets).
335# Handle them one by one.
336
337PHONY += $(MAKECMDGOALS) __build_one_by_one
338
339$(MAKECMDGOALS): __build_one_by_one
340	@:
341
342__build_one_by_one:
343	$(Q)set -e; \
344	for i in $(MAKECMDGOALS); do \
345		$(MAKE) -f $(srctree)/Makefile $$i; \
346	done
347
348else # !mixed-build
349
350include scripts/Kbuild.include
351
352# Read KERNELRELEASE from include/config/kernel.release (if it exists)
353KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
354KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
355export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
356
357include scripts/subarch.include
358
359# Cross compiling and selecting different set of gcc/bin-utils
360# ---------------------------------------------------------------------------
361#
362# When performing cross compilation for other architectures ARCH shall be set
363# to the target architecture. (See arch/* for the possibilities).
364# ARCH can be set during invocation of make:
365# make ARCH=ia64
366# Another way is to have ARCH set in the environment.
367# The default ARCH is the host where make is executed.
368
369# CROSS_COMPILE specify the prefix used for all executables used
370# during compilation. Only gcc and related bin-utils executables
371# are prefixed with $(CROSS_COMPILE).
372# CROSS_COMPILE can be set on the command line
373# make CROSS_COMPILE=ia64-linux-
374# Alternatively CROSS_COMPILE can be set in the environment.
375# Default value for CROSS_COMPILE is not to prefix executables
376# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
377ARCH		?= $(SUBARCH)
378
379# Architecture as present in compile.h
380UTS_MACHINE 	:= $(ARCH)
381SRCARCH 	:= $(ARCH)
382
383# Additional ARCH settings for x86
384ifeq ($(ARCH),i386)
385        SRCARCH := x86
386endif
387ifeq ($(ARCH),x86_64)
388        SRCARCH := x86
389endif
390
391# Additional ARCH settings for sparc
392ifeq ($(ARCH),sparc32)
393       SRCARCH := sparc
394endif
395ifeq ($(ARCH),sparc64)
396       SRCARCH := sparc
397endif
398
399# Additional ARCH settings for sh
400ifeq ($(ARCH),sh64)
401       SRCARCH := sh
402endif
403
404KCONFIG_CONFIG	?= .config
405export KCONFIG_CONFIG
406
407# Default file for 'make defconfig'. This may be overridden by arch-Makefile.
408export KBUILD_DEFCONFIG := defconfig
409
410# SHELL used by kbuild
411CONFIG_SHELL := sh
412
413HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
414HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
415HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
416
417ifneq ($(LLVM),)
418HOSTCC	= clang
419HOSTCXX	= clang++
420else
421HOSTCC	= gcc
422HOSTCXX	= g++
423endif
424
425export KBUILD_USERCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
426			      -O2 -fomit-frame-pointer -std=gnu89
427export KBUILD_USERLDFLAGS :=
428
429KBUILD_HOSTCFLAGS   := $(KBUILD_USERCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
430KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
431KBUILD_HOSTLDFLAGS  := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
432KBUILD_HOSTLDLIBS   := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
433
434# Make variables (CC, etc...)
435CPP		= $(CC) -E
436CCACHE          = ccache
437ifneq ($(LLVM),)
438CC		= $(CCACHE) clang
439LD		= ld.lld
440AR		= llvm-ar
441NM		= llvm-nm
442OBJCOPY		= llvm-objcopy
443OBJDUMP		= llvm-objdump
444READELF		= llvm-readelf
445STRIP		= llvm-strip
446else
447CC		= $(CCACHE) $(CROSS_COMPILE)gcc
448LD		= $(CROSS_COMPILE)ld
449AR		= $(CROSS_COMPILE)ar
450NM		= $(CROSS_COMPILE)nm
451OBJCOPY		= $(CROSS_COMPILE)objcopy
452OBJDUMP		= $(CROSS_COMPILE)objdump
453READELF		= $(CROSS_COMPILE)readelf
454STRIP		= $(CROSS_COMPILE)strip
455endif
456PAHOLE		= pahole
457RESOLVE_BTFIDS	= $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
458LEX		= flex
459YACC		= bison
460AWK		= awk
461INSTALLKERNEL  := installkernel
462DEPMOD		= depmod
463PERL		= perl
464PYTHON		= python
465PYTHON3		= python3
466CHECK		= sparse
467BASH		= bash
468KGZIP		= gzip
469KBZIP2		= bzip2
470KLZOP		= lzop
471LZMA		= lzma
472LZ4		= lz4c
473XZ		= xz
474ZSTD		= zstd
475
476PAHOLE_FLAGS	= $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh)
477
478CHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
479		  -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
480NOSTDINC_FLAGS :=
481CFLAGS_MODULE   =
482AFLAGS_MODULE   =
483LDFLAGS_MODULE  =
484CFLAGS_KERNEL	=
485AFLAGS_KERNEL	=
486LDFLAGS_vmlinux =
487
488# Use USERINCLUDE when you must reference the UAPI directories only.
489USERINCLUDE    := \
490		-I$(srctree)/arch/$(SRCARCH)/include/uapi \
491		-I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
492		-I$(srctree)/include/uapi \
493		-I$(objtree)/include/generated/uapi \
494                -include $(srctree)/include/linux/kconfig.h
495
496# Use LINUXINCLUDE when you must reference the include/ directory.
497# Needed to be compatible with the O= option
498LINUXINCLUDE    := \
499		-I$(srctree)/arch/$(SRCARCH)/include \
500		-I$(objtree)/arch/$(SRCARCH)/include/generated \
501		$(if $(building_out_of_srctree),-I$(srctree)/include) \
502		-I$(objtree)/include \
503		$(USERINCLUDE)
504
505KBUILD_AFLAGS   := -D__ASSEMBLY__ -fno-PIE
506KBUILD_CFLAGS   := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
507		   -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
508		   -Werror=implicit-function-declaration -Werror=implicit-int \
509		   -Werror=return-type -Wno-format-security \
510		   -std=gnu89
511KBUILD_CPPFLAGS := -D__KERNEL__
512KBUILD_AFLAGS_KERNEL :=
513KBUILD_CFLAGS_KERNEL :=
514KBUILD_AFLAGS_MODULE  := -DMODULE
515KBUILD_CFLAGS_MODULE  := -DMODULE
516KBUILD_LDFLAGS_MODULE :=
517KBUILD_LDFLAGS :=
518CLANG_FLAGS :=
519
520export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
521export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
522export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
523export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD
524export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
525
526export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
527export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
528export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
529export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
530export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
531export PAHOLE_FLAGS
532
533# Files to ignore in find ... statements
534
535export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o    \
536			  -name CVS -o -name .pc -o -name .hg -o -name .git \) \
537			  -prune -o
538export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
539			 --exclude CVS --exclude .pc --exclude .hg --exclude .git
540
541# ===========================================================================
542# Rules shared between *config targets and build targets
543
544# Basic helpers built in scripts/basic/
545PHONY += scripts_basic
546scripts_basic:
547	$(Q)$(MAKE) $(build)=scripts/basic
548	$(Q)rm -f .tmp_quiet_recordmcount
549
550PHONY += outputmakefile
551# Before starting out-of-tree build, make sure the source tree is clean.
552# outputmakefile generates a Makefile in the output directory, if using a
553# separate output directory. This allows convenient use of make in the
554# output directory.
555# At the same time when output Makefile generated, generate .gitignore to
556# ignore whole output directory
557outputmakefile:
558ifdef building_out_of_srctree
559	$(Q)if [ -f $(srctree)/.config -o \
560		 -d $(srctree)/include/config -o \
561		 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
562		echo >&2 "***"; \
563		echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
564		echo >&2 "*** in $(abs_srctree)";\
565		echo >&2 "***"; \
566		false; \
567	fi
568	$(Q)ln -fsn $(srctree) source
569	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
570	$(Q)test -e .gitignore || \
571	{ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
572endif
573
574ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
575include $(srctree)/scripts/Makefile.clang
576endif
577
578# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
579# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
580# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
581# and from include/config/auto.conf.cmd to detect the compiler upgrade.
582CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1)
583
584ifdef config-build
585# ===========================================================================
586# *config targets only - make sure prerequisites are updated, and descend
587# in scripts/kconfig to make the *config target
588
589# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
590# KBUILD_DEFCONFIG may point out an alternative default configuration
591# used for 'make defconfig'
592include arch/$(SRCARCH)/Makefile
593export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
594
595config: outputmakefile scripts_basic FORCE
596	$(Q)$(MAKE) $(build)=scripts/kconfig $@
597
598%config: outputmakefile scripts_basic FORCE
599	$(Q)$(MAKE) $(build)=scripts/kconfig $@
600
601else #!config-build
602# ===========================================================================
603# Build targets only - this includes vmlinux, arch specific targets, clean
604# targets and others. In general all targets except *config targets.
605
606# If building an external module we do not care about the all: rule
607# but instead __all depend on modules
608PHONY += all
609ifeq ($(KBUILD_EXTMOD),)
610__all: all
611else
612__all: modules
613endif
614
615# Decide whether to build built-in, modular, or both.
616# Normally, just do built-in.
617
618KBUILD_MODULES :=
619KBUILD_BUILTIN := 1
620
621# If we have only "make modules", don't compile built-in objects.
622ifeq ($(MAKECMDGOALS),modules)
623  KBUILD_BUILTIN :=
624endif
625
626# If we have "make <whatever> modules", compile modules
627# in addition to whatever we do anyway.
628# Just "make" or "make all" shall build modules as well
629
630ifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECMDGOALS)),)
631  KBUILD_MODULES := 1
632endif
633
634ifeq ($(MAKECMDGOALS),)
635  KBUILD_MODULES := 1
636endif
637
638export KBUILD_MODULES KBUILD_BUILTIN
639
640ifdef need-config
641include include/config/auto.conf
642endif
643
644ifeq ($(KBUILD_EXTMOD),)
645# Objects we will link into vmlinux / subdirs we need to visit
646core-y		:= init/ usr/
647drivers-y	:= drivers/ sound/
648drivers-$(CONFIG_SAMPLES) += samples/
649drivers-y	+= net/ virt/
650libs-y		:= lib/
651vendor-$(CONFIG_OHOS_VENDOR) := vendor/
652endif # KBUILD_EXTMOD
653
654# The all: target is the default when no target is given on the
655# command line.
656# This allow a user to issue only 'make' to build a kernel including modules
657# Defaults to vmlinux, but the arch makefile usually adds further targets
658all: vmlinux
659
660CFLAGS_GCOV	:= -fprofile-arcs -ftest-coverage \
661	$(call cc-option,-fno-tree-loop-im) \
662	$(call cc-disable-warning,maybe-uninitialized,)
663export CFLAGS_GCOV
664
665# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
666ifdef CONFIG_FUNCTION_TRACER
667  CC_FLAGS_FTRACE := -pg
668endif
669
670ifdef CONFIG_CC_IS_GCC
671RETPOLINE_CFLAGS	:= $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register)
672RETPOLINE_CFLAGS	+= $(call cc-option,-mindirect-branch-cs-prefix)
673RETPOLINE_VDSO_CFLAGS	:= $(call cc-option,-mindirect-branch=thunk-inline -mindirect-branch-register)
674endif
675ifdef CONFIG_CC_IS_CLANG
676RETPOLINE_CFLAGS	:= -mretpoline-external-thunk
677RETPOLINE_VDSO_CFLAGS	:= -mretpoline
678endif
679
680ifdef CONFIG_RETHUNK
681RETHUNK_CFLAGS         := -mfunction-return=thunk-extern
682RETPOLINE_CFLAGS       += $(RETHUNK_CFLAGS)
683endif
684
685export RETPOLINE_CFLAGS
686export RETPOLINE_VDSO_CFLAGS
687
688include arch/$(SRCARCH)/Makefile
689
690ifdef need-config
691ifdef may-sync-config
692# Read in dependencies to all Kconfig* files, make sure to run syncconfig if
693# changes are detected. This should be included after arch/$(SRCARCH)/Makefile
694# because some architectures define CROSS_COMPILE there.
695include include/config/auto.conf.cmd
696
697$(KCONFIG_CONFIG):
698	@echo >&2 '***'
699	@echo >&2 '*** Configuration file "$@" not found!'
700	@echo >&2 '***'
701	@echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or'
702	@echo >&2 '*** "make menuconfig" or "make xconfig").'
703	@echo >&2 '***'
704	@/bin/false
705
706# The actual configuration files used during the build are stored in
707# include/generated/ and include/config/. Update them if .config is newer than
708# include/config/auto.conf (which mirrors .config).
709#
710# This exploits the 'multi-target pattern rule' trick.
711# The syncconfig should be executed only once to make all the targets.
712# (Note: use the grouped target '&:' when we bump to GNU Make 4.3)
713#
714# Do not use $(call cmd,...) here. That would suppress prompts from syncconfig,
715# so you cannot notice that Kconfig is waiting for the user input.
716%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h: $(KCONFIG_CONFIG)
717	$(Q)$(kecho) "  SYNC    $@"
718	$(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
719else # !may-sync-config
720# External modules and some install targets need include/generated/autoconf.h
721# and include/config/auto.conf but do not care if they are up-to-date.
722# Use auto.conf to trigger the test
723PHONY += include/config/auto.conf
724
725include/config/auto.conf:
726	$(Q)test -e include/generated/autoconf.h -a -e $@ || (		\
727	echo >&2;							\
728	echo >&2 "  ERROR: Kernel configuration is invalid.";		\
729	echo >&2 "         include/generated/autoconf.h or $@ are missing.";\
730	echo >&2 "         Run 'make oldconfig && make prepare' on kernel src to fix it.";	\
731	echo >&2 ;							\
732	/bin/false)
733
734endif # may-sync-config
735endif # need-config
736
737KBUILD_CFLAGS	+= $(call cc-option,-fno-delete-null-pointer-checks,)
738KBUILD_CFLAGS	+= $(call cc-disable-warning,frame-address,)
739KBUILD_CFLAGS	+= $(call cc-disable-warning, format-truncation)
740KBUILD_CFLAGS	+= $(call cc-disable-warning, format-overflow)
741KBUILD_CFLAGS	+= $(call cc-disable-warning, address-of-packed-member)
742
743ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
744KBUILD_CFLAGS += -O2
745else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3
746KBUILD_CFLAGS += -O3
747else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
748KBUILD_CFLAGS += -Os
749endif
750
751# Tell gcc to never replace conditional load with a non-conditional one
752KBUILD_CFLAGS	+= $(call cc-option,--param=allow-store-data-races=0)
753KBUILD_CFLAGS	+= $(call cc-option,-fno-allow-store-data-races)
754
755ifdef CONFIG_READABLE_ASM
756# Disable optimizations that make assembler listings hard to read.
757# reorder blocks reorders the control in the function
758# ipa clone creates specialized cloned functions
759# partial inlining inlines only parts of functions
760KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
761                 $(call cc-option,-fno-ipa-cp-clone,) \
762                 $(call cc-option,-fno-partial-inlining)
763endif
764
765ifneq ($(CONFIG_FRAME_WARN),0)
766KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN)
767endif
768
769stackp-flags-y                                    := -fno-stack-protector
770stackp-flags-$(CONFIG_STACKPROTECTOR)             := -fstack-protector
771stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG)      := -fstack-protector-strong
772
773KBUILD_CFLAGS += $(stackp-flags-y)
774
775ifdef CONFIG_CC_IS_CLANG
776KBUILD_CPPFLAGS += -Qunused-arguments
777KBUILD_CFLAGS += -Wno-format-invalid-specifier
778KBUILD_CFLAGS += -Wno-gnu
779# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
780# source of a reference will be _MergedGlobals and not on of the whitelisted names.
781# See modpost pattern 2
782KBUILD_CFLAGS += -mno-global-merge
783else
784
785# Warn about unmarked fall-throughs in switch statement.
786# Disabled for clang while comment to attribute conversion happens and
787# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed.
788KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough,)
789endif
790
791# These warnings generated too much noise in a regular build.
792# Use make W=1 to enable them (see scripts/Makefile.extrawarn)
793KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
794
795KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
796
797# These result in bogus false positives
798KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
799
800ifdef CONFIG_FRAME_POINTER
801KBUILD_CFLAGS	+= -fno-omit-frame-pointer -fno-optimize-sibling-calls
802else
803# Some targets (ARM with Thumb2, for example), can't be built with frame
804# pointers.  For those, we don't have FUNCTION_TRACER automatically
805# select FRAME_POINTER.  However, FUNCTION_TRACER adds -pg, and this is
806# incompatible with -fomit-frame-pointer with current GCC, so we don't use
807# -fomit-frame-pointer with FUNCTION_TRACER.
808ifndef CONFIG_FUNCTION_TRACER
809KBUILD_CFLAGS	+= -fomit-frame-pointer
810endif
811endif
812
813# Initialize all stack variables with a 0xAA pattern.
814ifdef CONFIG_INIT_STACK_ALL_PATTERN
815KBUILD_CFLAGS	+= -ftrivial-auto-var-init=pattern
816endif
817
818# Initialize all stack variables with a zero value.
819ifdef CONFIG_INIT_STACK_ALL_ZERO
820KBUILD_CFLAGS	+= -ftrivial-auto-var-init=zero
821ifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER
822# https://github.com/llvm/llvm-project/issues/44842
823KBUILD_CFLAGS	+= -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
824endif
825endif
826
827DEBUG_CFLAGS	:=
828
829# Workaround for GCC versions < 5.0
830# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801
831ifdef CONFIG_CC_IS_GCC
832DEBUG_CFLAGS	+= $(call cc-ifversion, -lt, 0500, $(call cc-option, -fno-var-tracking-assignments))
833endif
834
835ifdef CONFIG_DEBUG_INFO
836
837ifdef CONFIG_DEBUG_INFO_SPLIT
838DEBUG_CFLAGS	+= -gsplit-dwarf
839else
840DEBUG_CFLAGS	+= -g
841endif
842
843ifdef CONFIG_AS_IS_LLVM
844KBUILD_AFLAGS	+= -g
845else
846KBUILD_AFLAGS	+= -Wa,-gdwarf-2
847endif
848
849ifdef CONFIG_DEBUG_INFO_DWARF4
850DEBUG_CFLAGS	+= -gdwarf-4
851endif
852
853ifdef CONFIG_DEBUG_INFO_REDUCED
854DEBUG_CFLAGS	+= $(call cc-option, -femit-struct-debug-baseonly) \
855		   $(call cc-option,-fno-var-tracking)
856endif
857
858ifdef CONFIG_DEBUG_INFO_COMPRESSED
859DEBUG_CFLAGS	+= -gz=zlib
860KBUILD_AFLAGS	+= -gz=zlib
861KBUILD_LDFLAGS	+= --compress-debug-sections=zlib
862endif
863
864endif # CONFIG_DEBUG_INFO
865
866KBUILD_CFLAGS += $(DEBUG_CFLAGS)
867export DEBUG_CFLAGS
868
869ifdef CONFIG_FUNCTION_TRACER
870ifdef CONFIG_FTRACE_MCOUNT_USE_CC
871  CC_FLAGS_FTRACE	+= -mrecord-mcount
872  ifdef CONFIG_HAVE_NOP_MCOUNT
873    ifeq ($(call cc-option-yn, -mnop-mcount),y)
874      CC_FLAGS_FTRACE	+= -mnop-mcount
875      CC_FLAGS_USING	+= -DCC_USING_NOP_MCOUNT
876    endif
877  endif
878endif
879ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
880  ifdef CONFIG_HAVE_C_RECORDMCOUNT
881    BUILD_C_RECORDMCOUNT := y
882    export BUILD_C_RECORDMCOUNT
883  endif
884endif
885ifdef CONFIG_HAVE_FENTRY
886  ifeq ($(call cc-option-yn, -mfentry),y)
887    CC_FLAGS_FTRACE	+= -mfentry
888    CC_FLAGS_USING	+= -DCC_USING_FENTRY
889  endif
890endif
891export CC_FLAGS_FTRACE
892KBUILD_CFLAGS	+= $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING)
893KBUILD_AFLAGS	+= $(CC_FLAGS_USING)
894endif
895
896# We trigger additional mismatches with less inlining
897ifdef CONFIG_DEBUG_SECTION_MISMATCH
898KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
899endif
900
901ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
902KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
903LDFLAGS_vmlinux += --gc-sections
904endif
905
906ifdef CONFIG_SHADOW_CALL_STACK
907CC_FLAGS_SCS	:= -fsanitize=shadow-call-stack
908KBUILD_CFLAGS	+= $(CC_FLAGS_SCS)
909export CC_FLAGS_SCS
910endif
911
912ifdef CONFIG_LTO_CLANG
913ifdef CONFIG_LTO_CLANG_THIN
914CC_FLAGS_LTO	:= -flto=thin -fsplit-lto-unit
915KBUILD_LDFLAGS	+= --thinlto-cache-dir=$(extmod-prefix).thinlto-cache
916else
917CC_FLAGS_LTO	:= -flto
918endif
919CC_FLAGS_LTO	+= -fvisibility=hidden
920
921# Limit inlining across translation units to reduce binary size
922KBUILD_LDFLAGS += -mllvm -import-instr-limit=5
923endif
924
925ifdef CONFIG_LTO
926KBUILD_CFLAGS	+= -fno-lto $(CC_FLAGS_LTO)
927KBUILD_AFLAGS	+= -fno-lto
928export CC_FLAGS_LTO
929endif
930
931ifdef CONFIG_CFI_CLANG
932CC_FLAGS_CFI	:= -fsanitize=cfi \
933		   -fsanitize-cfi-cross-dso \
934		   -fno-sanitize-cfi-canonical-jump-tables \
935		   -fno-sanitize-trap=cfi \
936		   -fno-sanitize-blacklist
937
938ifdef CONFIG_CFI_PERMISSIVE
939CC_FLAGS_CFI	+= -fsanitize-recover=cfi
940endif
941
942# If LTO flags are filtered out, we must also filter out CFI.
943CC_FLAGS_LTO	+= $(CC_FLAGS_CFI)
944KBUILD_CFLAGS	+= $(CC_FLAGS_CFI)
945export CC_FLAGS_CFI
946endif
947
948ifdef CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_32B
949KBUILD_CFLAGS += -falign-functions=32
950endif
951
952# arch Makefile may override CC so keep this after arch Makefile is included
953NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
954
955# warn about C99 declaration after statement
956KBUILD_CFLAGS += -Wdeclaration-after-statement
957
958# Variable Length Arrays (VLAs) should not be used anywhere in the kernel
959KBUILD_CFLAGS += -Wvla
960
961# disable pointer signed / unsigned warnings in gcc 4.0
962KBUILD_CFLAGS += -Wno-pointer-sign
963
964# disable stringop warnings in gcc 8+
965KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
966
967# We'll want to enable this eventually, but it's not going away for 5.7 at least
968KBUILD_CFLAGS += $(call cc-disable-warning, zero-length-bounds)
969KBUILD_CFLAGS += $(call cc-disable-warning, array-bounds)
970KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
971
972# Another good warning that we'll want to enable eventually
973KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
974
975# Enabled with W=2, disabled by default as noisy
976KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
977
978# disable invalid "can't wrap" optimizations for signed / pointers
979KBUILD_CFLAGS	+= -fno-strict-overflow
980
981# Make sure -fstack-check isn't enabled (like gentoo apparently did)
982KBUILD_CFLAGS  += -fno-stack-check
983
984# conserve stack if available
985KBUILD_CFLAGS   += $(call cc-option,-fconserve-stack)
986
987# Prohibit date/time macros, which would make the build non-deterministic
988KBUILD_CFLAGS   += -Werror=date-time
989
990# enforce correct pointer usage
991KBUILD_CFLAGS   += $(call cc-option,-Werror=incompatible-pointer-types)
992
993# Require designated initializers for all marked structures
994KBUILD_CFLAGS   += $(call cc-option,-Werror=designated-init)
995
996# change __FILE__ to the relative path from the srctree
997KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
998
999# include additional Makefiles when needed
1000include-y			:= scripts/Makefile.extrawarn
1001include-$(CONFIG_KASAN)		+= scripts/Makefile.kasan
1002include-$(CONFIG_KCSAN)		+= scripts/Makefile.kcsan
1003include-$(CONFIG_UBSAN)		+= scripts/Makefile.ubsan
1004include-$(CONFIG_KCOV)		+= scripts/Makefile.kcov
1005include-$(CONFIG_GCC_PLUGINS)	+= scripts/Makefile.gcc-plugins
1006
1007include $(addprefix $(srctree)/, $(include-y))
1008
1009# scripts/Makefile.gcc-plugins is intentionally included last.
1010# Do not add $(call cc-option,...) below this line. When you build the kernel
1011# from the clean source tree, the GCC plugins do not exist at this point.
1012
1013# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments
1014KBUILD_CPPFLAGS += $(KCPPFLAGS)
1015KBUILD_AFLAGS   += $(KAFLAGS)
1016KBUILD_CFLAGS   += $(KCFLAGS)
1017
1018KBUILD_LDFLAGS_MODULE += --build-id=sha1
1019LDFLAGS_vmlinux += --build-id=sha1
1020
1021KBUILD_LDFLAGS	+= -z noexecstack
1022KBUILD_LDFLAGS	+= $(call ld-option,--no-warn-rwx-segments)
1023
1024ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
1025LDFLAGS_vmlinux	+= $(call ld-option, -X,)
1026endif
1027
1028ifeq ($(CONFIG_RELR),y)
1029LDFLAGS_vmlinux	+= --pack-dyn-relocs=relr --use-android-relr-tags
1030endif
1031
1032# We never want expected sections to be placed heuristically by the
1033# linker. All sections should be explicitly named in the linker script.
1034ifdef CONFIG_LD_ORPHAN_WARN
1035LDFLAGS_vmlinux += --orphan-handling=warn
1036endif
1037
1038# Align the bit size of userspace programs with the kernel
1039KBUILD_USERCFLAGS  += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
1040KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
1041
1042# make the checker run with the right architecture
1043CHECKFLAGS += --arch=$(ARCH)
1044
1045# insure the checker run with the right endianness
1046CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
1047
1048# the checker needs the correct machine size
1049CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
1050
1051# Default kernel image to build when no specific target is given.
1052# KBUILD_IMAGE may be overruled on the command line or
1053# set in the environment
1054# Also any assignments in arch/$(ARCH)/Makefile take precedence over
1055# this default value
1056export KBUILD_IMAGE ?= vmlinux
1057
1058#
1059# INSTALL_PATH specifies where to place the updated kernel and system map
1060# images. Default is /boot, but you can set it to other values
1061export	INSTALL_PATH ?= /boot
1062
1063#
1064# INSTALL_DTBS_PATH specifies a prefix for relocations required by build roots.
1065# Like INSTALL_MOD_PATH, it isn't defined in the Makefile, but can be passed as
1066# an argument if needed. Otherwise it defaults to the kernel install path
1067#
1068export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE)
1069
1070#
1071# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
1072# relocations required by build roots.  This is not defined in the
1073# makefile but the argument can be passed to make if needed.
1074#
1075
1076MODLIB	= $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
1077export MODLIB
1078
1079#
1080# INSTALL_MOD_STRIP, if defined, will cause modules to be
1081# stripped after they are installed.  If INSTALL_MOD_STRIP is '1', then
1082# the default option --strip-debug will be used.  Otherwise,
1083# INSTALL_MOD_STRIP value will be used as the options to the strip command.
1084
1085ifdef INSTALL_MOD_STRIP
1086ifeq ($(INSTALL_MOD_STRIP),1)
1087mod_strip_cmd = $(STRIP) --strip-debug
1088else
1089mod_strip_cmd = $(STRIP) $(INSTALL_MOD_STRIP)
1090endif # INSTALL_MOD_STRIP=1
1091else
1092mod_strip_cmd = true
1093endif # INSTALL_MOD_STRIP
1094export mod_strip_cmd
1095
1096# CONFIG_MODULE_COMPRESS, if defined, will cause module to be compressed
1097# after they are installed in agreement with CONFIG_MODULE_COMPRESS_GZIP
1098# or CONFIG_MODULE_COMPRESS_XZ.
1099
1100mod_compress_cmd = true
1101ifdef CONFIG_MODULE_COMPRESS
1102  ifdef CONFIG_MODULE_COMPRESS_GZIP
1103    mod_compress_cmd = $(KGZIP) -n -f
1104  endif # CONFIG_MODULE_COMPRESS_GZIP
1105  ifdef CONFIG_MODULE_COMPRESS_XZ
1106    mod_compress_cmd = $(XZ) -f
1107  endif # CONFIG_MODULE_COMPRESS_XZ
1108endif # CONFIG_MODULE_COMPRESS
1109export mod_compress_cmd
1110
1111ifdef CONFIG_MODULE_SIG_ALL
1112$(eval $(call config_filename,MODULE_SIG_KEY))
1113
1114mod_sign_cmd = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY) certs/signing_key.x509
1115else
1116mod_sign_cmd = true
1117endif
1118export mod_sign_cmd
1119
1120HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
1121
1122has_libelf = $(call try-run,\
1123               echo "int main() {}" | $(HOSTCC) $(KBUILD_HOSTLDFLAGS) -xc -o /dev/null $(HOST_LIBELF_LIBS) -,1,0)
1124
1125ifdef CONFIG_STACK_VALIDATION
1126  ifeq ($(has_libelf),1)
1127    objtool_target := tools/objtool FORCE
1128  else
1129    SKIP_STACK_VALIDATION := 1
1130    export SKIP_STACK_VALIDATION
1131  endif
1132endif
1133
1134PHONY += resolve_btfids_clean
1135
1136resolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids
1137
1138# tools/bpf/resolve_btfids directory might not exist
1139# in output directory, skip its clean in that case
1140resolve_btfids_clean:
1141ifneq ($(wildcard $(resolve_btfids_O)),)
1142	$(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean
1143endif
1144
1145ifdef CONFIG_BPF
1146ifdef CONFIG_DEBUG_INFO_BTF
1147  ifeq ($(has_libelf),1)
1148    resolve_btfids_target := tools/bpf/resolve_btfids FORCE
1149  else
1150    ERROR_RESOLVE_BTFIDS := 1
1151  endif
1152endif # CONFIG_DEBUG_INFO_BTF
1153endif # CONFIG_BPF
1154
1155PHONY += prepare0
1156
1157export MODORDER := $(extmod-prefix)modules.order
1158export MODULES_NSDEPS := $(extmod-prefix)modules.nsdeps
1159
1160ifeq ($(KBUILD_EXTMOD),)
1161core-y		+= kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ io_uring/
1162
1163vmlinux-dirs	:= $(patsubst %/,%,$(filter %/, \
1164		     $(core-y) $(core-m) $(drivers-y) $(drivers-m) $(vendor-y) \
1165		     $(libs-y) $(libs-m)))
1166
1167vmlinux-alldirs	:= $(sort $(vmlinux-dirs) Documentation \
1168		     $(patsubst %/,%,$(filter %/, $(core-) \
1169			$(drivers-) $(vendor-) $(libs-))))
1170
1171build-dirs	:= $(vmlinux-dirs)
1172clean-dirs	:= $(vmlinux-alldirs)
1173
1174subdir-modorder := $(addsuffix /modules.order, $(build-dirs))
1175
1176# Externally visible symbols (used by link-vmlinux.sh)
1177KBUILD_VMLINUX_OBJS := $(head-y) $(patsubst %/,%/built-in.a, $(core-y))
1178KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(filter %/, $(libs-y)))
1179ifdef CONFIG_MODULES
1180KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
1181KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
1182else
1183KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
1184endif
1185KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y))
1186KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(vendor-y))
1187
1188export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS
1189export KBUILD_LDS          := arch/$(SRCARCH)/kernel/vmlinux.lds
1190# used by scripts/Makefile.package
1191export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) LICENSES arch include scripts tools)
1192
1193vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)
1194
1195# Recurse until adjust_autoksyms.sh is satisfied
1196PHONY += autoksyms_recursive
1197ifdef CONFIG_TRIM_UNUSED_KSYMS
1198# For the kernel to actually contain only the needed exported symbols,
1199# we have to build modules as well to determine what those symbols are.
1200# (this can be evaluated only once include/config/auto.conf has been included)
1201KBUILD_MODULES := 1
1202
1203autoksyms_recursive: descend modules.order
1204	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \
1205	  "$(MAKE) -f $(srctree)/Makefile autoksyms_recursive"
1206endif
1207
1208autoksyms_h := $(if $(CONFIG_TRIM_UNUSED_KSYMS), include/generated/autoksyms.h)
1209
1210quiet_cmd_autoksyms_h = GEN     $@
1211      cmd_autoksyms_h = mkdir -p $(dir $@); \
1212			$(CONFIG_SHELL) $(srctree)/scripts/gen_autoksyms.sh $@
1213
1214$(autoksyms_h):
1215	$(call cmd,autoksyms_h)
1216
1217ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
1218
1219# Final link of vmlinux with optional arch pass after final link
1220cmd_link-vmlinux =                                                 \
1221	$(CONFIG_SHELL) $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)";    \
1222	$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
1223
1224vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
1225	+$(call if_changed,link-vmlinux)
1226
1227targets := vmlinux
1228
1229# The actual objects are generated when descending,
1230# make sure no implicit rule kicks in
1231$(sort $(vmlinux-deps) $(subdir-modorder)): descend ;
1232
1233filechk_kernel.release = \
1234	echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
1235
1236# Store (new) KERNELRELEASE string in include/config/kernel.release
1237include/config/kernel.release: FORCE
1238	$(call filechk,kernel.release)
1239
1240# Additional helpers built in scripts/
1241# Carefully list dependencies so we do not try to build scripts twice
1242# in parallel
1243PHONY += scripts
1244scripts: scripts_basic scripts_dtc
1245	$(Q)$(MAKE) $(build)=$(@)
1246
1247# Things we need to do before we recursively start building the kernel
1248# or the modules are listed in "prepare".
1249# A multi level approach is used. prepareN is processed before prepareN-1.
1250# archprepare is used in arch Makefiles and when processed asm symlink,
1251# version.h and scripts_basic is processed / created.
1252
1253PHONY += prepare archprepare
1254
1255archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \
1256	asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h \
1257	include/generated/autoconf.h
1258
1259prepare0: archprepare
1260	$(Q)$(MAKE) $(build)=scripts/mod
1261	$(Q)$(MAKE) $(build)=.
1262
1263# All the preparing..
1264prepare: prepare0 prepare-objtool prepare-resolve_btfids
1265
1266# Support for using generic headers in asm-generic
1267asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj
1268
1269PHONY += asm-generic uapi-asm-generic
1270asm-generic: uapi-asm-generic
1271	$(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \
1272	generic=include/asm-generic
1273uapi-asm-generic:
1274	$(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \
1275	generic=include/uapi/asm-generic
1276
1277PHONY += prepare-objtool prepare-resolve_btfids
1278prepare-objtool: $(objtool_target)
1279ifeq ($(SKIP_STACK_VALIDATION),1)
1280ifdef CONFIG_UNWINDER_ORC
1281	@echo "error: Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1282	@false
1283else
1284	@echo "warning: Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1285endif
1286endif
1287
1288prepare-resolve_btfids: $(resolve_btfids_target)
1289ifeq ($(ERROR_RESOLVE_BTFIDS),1)
1290	@echo "error: Cannot resolve BTF IDs for CONFIG_DEBUG_INFO_BTF, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1291	@false
1292endif
1293# Generate some files
1294# ---------------------------------------------------------------------------
1295
1296# KERNELRELEASE can change from a few different places, meaning version.h
1297# needs to be updated, so this check is forced on all builds
1298
1299uts_len := 64
1300define filechk_utsrelease.h
1301	if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
1302	  echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2;    \
1303	  exit 1;                                                         \
1304	fi;                                                               \
1305	echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"
1306endef
1307
1308define filechk_version.h
1309	if [ $(SUBLEVEL) -gt 255 ]; then                                 \
1310		echo \#define LINUX_VERSION_CODE $(shell                 \
1311		expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + 255); \
1312	else                                                             \
1313		echo \#define LINUX_VERSION_CODE $(shell                 \
1314		expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \
1315	fi;                                                              \
1316	echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) +  \
1317	((c) > 255 ? 255 : (c)))'
1318endef
1319
1320$(version_h): PATCHLEVEL := $(if $(PATCHLEVEL), $(PATCHLEVEL), 0)
1321$(version_h): SUBLEVEL := $(if $(SUBLEVEL), $(SUBLEVEL), 0)
1322$(version_h): FORCE
1323	$(call filechk,version.h)
1324	$(Q)rm -f $(old_version_h)
1325
1326include/generated/utsrelease.h: include/config/kernel.release FORCE
1327	$(call filechk,utsrelease.h)
1328
1329PHONY += headerdep
1330headerdep:
1331	$(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \
1332	$(srctree)/scripts/headerdep.pl -I$(srctree)/include
1333
1334# ---------------------------------------------------------------------------
1335# Kernel headers
1336
1337#Default location for installed headers
1338export INSTALL_HDR_PATH = $(objtree)/usr
1339
1340quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include
1341      cmd_headers_install = \
1342	mkdir -p $(INSTALL_HDR_PATH); \
1343	rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
1344	usr/include $(INSTALL_HDR_PATH)
1345
1346PHONY += headers_install
1347headers_install: headers
1348	$(call cmd,headers_install)
1349
1350PHONY += archheaders archscripts
1351
1352hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
1353
1354PHONY += headers
1355headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
1356	$(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \
1357	  $(error Headers not exportable for the $(SRCARCH) architecture))
1358	$(Q)$(MAKE) $(hdr-inst)=include/uapi
1359	$(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi
1360
1361# Deprecated. It is no-op now.
1362PHONY += headers_check
1363headers_check:
1364	@:
1365
1366ifdef CONFIG_HEADERS_INSTALL
1367prepare: headers
1368endif
1369
1370PHONY += scripts_unifdef
1371scripts_unifdef: scripts_basic
1372	$(Q)$(MAKE) $(build)=scripts scripts/unifdef
1373
1374# ---------------------------------------------------------------------------
1375# Kernel selftest
1376
1377PHONY += kselftest
1378kselftest:
1379	$(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests
1380
1381kselftest-%: FORCE
1382	$(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
1383
1384PHONY += kselftest-merge
1385kselftest-merge:
1386	$(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!))
1387	$(Q)find $(srctree)/tools/testing/selftests -name config | \
1388		xargs $(srctree)/scripts/kconfig/merge_config.sh -m $(objtree)/.config
1389	$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
1390
1391# ---------------------------------------------------------------------------
1392# Devicetree files
1393
1394ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)
1395dtstree := arch/$(SRCARCH)/boot/dts
1396endif
1397
1398ifneq ($(dtstree),)
1399
1400%.dtb: include/config/kernel.release scripts_dtc
1401	$(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
1402
1403PHONY += dtbs dtbs_install dtbs_check
1404dtbs: include/config/kernel.release scripts_dtc
1405	$(Q)$(MAKE) $(build)=$(dtstree)
1406
1407ifneq ($(filter dtbs_check, $(MAKECMDGOALS)),)
1408export CHECK_DTBS=y
1409dtbs: dt_binding_check
1410endif
1411
1412dtbs_check: dtbs
1413
1414dtbs_install:
1415	$(Q)$(MAKE) $(dtbinst)=$(dtstree) dst=$(INSTALL_DTBS_PATH)
1416
1417ifdef CONFIG_OF_EARLY_FLATTREE
1418all: dtbs
1419endif
1420
1421endif
1422
1423PHONY += scripts_dtc
1424scripts_dtc: scripts_basic
1425	$(Q)$(MAKE) $(build)=scripts/dtc
1426
1427ifneq ($(filter dt_binding_check, $(MAKECMDGOALS)),)
1428export CHECK_DT_BINDING=y
1429endif
1430
1431PHONY += dt_binding_check
1432dt_binding_check: scripts_dtc
1433	$(Q)$(MAKE) $(build)=Documentation/devicetree/bindings
1434
1435# ---------------------------------------------------------------------------
1436# Modules
1437
1438ifdef CONFIG_MODULES
1439
1440# By default, build modules as well
1441
1442all: modules
1443
1444# When we're building modules with modversions, we need to consider
1445# the built-in objects during the descend as well, in order to
1446# make sure the checksums are up to date before we record them.
1447ifdef CONFIG_MODVERSIONS
1448  KBUILD_BUILTIN := 1
1449endif
1450
1451# Build modules
1452#
1453# A module can be listed more than once in obj-m resulting in
1454# duplicate lines in modules.order files.  Those are removed
1455# using awk while concatenating to the final file.
1456
1457PHONY += modules
1458modules: $(if $(KBUILD_BUILTIN),vmlinux) modules_check modules_prepare
1459
1460PHONY += modules_check
1461modules_check: modules.order
1462	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
1463
1464cmd_modules_order = $(AWK) '!x[$$0]++' $(real-prereqs) > $@
1465
1466modules.order: $(subdir-modorder) FORCE
1467	$(call if_changed,modules_order)
1468
1469targets += modules.order
1470
1471# Target to prepare building external modules
1472PHONY += modules_prepare
1473modules_prepare: prepare
1474	$(Q)$(MAKE) $(build)=scripts scripts/module.lds
1475
1476modules_install: __modinst_pre
1477PHONY += __modinst_pre
1478__modinst_pre:
1479	@rm -rf $(MODLIB)/kernel
1480	@rm -f $(MODLIB)/source
1481	@mkdir -p $(MODLIB)/kernel
1482	@ln -s $(abspath $(srctree)) $(MODLIB)/source
1483	@if [ ! $(objtree) -ef  $(MODLIB)/build ]; then \
1484		rm -f $(MODLIB)/build ; \
1485		ln -s $(CURDIR) $(MODLIB)/build ; \
1486	fi
1487	@sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order
1488	@cp -f modules.builtin $(MODLIB)/
1489	@cp -f $(objtree)/modules.builtin.modinfo $(MODLIB)/
1490
1491ifeq ($(CONFIG_MODULE_SIG), y)
1492PHONY += modules_sign
1493modules_sign:
1494	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modsign
1495endif
1496
1497endif # CONFIG_MODULES
1498
1499###
1500# Cleaning is done on three levels.
1501# make clean     Delete most generated files
1502#                Leave enough to build external modules
1503# make mrproper  Delete the current configuration, and all generated files
1504# make distclean Remove editor backup files, patch leftover files and the like
1505
1506# Directories & files removed with 'make clean'
1507CLEAN_FILES += include/ksym vmlinux.symvers modules-only.symvers \
1508	       modules.builtin modules.builtin.modinfo modules.nsdeps \
1509	       compile_commands.json .thinlto-cache
1510
1511# Directories & files removed with 'make mrproper'
1512MRPROPER_FILES += include/config include/generated          \
1513		  arch/$(SRCARCH)/include/generated .tmp_objdiff \
1514		  debian snap tar-install \
1515		  .config .config.old .version \
1516		  Module.symvers \
1517		  signing_key.pem signing_key.priv signing_key.x509	\
1518		  x509.genkey extra_certificates signing_key.x509.keyid	\
1519		  signing_key.x509.signer vmlinux-gdb.py \
1520		  *.spec
1521
1522# Directories & files removed with 'make distclean'
1523DISTCLEAN_FILES += tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
1524
1525# clean - Delete most, but leave enough to build external modules
1526#
1527clean: rm-files := $(CLEAN_FILES)
1528
1529PHONY += archclean vmlinuxclean
1530
1531vmlinuxclean:
1532	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
1533	$(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
1534
1535clean: archclean vmlinuxclean resolve_btfids_clean
1536
1537# mrproper - Delete all generated files, including .config
1538#
1539mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
1540mrproper-dirs      := $(addprefix _mrproper_,scripts)
1541
1542PHONY += $(mrproper-dirs) mrproper
1543$(mrproper-dirs):
1544	$(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
1545
1546mrproper: clean $(mrproper-dirs)
1547	$(call cmd,rmfiles)
1548
1549# distclean
1550#
1551distclean: rm-files := $(wildcard $(DISTCLEAN_FILES))
1552
1553PHONY += distclean
1554
1555distclean: mrproper
1556	$(call cmd,rmfiles)
1557	@find $(srctree) $(RCS_FIND_IGNORE) \
1558		\( -name '*.orig' -o -name '*.rej' -o -name '*~' \
1559		-o -name '*.bak' -o -name '#*#' -o -name '*%' \
1560		-o -name 'core' \) \
1561		-type f -print | xargs rm -f
1562
1563
1564# Packaging of the kernel to various formats
1565# ---------------------------------------------------------------------------
1566
1567%src-pkg: FORCE
1568	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
1569%pkg: include/config/kernel.release FORCE
1570	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
1571
1572# Brief documentation of the typical targets used
1573# ---------------------------------------------------------------------------
1574
1575boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig)
1576boards := $(sort $(notdir $(boards)))
1577board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
1578board-dirs := $(sort $(notdir $(board-dirs:/=)))
1579
1580PHONY += help
1581help:
1582	@echo  'Cleaning targets:'
1583	@echo  '  clean		  - Remove most generated files but keep the config and'
1584	@echo  '                    enough build support to build external modules'
1585	@echo  '  mrproper	  - Remove all generated files + config + various backup files'
1586	@echo  '  distclean	  - mrproper + remove editor backup and patch files'
1587	@echo  ''
1588	@echo  'Configuration targets:'
1589	@$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
1590	@echo  ''
1591	@echo  'Other generic targets:'
1592	@echo  '  all		  - Build all targets marked with [*]'
1593	@echo  '* vmlinux	  - Build the bare kernel'
1594	@echo  '* modules	  - Build all modules'
1595	@echo  '  modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
1596	@echo  '  dir/            - Build all files in dir and below'
1597	@echo  '  dir/file.[ois]  - Build specified target only'
1598	@echo  '  dir/file.ll     - Build the LLVM assembly file'
1599	@echo  '                    (requires compiler support for LLVM assembly generation)'
1600	@echo  '  dir/file.lst    - Build specified mixed source/assembly target only'
1601	@echo  '                    (requires a recent binutils and recent build (System.map))'
1602	@echo  '  dir/file.ko     - Build module including final link'
1603	@echo  '  modules_prepare - Set up for building external modules'
1604	@echo  '  tags/TAGS	  - Generate tags file for editors'
1605	@echo  '  cscope	  - Generate cscope index'
1606	@echo  '  gtags           - Generate GNU GLOBAL index'
1607	@echo  '  kernelrelease	  - Output the release version string (use with make -s)'
1608	@echo  '  kernelversion	  - Output the version stored in Makefile (use with make -s)'
1609	@echo  '  image_name	  - Output the image name (use with make -s)'
1610	@echo  '  headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
1611	 echo  '                    (default: $(INSTALL_HDR_PATH))'; \
1612	 echo  ''
1613	@echo  'Static analysers:'
1614	@echo  '  checkstack      - Generate a list of stack hogs'
1615	@echo  '  versioncheck    - Sanity check on version.h usage'
1616	@echo  '  includecheck    - Check for duplicate included header files'
1617	@echo  '  export_report   - List the usages of all exported symbols'
1618	@echo  '  headerdep       - Detect inclusion cycles in headers'
1619	@echo  '  coccicheck      - Check with Coccinelle'
1620	@echo  '  clang-analyzer  - Check with clang static analyzer'
1621	@echo  '  clang-tidy      - Check with clang-tidy'
1622	@echo  ''
1623	@echo  'Tools:'
1624	@echo  '  nsdeps          - Generate missing symbol namespace dependencies'
1625	@echo  ''
1626	@echo  'Kernel selftest:'
1627	@echo  '  kselftest         - Build and run kernel selftest'
1628	@echo  '                      Build, install, and boot kernel before'
1629	@echo  '                      running kselftest on it'
1630	@echo  '                      Run as root for full coverage'
1631	@echo  '  kselftest-all     - Build kernel selftest'
1632	@echo  '  kselftest-install - Build and install kernel selftest'
1633	@echo  '  kselftest-clean   - Remove all generated kselftest files'
1634	@echo  '  kselftest-merge   - Merge all the config dependencies of'
1635	@echo  '		      kselftest to existing .config.'
1636	@echo  ''
1637	@$(if $(dtstree), \
1638		echo 'Devicetree:'; \
1639		echo '* dtbs             - Build device tree blobs for enabled boards'; \
1640		echo '  dtbs_install     - Install dtbs to $(INSTALL_DTBS_PATH)'; \
1641		echo '  dt_binding_check - Validate device tree binding documents'; \
1642		echo '  dtbs_check       - Validate device tree source files';\
1643		echo '')
1644
1645	@echo 'Userspace tools targets:'
1646	@echo '  use "make tools/help"'
1647	@echo '  or  "cd tools; make help"'
1648	@echo  ''
1649	@echo  'Kernel packaging:'
1650	@$(MAKE) -f $(srctree)/scripts/Makefile.package help
1651	@echo  ''
1652	@echo  'Documentation targets:'
1653	@$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
1654	@echo  ''
1655	@echo  'Architecture specific targets ($(SRCARCH)):'
1656	@$(if $(archhelp),$(archhelp),\
1657		echo '  No architecture specific help defined for $(SRCARCH)')
1658	@echo  ''
1659	@$(if $(boards), \
1660		$(foreach b, $(boards), \
1661		printf "  %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
1662		echo '')
1663	@$(if $(board-dirs), \
1664		$(foreach b, $(board-dirs), \
1665		printf "  %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
1666		printf "  %-16s - Show all of the above\\n" help-boards; \
1667		echo '')
1668
1669	@echo  '  make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
1670	@echo  '  make V=2   [targets] 2 => give reason for rebuild of target'
1671	@echo  '  make O=dir [targets] Locate all output files in "dir", including .config'
1672	@echo  '  make C=1   [targets] Check re-compiled c source with $$CHECK'
1673	@echo  '                       (sparse by default)'
1674	@echo  '  make C=2   [targets] Force check of all c source with $$CHECK'
1675	@echo  '  make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections'
1676	@echo  '  make W=n   [targets] Enable extra build checks, n=1,2,3 where'
1677	@echo  '		1: warnings which may be relevant and do not occur too often'
1678	@echo  '		2: warnings which occur quite often but may still be relevant'
1679	@echo  '		3: more obscure warnings, can most likely be ignored'
1680	@echo  '		Multiple levels can be combined with W=12 or W=123'
1681	@echo  ''
1682	@echo  'Execute "make" or "make all" to build all targets marked with [*] '
1683	@echo  'For further info see the ./README file'
1684
1685
1686help-board-dirs := $(addprefix help-,$(board-dirs))
1687
1688help-boards: $(help-board-dirs)
1689
1690boards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)))
1691
1692$(help-board-dirs): help-%:
1693	@echo  'Architecture specific targets ($(SRCARCH) $*):'
1694	@$(if $(boards-per-dir), \
1695		$(foreach b, $(boards-per-dir), \
1696		printf "  %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
1697		echo '')
1698
1699
1700# Documentation targets
1701# ---------------------------------------------------------------------------
1702DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \
1703	       linkcheckdocs dochelp refcheckdocs
1704PHONY += $(DOC_TARGETS)
1705$(DOC_TARGETS):
1706	$(Q)$(MAKE) $(build)=Documentation $@
1707
1708# Misc
1709# ---------------------------------------------------------------------------
1710
1711PHONY += scripts_gdb
1712scripts_gdb: prepare0
1713	$(Q)$(MAKE) $(build)=scripts/gdb
1714	$(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
1715
1716ifdef CONFIG_GDB_SCRIPTS
1717all: scripts_gdb
1718endif
1719
1720else # KBUILD_EXTMOD
1721
1722###
1723# External module support.
1724# When building external modules the kernel used as basis is considered
1725# read-only, and no consistency checks are made and the make
1726# system is not used on the basis kernel. If updates are required
1727# in the basis kernel ordinary make commands (without M=...) must
1728# be used.
1729#
1730# The following are the only valid targets when building external
1731# modules.
1732# make M=dir clean     Delete all automatically generated files
1733# make M=dir modules   Make all modules in specified dir
1734# make M=dir	       Same as 'make M=dir modules'
1735# make M=dir modules_install
1736#                      Install the modules built in the module directory
1737#                      Assumes install directory is already created
1738
1739# We are always building only modules.
1740KBUILD_BUILTIN :=
1741KBUILD_MODULES := 1
1742
1743build-dirs := $(KBUILD_EXTMOD)
1744$(MODORDER): descend
1745	@:
1746
1747compile_commands.json: $(extmod-prefix)compile_commands.json
1748PHONY += compile_commands.json
1749
1750clean-dirs := $(KBUILD_EXTMOD)
1751clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \
1752	$(KBUILD_EXTMOD)/compile_commands.json $(KBUILD_EXTMOD)/.thinlto-cache
1753
1754PHONY += help
1755help:
1756	@echo  '  Building external modules.'
1757	@echo  '  Syntax: make -C path/to/kernel/src M=$$PWD target'
1758	@echo  ''
1759	@echo  '  modules         - default target, build the module(s)'
1760	@echo  '  modules_install - install the module'
1761	@echo  '  clean           - remove generated files in module directory only'
1762	@echo  ''
1763
1764# no-op for external module builds
1765PHONY += prepare modules_prepare
1766
1767endif # KBUILD_EXTMOD
1768
1769# ---------------------------------------------------------------------------
1770# Modules
1771
1772PHONY += modules modules_install
1773
1774ifdef CONFIG_MODULES
1775
1776modules: $(MODORDER)
1777	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1778
1779quiet_cmd_depmod = DEPMOD  $(KERNELRELEASE)
1780      cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \
1781                   $(KERNELRELEASE)
1782
1783modules_install:
1784	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1785	$(call cmd,depmod)
1786
1787else # CONFIG_MODULES
1788
1789# Modules not configured
1790# ---------------------------------------------------------------------------
1791
1792modules modules_install:
1793	@echo >&2 '***'
1794	@echo >&2 '*** The present kernel configuration has modules disabled.'
1795	@echo >&2 '*** To use the module feature, please run "make menuconfig" etc.'
1796	@echo >&2 '*** to enable CONFIG_MODULES.'
1797	@echo >&2 '***'
1798	@exit 1
1799
1800KBUILD_MODULES :=
1801
1802endif # CONFIG_MODULES
1803
1804# Single targets
1805# ---------------------------------------------------------------------------
1806# To build individual files in subdirectories, you can do like this:
1807#
1808#   make foo/bar/baz.s
1809#
1810# The supported suffixes for single-target are listed in 'single-targets'
1811#
1812# To build only under specific subdirectories, you can do like this:
1813#
1814#   make foo/bar/baz/
1815
1816ifdef single-build
1817
1818# .ko is special because modpost is needed
1819single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
1820single-no-ko := $(sort $(patsubst %.ko,%.mod, $(MAKECMDGOALS)))
1821
1822$(single-ko): single_modpost
1823	@:
1824$(single-no-ko): descend
1825	@:
1826
1827# Remove MODORDER when done because it is not the real one.
1828PHONY += single_modpost
1829single_modpost: $(single-no-ko) modules_prepare
1830	$(Q){ $(foreach m, $(single-ko), echo $(extmod-prefix)$m;) } > $(MODORDER)
1831	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1832	$(Q)rm -f $(MODORDER)
1833
1834export KBUILD_SINGLE_TARGETS := $(addprefix $(extmod-prefix), $(single-no-ko))
1835
1836# trim unrelated directories
1837build-dirs := $(foreach d, $(build-dirs), \
1838			$(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d)))
1839
1840endif
1841
1842# Handle descending into subdirectories listed in $(build-dirs)
1843# Preset locale variables to speed up the build process. Limit locale
1844# tweaks to this spot to avoid wrong language settings when running
1845# make menuconfig etc.
1846# Error messages still appears in the original language
1847PHONY += descend $(build-dirs)
1848descend: $(build-dirs)
1849$(build-dirs): prepare
1850	$(Q)$(MAKE) $(build)=$@ \
1851	single-build=$(if $(filter-out $@/, $(filter $@/%, $(KBUILD_SINGLE_TARGETS))),1) \
1852	need-builtin=1 need-modorder=1
1853
1854clean-dirs := $(addprefix _clean_, $(clean-dirs))
1855PHONY += $(clean-dirs) clean
1856$(clean-dirs):
1857	$(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1858
1859clean: $(clean-dirs)
1860	$(call cmd,rmfiles)
1861	@find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
1862		\( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \
1863		-o -name '*.ko.*' \
1864		-o -name '*.dtb' -o -name '*.dtb.S' -o -name '*.dt.yaml' \
1865		-o -name '*.dwo' -o -name '*.lst' \
1866		-o -name '*.su' -o -name '*.mod' \
1867		-o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
1868		-o -name '*.lex.c' -o -name '*.tab.[ch]' \
1869		-o -name '*.asn1.[ch]' \
1870		-o -name '*.symtypes' -o -name 'modules.order' \
1871		-o -name '.tmp_*.o.*' \
1872		-o -name '*.c.[012]*.*' \
1873		-o -name '*.ll' \
1874		-o -name '*.gcno' \
1875		-o -name '*.*.symversions' \) -type f -print | xargs rm -f
1876
1877# Generate tags for editors
1878# ---------------------------------------------------------------------------
1879quiet_cmd_tags = GEN     $@
1880      cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@
1881
1882tags TAGS cscope gtags: FORCE
1883	$(call cmd,tags)
1884
1885# Script to generate missing namespace dependencies
1886# ---------------------------------------------------------------------------
1887
1888PHONY += nsdeps
1889nsdeps: export KBUILD_NSDEPS=1
1890nsdeps: modules
1891	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps
1892
1893# Clang Tooling
1894# ---------------------------------------------------------------------------
1895
1896quiet_cmd_gen_compile_commands = GEN     $@
1897      cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
1898
1899$(extmod-prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \
1900	$(if $(KBUILD_EXTMOD),,$(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)) \
1901	$(if $(CONFIG_MODULES), $(MODORDER)) FORCE
1902	$(call if_changed,gen_compile_commands)
1903
1904targets += $(extmod-prefix)compile_commands.json
1905
1906PHONY += clang-tidy clang-analyzer
1907
1908ifdef CONFIG_CC_IS_CLANG
1909quiet_cmd_clang_tools = CHECK   $<
1910      cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $<
1911
1912clang-tidy clang-analyzer: $(extmod-prefix)compile_commands.json
1913	$(call cmd,clang_tools)
1914else
1915clang-tidy clang-analyzer:
1916	@echo "$@ requires CC=clang" >&2
1917	@false
1918endif
1919
1920# Scripts to check various things for consistency
1921# ---------------------------------------------------------------------------
1922
1923PHONY += includecheck versioncheck coccicheck export_report
1924
1925includecheck:
1926	find $(srctree)/* $(RCS_FIND_IGNORE) \
1927		-name '*.[hcS]' -type f -print | sort \
1928		| xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
1929
1930versioncheck:
1931	find $(srctree)/* $(RCS_FIND_IGNORE) \
1932		-name '*.[hcS]' -type f -print | sort \
1933		| xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
1934
1935coccicheck:
1936	$(Q)$(BASH) $(srctree)/scripts/$@
1937
1938export_report:
1939	$(PERL) $(srctree)/scripts/export_report.pl
1940
1941PHONY += checkstack kernelrelease kernelversion image_name
1942
1943# UML needs a little special treatment here.  It wants to use the host
1944# toolchain, so needs $(SUBARCH) passed to checkstack.pl.  Everyone
1945# else wants $(ARCH), including people doing cross-builds, which means
1946# that $(SUBARCH) doesn't work here.
1947ifeq ($(ARCH), um)
1948CHECKSTACK_ARCH := $(SUBARCH)
1949else
1950CHECKSTACK_ARCH := $(ARCH)
1951endif
1952checkstack:
1953	$(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
1954	$(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH)
1955
1956kernelrelease:
1957	@echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
1958
1959kernelversion:
1960	@echo $(KERNELVERSION)
1961
1962image_name:
1963	@echo $(KBUILD_IMAGE)
1964
1965# Clear a bunch of variables before executing the submake
1966
1967ifeq ($(quiet),silent_)
1968tools_silent=s
1969endif
1970
1971tools/: FORCE
1972	$(Q)mkdir -p $(objtree)/tools
1973	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
1974
1975tools/%: FORCE
1976	$(Q)mkdir -p $(objtree)/tools
1977	$(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
1978
1979quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN   $(wildcard $(rm-files)))
1980      cmd_rmfiles = rm -rf $(rm-files)
1981
1982# read saved command lines for existing targets
1983existing-targets := $(wildcard $(sort $(targets)))
1984
1985-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
1986
1987endif # config-build
1988endif # mixed-build
1989endif # need-sub-make
1990
1991PHONY += FORCE
1992FORCE:
1993
1994# Declare the contents of the PHONY variable as phony.  We keep that
1995# information in a variable so we can use it in if_changed and friends.
1996.PHONY: $(PHONY)
1997