Something went wrong. Try again.
(I'm so sorry!) Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
Something went wrong. Try again.
kernel Makefile
81 kB · 2404 lines
Makefile
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405# SPDX-License-Identifier: GPL-2.0VERSION = 7PATCHLEVEL = 3SUBLEVEL = 0EXTRAVERSION =NAME = Baby Opossum Posse
# *DOCUMENTATION*# To see a list of typical targets execute "make help"# More info can be located in ./README# Comments in this file are targeted only to the developer, do not# expect to learn how to build the kernel reading this file.
ifeq ($(filter output-sync,$(.FEATURES)),)$(error GNU Make >= 4.0 is required. Your Make version is $(MAKE_VERSION))endif
$(if $(filter __%, $(MAKECMDGOALS)), \ $(error targets prefixed with '__' are only for internal use))
# That's our default target when none is given on the command linePHONY := __all__all:
# We are using a recursive build, so we need to do a little thinking# to get the ordering right.## Most importantly: sub-Makefiles should only ever modify files in# their own directory. If in some directory we have a dependency on# a file in another dir (which doesn't happen often, but it's often# unavoidable when linking the built-in.a targets which finally# turn into vmlinux), we will call a sub make in that other dir, and# after that we are sure that everything which is in that other dir# is now up to date.## The only cases where we need to modify files which have global# effects are thus separated out and done before the recursive# descending is started. They are now explicitly listed as the# prepare rule.
this-makefile := $(lastword $(MAKEFILE_LIST))abs_srctree := $(realpath $(dir $(this-makefile)))abs_output := $(CURDIR)
ifneq ($(sub_make_done),1)
# Do not use make's built-in rules and variables# (this increases performance and avoids hard-to-debug behaviour)MAKEFLAGS += -rR
# Avoid funny character set dependenciesunexport LC_ALLLC_COLLATE=CLC_NUMERIC=Cexport LC_COLLATE LC_NUMERIC
# Avoid interference with shell env settingsunexport GREP_OPTIONS
# Beautify output# ---------------------------------------------------------------------------## Most of build commands in Kbuild start with "cmd_". You can optionally define# "quiet_cmd_*". If defined, the short log is printed. Otherwise, no log from# that command is printed by default.## e.g.)# quiet_cmd_depmod = DEPMOD $(MODLIB)# cmd_depmod = $(srctree)/scripts/depmod.sh $(DEPMOD) $(KERNELRELEASE)## A simple variant is to prefix commands with $(Q) - that's useful# for commands that shall be hidden in non-verbose mode.## $(Q)$(MAKE) $(build)=scripts/basic## If KBUILD_VERBOSE contains 1, the whole command is echoed.# If KBUILD_VERBOSE contains 2, the reason for rebuilding is printed.## To put more focus on warnings, be less verbose as default# Use 'make V=1' to see the full commands
ifeq ("$(origin V)", "command line") KBUILD_VERBOSE = $(V)endif
quiet = quiet_Q = @
ifneq ($(findstring 1, $(KBUILD_VERBOSE)),) quiet = Q =endif
# If the user is running make -s (silent mode), suppress echoing of# commandsifneq ($(findstring s,$(firstword -$(MAKEFLAGS))),)quiet=silent_override KBUILD_VERBOSE :=endif
export quiet Q KBUILD_VERBOSE
# Call a source code checker (by default, "sparse") as part of the# C compilation.## Use 'make C=1' to enable checking of only re-compiled files.# Use 'make C=2' to enable checking of *all* source files, regardless# of whether they are re-compiled or not.## See the file "Documentation/dev-tools/sparse.rst" for more details,# including where to get the "sparse" utility.
ifeq ("$(origin C)", "command line") KBUILD_CHECKSRC = $(C)endififndef KBUILD_CHECKSRC KBUILD_CHECKSRC = 0endif
export KBUILD_CHECKSRC
# Enable "clippy" (a linter) as part of the Rust compilation.## Use 'make CLIPPY=1' to enable it.ifeq ("$(origin CLIPPY)", "command line") KBUILD_CLIPPY := $(CLIPPY)endif
export KBUILD_CLIPPY
# Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the# directory of external module to build. Setting M= takes precedence.ifeq ("$(origin M)", "command line") KBUILD_EXTMOD := $(M)endif
ifeq ("$(origin MO)", "command line") KBUILD_EXTMOD_OUTPUT := $(MO)endif
$(if $(word 2, $(KBUILD_EXTMOD)), \ $(error building multiple external modules is not supported))
$(foreach x, % :, $(if $(findstring $x, $(KBUILD_EXTMOD)), \ $(error module directory path cannot contain '$x')))
# Remove trailing slashesifneq ($(filter %/, $(KBUILD_EXTMOD)),)KBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD).)endif
export KBUILD_EXTMOD
ifeq ("$(origin W)", "command line") KBUILD_EXTRA_WARN := $(W)endif
export KBUILD_EXTRA_WARN
# Kbuild will save output files in the current working directory.# This does not need to match to the root of the kernel source tree.## For example, you can do this:## cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile## If you want to save output files in a different location, there are# two syntaxes to specify it.## 1) O=# Use "make O=dir/to/store/output/files/"## 2) Set KBUILD_OUTPUT# Set the environment variable KBUILD_OUTPUT to point to the output directory.# export KBUILD_OUTPUT=dir/to/store/output/files/; make## The O= assignment takes precedence over the KBUILD_OUTPUT environment# variable.
ifeq ("$(origin O)", "command line") KBUILD_OUTPUT := $(O)endif
ifdef KBUILD_EXTMOD ifdef KBUILD_OUTPUT objtree := $(realpath $(KBUILD_OUTPUT)) $(if $(objtree),,$(error specified kernel directory "$(KBUILD_OUTPUT)" does not exist)) else objtree := $(abs_srctree) endif # If Make is invoked from the kernel directory (either kernel # source directory or kernel build directory), external modules # are built in $(KBUILD_EXTMOD) for backward compatibility, # otherwise, built in the current directory. output := $(or $(KBUILD_EXTMOD_OUTPUT),$(if $(filter $(CURDIR),$(objtree) $(abs_srctree)),$(KBUILD_EXTMOD))) # KBUILD_EXTMOD might be a relative path. Remember its absolute path before # Make changes the working directory. srcroot := $(realpath $(KBUILD_EXTMOD)) $(if $(srcroot),,$(error specified external module directory "$(KBUILD_EXTMOD)" does not exist))else objtree := . output := $(KBUILD_OUTPUT)endif
export objtree srcroot
# Do we want to change the working directory?ifneq ($(output),)# $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first.$(shell mkdir -p "$(output)")# $(realpath ...) resolves symlinksabs_output := $(realpath $(output))$(if $(abs_output),,$(error failed to create output directory "$(output)"))endif
ifneq ($(words $(subst :, ,$(abs_srctree))), 1)$(error source directory cannot contain spaces or colons)endif
export sub_make_done := 1
endif # sub_make_done
ifeq ($(abs_output),$(CURDIR))# Suppress "Entering directory ..." if we are at the final work directory.no-print-directory := --no-print-directoryelse# Recursion to show "Entering directory ..."need-sub-make := 1endif
ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),)# If --no-print-directory is unset, recurse once again to set it.# You may end up recursing into __sub-make twice. This is needed due to the# behavior change in GNU Make 4.4.1.need-sub-make := 1endif
ifeq ($(need-sub-make),1)
PHONY += $(MAKECMDGOALS) __sub-make
$(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make @:
# Invoke a second make in the output directory, passing relevant variables__sub-make: $(Q)$(MAKE) $(no-print-directory) -C $(abs_output) \ -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
else # need-sub-make
# We process the rest of the Makefile if this is the final invocation of make
ifndef KBUILD_EXTMODsrcroot := $(abs_srctree)endif
ifeq ($(srcroot),$(CURDIR))building_out_of_srctree :=elseexport building_out_of_srctree := 1endif
ifdef KBUILD_ABS_SRCTREE # Do nothing. Use the absolute path.else ifeq ($(srcroot),$(CURDIR)) # Building in the source. srcroot := .else ifeq ($(srcroot)/,$(dir $(CURDIR))) # Building in a subdirectory of the source. srcroot := ..endif
export srctree := $(if $(KBUILD_EXTMOD),$(abs_srctree),$(srcroot))
ifdef building_out_of_srctreeexport VPATH := $(srcroot)elseVPATH :=endif
# To make sure we do not include .config for any of the *config targets# catch them early, and hand them over to scripts/kconfig/Makefile# It is allowed to specify more targets when calling make, including# mixing *config targets and build targets.# For example 'make oldconfig all'.# Detect when mixed targets is specified, and make a second invocation# of make so .config is not included in this case either (for *config).
version_h := include/generated/uapi/linux/version.h
clean-targets := %clean mrproper cleandocsno-dot-config-targets := $(clean-targets) \ cscope gtags TAGS tags help% %docs check% coccicheck \ kconfig-sym-check \ $(version_h) headers headers_% archheaders archscripts \ %asm-generic kernelversion %src-pkg dt_binding_check \ dt_style_selftest \ outputmakefile rustavailable rustfmt rustfmtcheck \ run-commandno-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \ image_namesingle-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %/
config-build :=mixed-build :=need-config := 1may-sync-config := 1single-build :=
ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) need-config := endifendif
ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),) ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),) may-sync-config := endifendif
need-compiler := $(may-sync-config)
ifneq ($(KBUILD_EXTMOD),) may-sync-config :=endif
ifeq ($(KBUILD_EXTMOD),) ifneq ($(filter %config,$(MAKECMDGOALS)),) config-build := 1 ifneq ($(words $(MAKECMDGOALS)),1) mixed-build := 1 endif endifendif
# We cannot build single targets and the others at the same timeifneq ($(filter $(single-targets), $(MAKECMDGOALS)),) single-build := 1 ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),) mixed-build := 1 endifendif
# For "make -j clean all", "make -j mrproper defconfig all", etc.ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),) ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) mixed-build := 1 endifendif
# install and modules_install need also be processed one by oneifneq ($(filter install,$(MAKECMDGOALS)),) ifneq ($(filter modules_install,$(MAKECMDGOALS)),) mixed-build := 1 endifendif
ifdef mixed-build# ===========================================================================# We're called with mixed targets (*config and build targets).# Handle them one by one.
PHONY += $(MAKECMDGOALS) __build_one_by_one
$(MAKECMDGOALS): __build_one_by_one @:
__build_one_by_one: $(Q)set -e; \ for i in $(MAKECMDGOALS); do \ $(MAKE) -f $(srctree)/Makefile $$i; \ done
else # !mixed-build
include $(srctree)/scripts/Kbuild.include
# Read KERNELRELEASE from include/config/kernel.release (if it exists)KERNELRELEASE = $(call read-file, $(objtree)/include/config/kernel.release)KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
include $(srctree)/scripts/subarch.include
# Cross compiling and selecting different set of gcc/bin-utils# ---------------------------------------------------------------------------## When performing cross compilation for other architectures ARCH shall be set# to the target architecture. (See arch/* for the possibilities).# ARCH can be set during invocation of make:# make ARCH=arm64# Another way is to have ARCH set in the environment.# The default ARCH is the host where make is executed.
# CROSS_COMPILE specify the prefix used for all executables used# during compilation. Only gcc and related bin-utils executables# are prefixed with $(CROSS_COMPILE).# CROSS_COMPILE can be set on the command line# make CROSS_COMPILE=aarch64-linux-gnu-# Alternatively CROSS_COMPILE can be set in the environment.# Default value for CROSS_COMPILE is not to prefix executables# Note: Some architectures assign CROSS_COMPILE in their arch/*/MakefileARCH ?= $(SUBARCH)
# Architecture as present in compile.hUTS_MACHINE := $(ARCH)SRCARCH := $(ARCH)
# Additional ARCH settings for x86ifeq ($(ARCH),i386) SRCARCH := x86endififeq ($(ARCH),x86_64) SRCARCH := x86endif
# Additional ARCH settings for sparcifeq ($(ARCH),sparc32) SRCARCH := sparcendififeq ($(ARCH),sparc64) SRCARCH := sparcendif
# Additional ARCH settings for pariscifeq ($(ARCH),parisc64) SRCARCH := pariscendif
export cross_compiling :=ifneq ($(SRCARCH),$(SUBARCH))cross_compiling := 1endif
KCONFIG_CONFIG ?= .configexport KCONFIG_CONFIG
# SHELL used by kbuildCONFIG_SHELL := sh
HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
ifneq ($(LLVM),)ifneq ($(filter %/,$(LLVM)),)LLVM_PREFIX := $(LLVM)else ifneq ($(filter -%,$(LLVM)),)LLVM_SUFFIX := $(LLVM)else ifneq ($(LLVM),1)$(error Invalid value for LLVM, see Documentation/kbuild/llvm.rst)endif
HOSTCC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)HOSTCXX = $(LLVM_PREFIX)clang++$(LLVM_SUFFIX)elseHOSTCC = gccHOSTCXX = g++endifHOSTRUSTC = rustcHOSTPKG_CONFIG = pkg-config
# the KERNELDOC macro needs to be exported, as scripts/Makefile.build# has a logic to call itKERNELDOC = $(srctree)/tools/docs/kernel-docexport KERNELDOC
KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \ -O2 -fomit-frame-pointer -std=gnu11KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)KBUILD_USERLDFLAGS := $(USERLDFLAGS)
# These flags apply to all Rust code in the tree, including the kernel and# host programs.## `-Aclippy::unwrap_or_default`: the lint is buggy [1] and ignores our# MSRV. It can trigger depending on the optimization level.# [1] https://github.com/rust-lang/rust-clippy/issues/17379export rust_common_flags := --edition=2021 \ -Zbinary_dep_depinfo=y \ -Astable_features \ -Aunused_features \ -Dnon_ascii_idents \ -Dunsafe_op_in_unsafe_fn \ -Wmissing_docs \ -Wrust_2018_idioms \ -Wunreachable_pub \ -Wclippy::all \ -Wclippy::as_ptr_cast_mut \ -Wclippy::as_underscore \ -Wclippy::cast_lossless \ -Aclippy::collapsible_if \ -Aclippy::collapsible_match \ -Wclippy::ignored_unit_patterns \ -Aclippy::incompatible_msrv \ -Wclippy::mut_mut \ -Wclippy::needless_bitwise_bool \ -Aclippy::needless_lifetimes \ -Wclippy::no_mangle_with_rust_abi \ -Wclippy::ptr_as_ptr \ -Wclippy::ptr_cast_constness \ -Wclippy::ref_as_ptr \ -Wclippy::undocumented_unsafe_blocks \ -Aclippy::uninlined_format_args \ -Wclippy::unnecessary_safety_comment \ -Wclippy::unnecessary_safety_doc \ -Aclippy::unwrap_or_default \ -Wrustdoc::missing_crate_level_docs \ -Wrustdoc::unescaped_backticks
KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \ $(HOSTCFLAGS) -I $(srctree)/scripts/includeKBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \ -I $(srctree)/scripts/includeKBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \ -Zallow-features=KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)KBUILD_PROCMACROLDFLAGS := $(or $(PROCMACROLDFLAGS),$(KBUILD_HOSTLDFLAGS))
# Make variables (CC, etc...)CPP = $(CC) -Eifneq ($(LLVM),)CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)LLVM_LINK = $(LLVM_PREFIX)llvm-link$(LLVM_SUFFIX)NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX)OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)READELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)ifeq ($(filter -fuse-ld=% --ld-path=%,$(KBUILD_HOSTLDFLAGS)),)KBUILD_HOSTLDFLAGS += -fuse-ld=lldendifelseCC = $(CROSS_COMPILE)gccLD = $(CROSS_COMPILE)ldAR = $(CROSS_COMPILE)arNM = $(CROSS_COMPILE)nmOBJCOPY = $(CROSS_COMPILE)objcopyOBJDUMP = $(CROSS_COMPILE)objdumpREADELF = $(CROSS_COMPILE)readelfSTRIP = $(CROSS_COMPILE)stripendifRUSTC = rustcRUSTDOC = rustdocRUSTFMT = rustfmtCLIPPY_DRIVER = clippy-driverBINDGEN = bindgenPAHOLE = paholeRESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfidsLEX = flexYACC = bisonAWK = awkINSTALLKERNEL := installkernelPERL = perlPYTHON3 = python3CHECK = sparseBASH = bashKGZIP = gzipKBZIP2 = bzip2KLZOP = lzopLZMA = lzmaLZ4 = lz4XZ = xzZSTD = zstdTAR = tar
CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)NOSTDINC_FLAGS :=CFLAGS_MODULE =RUSTFLAGS_MODULE =AFLAGS_MODULE =LDFLAGS_MODULE =CFLAGS_KERNEL =RUSTFLAGS_KERNEL =AFLAGS_KERNEL =LDFLAGS_vmlinux =
# Use USERINCLUDE when you must reference the UAPI directories only.USERINCLUDE := \ -I$(srctree)/arch/$(SRCARCH)/include/uapi \ -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \ -I$(srctree)/include/uapi \ -I$(objtree)/include/generated/uapi \ -include $(srctree)/include/linux/compiler-version.h \ -include $(srctree)/include/linux/kconfig.h
# Use LINUXINCLUDE when you must reference the include/ directory.# Needed to be compatible with the O= optionLINUXINCLUDE := \ -I$(srctree)/arch/$(SRCARCH)/include \ -I$(objtree)/arch/$(SRCARCH)/include/generated \ -I$(srctree)/include \ -I$(objtree)/include \ $(USERINCLUDE)
KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
KBUILD_CFLAGS :=KBUILD_CFLAGS += -fshort-wcharKBUILD_CFLAGS += -funsigned-charKBUILD_CFLAGS += -fno-commonKBUILD_CFLAGS += -fno-PIEKBUILD_CFLAGS += -fno-strict-aliasing
KBUILD_CPPFLAGS := -D__KERNEL__KBUILD_RUSTFLAGS := $(rust_common_flags) \ -Cpanic=abort -Cembed-bitcode=n -Clto=n \ -Cforce-unwind-tables=n -Ccodegen-units=1 \ -Csymbol-mangling-version=v0 \ -Crelocation-model=static \ -Zfunction-sections=n \ -Wclippy::float_arithmeticKBUILD_RUSTFLAGS_OPTION_CHKS :=
KBUILD_AFLAGS_KERNEL :=KBUILD_CFLAGS_KERNEL :=KBUILD_RUSTFLAGS_KERNEL :=KBUILD_AFLAGS_MODULE := -DMODULEKBUILD_CFLAGS_MODULE := -DMODULEKBUILD_RUSTFLAGS_MODULE := --cfg MODULEKBUILD_LDFLAGS_MODULE :=KBUILD_LDFLAGS :=CLANG_FLAGS :=
ifeq ($(KBUILD_CLIPPY),1) RUSTC_OR_CLIPPY_QUIET := CLIPPY RUSTC_OR_CLIPPY = $(CLIPPY_DRIVER)else RUSTC_OR_CLIPPY_QUIET := RUSTC RUSTC_OR_CLIPPY = $(RUSTC)endif
# Allows the usage of unstable features in stable compilers.export RUSTC_BOOTSTRAP := 1
# Allows finding `.clippy.toml` in out-of-srctree builds.export CLIPPY_CONF_DIR := $(srctree)
export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIGexport RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN LLVM_LINKexport HOSTRUSTC KBUILD_HOSTRUSTFLAGSexport CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNELexport PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXXexport KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD TARexport KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS KBUILD_PROCMACROLDFLAGS LDFLAGS_MODULEexport KBUILD_USERCFLAGS KBUILD_USERLDFLAGS
export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGSexport KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULEexport KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE KBUILD_RUSTFLAGS_OPTION_CHKSexport KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULEexport KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULEexport KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL
# Files to ignore in find ... statements
export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \ -name CVS -o -name .pc -o -name .hg -o -name .git \) \ -prune -o
# ===========================================================================# Rules shared between *config targets and build targets
# Basic helpers built in scripts/basic/PHONY += scripts_basicscripts_basic: KBUILD_HOSTCFLAGS := $(KBUILD_HOSTCFLAGS)scripts_basic: KBUILD_HOSTLDFLAGS := $(KBUILD_HOSTLDFLAGS)scripts_basic: $(Q)$(MAKE) $(build)=scripts/basic
PHONY += outputmakefileifdef building_out_of_srctree# Before starting out-of-tree build, make sure the source tree is clean.# outputmakefile generates a Makefile in the output directory, if using a# separate output directory. This allows convenient use of make in the# output directory.# At the same time when output Makefile generated, generate .gitignore to# ignore whole output directory
ifdef KBUILD_EXTMODprint_env_for_makefile = \ echo "export KBUILD_OUTPUT = $(objtree)"; \ echo "export KBUILD_EXTMOD = $(realpath $(srcroot))" ; \ echo "export KBUILD_EXTMOD_OUTPUT = $(CURDIR)"elseprint_env_for_makefile = \ echo "export KBUILD_OUTPUT = $(CURDIR)"endif
filechk_makefile = { \ echo "\# Automatically generated by $(abs_srctree)/Makefile: don't edit"; \ $(print_env_for_makefile); \ echo "include $(abs_srctree)/Makefile"; \ }
PHONY += $(CURDIR)/Makefile$(CURDIR)/Makefile: FORCE $(call filechk,makefile)
outputmakefile: $(CURDIR)/Makefileifeq ($(KBUILD_EXTMOD),) @if [ -f $(srctree)/.config -o \ -d $(srctree)/include/config -o \ -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \ echo >&2 "***"; \ echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \ echo >&2 "*** in $(abs_srctree)";\ echo >&2 "***"; \ false; \ fielse @if [ -f $(srcroot)/modules.order ]; then \ echo >&2 "***"; \ echo >&2 "*** The external module source tree is not clean."; \ echo >&2 "*** Please run 'make -C $(abs_srctree) M=$(realpath $(srcroot)) clean'"; \ echo >&2 "***"; \ false; \ fiendif $(Q)ln -fsn $(srcroot) source $(Q)test -e .gitignore || \ { echo "# this is build directory, ignore it"; echo "*"; } > .gitignoreendif
# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.# CC_VERSION_TEXT, RUSTC_VERSION_TEXT and PAHOLE_VERSION are referenced from# Kconfig (so they need export), and from include/config/auto.conf.cmd to# detect the version changes between builds.CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))RUSTC_VERSION_TEXT = $(subst $(pound),,$(shell $(RUSTC) --version 2>/dev/null))PAHOLE_VERSION = $(shell $(srctree)/scripts/pahole-version.sh $(PAHOLE))
ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)include $(srctree)/scripts/Makefile.clangendif
# Include this also for config targets because some architectures need# cc-cross-prefix to determine CROSS_COMPILE.ifdef need-compilerinclude $(srctree)/scripts/Makefile.compilerendif
ifdef config-build# ===========================================================================# *config targets only - make sure prerequisites are updated, and descend# in scripts/kconfig to make the *config target
# Read arch-specific Makefile to set KBUILD_DEFCONFIG as needed.# KBUILD_DEFCONFIG may point out an alternative default configuration# used for 'make defconfig'include $(srctree)/arch/$(SRCARCH)/Makefileexport KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT RUSTC_VERSION_TEXT PAHOLE_VERSION
config: outputmakefile scripts_basic FORCE $(Q)$(MAKE) $(build)=scripts/kconfig $@
%config: outputmakefile scripts_basic FORCE $(Q)$(MAKE) $(build)=scripts/kconfig $@
else #!config-build# ===========================================================================# Build targets only - this includes vmlinux, arch-specific targets, clean# targets and others. In general all targets except *config targets.
# If building an external module we do not care about the all: rule# but instead __all depend on modulesPHONY += allifeq ($(KBUILD_EXTMOD),)__all: allelse__all: modulesendif
targets :=
# Decide whether to build built-in, modular, or both.# Normally, just do built-in.
KBUILD_MODULES :=KBUILD_BUILTIN := y
# If we have only "make modules", don't compile built-in objects.ifeq ($(MAKECMDGOALS),modules) KBUILD_BUILTIN :=endif
# If we have "make <whatever> modules", compile modules# in addition to whatever we do anyway.# Just "make" or "make all" shall build modules as well
ifneq ($(filter all modules nsdeps compile_commands.json clang-% sbom,$(MAKECMDGOALS)),) KBUILD_MODULES := yendif
ifeq ($(MAKECMDGOALS),) KBUILD_MODULES := yendif
export KBUILD_MODULES KBUILD_BUILTIN
ifdef need-configinclude $(objtree)/include/config/auto.confendif
CC_FLAGS_DIALECT := -std=gnu11# Allow including a tagged struct or union anonymously in another struct/union.CC_FLAGS_DIALECT += $(CONFIG_CC_MS_EXTENSIONS)# Clang enables warnings about GNU and Microsoft extensions by default, disable# them because this is expected with the above options.ifdef CONFIG_CC_IS_CLANGCC_FLAGS_DIALECT += -Wno-gnuCC_FLAGS_DIALECT += -Wno-microsoft-anon-tagendifexport CC_FLAGS_DIALECTKBUILD_CFLAGS += $(CC_FLAGS_DIALECT)
ifeq ($(KBUILD_EXTMOD),)# Objects we will link into vmlinux / subdirs we need to visitcore-y :=drivers-y :=libs-y := lib/endif # KBUILD_EXTMOD
# The all: target is the default when no target is given on the# command line.# This allow a user to issue only 'make' to build a kernel including modules# Defaults to vmlinux, but the arch makefile usually adds further targetsall: vmlinux
# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.ifdef CONFIG_FUNCTION_TRACER CC_FLAGS_FTRACE := -pgendif
ifdef CONFIG_TRACEPOINTS# To check for unused tracepoints (tracepoints that are defined but never# called), run with:## make UT=1## Each unused tracepoints can take up to 5KB of memory in the running kernel.# It is best to remove any that are not used.## This command line option will be removed when all current unused# tracepoints are removed.
ifeq ("$(origin UT)", "command line") WARN_ON_UNUSED_TRACEPOINTS := $(UT)endifendif # CONFIG_TRACEPOINTS
export WARN_ON_UNUSED_TRACEPOINTS
# Per-version Rust flags. These are like `rust_common_flags`, but may# depend on the Rust compiler version (e.g. using `rustc-min-version`).## `-Aclippy::precedence`: the lint was extended in Rust 1.85.0 to# include bitmasking and shift operations. However, because it generated# many hits, in Rust 1.86.0 it was split into a new `precedence_bits`# lint which is not enabled by default.rust_common_flags_per_version := \ $(if $(call rustc-min-version,108600),,-Aclippy::precedence)
rust_common_flags += $(rust_common_flags_per_version)KBUILD_HOSTRUSTFLAGS += $(rust_common_flags_per_version) $(HOSTRUSTFLAGS)KBUILD_RUSTFLAGS += $(rust_common_flags_per_version)
include $(srctree)/arch/$(SRCARCH)/Makefile
ifdef need-configifdef may-sync-config# Read in dependencies to all Kconfig* files, make sure to run syncconfig if# changes are detected. This should be included after arch/$(SRCARCH)/Makefile# because some architectures define CROSS_COMPILE there.include include/config/auto.conf.cmd
$(KCONFIG_CONFIG): @echo >&2 '***' @echo >&2 '*** Configuration file "$@" not found!' @echo >&2 '***' @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or' @echo >&2 '*** "make menuconfig" or "make xconfig").' @echo >&2 '***' @/bin/false
# The actual configuration files used during the build are stored in# include/generated/ and include/config/. Update them if .config is newer than# include/config/auto.conf (which mirrors .config).## This exploits the 'multi-target pattern rule' trick.# The syncconfig should be executed only once to make all the targets.# (Note: use the grouped target '&:' when we bump to GNU Make 4.3)## Do not use $(call cmd,...) here. That would suppress prompts from syncconfig,# so you cannot notice that Kconfig is waiting for the user input.%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h %/generated/rustc_cfg: $(KCONFIG_CONFIG) $(Q)$(kecho) " SYNC $@" $(Q)$(MAKE) -f $(srctree)/Makefile syncconfigelse # !may-sync-config# External modules and some install targets need include/generated/autoconf.h# and include/config/auto.conf but do not care if they are up-to-date.# Use auto.conf to show the error message
checked-configs := $(addprefix $(objtree)/, include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf)missing-configs := $(filter-out $(wildcard $(checked-configs)), $(checked-configs))
ifdef missing-configsPHONY += $(objtree)/include/config/auto.conf
$(objtree)/include/config/auto.conf: @echo >&2 '***' @echo >&2 '*** ERROR: Kernel configuration is invalid. The following files are missing:' @printf >&2 '*** - %s\n' $(missing-configs) @echo >&2 '*** Run "make oldconfig && make prepare" on kernel source to fix it.' @echo >&2 '***' @/bin/falseendif
endif # may-sync-configendif # need-config
KBUILD_CFLAGS += -fno-delete-null-pointer-checks
ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCEKBUILD_CFLAGS += -O2KBUILD_RUSTFLAGS += -Copt-level=2else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZEKBUILD_CFLAGS += -OsKBUILD_RUSTFLAGS += -Copt-level=sendif
# Always set `debug-assertions` and `overflow-checks` because their default# depends on `opt-level` and `debug-assertions`, respectively.KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n)KBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n)
# Tell gcc to never replace conditional load with a non-conditional oneifdef CONFIG_CC_IS_GCC# gcc-10 renamed --param=allow-store-data-races=0 to# -fno-allow-store-data-races.KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races)endif
ifdef CONFIG_READABLE_ASM# Disable optimizations that make assembler listings hard to read.# reorder blocks reorders the control in the function# ipa clone creates specialized cloned functions# partial inlining inlines only parts of functionsKBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inliningendif
stackp-flags-y := -fno-stack-protectorstackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protectorstackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
KBUILD_CFLAGS += $(stackp-flags-y)
ifdef CONFIG_FRAME_POINTERKBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-callsKBUILD_RUSTFLAGS += -Cforce-frame-pointers=y# Work around rustc bug on compilers without# https://github.com/rust-lang/rust/pull/156980.KBUILD_RUSTFLAGS += $(if $(call rustc-min-version,109800),,-Zllvm_module_flag=frame-pointer:u32:2:max)else# Some targets (ARM with Thumb2, for example), can't be built with frame# pointers. For those, we don't have FUNCTION_TRACER automatically# select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is# incompatible with -fomit-frame-pointer with current GCC, so we don't use# -fomit-frame-pointer with FUNCTION_TRACER.# In the Rust target specification, "frame-pointer" is set explicitly# to "may-omit".ifndef CONFIG_FUNCTION_TRACERKBUILD_CFLAGS += -fomit-frame-pointerendifendif
# Initialize all stack variables with a 0xAA pattern.ifdef CONFIG_INIT_STACK_ALL_PATTERNKBUILD_CFLAGS += -ftrivial-auto-var-init=patternendif
# Initialize all stack variables with a zero value.ifdef CONFIG_INIT_STACK_ALL_ZEROKBUILD_CFLAGS += -ftrivial-auto-var-init=zeroifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER# https://github.com/llvm/llvm-project/issues/44842CC_AUTO_VAR_INIT_ZERO_ENABLER := -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clangexport CC_AUTO_VAR_INIT_ZERO_ENABLERKBUILD_CFLAGS += $(CC_AUTO_VAR_INIT_ZERO_ENABLER)endifendif
ifdef CONFIG_KMALLOC_PARTITION_TYPED# KMALLOC_PARTITION_CACHES_NR + 1KBUILD_CFLAGS += -falloc-token-max=16endif
ifdef CONFIG_CC_IS_CLANGifdef CONFIG_CC_HAS_COUNTED_BY_PTRKBUILD_CFLAGS += -fexperimental-late-parse-attributesendifendif
# Explicitly clear padding bits during variable initializationKBUILD_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all)
# While VLAs have been removed, GCC produces unreachable stack probes# for the randomize_kstack_offset feature. Disable it for all compilers.KBUILD_CFLAGS += $(call cc-option, -fno-stack-clash-protection)
# Get details on warnings generated due to GCC value tracking.KBUILD_CFLAGS += $(call cc-option, -fdiagnostics-show-context=2)
# Show inlining notes for __attribute__((warning/error)) call chains.# GCC supports this unconditionally while Clang 23+ provides a flag.KBUILD_CFLAGS += $(call cc-option, -fdiagnostics-show-inlining-chain)
# Clear used registers at func exit (to reduce data lifetime and ROP gadgets).ifdef CONFIG_ZERO_CALL_USED_REGSKBUILD_CFLAGS += -fzero-call-used-regs=used-gprendif
ifdef CONFIG_FUNCTION_TRACERifdef CONFIG_FTRACE_MCOUNT_USE_CC CC_FLAGS_FTRACE += -mrecord-mcount ifdef CONFIG_HAVE_NOP_MCOUNT ifeq ($(call cc-option-yn, -mnop-mcount),y) CC_FLAGS_FTRACE += -mnop-mcount CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT endif endifendififdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL ifdef CONFIG_HAVE_OBJTOOL_NOP_MCOUNT CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT endifendififdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT ifdef CONFIG_HAVE_C_RECORDMCOUNT BUILD_C_RECORDMCOUNT := y export BUILD_C_RECORDMCOUNT endifendififdef CONFIG_HAVE_FENTRY # s390-linux-gnu-gcc did not support -mfentry until gcc-9. ifeq ($(call cc-option-yn, -mfentry),y) CC_FLAGS_FTRACE += -mfentry CC_FLAGS_USING += -DCC_USING_FENTRY endifendifexport CC_FLAGS_FTRACEKBUILD_CFLAGS += $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING)KBUILD_AFLAGS += $(CC_FLAGS_USING)endif
# We trigger additional mismatches with less inliningifdef CONFIG_DEBUG_SECTION_MISMATCHKBUILD_CFLAGS += -fno-inline-functions-called-onceendif
# `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0).ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATIONKBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sectionsKBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=yLDFLAGS_vmlinux += --gc-sectionsendif
ifdef CONFIG_SHADOW_CALL_STACKifndef CONFIG_DYNAMIC_SCSCC_FLAGS_SCS := -fsanitize=shadow-call-stackKBUILD_CFLAGS += $(CC_FLAGS_SCS)KBUILD_RUSTFLAGS += -Zsanitizer=shadow-call-stackendifexport CC_FLAGS_SCSendif
ifdef CONFIG_RUST_INLINE_HELPERS# `rustc` normally emits traps for unreachable paths during code generation.# With inline helpers, Clang performs code generation from the linked bitcode# instead, so request the same behavior explicitly. Otherwise `objtool` may# follow an impossible Rust path into the next function.CC_FLAGS_RUST_INLINE_HELPERS := -mllvm -trap-unreachable \ -mllvm -no-trap-after-noreturnexport CC_FLAGS_RUST_INLINE_HELPERSendif
ifdef CONFIG_LTO_CLANGifdef CONFIG_LTO_CLANG_FULLCC_FLAGS_LTO := -fltoelseCC_FLAGS_LTO := -flto=thin -fsplit-lto-unit
# These LLVM options were initially added with only in-process ThinLTO# support, so avoid distributed ThinLTO support for now.ifdef CONFIG_LTO_CLANG_THINKBUILD_LDFLAGS += $(call ld-option,--lto-whole-program-visibility -mllvm -always-rename-promoted-locals=false)endifendifCC_FLAGS_LTO += -fvisibility=hidden
# Limit inlining across translation units to reduce binary sizeKBUILD_LDFLAGS += -mllvm -import-instr-limit=5endif
ifdef CONFIG_LTOKBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO)KBUILD_AFLAGS += -fno-ltoexport CC_FLAGS_LTOendif
ifdef CONFIG_CFICC_FLAGS_CFI := -fsanitize=kcfiifdef CONFIG_CFI_ICALL_NORMALIZE_INTEGERS CC_FLAGS_CFI += -fsanitize-cfi-icall-experimental-normalize-integersendififdef CONFIG_FINEIBT_BHI CC_FLAGS_CFI += -fsanitize-kcfi-arityendififdef CONFIG_RUST # Always pass -Zsanitizer-cfi-normalize-integers as CONFIG_RUST selects # CONFIG_CFI_ICALL_NORMALIZE_INTEGERS. # Disable function merging as LLVM incorrectly merges functions with different KCFI types. RUSTC_FLAGS_CFI := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers -Zmerge-functions=disabled KBUILD_RUSTFLAGS += $(RUSTC_FLAGS_CFI) export RUSTC_FLAGS_CFIendifKBUILD_CFLAGS += $(CC_FLAGS_CFI)export CC_FLAGS_CFIendif
# Architectures can define flags to add/remove for floating-point supportCC_FLAGS_FPU += -D_LINUX_FPU_COMPILATION_UNITexport CC_FLAGS_FPUexport CC_FLAGS_NO_FPU
ifneq ($(CONFIG_FUNCTION_ALIGNMENT),0)# Set the minimal function alignment. Use the newer GCC option# -fmin-function-alignment if it is available, or fall back to -falign-funtions.# See also CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT.ifdef CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENTKBUILD_CFLAGS += -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT)elseKBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT)endifendif
# arch Makefile may override CC so keep this after arch Makefile is includedNOSTDINC_FLAGS += -nostdinc
# To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE,# the kernel uses only C99 flexible arrays for dynamically sized trailing# arrays. Enforce this for everything that may examine structure sizes and# perform bounds checking.KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
# disable invalid "can't wrap" optimizations for signed / pointersKBUILD_CFLAGS += -fno-strict-overflow
# Make sure -fstack-check isn't enabled (like gentoo apparently did)KBUILD_CFLAGS += -fno-stack-check
# conserve stack if availableifdef CONFIG_CC_IS_GCCKBUILD_CFLAGS += -fconserve-stackendif
# Ensure compilers do not transform certain loops into calls to wcslen()KBUILD_CFLAGS += -fno-builtin-wcslen
CFLAGS_GCOV := -fprofile-arcs -ftest-coverageifdef CONFIG_CC_IS_GCCCFLAGS_GCOV += -fno-tree-loop-im# Use atomic counter updates to avoid concurrent-access crashes in GCOV.# Only enable if -fprofile-update=prefer-atomic does not introduce new# undefined symbols (e.g. libatomic calls that the kernel cannot link).CFLAGS_GCOV += $(call try-run,\ echo 'long long x; void f(void){x++;}' | \ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -w -fprofile-arcs \ -ftest-coverage -x c - -c -o "$$TMP.base" && \ echo 'long long x; void f(void){x++;}' | \ $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -w -fprofile-arcs \ -ftest-coverage -fprofile-update=prefer-atomic \ -x c - -c -o "$$TMP" && \ $(NM) "$$TMP.base" | grep ' U ' > "$$TMP.ubase" || true ; \ $(NM) "$$TMP" | grep ' U ' > "$$TMP.utest" || true ; \ cmp -s "$$TMP.ubase" "$$TMP.utest",\ -fprofile-update=prefer-atomic)endifexport CFLAGS_GCOV
# change __FILE__ to the relative path to the source directoryifdef building_out_of_srctreeKBUILD_CPPFLAGS += -fmacro-prefix-map=$(srcroot)/=ifeq ($(call rustc-option-yn, --remap-path-scope=macro),y)KBUILD_RUSTFLAGS += --remap-path-prefix=$(srcroot)/= --remap-path-scope=macroendifendif
# include additional Makefiles when neededinclude-y := scripts/Makefile.warninclude-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debuginclude-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btfinclude-$(CONFIG_KASAN) += scripts/Makefile.kasaninclude-$(CONFIG_KCSAN) += scripts/Makefile.kcsaninclude-$(CONFIG_KMSAN) += scripts/Makefile.kmsaninclude-$(CONFIG_UBSAN) += scripts/Makefile.ubsaninclude-$(CONFIG_KCOV) += scripts/Makefile.kcovinclude-$(CONFIG_RANDSTRUCT) += scripts/Makefile.randstructinclude-$(CONFIG_KSTACK_ERASE) += scripts/Makefile.kstack_eraseinclude-$(CONFIG_AUTOFDO_CLANG) += scripts/Makefile.autofdoinclude-$(CONFIG_PROPELLER_CLANG) += scripts/Makefile.propellerinclude-$(CONFIG_WARN_CONTEXT_ANALYSIS) += scripts/Makefile.context-analysisinclude-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins
include $(addprefix $(srctree)/, $(include-y))
# scripts/Makefile.gcc-plugins is intentionally included last.# Do not add $(call cc-option,...) below this line. When you build the kernel# from the clean source tree, the GCC plugins do not exist at this point.
# Add user supplied CPPFLAGS, AFLAGS, CFLAGS and RUSTFLAGS as the last assignmentsKBUILD_CPPFLAGS += $(KCPPFLAGS)KBUILD_AFLAGS += $(KAFLAGS)KBUILD_CFLAGS += $(KCFLAGS)KBUILD_RUSTFLAGS += $(KRUSTFLAGS)
KBUILD_LDFLAGS_MODULE += --build-id=sha1LDFLAGS_vmlinux += --build-id=sha1
# Specific code, such as outlined KASAN checks, may be placed in# COMDAT-deduplicated sections. Use --force-group-allocation to resolve these# groups when linking modules. The option is available from ld.bfd 2.29 and# ld.lld 19.1.0.KBUILD_LDFLAGS_MODULE += $(call ld-option,--force-group-allocation)
KBUILD_LDFLAGS += -z noexecstackifeq ($(CONFIG_LD_IS_BFD),y)KBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments)endif
ifeq ($(CONFIG_STRIP_ASM_SYMS),y)LDFLAGS_vmlinux += -Xendif
ifeq ($(CONFIG_RELR),y)# ld.lld before 15 did not support -z pack-relative-relocs.LDFLAGS_vmlinux += $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs)endif
# We never want expected sections to be placed heuristically by the# linker. All sections should be explicitly named in the linker script.ifdef CONFIG_LD_ORPHAN_WARNLDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)endif
ifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),)LDFLAGS_vmlinux += --emit-relocs --discard-noneendif
# Align the architecture of userspace programs with the kernelUSERFLAGS_FROM_KERNEL := --target=%
ifdef CONFIG_ARCH_USERFLAGSKBUILD_USERCFLAGS += $(CONFIG_ARCH_USERFLAGS)KBUILD_USERLDFLAGS += $(CONFIG_ARCH_USERFLAGS)else# If not overridden also inherit the bit sizeUSERFLAGS_FROM_KERNEL += -m32 -m64endif
KBUILD_USERCFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))KBUILD_USERLDFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS))
# userspace programs are linked via the compiler, use the correct linkerifdef CONFIG_CC_IS_CLANGKBUILD_USERLDFLAGS += --ld-path=$(LD)endif
# make the checker run with the right architectureCHECKFLAGS += --arch=$(ARCH)
# insure the checker run with the right endiannessCHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
# the checker needs the correct machine sizeCHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
# Validate the checker is available and functionalifneq ($(KBUILD_CHECKSRC), 0) ifneq ($(shell $(srctree)/scripts/checker-valid.sh $(CHECK) $(CHECKFLAGS)), 1) $(warning C=$(KBUILD_CHECKSRC) specified, but $(CHECK) is not available or not up to date) KBUILD_CHECKSRC = 0 endifendif
# Default kernel image to build when no specific target is given.# KBUILD_IMAGE may be overruled on the command line or# set in the environment# Also any assignments in arch/$(ARCH)/Makefile take precedence over# this default valueexport KBUILD_IMAGE ?= vmlinux
## INSTALL_PATH specifies where to place the updated kernel and system map# images. Default is /boot, but you can set it to other valuesexport INSTALL_PATH ?= /boot
## INSTALL_DTBS_PATH specifies a prefix for relocations required by build roots.# Like INSTALL_MOD_PATH, it isn't defined in the Makefile, but can be passed as# an argument if needed. Otherwise it defaults to the kernel install path#export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE)
## INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory# relocations required by build roots. This is not defined in the# makefile but the argument can be passed to make if needed.#
MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)export MODLIB
PHONY += prepare0
ifeq ($(KBUILD_EXTMOD),)
build-dir := .clean-dirs := $(sort . Documentation \ $(patsubst %/,%,$(filter %/, $(core-) \ $(drivers-) $(libs-))))
export ARCH_CORE := $(core-y)export ARCH_LIB := $(filter %/, $(libs-y))export ARCH_DRIVERS := $(drivers-y) $(drivers-m)# Externally visible symbols (used by link-vmlinux.sh)
KBUILD_VMLINUX_OBJS := built-in.a $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBSexport KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
ifdef CONFIG_TRIM_UNUSED_KSYMS# For the kernel to actually contain only the needed exported symbols,# we have to build modules as well to determine what those symbols are.KBUILD_MODULES := yendif
PHONY += vmlinux_avmlinux_a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_a
vmlinux.a: vmlinux_a @:
PHONY += vmlinux_ovmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_o
vmlinux.o: vmlinux_o @:
PHONY += vmlinux# LDFLAGS_vmlinux in the top Makefile defines linker flags for the top vmlinux,# not for decompressors. LDFLAGS_vmlinux in arch/*/boot/compressed/Makefile is# unrelated; the decompressors just happen to have the same base name,# arch/*/boot/compressed/vmlinux.# Export LDFLAGS_vmlinux only to scripts/Makefile.vmlinux.## _LDFLAGS_vmlinux is a workaround for the 'private export' bug:# https://savannah.gnu.org/bugs/?61463# For Make > 4.4, the following simple code will work:# vmlinux: private export LDFLAGS_vmlinux := $(LDFLAGS_vmlinux)vmlinux: private _LDFLAGS_vmlinux := $(LDFLAGS_vmlinux)vmlinux: export LDFLAGS_vmlinux = $(_LDFLAGS_vmlinux)vmlinux: vmlinux.o $(KBUILD_LDS) modpost $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux
# The actual objects are generated when descending,# make sure no implicit rule kicks in$(sort $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)): . ;
ifeq ($(origin KERNELRELEASE),file)filechk_kernel.release = $(srctree)/scripts/setlocalversion $(srctree)elsefilechk_kernel.release = echo $(KERNELRELEASE)endif
# Store (new) KERNELRELEASE string in include/config/kernel.releaseinclude/config/kernel.release: FORCE $(call filechk,kernel.release)
# Additional helpers built in scripts/# Carefully list dependencies so we do not try to build scripts twice# in parallelPHONY += scriptsscripts: scripts_basic scripts_dtc $(Q)$(MAKE) $(build)=$(@)
# Things we need to do before we recursively start building the kernel# or the modules are listed in "prepare".# A multi level approach is used. prepareN is processed before prepareN-1.# archprepare is used in arch Makefiles and when processed asm symlink,# version.h and scripts_basic is processed / created.
PHONY += prepare archprepare
archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \ asm-generic $(version_h) include/generated/utsrelease.h \ include/generated/compile.h include/generated/autoconf.h \ include/generated/rustc_cfg remove-stale-files
prepare0: archprepare $(Q)$(MAKE) $(build)=scripts/mod $(Q)$(MAKE) $(build)=. prepare
# All the preparing..prepare: prepare0ifdef CONFIG_RUST +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh $(Q)$(MAKE) $(build)=rustendif
PHONY += remove-stale-filesremove-stale-files: $(Q)$(srctree)/scripts/remove-stale-files
# Support for using generic headers in asm-genericasm-generic := -f $(srctree)/scripts/Makefile.asm-headers obj
PHONY += asm-generic uapi-asm-genericasm-generic: uapi-asm-generic $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \ generic=include/asm-genericuapi-asm-generic: $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \ generic=include/uapi/asm-generic
# Generate some files# ---------------------------------------------------------------------------
# KERNELRELEASE can change from a few different places, meaning version.h# needs to be updated, so this check is forced on all builds
uts_len := 64define filechk_utsrelease.h if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \ echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \ exit 1; \ fi; \ echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"endef
define filechk_version.h if [ $(SUBLEVEL) -gt 255 ]; then \ echo \#define LINUX_VERSION_CODE $(shell \ expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + 255); \ else \ echo \#define LINUX_VERSION_CODE $(shell \ expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ fi; \ echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ ((c) > 255 ? 255 : (c)))'; \ echo \#define LINUX_VERSION_MAJOR $(VERSION); \ echo \#define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL); \ echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL)endef
$(version_h): private PATCHLEVEL := $(or $(PATCHLEVEL), 0)$(version_h): private SUBLEVEL := $(or $(SUBLEVEL), 0)$(version_h): FORCE $(call filechk,version.h)
include/generated/utsrelease.h: include/config/kernel.release FORCE $(call filechk,utsrelease.h)
filechk_compile.h = $(srctree)/scripts/mkcompile_h \ "$(UTS_MACHINE)" "$(CONFIG_CC_VERSION_TEXT)" "$(LD)"
include/generated/compile.h: FORCE $(call filechk,compile.h)
PHONY += headerdepheaderdep: $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \ $(srctree)/scripts/headerdep.pl -I$(srctree)/include
# ---------------------------------------------------------------------------# Kernel headers
#Default location for installed headersexport INSTALL_HDR_PATH = $(objtree)/usr
quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include cmd_headers_install = \ mkdir -p $(INSTALL_HDR_PATH); \ rsync -mrl --include='*/' --include='*\.h' --exclude='*' \ usr/include $(INSTALL_HDR_PATH)
PHONY += headers_installheaders_install: headers $(call cmd,headers_install)
PHONY += archheaders archscripts
hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
PHONY += headersheaders: $(version_h) scripts_unifdef uapi-asm-generic archheadersifdef HEADER_ARCH $(Q)$(MAKE) -f $(srctree)/Makefile HEADER_ARCH= SRCARCH=$(HEADER_ARCH) headerselse $(Q)$(MAKE) $(hdr-inst)=include/uapi $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapiendif
ifdef CONFIG_HEADERS_INSTALLprepare: headersendif
PHONY += usr_gen_init_cpiousr_gen_init_cpio: scripts_basic $(Q)$(MAKE) $(build)=usr usr/gen_init_cpio
PHONY += scripts_unifdefscripts_unifdef: scripts_basic $(Q)$(MAKE) $(build)=scripts scripts/unifdef
PHONY += scripts_gen_packed_field_checksscripts_gen_packed_field_checks: scripts_basic $(Q)$(MAKE) $(build)=scripts scripts/gen_packed_field_checks
# ---------------------------------------------------------------------------# Install
# Many distributions have the custom install script, /sbin/installkernel.# If DKMS is installed, 'make install' will eventually recurse back# to this Makefile to build and install external modules.# Cancel sub_make_done so that options such as M=, V=, etc. are parsed.
quiet_cmd_install = INSTALL $(INSTALL_PATH) cmd_install = unset sub_make_done; $(srctree)/scripts/install.sh
# ---------------------------------------------------------------------------# vDSO install
PHONY += vdso_installvdso_install: export INSTALL_FILES = $(vdso-install-y)vdso_install: $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vdsoinst
# ---------------------------------------------------------------------------# Tools
ifdef CONFIG_OBJTOOLprepare: tools/objtoolendif
ifdef CONFIG_BPFifdef CONFIG_DEBUG_INFO_BTFprepare: tools/bpf/resolve_btfidsendifendif
# tools/bootconfig renders the embedded bootconfig into a cmdline at build time.ifdef CONFIG_CMDLINE_FROM_BOOTCONFIGprepare: tools/bootconfigendif
# tools/bootconfig is run on the build host during prepare, so force a host# binary here; its own Makefile keeps $(CC) for standalone and cross builds.# CROSS_COMPILE= is cleared so tools/scripts/Makefile.include does not inject# the target's --target=/--sysroot= flags into the host clang invocation under# LLVM=1 cross builds (which would produce a target binary that fails to exec).tools/bootconfig: export CC := $(HOSTCC)tools/bootconfig: FORCE $(Q)mkdir -p $(objtree)/tools $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ \ bootconfig CROSS_COMPILE=
# The tools build system is not a part of Kbuild and tends to introduce# its own unique issues. If you need to integrate a new tool into Kbuild,# please consider locating that tool outside the tools/ tree and using the# standard Kbuild "hostprogs" syntax instead of adding a new tools/* entry# here. See Documentation/kbuild/makefiles.rst for details.
PHONY += resolve_btfids_clean
resolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids
# tools/bpf/resolve_btfids directory might not exist# in output directory, skip its clean in that caseresolve_btfids_clean:ifneq ($(wildcard $(resolve_btfids_O)),) $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) cleanendif
PHONY += objtool_clean objtool_mrproper
objtool_O = $(abspath $(objtree))/tools/objtool
objtool_clean objtool_mrproper:ifneq ($(wildcard $(objtool_O)),) $(Q)$(MAKE) -sC $(abs_srctree)/tools/objtool O=$(objtool_O) srctree=$(abs_srctree) $(patsubst objtool_%,%,$@)endif
PHONY += bootconfig_clean
bootconfig_O = $(abspath $(objtree))/tools/bootconfig
bootconfig_clean:ifneq ($(wildcard $(bootconfig_O)),) $(Q)$(MAKE) -sC $(srctree)/tools/bootconfig O=$(bootconfig_O) cleanendif
tools/: FORCE $(Q)mkdir -p $(objtree)/tools $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
tools/%: FORCE $(Q)mkdir -p $(objtree)/tools $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
# ---------------------------------------------------------------------------# Kernel selftest
PHONY += kselftestkselftest: headers $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests run_tests
kselftest-%: headers FORCE $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests $*
PHONY += kselftest-mergekselftest-merge: $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!)) $(Q)find $(srctree)/tools/testing/selftests -name config -o -name config.$(UTS_MACHINE) | \ xargs $(srctree)/scripts/kconfig/merge_config.sh -y -m $(objtree)/.config $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
# ---------------------------------------------------------------------------# Devicetree files
ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)dtstree := arch/$(SRCARCH)/boot/dtsendif
dtbindingtree := Documentation/devicetree/bindings
%.yaml: dtbs_prepare $(Q)$(MAKE) $(build)=$(dtbindingtree) \ $(dtbindingtree)/$(patsubst %.yaml,%.example.dtb,$@) dt_binding_check_one
ifneq ($(dtstree),)
%.dtb: dtbs_prepare $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
%.dtbo: dtbs_prepare $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
PHONY += dtbs dtbs_prepare dtbs_install dtbs_checkdtbs: dtbs_prepare $(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1
# include/config/kernel.release is actually needed when installing DTBs because# INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make# dtbs_install depend on it as dtbs_install may run as root.dtbs_prepare: include/config/kernel.release scripts_dtc
ifneq ($(filter dtbs_check %.yaml, $(MAKECMDGOALS)),)export CHECK_DTBS=yendif
ifneq ($(CHECK_DTBS),)dtbs_prepare: dt_binding_schemasendif
dtbs_check: dtbs
dtbs_install: $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree)
ifdef CONFIG_OF_EARLY_FLATTREEall: dtbsendif
ifdef CONFIG_GENERIC_BUILTIN_DTBvmlinux: dtbsendif
endif
PHONY += scripts_dtcscripts_dtc: scripts_basic $(Q)$(MAKE) $(build)=scripts/dtc
ifneq ($(filter dt_binding_check, $(MAKECMDGOALS)),)export CHECK_DTBS=yendif
PHONY += dt_binding_check dt_binding_schemasdt_binding_check: dt_binding_schemas scripts_dtc $(Q)$(MAKE) $(build)=$(dtbindingtree) $@
dt_binding_schemas: $(Q)$(MAKE) $(build)=$(dtbindingtree)
PHONY += dt_compatible_checkdt_compatible_check: dt_binding_schemas $(Q)$(MAKE) $(build)=$(dtbindingtree) $@
PHONY += dt_style_selftestdt_style_selftest: $(Q)$(srctree)/scripts/dtc/dt-style-selftest/run.sh
# ---------------------------------------------------------------------------# Modules
ifdef CONFIG_MODULES
# By default, build modules as well
all: modules
# When we're building modules with modversions, we need to consider# the built-in objects during the descend as well, in order to# make sure the checksums are up to date before we record them.ifdef CONFIG_MODVERSIONS KBUILD_BUILTIN := yendif
# Build modules#
# *.ko are usually independent of vmlinux, but CONFIG_DEBUG_INFO_BTF_MODULES# is an exception.ifdef CONFIG_DEBUG_INFO_BTF_MODULESKBUILD_BUILTIN := ymodules: vmlinuxendif
modules: modules_prepare
# Target to prepare building external modulesmodules_prepare: prepare $(Q)$(MAKE) $(build)=scripts scripts/module.lds
endif # CONFIG_MODULES
#### Cleaning is done on three levels.# make clean Delete most generated files# Leave enough to build external modules# make mrproper Delete the current configuration, and all generated files# make distclean Remove editor backup files, patch leftover files and the like
# Directories & files removed with 'make clean'CLEAN_FILES += vmlinux.symvers modules-only.symvers \ modules.builtin modules.builtin.modinfo modules.nsdeps \ modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \ vmlinux.thinlto-index builtin.order \ compile_commands.json rust/test \ rust-project.json .vmlinux.objs .vmlinux.export.c \ .builtin-dtbs-list .builtin-dtbs.S sbom-*.spdx.json
# Directories & files removed with 'make mrproper'MRPROPER_FILES += include/config include/generated \ arch/$(SRCARCH)/include/generated .objdiff \ debian snap tar-install PKGBUILD pacman \ .config .config.old .version \ Module.symvers \ certs/signing_key.pem \ certs/x509.genkey \ vmlinux-gdb.py \ rpmbuild \ rust/libmacros.so rust/libmacros.dylib \ rust/libpin_init_internal.so rust/libpin_init_internal.dylib \ rust/libzerocopy_derive.so rust/libzerocopy_derive.dylib
# clean - Delete most, but leave enough to build external modules#clean: private rm-files := $(CLEAN_FILES)
PHONY += archclean vmlinuxclean
vmlinuxclean: $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
clean: archclean vmlinuxclean resolve_btfids_clean objtool_clean bootconfig_clean
# mrproper - Delete all generated files, including .config#mrproper: private rm-files := $(MRPROPER_FILES)mrproper-dirs := $(addprefix _mrproper_,scripts)
PHONY += $(mrproper-dirs) mrproper$(mrproper-dirs): $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
mrproper: clean objtool_mrproper $(mrproper-dirs) $(call cmd,rmfiles) @find . $(RCS_FIND_IGNORE) \ \( -name '*.rmeta' \) \ -type f -print | xargs rm -f
# distclean#PHONY += distclean
distclean: mrproper @find . $(RCS_FIND_IGNORE) \ \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ -o -name '*.bak' -o -name '#*#' -o -name '*%' \ -o -name 'core' -o -name tags -o -name TAGS -o -name 'cscope*' \ -o -name GPATH -o -name GRTAGS -o -name GSYMS -o -name GTAGS \) \ -type f -print | xargs rm -f
# Packaging of the kernel to various formats# ---------------------------------------------------------------------------
modules-cpio-pkg: usr_gen_init_cpio
%src-pkg: FORCE $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@%pkg: include/config/kernel.release FORCE $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
# Brief documentation of the typical targets used# ---------------------------------------------------------------------------
boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig)boards := $(sort $(notdir $(boards)))board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))board-dirs := $(sort $(notdir $(board-dirs:/=)))
PHONY += helphelp: @echo 'Cleaning targets:' @echo ' clean - Remove most generated files but keep the config and' @echo ' enough build support to build external modules' @echo ' mrproper - Remove all generated files + config + various backup files' @echo ' distclean - mrproper + remove editor backup and patch files' @echo '' @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help @echo '' @echo 'Other generic targets:' @echo ' all - Build all targets marked with [*]' @echo '* vmlinux - Build the bare kernel' @echo '* modules - Build all modules' @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)' @echo ' vdso_install - Install unstripped vdso to INSTALL_MOD_PATH (default: /)' @echo ' dir/ - Build all files in dir and below' @echo ' dir/file.[ois] - Build specified target only' @echo ' dir/file.ll - Build the LLVM assembly file' @echo ' (requires compiler support for LLVM assembly generation)' @echo ' dir/file.lst - Build specified mixed source/assembly target only' @echo ' (requires a recent binutils and recent build (System.map))' @echo ' dir/file.ko - Build module including final link' @echo ' modules_prepare - Set up for building external modules' @echo ' tags/TAGS - Generate tags file for editors' @echo ' cscope - Generate cscope index' @echo ' gtags - Generate GNU GLOBAL index' @echo ' kernelrelease - Output the release version string (use with make -s)' @echo ' kernelversion - Output the version stored in Makefile (use with make -s)' @echo ' image_name - Output the image name (use with make -s)' @echo ' headers - Build ready-to-install UAPI headers in usr/include' @echo ' headers_install - Install sanitised kernel UAPI headers to INSTALL_HDR_PATH'; \ echo ' (default: $(INSTALL_HDR_PATH))'; \ echo '' @echo 'Static analysers:' @echo ' checkstack - Generate a list of stack hogs and consider all functions' @echo ' with a stack size larger than MINSTACKSIZE (default: 100)' @echo ' versioncheck - Sanity check on version.h usage' @echo ' includecheck - Check for duplicate included header files' @echo ' headerdep - Detect inclusion cycles in headers' @echo ' coccicheck - Check with Coccinelle' @echo ' kconfig-sym-check - Check for dangling Kconfig symbol references' @echo ' clang-analyzer - Check with clang static analyzer' @echo ' clang-tidy - Check with clang-tidy' @echo '' @echo 'Tools:' @echo ' nsdeps - Generate missing symbol namespace dependencies' @echo ' sbom - Generate Software Bill of Materials' @echo '' @echo 'Kernel selftest:' @echo ' kselftest - Build and run kernel selftest' @echo ' Build, install, and boot kernel before' @echo ' running kselftest on it' @echo ' Run as root for full coverage' @echo ' kselftest-all - Build kernel selftest' @echo ' kselftest-install - Build and install kernel selftest' @echo ' kselftest-clean - Remove all generated kselftest files' @echo ' kselftest-merge - Merge all the config dependencies of' @echo ' kselftest to existing .config.' @echo '' @echo 'Rust targets:' @echo ' rustavailable - Checks whether the Rust toolchain is' @echo ' available and, if not, explains why.' @echo ' rustfmt - Reformat all the Rust code in the kernel' @echo ' rustfmtcheck - Checks if all the Rust code in the kernel' @echo ' is formatted, printing a diff otherwise.' @echo ' rustdoc - Generate Rust documentation' @echo ' (requires kernel .config)' @echo ' rusttest - Runs the Rust tests' @echo ' (requires kernel .config; downloads external repos)' @echo ' rust-analyzer - Generate rust-project.json rust-analyzer support file' @echo ' (requires kernel .config)' @echo ' dir/file.[os] - Build specified target only' @echo ' dir/file.rsi - Build macro expanded source, similar to C preprocessing.' @echo ' Run with RUSTFMT=n to skip reformatting if needed.' @echo ' The output is not intended to be compilable.' @echo ' dir/file.ll - Build the LLVM assembly file' @echo '' @$(if $(dtstree), \ echo 'Devicetree:'; \ echo '* dtbs - Build device tree blobs for enabled boards'; \ echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \ echo ' dt_binding_check - Validate device tree binding documents and examples'; \ echo ' dt_binding_schemas - Build processed device tree binding schemas'; \ echo ' dt_style_selftest - Run dt-check-style fixture tests'; \ echo ' dtbs_check - Validate device tree source files';\ echo '')
@echo 'Userspace tools targets:' @echo ' use "make tools/help"' @echo ' or "cd tools; make help"' @echo '' @echo 'Kernel packaging:' @$(MAKE) -f $(srctree)/scripts/Makefile.package help @echo '' @echo 'Documentation targets:' @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp @echo '' @echo 'Architecture-specific targets ($(SRCARCH)):' @$(or $(archhelp),\ echo ' No architecture-specific help defined for $(SRCARCH)') @echo '' @$(if $(boards), \ $(foreach b, $(boards), \ printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \ echo '') @$(if $(board-dirs), \ $(foreach b, $(board-dirs), \ printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \ printf " %-16s - Show all of the above\\n" help-boards; \ echo '')
@echo ' make V=n [targets] 1: verbose build' @echo ' 2: give reason for rebuild of target' @echo ' V=1 and V=2 can be combined with V=12' @echo ' make O=dir [targets] Locate all output files in "dir", including .config' @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK' @echo ' (sparse by default)' @echo ' make C=2 [targets] Force check of all c source with $$CHECK' @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections' @echo ' make W=n [targets] Enable extra build checks, n=1,2,3,c,e where' @echo ' 1: warnings which may be relevant and do not occur too often' @echo ' 2: warnings which occur quite often but may still be relevant' @echo ' 3: more obscure warnings, can most likely be ignored' @echo ' c: extra checks in the configuration stage (Kconfig)' @echo ' e: warnings are being treated as errors' @echo ' Multiple levels can be combined with W=12 or W=123' @echo ' make UT=1 [targets] Warn if a tracepoint is defined but not used.' @echo ' [ This will be removed when all current unused tracepoints are eliminated. ]' @$(if $(dtstree), \ echo ' make CHECK_DTBS=1 [targets] Check all generated dtb files against schema'; \ echo ' This can be applied both to "dtbs" and to individual "foo.dtb" targets' ; \ ) @echo '' @echo 'Execute "make" or "make all" to build all targets marked with [*] ' @echo 'For further info see the ./README file'
help-board-dirs := $(addprefix help-,$(board-dirs))
help-boards: $(help-board-dirs)
boards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)))
$(help-board-dirs): help-%: @echo 'Architecture-specific targets ($(SRCARCH) $*):' @$(if $(boards-per-dir), \ $(foreach b, $(boards-per-dir), \ printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \ echo '')
# Documentation targets# ---------------------------------------------------------------------------DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ linkcheckdocs dochelp refcheckdocs texinfodocs infodocs mandocs \ htmldocs-redirects
PHONY += $(DOC_TARGETS)$(DOC_TARGETS): $(Q)$(MAKE) $(build)=Documentation $@
# Rust targets# ---------------------------------------------------------------------------
# "Is Rust available?" targetPHONY += rustavailablerustavailable: +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh && echo "Rust is available!"
# Documentation target## Using the singular to avoid running afoul of `no-dot-config-targets`.PHONY += rustdocrustdoc: prepare $(Q)$(MAKE) $(build)=rust $@
# Testing targetPHONY += rusttestrusttest: prepare $(Q)$(MAKE) $(build)=rust $@
# Formatting targets## Generated files as well as vendored crates are skipped.PHONY += rustfmt rustfmtcheck
rustfmt: $(Q)find $(srctree) $(RCS_FIND_IGNORE) \ \( \ -path $(srctree)/rust/proc-macro2 \ -o -path $(srctree)/rust/quote \ -o -path $(srctree)/rust/syn \ -o -path $(srctree)/rust/zerocopy \ -o -path $(srctree)/rust/zerocopy-derive \ \) -prune -o \ -type f -a -name '*.rs' -a ! -name '*generated*' -print \ | xargs $(RUSTFMT) $(rustfmt_flags)
rustfmtcheck: rustfmt_flags = --checkrustfmtcheck: rustfmt
# Misc# ---------------------------------------------------------------------------
PHONY += misc-checkmisc-check: $(Q)$(srctree)/scripts/misc-check
all: misc-check
PHONY += scripts_gdbscripts_gdb: prepare0 $(Q)$(MAKE) $(build)=scripts/gdb $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
ifdef CONFIG_GDB_SCRIPTSall: scripts_gdbendif
else # KBUILD_EXTMOD
filechk_kernel.release = echo $(KERNELRELEASE)
#### External module support.# When building external modules the kernel used as basis is considered# read-only, and no consistency checks are made and the make# system is not used on the basis kernel. If updates are required# in the basis kernel ordinary make commands (without M=...) must be used.
# We are always building only modules.KBUILD_BUILTIN :=KBUILD_MODULES := y
build-dir := .
clean-dirs := .clean: private rm-files := Module.symvers modules.nsdeps compile_commands.json
PHONY += prepare# now expand this into a simple variable to reduce the cost of shell evaluationsprepare: CC_VERSION_TEXT := $(CC_VERSION_TEXT)prepare: PAHOLE_VERSION := $(PAHOLE_VERSION)prepare: @if [ "$(CC_VERSION_TEXT)" != "$(CONFIG_CC_VERSION_TEXT)" ]; then \ echo >&2 "warning: the compiler differs from the one used to build the kernel"; \ echo >&2 " The kernel was built by: $(CONFIG_CC_VERSION_TEXT)"; \ echo >&2 " You are using: $(CC_VERSION_TEXT)"; \ fi @if [ "$(PAHOLE_VERSION)" != "$(CONFIG_PAHOLE_VERSION)" ]; then \ echo >&2 "warning: pahole version differs from the one used to build the kernel"; \ echo >&2 " The kernel was built with: $(CONFIG_PAHOLE_VERSION)"; \ echo >&2 " You are using: $(PAHOLE_VERSION)"; \ fi
PHONY += helphelp: @echo ' Building external modules.' @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target' @echo '' @echo ' modules - default target, build the module(s)' @echo ' modules_install - install the module' @echo ' clean - remove generated files in module directory only' @echo ' rust-analyzer - generate rust-project.json rust-analyzer support file' @echo ''
ifndef CONFIG_MODULESmodules modules_install: __external_modules_error__external_modules_error: @echo >&2 '***' @echo >&2 '*** The present kernel disabled CONFIG_MODULES.' @echo >&2 '*** You cannot build or install external modules.' @echo >&2 '***' @falseendif
endif # KBUILD_EXTMOD
# ---------------------------------------------------------------------------# Modules
PHONY += modules modules_install modules_sign modules_prepare
modules_install: $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst \ sign-only=$(if $(filter modules_install,$(MAKECMDGOALS)),,y)
ifeq ($(CONFIG_MODULE_SIG),y)# modules_sign is a subset of modules_install.# 'make modules_install modules_sign' is equivalent to 'make modules_install'.modules_sign: modules_install @:elsemodules_sign: @echo >&2 '***' @echo >&2 '*** CONFIG_MODULE_SIG is disabled. You cannot sign modules.' @echo >&2 '***' @falseendif
ifdef CONFIG_MODULES
modules.order: $(build-dir) @:
# KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.# This is solely useful to speed up test compiles.modules: modpostifneq ($(KBUILD_MODPOST_NOFINAL),1) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinalendif
PHONY += modules_checkmodules_check: modules.order $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
else # CONFIG_MODULES
modules: @:
KBUILD_MODULES :=
endif # CONFIG_MODULES
PHONY += modpostmodpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \ $(if $(KBUILD_MODULES), modules_check) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
# Single targets# ---------------------------------------------------------------------------# To build individual files in subdirectories, you can do like this:## make foo/bar/baz.s## The supported suffixes for single-target are listed in 'single-targets'## To build only under specific subdirectories, you can do like this:## make foo/bar/baz/
ifdef single-build
# .ko is special because modpost is neededsingle-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \ $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
$(single-ko): single_modules @:$(single-no-ko): $(build-dir) @:
# Remove modules.order when done because it is not the real one.PHONY += single_modulessingle_modules: $(single-no-ko) modules_prepare $(Q){ $(foreach m, $(single-ko), echo $(m:%.ko=%.o);) } > modules.order $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpostifneq ($(KBUILD_MODPOST_NOFINAL),1) $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinalendif $(Q)rm -f modules.order
single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
KBUILD_MODULES := y
endif
prepare: outputmakefile
# Preset locale variables to speed up the build process. Limit locale# tweaks to this spot to avoid wrong language settings when running# make menuconfig etc.# Error messages still appears in the original languagePHONY += $(build-dir)$(build-dir): prepare $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals)
clean-dirs := $(addprefix _clean_, $(clean-dirs))PHONY += $(clean-dirs) clean$(clean-dirs): $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
clean: $(clean-dirs) $(call cmd,rmfiles) @find . $(RCS_FIND_IGNORE) \ \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \ -o -name '*.ko.*' -o -name '*.o.thinlto.bc' \ -o -name '*.dtb' -o -name '*.dtbo' \ -o -name '*.dtb.S' -o -name '*.dtbo.S' \ -o -name '*.dt.yaml' -o -name 'dtbs-list' \ -o -name '*.dwo' -o -name '*.lst' \ -o -name '*.su' -o -name '*.mod' \ -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ -o -name '*.lex.c' -o -name '*.tab.[ch]' \ -o -name '*.asn1.[ch]' \ -o -name '*.symtypes' -o -name 'modules.order' \ -o -name '*.c.[012]*.*' \ -o -name '*.ll' \ -o -name '*.gcno' \ -o -name '*.long-type-*.txt' \ \) -type f -print \ -o -name '.tmp_*' -print \ | xargs rm -rf
# Generate tags for editors# ---------------------------------------------------------------------------quiet_cmd_tags = GEN $@ cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@
tags TAGS cscope gtags: FORCE $(call cmd,tags)
# Generate rust-project.json (a file that describes the structure of non-Cargo# Rust projects) for rust-analyzer (an implementation of the Language Server# Protocol).PHONY += rust-analyzerrust-analyzer: +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.shifdef KBUILD_EXTMOD# FIXME: external modules must not descend into a sub-directory of the kernel $(Q)$(MAKE) $(build)=$(objtree)/rust src=$(srctree)/rust $@else $(Q)$(MAKE) $(build)=rust $@endif
# Script to generate missing namespace dependencies# ---------------------------------------------------------------------------
PHONY += nsdepsnsdeps: export KBUILD_NSDEPS=1nsdeps: modules $(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps
# Script to generate .spdx.json SBOM documents describing the build# ---------------------------------------------------------------------------
ifdef building_out_of_srctreesbom_targets := sbom-source.spdx.jsonendifsbom_targets += sbom-build.spdx.json sbom-output.spdx.jsonquiet_cmd_sbom = GEN $(sbom_targets) cmd_sbom = printf "%s\n" "$(KBUILD_IMAGE)" >"$(tmp-target)"; \ $(if $(CONFIG_MODULES),sed 's/\.o$$/.ko/' $(objtree)/modules.order >> "$(tmp-target)";) \ $(PYTHON3) $(srctree)/scripts/sbom/sbom.py \ --src-tree $(abspath $(srctree)) \ --obj-tree $(abspath $(objtree)) \ --roots-file "$(tmp-target)" \ --output-directory $(abspath $(objtree)) \ --generate-spdx \ --package-license "GPL-2.0 WITH Linux-syscall-note" \ --package-version "$(KERNELVERSION)" \ --write-output-on-error;PHONY += sbomsbom: $(notdir $(KBUILD_IMAGE)) include/generated/autoconf.h $(if $(CONFIG_MODULES),modules modules.order) $(call cmd,sbom)
# Clang Tooling# ---------------------------------------------------------------------------
quiet_cmd_gen_compile_commands = GEN $@ cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
compile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \ $(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \ $(if $(CONFIG_MODULES), modules.order) FORCE $(call if_changed,gen_compile_commands)
targets += compile_commands.json
PHONY += clang-tidy clang-analyzer
ifdef CONFIG_CC_IS_CLANGquiet_cmd_clang_tools = CHECK $< cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $<
clang-tidy clang-analyzer: compile_commands.json $(call cmd,clang_tools)elseclang-tidy clang-analyzer: @echo "$@ requires CC=clang" >&2 @falseendif
# Scripts to check various things for consistency# ---------------------------------------------------------------------------
PHONY += includecheck versioncheck coccicheck kconfig-sym-check
includecheck: find $(srctree)/* $(RCS_FIND_IGNORE) \ -name '*.[hcS]' -type f -print | sort \ | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
versioncheck: find $(srctree)/* $(RCS_FIND_IGNORE) \ -name '*.[hcS]' -type f -print | sort \ | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
coccicheck: $(Q)$(BASH) $(srctree)/scripts/$@
kconfig-sym-check: $(Q)$(PERL) $(srctree)/scripts/kconfig/kconfig-sym-check.pl $(srctree) $(KCONFIG_SYM_CHECK_EXCLUDES)
PHONY += checkstack kernelrelease kernelversion image_name
# UML needs a little special treatment here. It wants to use the host# toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone# else wants $(ARCH), including people doing cross-builds, which means# that $(SUBARCH) doesn't work here.ifeq ($(ARCH), um)CHECKSTACK_ARCH := $(SUBARCH)elseCHECKSTACK_ARCH := $(ARCH)endifMINSTACKSIZE ?= 100checkstack: $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \ $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH) $(MINSTACKSIZE)
kernelrelease: @$(filechk_kernel.release)
kernelversion: @echo $(KERNELVERSION)
image_name: @echo $(KBUILD_IMAGE)
PHONY += run-commandrun-command: $(Q)$(KBUILD_RUN_COMMAND)
quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files))) cmd_rmfiles = rm -rf $(rm-files)
# read saved command lines for existing targetsexisting-targets := $(wildcard $(sort $(targets)))
-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
endif # config-buildendif # mixed-buildendif # need-sub-make
PHONY += FORCEFORCE:
# Declare the contents of the PHONY variable as phony. We keep that# information in a variable so we can use it in if_changed and friends..PHONY: $(PHONY)