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