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