1b2441318SGreg Kroah-Hartman# SPDX-License-Identifier: GPL-2.0 26de23f81SLinus TorvaldsVERSION = 7 3*dc59e4feSLinus TorvaldsPATCHLEVEL = 2 455922c9dSLinus TorvaldsSUBLEVEL = 0 5*dc59e4feSLinus TorvaldsEXTRAVERSION = 61613e604SLinus TorvaldsNAME = Baby Opossum Posse 71da177e4SLinus Torvalds 81da177e4SLinus Torvalds# *DOCUMENTATION* 91da177e4SLinus Torvalds# To see a list of typical targets execute "make help" 101da177e4SLinus Torvalds# More info can be located in ./README 111da177e4SLinus Torvalds# Comments in this file are targeted only to the developer, do not 121da177e4SLinus Torvalds# expect to learn how to build the kernel reading this file. 131da177e4SLinus Torvalds 145f99665eSMasahiro Yamadaifeq ($(filter output-sync,$(.FEATURES)),) 155f99665eSMasahiro Yamada$(error GNU Make >= 4.0 is required. Your Make version is $(MAKE_VERSION)) 1687d599fcSMasahiro Yamadaendif 1787d599fcSMasahiro Yamada 18121c2a13SMasahiro Yamada$(if $(filter __%, $(MAKECMDGOALS)), \ 19121c2a13SMasahiro Yamada $(error targets prefixed with '__' are only for internal use)) 20121c2a13SMasahiro Yamada 21ba634eceSMasahiro Yamada# That's our default target when none is given on the command line 22121c2a13SMasahiro YamadaPHONY := __all 23121c2a13SMasahiro Yamada__all: 24ba634eceSMasahiro Yamada 251da177e4SLinus Torvalds# We are using a recursive build, so we need to do a little thinking 261da177e4SLinus Torvalds# to get the ordering right. 271da177e4SLinus Torvalds# 281da177e4SLinus Torvalds# Most importantly: sub-Makefiles should only ever modify files in 291da177e4SLinus Torvalds# their own directory. If in some directory we have a dependency on 301da177e4SLinus Torvalds# a file in another dir (which doesn't happen often, but it's often 31f49821eeSNicholas Piggin# unavoidable when linking the built-in.a targets which finally 321da177e4SLinus Torvalds# turn into vmlinux), we will call a sub make in that other dir, and 331da177e4SLinus Torvalds# after that we are sure that everything which is in that other dir 341da177e4SLinus Torvalds# is now up to date. 351da177e4SLinus Torvalds# 361da177e4SLinus Torvalds# The only cases where we need to modify files which have global 371da177e4SLinus Torvalds# effects are thus separated out and done before the recursive 381da177e4SLinus Torvalds# descending is started. They are now explicitly listed as the 391da177e4SLinus Torvalds# prepare rule. 401da177e4SLinus Torvalds 415fa94cebSMasahiro Yamadathis-makefile := $(lastword $(MAKEFILE_LIST)) 42e2bad142SMasahiro Yamadaabs_srctree := $(realpath $(dir $(this-makefile))) 435ea17216SMasahiro Yamadaabs_output := $(CURDIR) 445fa94cebSMasahiro Yamada 45221cc2d2SMasahiro Yamadaifneq ($(sub_make_done),1) 463812b8c5SMasahiro Yamada 473812b8c5SMasahiro Yamada# Do not use make's built-in rules and variables 483812b8c5SMasahiro Yamada# (this increases performance and avoids hard-to-debug behaviour) 493812b8c5SMasahiro YamadaMAKEFLAGS += -rR 503812b8c5SMasahiro Yamada 513812b8c5SMasahiro Yamada# Avoid funny character set dependencies 523812b8c5SMasahiro Yamadaunexport LC_ALL 533812b8c5SMasahiro YamadaLC_COLLATE=C 543812b8c5SMasahiro YamadaLC_NUMERIC=C 553812b8c5SMasahiro Yamadaexport LC_COLLATE LC_NUMERIC 563812b8c5SMasahiro Yamada 573812b8c5SMasahiro Yamada# Avoid interference with shell env settings 583812b8c5SMasahiro Yamadaunexport GREP_OPTIONS 593812b8c5SMasahiro Yamada 60066b7ed9SMichal Marek# Beautify output 61066b7ed9SMichal Marek# --------------------------------------------------------------------------- 62066b7ed9SMichal Marek# 638962b6b4SMasahiro Yamada# Most of build commands in Kbuild start with "cmd_". You can optionally define 648962b6b4SMasahiro Yamada# "quiet_cmd_*". If defined, the short log is printed. Otherwise, no log from 658962b6b4SMasahiro Yamada# that command is printed by default. 66066b7ed9SMichal Marek# 678962b6b4SMasahiro Yamada# e.g.) 688962b6b4SMasahiro Yamada# quiet_cmd_depmod = DEPMOD $(MODLIB) 698962b6b4SMasahiro Yamada# cmd_depmod = $(srctree)/scripts/depmod.sh $(DEPMOD) $(KERNELRELEASE) 70066b7ed9SMichal Marek# 71066b7ed9SMichal Marek# A simple variant is to prefix commands with $(Q) - that's useful 72066b7ed9SMichal Marek# for commands that shall be hidden in non-verbose mode. 73066b7ed9SMichal Marek# 748962b6b4SMasahiro Yamada# $(Q)$(MAKE) $(build)=scripts/basic 75066b7ed9SMichal Marek# 766ae4b986SMasahiro Yamada# If KBUILD_VERBOSE contains 1, the whole command is echoed. 776ae4b986SMasahiro Yamada# If KBUILD_VERBOSE contains 2, the reason for rebuilding is printed. 78066b7ed9SMichal Marek# 791da177e4SLinus Torvalds# To put more focus on warnings, be less verbose as default 801da177e4SLinus Torvalds# Use 'make V=1' to see the full commands 811da177e4SLinus Torvalds 821da177e4SLinus Torvaldsifeq ("$(origin V)", "command line") 831da177e4SLinus Torvalds KBUILD_VERBOSE = $(V) 841da177e4SLinus Torvaldsendif 851da177e4SLinus Torvalds 86066b7ed9SMichal Marekquiet = quiet_ 87066b7ed9SMichal MarekQ = @ 886ae4b986SMasahiro Yamada 896ae4b986SMasahiro Yamadaifneq ($(findstring 1, $(KBUILD_VERBOSE)),) 906ae4b986SMasahiro Yamada quiet = 916ae4b986SMasahiro Yamada Q = 92066b7ed9SMichal Marekendif 93066b7ed9SMichal Marek 94066b7ed9SMichal Marek# If the user is running make -s (silent mode), suppress echoing of 95066b7ed9SMichal Marek# commands 965f99665eSMasahiro Yamadaifneq ($(findstring s,$(firstword -$(MAKEFLAGS))),) 97066b7ed9SMichal Marekquiet=silent_ 9883d98d73SMasahiro Yamadaoverride KBUILD_VERBOSE := 99066b7ed9SMichal Marekendif 100066b7ed9SMichal Marek 101066b7ed9SMichal Marekexport quiet Q KBUILD_VERBOSE 102066b7ed9SMichal Marek 103bcf637f5SMasahiro Yamada# Call a source code checker (by default, "sparse") as part of the 104bcf637f5SMasahiro Yamada# C compilation. 105bcf637f5SMasahiro Yamada# 106bcf637f5SMasahiro Yamada# Use 'make C=1' to enable checking of only re-compiled files. 107bcf637f5SMasahiro Yamada# Use 'make C=2' to enable checking of *all* source files, regardless 108bcf637f5SMasahiro Yamada# of whether they are re-compiled or not. 109bcf637f5SMasahiro Yamada# 110bcf637f5SMasahiro Yamada# See the file "Documentation/dev-tools/sparse.rst" for more details, 111bcf637f5SMasahiro Yamada# including where to get the "sparse" utility. 112bcf637f5SMasahiro Yamada 113bcf637f5SMasahiro Yamadaifeq ("$(origin C)", "command line") 114bcf637f5SMasahiro Yamada KBUILD_CHECKSRC = $(C) 115bcf637f5SMasahiro Yamadaendif 116bcf637f5SMasahiro Yamadaifndef KBUILD_CHECKSRC 117bcf637f5SMasahiro Yamada KBUILD_CHECKSRC = 0 118bcf637f5SMasahiro Yamadaendif 119bcf637f5SMasahiro Yamada 120bcf637f5SMasahiro Yamadaexport KBUILD_CHECKSRC 121bcf637f5SMasahiro Yamada 1222f7ab126SMiguel Ojeda# Enable "clippy" (a linter) as part of the Rust compilation. 1232f7ab126SMiguel Ojeda# 1242f7ab126SMiguel Ojeda# Use 'make CLIPPY=1' to enable it. 1252f7ab126SMiguel Ojedaifeq ("$(origin CLIPPY)", "command line") 1262f7ab126SMiguel Ojeda KBUILD_CLIPPY := $(CLIPPY) 1272f7ab126SMiguel Ojedaendif 1282f7ab126SMiguel Ojeda 1292f7ab126SMiguel Ojedaexport KBUILD_CLIPPY 1302f7ab126SMiguel Ojeda 131bcf637f5SMasahiro Yamada# Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the 132bcf637f5SMasahiro Yamada# directory of external module to build. Setting M= takes precedence. 133bcf637f5SMasahiro Yamadaifeq ("$(origin M)", "command line") 134bcf637f5SMasahiro Yamada KBUILD_EXTMOD := $(M) 135bcf637f5SMasahiro Yamadaendif 136bcf637f5SMasahiro Yamada 13711b3d517SMasahiro Yamadaifeq ("$(origin MO)", "command line") 13811b3d517SMasahiro Yamada KBUILD_EXTMOD_OUTPUT := $(MO) 13911b3d517SMasahiro Yamadaendif 14011b3d517SMasahiro Yamada 141bcf637f5SMasahiro Yamada$(if $(word 2, $(KBUILD_EXTMOD)), \ 142bcf637f5SMasahiro Yamada $(error building multiple external modules is not supported)) 143bcf637f5SMasahiro Yamada 1449a68fd7fSMasahiro Yamada$(foreach x, % :, $(if $(findstring $x, $(KBUILD_EXTMOD)), \ 1459a68fd7fSMasahiro Yamada $(error module directory path cannot contain '$x'))) 1469a68fd7fSMasahiro Yamada 14774ee585bSMasahiro Yamada# Remove trailing slashes 14874ee585bSMasahiro Yamadaifneq ($(filter %/, $(KBUILD_EXTMOD)),) 14974ee585bSMasahiro YamadaKBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD).) 15074ee585bSMasahiro Yamadaendif 15174ee585bSMasahiro Yamada 152bcf637f5SMasahiro Yamadaexport KBUILD_EXTMOD 153bcf637f5SMasahiro Yamada 15492ef432fSMasahiro Yamadaifeq ("$(origin W)", "command line") 15592ef432fSMasahiro Yamada KBUILD_EXTRA_WARN := $(W) 15692ef432fSMasahiro Yamadaendif 15792ef432fSMasahiro Yamada 15892ef432fSMasahiro Yamadaexport KBUILD_EXTRA_WARN 15992ef432fSMasahiro Yamada 16025b146c5SMasahiro Yamada# Kbuild will save output files in the current working directory. 16125b146c5SMasahiro Yamada# This does not need to match to the root of the kernel source tree. 16225b146c5SMasahiro Yamada# 16325b146c5SMasahiro Yamada# For example, you can do this: 16425b146c5SMasahiro Yamada# 16525b146c5SMasahiro Yamada# cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile 16625b146c5SMasahiro Yamada# 16725b146c5SMasahiro Yamada# If you want to save output files in a different location, there are 16825b146c5SMasahiro Yamada# two syntaxes to specify it. 16925b146c5SMasahiro Yamada# 1701da177e4SLinus Torvalds# 1) O= 1711da177e4SLinus Torvalds# Use "make O=dir/to/store/output/files/" 1721da177e4SLinus Torvalds# 1731da177e4SLinus Torvalds# 2) Set KBUILD_OUTPUT 17425b146c5SMasahiro Yamada# Set the environment variable KBUILD_OUTPUT to point to the output directory. 17525b146c5SMasahiro Yamada# export KBUILD_OUTPUT=dir/to/store/output/files/; make 1761da177e4SLinus Torvalds# 1771da177e4SLinus Torvalds# The O= assignment takes precedence over the KBUILD_OUTPUT environment 1781da177e4SLinus Torvalds# variable. 1791da177e4SLinus Torvalds 1801da177e4SLinus Torvaldsifeq ("$(origin O)", "command line") 1811da177e4SLinus Torvalds KBUILD_OUTPUT := $(O) 1821da177e4SLinus Torvaldsendif 1831da177e4SLinus Torvalds 18413b25489SMasahiro Yamadaifdef KBUILD_EXTMOD 18513b25489SMasahiro Yamada ifdef KBUILD_OUTPUT 18613b25489SMasahiro Yamada objtree := $(realpath $(KBUILD_OUTPUT)) 18713b25489SMasahiro Yamada $(if $(objtree),,$(error specified kernel directory "$(KBUILD_OUTPUT)" does not exist)) 18813b25489SMasahiro Yamada else 1898cd07cc6SMasahiro Yamada objtree := $(abs_srctree) 19013b25489SMasahiro Yamada endif 1918cd07cc6SMasahiro Yamada # If Make is invoked from the kernel directory (either kernel 1928cd07cc6SMasahiro Yamada # source directory or kernel build directory), external modules 1938cd07cc6SMasahiro Yamada # are built in $(KBUILD_EXTMOD) for backward compatibility, 1948cd07cc6SMasahiro Yamada # otherwise, built in the current directory. 1958cd07cc6SMasahiro Yamada output := $(or $(KBUILD_EXTMOD_OUTPUT),$(if $(filter $(CURDIR),$(objtree) $(abs_srctree)),$(KBUILD_EXTMOD))) 19613b25489SMasahiro Yamada # KBUILD_EXTMOD might be a relative path. Remember its absolute path before 19713b25489SMasahiro Yamada # Make changes the working directory. 19813b25489SMasahiro Yamada srcroot := $(realpath $(KBUILD_EXTMOD)) 19913b25489SMasahiro Yamada $(if $(srcroot),,$(error specified external module directory "$(KBUILD_EXTMOD)" does not exist)) 20013b25489SMasahiro Yamadaelse 20113b25489SMasahiro Yamada objtree := . 202d1711360SMasahiro Yamada output := $(KBUILD_OUTPUT) 20313b25489SMasahiro Yamadaendif 20413b25489SMasahiro Yamada 20513b25489SMasahiro Yamadaexport objtree srcroot 206d1711360SMasahiro Yamada 207d1711360SMasahiro Yamada# Do we want to change the working directory? 208d1711360SMasahiro Yamadaifneq ($(output),) 2097beba04eSMasahiro Yamada# $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first. 210d1711360SMasahiro Yamada$(shell mkdir -p "$(output)") 21125b146c5SMasahiro Yamada# $(realpath ...) resolves symlinks 212d1711360SMasahiro Yamadaabs_output := $(realpath $(output)) 213d1711360SMasahiro Yamada$(if $(abs_output),,$(error failed to create output directory "$(output)")) 214d1711360SMasahiro Yamadaendif 21525b146c5SMasahiro Yamada 21625b146c5SMasahiro Yamadaifneq ($(words $(subst :, ,$(abs_srctree))), 1) 21725b146c5SMasahiro Yamada$(error source directory cannot contain spaces or colons) 21825b146c5SMasahiro Yamadaendif 21925b146c5SMasahiro Yamada 220221cc2d2SMasahiro Yamadaexport sub_make_done := 1 221221cc2d2SMasahiro Yamada 2225fc10e76SMasahiro Yamadaendif # sub_make_done 2235fc10e76SMasahiro Yamada 2245ea17216SMasahiro Yamadaifeq ($(abs_output),$(CURDIR)) 2255fc10e76SMasahiro Yamada# Suppress "Entering directory ..." if we are at the final work directory. 2265fc10e76SMasahiro Yamadano-print-directory := --no-print-directory 2275fc10e76SMasahiro Yamadaelse 2285fc10e76SMasahiro Yamada# Recursion to show "Entering directory ..." 2295fc10e76SMasahiro Yamadaneed-sub-make := 1 2305fc10e76SMasahiro Yamadaendif 2315fc10e76SMasahiro Yamada 2325fc10e76SMasahiro Yamadaifeq ($(filter --no-print-directory, $(MAKEFLAGS)),) 2335fc10e76SMasahiro Yamada# If --no-print-directory is unset, recurse once again to set it. 2345fc10e76SMasahiro Yamada# You may end up recursing into __sub-make twice. This is needed due to the 2355fc10e76SMasahiro Yamada# behavior change in GNU Make 4.4.1. 2365fc10e76SMasahiro Yamadaneed-sub-make := 1 2375fc10e76SMasahiro Yamadaendif 2385fc10e76SMasahiro Yamada 239688931a5SMasahiro Yamadaifeq ($(need-sub-make),1) 240688931a5SMasahiro Yamada 241121c2a13SMasahiro YamadaPHONY += $(MAKECMDGOALS) __sub-make 2420b35786dSMilton Miller 243121c2a13SMasahiro Yamada$(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make 24416f89098SCharles Keepax @: 2450b35786dSMilton Miller 246c4e6fff1SCao jin# Invoke a second make in the output directory, passing relevant variables 247121c2a13SMasahiro Yamada__sub-make: 2485ea17216SMasahiro Yamada $(Q)$(MAKE) $(no-print-directory) -C $(abs_output) \ 2495fc10e76SMasahiro Yamada -f $(abs_srctree)/Makefile $(MAKECMDGOALS) 2501da177e4SLinus Torvalds 2515fc10e76SMasahiro Yamadaelse # need-sub-make 252688931a5SMasahiro Yamada 2531da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make 2547ff52571SMasahiro Yamada 25513b25489SMasahiro Yamadaifndef KBUILD_EXTMOD 25613b25489SMasahiro Yamadasrcroot := $(abs_srctree) 25713b25489SMasahiro Yamadaendif 25813b25489SMasahiro Yamada 25913b25489SMasahiro Yamadaifeq ($(srcroot),$(CURDIR)) 260051f278eSMasahiro Yamadabuilding_out_of_srctree := 2619da0763bSMichal Marekelse 26213b25489SMasahiro Yamadaexport building_out_of_srctree := 1 2639da0763bSMichal Marekendif 2642c1f4f12SMasahiro Yamada 26513b25489SMasahiro Yamadaifdef KBUILD_ABS_SRCTREE 26613b25489SMasahiro Yamada # Do nothing. Use the absolute path. 26713b25489SMasahiro Yamadaelse ifeq ($(srcroot),$(CURDIR)) 26813b25489SMasahiro Yamada # Building in the source. 26913b25489SMasahiro Yamada srcroot := . 27013b25489SMasahiro Yamadaelse ifeq ($(srcroot)/,$(dir $(CURDIR))) 27113b25489SMasahiro Yamada # Building in a subdirectory of the source. 27213b25489SMasahiro Yamada srcroot := .. 27395fd3f87SMasahiro Yamadaendif 2742c1f4f12SMasahiro Yamada 27513b25489SMasahiro Yamadaexport srctree := $(if $(KBUILD_EXTMOD),$(abs_srctree),$(srcroot)) 276b1992c37SMasahiro Yamada 277b1992c37SMasahiro Yamadaifdef building_out_of_srctree 27813b25489SMasahiro Yamadaexport VPATH := $(srcroot) 27913b25489SMasahiro Yamadaelse 28013b25489SMasahiro YamadaVPATH := 281b1992c37SMasahiro Yamadaendif 2821da177e4SLinus Torvalds 2832c1f4f12SMasahiro Yamada# To make sure we do not include .config for any of the *config targets 2842c1f4f12SMasahiro Yamada# catch them early, and hand them over to scripts/kconfig/Makefile 2852c1f4f12SMasahiro Yamada# It is allowed to specify more targets when calling make, including 2862c1f4f12SMasahiro Yamada# mixing *config targets and build targets. 2872c1f4f12SMasahiro Yamada# For example 'make oldconfig all'. 2882c1f4f12SMasahiro Yamada# Detect when mixed targets is specified, and make a second invocation 2892c1f4f12SMasahiro Yamada# of make so .config is not included in this case either (for *config). 2902c1f4f12SMasahiro Yamada 2912c1f4f12SMasahiro Yamadaversion_h := include/generated/uapi/linux/version.h 2922c1f4f12SMasahiro Yamada 29322340a06SMasahiro Yamadaclean-targets := %clean mrproper cleandocs 29422340a06SMasahiro Yamadano-dot-config-targets := $(clean-targets) \ 2952c1f4f12SMasahiro Yamada cscope gtags TAGS tags help% %docs check% coccicheck \ 296f58316a4SAndrew Jones kconfig-sym-check \ 29759b2bd05SMasahiro Yamada $(version_h) headers headers_% archheaders archscripts \ 2984623980dSDavid Engraf %asm-generic kernelversion %src-pkg dt_binding_check \ 299efb6347dSDaniel Golle dt_style_selftest \ 300d8ad80a8SThomas Weißschuh outputmakefile rustavailable rustfmt rustfmtcheck \ 301d8ad80a8SThomas Weißschuh run-command 302eb931e12SMasahiro Yamadano-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \ 303993bdde9SMasahiro Yamada image_name 30491ca8be3SMasahiro Yamadasingle-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %/ 3052c1f4f12SMasahiro Yamada 3062042b548SMasahiro Yamadaconfig-build := 3072042b548SMasahiro Yamadamixed-build := 3082042b548SMasahiro Yamadaneed-config := 1 309d7942413SMasahiro Yamadamay-sync-config := 1 310394053f4SMasahiro Yamadasingle-build := 3112c1f4f12SMasahiro Yamada 3122c1f4f12SMasahiro Yamadaifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),) 3132c1f4f12SMasahiro Yamada ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),) 3142042b548SMasahiro Yamada need-config := 3152c1f4f12SMasahiro Yamada endif 3162c1f4f12SMasahiro Yamadaendif 3172c1f4f12SMasahiro Yamada 318d7942413SMasahiro Yamadaifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),) 319d7942413SMasahiro Yamada ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),) 3202042b548SMasahiro Yamada may-sync-config := 321d7942413SMasahiro Yamada endif 322d7942413SMasahiro Yamadaendif 323d7942413SMasahiro Yamada 3249d361173SMasahiro Yamadaneed-compiler := $(may-sync-config) 3259d361173SMasahiro Yamada 326d7942413SMasahiro Yamadaifneq ($(KBUILD_EXTMOD),) 3272042b548SMasahiro Yamada may-sync-config := 328d7942413SMasahiro Yamadaendif 329d7942413SMasahiro Yamada 3302c1f4f12SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),) 331efbf9726SMasahiro Yamada ifneq ($(filter %config,$(MAKECMDGOALS)),) 3322042b548SMasahiro Yamada config-build := 1 3332c1f4f12SMasahiro Yamada ifneq ($(words $(MAKECMDGOALS)),1) 3342042b548SMasahiro Yamada mixed-build := 1 3352c1f4f12SMasahiro Yamada endif 3362c1f4f12SMasahiro Yamada endif 3372c1f4f12SMasahiro Yamadaendif 33822340a06SMasahiro Yamada 339394053f4SMasahiro Yamada# We cannot build single targets and the others at the same time 340394053f4SMasahiro Yamadaifneq ($(filter $(single-targets), $(MAKECMDGOALS)),) 341394053f4SMasahiro Yamada single-build := 1 342394053f4SMasahiro Yamada ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),) 343394053f4SMasahiro Yamada mixed-build := 1 344394053f4SMasahiro Yamada endif 345394053f4SMasahiro Yamadaendif 346394053f4SMasahiro Yamada 34722340a06SMasahiro Yamada# For "make -j clean all", "make -j mrproper defconfig all", etc. 34822340a06SMasahiro Yamadaifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),) 34922340a06SMasahiro Yamada ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),) 3502042b548SMasahiro Yamada mixed-build := 1 35122340a06SMasahiro Yamada endif 35222340a06SMasahiro Yamadaendif 35322340a06SMasahiro Yamada 3542c1f4f12SMasahiro Yamada# install and modules_install need also be processed one by one 3552c1f4f12SMasahiro Yamadaifneq ($(filter install,$(MAKECMDGOALS)),) 3562c1f4f12SMasahiro Yamada ifneq ($(filter modules_install,$(MAKECMDGOALS)),) 3572042b548SMasahiro Yamada mixed-build := 1 3582c1f4f12SMasahiro Yamada endif 3592c1f4f12SMasahiro Yamadaendif 3602c1f4f12SMasahiro Yamada 3612042b548SMasahiro Yamadaifdef mixed-build 3622c1f4f12SMasahiro Yamada# =========================================================================== 3632c1f4f12SMasahiro Yamada# We're called with mixed targets (*config and build targets). 3642c1f4f12SMasahiro Yamada# Handle them one by one. 3652c1f4f12SMasahiro Yamada 3662c1f4f12SMasahiro YamadaPHONY += $(MAKECMDGOALS) __build_one_by_one 3672c1f4f12SMasahiro Yamada 368121c2a13SMasahiro Yamada$(MAKECMDGOALS): __build_one_by_one 3692c1f4f12SMasahiro Yamada @: 3702c1f4f12SMasahiro Yamada 3712c1f4f12SMasahiro Yamada__build_one_by_one: 3722c1f4f12SMasahiro Yamada $(Q)set -e; \ 3732c1f4f12SMasahiro Yamada for i in $(MAKECMDGOALS); do \ 3742c1f4f12SMasahiro Yamada $(MAKE) -f $(srctree)/Makefile $$i; \ 3752c1f4f12SMasahiro Yamada done 3762c1f4f12SMasahiro Yamada 3772042b548SMasahiro Yamadaelse # !mixed-build 3782c1f4f12SMasahiro Yamada 3793204a7fbSMasahiro Yamadainclude $(srctree)/scripts/Kbuild.include 3802c1f4f12SMasahiro Yamada 3812c1f4f12SMasahiro Yamada# Read KERNELRELEASE from include/config/kernel.release (if it exists) 382214c0eeaSMasahiro YamadaKERNELRELEASE = $(call read-file, $(objtree)/include/config/kernel.release) 3832c1f4f12SMasahiro YamadaKERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION) 3842c1f4f12SMasahiro Yamadaexport VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION 3852c1f4f12SMasahiro Yamada 3863204a7fbSMasahiro Yamadainclude $(srctree)/scripts/subarch.include 3871da177e4SLinus Torvalds 3881da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils 3891da177e4SLinus Torvalds# --------------------------------------------------------------------------- 3901da177e4SLinus Torvalds# 3911da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set 3921da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities). 3931da177e4SLinus Torvalds# ARCH can be set during invocation of make: 39494483490SArd Biesheuvel# make ARCH=arm64 3951da177e4SLinus Torvalds# Another way is to have ARCH set in the environment. 3961da177e4SLinus Torvalds# The default ARCH is the host where make is executed. 3971da177e4SLinus Torvalds 3981da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used 3991da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables 4001da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE). 4011da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line 40294483490SArd Biesheuvel# make CROSS_COMPILE=aarch64-linux-gnu- 4031da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment. 4041da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables 4051da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile 4062331d1a6SSam RavnborgARCH ?= $(SUBARCH) 4071da177e4SLinus Torvalds 4081da177e4SLinus Torvalds# Architecture as present in compile.h 4091da177e4SLinus TorvaldsUTS_MACHINE := $(ARCH) 4106752ed90SThomas GleixnerSRCARCH := $(ARCH) 4111da177e4SLinus Torvalds 412d746d647SSam Ravnborg# Additional ARCH settings for x86 413d746d647SSam Ravnborgifeq ($(ARCH),i386) 414d746d647SSam Ravnborg SRCARCH := x86 415d746d647SSam Ravnborgendif 416d746d647SSam Ravnborgifeq ($(ARCH),x86_64) 417d746d647SSam Ravnborg SRCARCH := x86 418d746d647SSam Ravnborgendif 41974b469f2SSam Ravnborg 4205e538790SSam Ravnborg# Additional ARCH settings for sparc 421e69f58c0SNamhyung Kimifeq ($(ARCH),sparc32) 422e69f58c0SNamhyung Kim SRCARCH := sparc 423e69f58c0SNamhyung Kimendif 424a439fe51SSam Ravnborgifeq ($(ARCH),sparc64) 4255e538790SSam Ravnborg SRCARCH := sparc 426a439fe51SSam Ravnborgendif 4272fb9b1bdSSam Ravnborg 4285f6e0fe0SMasahiro Yamada# Additional ARCH settings for parisc 4295f6e0fe0SMasahiro Yamadaifeq ($(ARCH),parisc64) 4305f6e0fe0SMasahiro Yamada SRCARCH := parisc 4315f6e0fe0SMasahiro Yamadaendif 4325f6e0fe0SMasahiro Yamada 433f02aa48dSMasahiro Yamadaexport cross_compiling := 434f02aa48dSMasahiro Yamadaifneq ($(SRCARCH),$(SUBARCH)) 435f02aa48dSMasahiro Yamadacross_compiling := 1 436f02aa48dSMasahiro Yamadaendif 437f02aa48dSMasahiro Yamada 43814cdd3c4SRoman ZippelKCONFIG_CONFIG ?= .config 43941263fc6SBen Gardinerexport KCONFIG_CONFIG 44014cdd3c4SRoman Zippel 4411da177e4SLinus Torvalds# SHELL used by kbuild 442858805b3SMasahiro YamadaCONFIG_SHELL := sh 4431da177e4SLinus Torvalds 4446d79a7b4SMasahiro YamadaHOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null) 4456d79a7b4SMasahiro YamadaHOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null) 4466d79a7b4SMasahiro YamadaHOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null) 447d7f14c66SUwe Kleine-König 448a0d1c951SMasahiro Yamadaifneq ($(LLVM),) 449e9c28192SNathan Chancellorifneq ($(filter %/,$(LLVM)),) 450e9c28192SNathan ChancellorLLVM_PREFIX := $(LLVM) 451e9c28192SNathan Chancellorelse ifneq ($(filter -%,$(LLVM)),) 452e9c28192SNathan ChancellorLLVM_SUFFIX := $(LLVM) 453502678b8SThomas Weißschuhelse ifneq ($(LLVM),1) 454502678b8SThomas Weißschuh$(error Invalid value for LLVM, see Documentation/kbuild/llvm.rst) 455e9c28192SNathan Chancellorendif 456e9c28192SNathan Chancellor 457e9c28192SNathan ChancellorHOSTCC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX) 458e9c28192SNathan ChancellorHOSTCXX = $(LLVM_PREFIX)clang++$(LLVM_SUFFIX) 459a0d1c951SMasahiro Yamadaelse 4601da177e4SLinus TorvaldsHOSTCC = gcc 4611da177e4SLinus TorvaldsHOSTCXX = g++ 462a0d1c951SMasahiro Yamadaendif 4632f7ab126SMiguel OjedaHOSTRUSTC = rustc 464d5ea4fecSChun-Tse ShaoHOSTPKG_CONFIG = pkg-config 4657f3a59dbSMasahiro Yamada 466110214e4SMauro Carvalho Chehab# the KERNELDOC macro needs to be exported, as scripts/Makefile.build 467110214e4SMauro Carvalho Chehab# has a logic to call it 468eba6ffd1SJonathan CorbetKERNELDOC = $(srctree)/tools/docs/kernel-doc 469110214e4SMauro Carvalho Chehabexport KERNELDOC 470110214e4SMauro Carvalho Chehab 471f67695c9SElliot BermanKBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \ 472b5ec6fd2SPeter Zijlstra -O2 -fomit-frame-pointer -std=gnu11 473f67695c9SElliot BermanKBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS) 474f67695c9SElliot BermanKBUILD_USERLDFLAGS := $(USERLDFLAGS) 4757f3a59dbSMasahiro Yamada 4762f7ab126SMiguel Ojeda# These flags apply to all Rust code in the tree, including the kernel and 4772f7ab126SMiguel Ojeda# host programs. 4782f7ab126SMiguel Ojeda# 4792f7ab126SMiguel Ojeda# `-Aclippy::unwrap_or_default`: the lint is buggy [1] and ignores our 4808e95e53cSMiguel Ojeda# MSRV. It can trigger depending on the optimization level. 481592c61f3SMiguel Ojeda# [1] https://github.com/rust-lang/rust-clippy/issues/17379 482f8f88aa2SMiguel Ojedaexport rust_common_flags := --edition=2021 \ 483a135aa3dSMiguel Ojeda -Zbinary_dep_depinfo=y \ 484a135aa3dSMiguel Ojeda -Astable_features \ 485f8f88aa2SMiguel Ojeda -Aunused_features \ 486f8f88aa2SMiguel Ojeda -Dnon_ascii_idents \ 487bb421b51SMiguel Ojeda -Dunsafe_op_in_unsafe_fn \ 48823773bd8STamir Duberstein -Wmissing_docs \ 4895e305505STamir Duberstein -Wrust_2018_idioms \ 490b7c8d7a8STamir Duberstein -Wunreachable_pub \ 4912adc8664SMiguel Ojeda -Wclippy::all \ 492838d852dSMiguel Ojeda -Wclippy::as_ptr_cast_mut \ 4933fcc2339SMiguel Ojeda -Wclippy::as_underscore \ 4947ed18860SMiguel Ojeda -Wclippy::cast_lossless \ 495bb421b51SMiguel Ojeda -Aclippy::collapsible_if \ 496f8f88aa2SMiguel Ojeda -Aclippy::collapsible_match \ 49760fc1e67SMiguel Ojeda -Wclippy::ignored_unit_patterns \ 498f8f88aa2SMiguel Ojeda -Aclippy::incompatible_msrv \ 499fcad9bbfSTamir Duberstein -Wclippy::mut_mut \ 500d8c9e735STamir Duberstein -Wclippy::needless_bitwise_bool \ 501dc35ddcfSTamir Duberstein -Aclippy::needless_lifetimes \ 502db4f72c9SMiguel Ojeda -Wclippy::no_mangle_with_rust_abi \ 50310eea3c1SMiguel Ojeda -Wclippy::ptr_as_ptr \ 504c28bfe76SMiguel Ojeda -Wclippy::ptr_cast_constness \ 50523f42dc0SMiguel Ojeda -Wclippy::ref_as_ptr \ 506bef83245SMiguel Ojeda -Wclippy::undocumented_unsafe_blocks \ 507bef83245SMiguel Ojeda -Aclippy::uninlined_format_args \ 5082f7ab126SMiguel Ojeda -Wclippy::unnecessary_safety_comment \ 509fbaf242cSMasahiro Yamada -Wclippy::unnecessary_safety_doc \ 510fbaf242cSMasahiro Yamada -Aclippy::unwrap_or_default \ 511fbaf242cSMasahiro Yamada -Wrustdoc::missing_crate_level_docs \ 512fbaf242cSMasahiro Yamada -Wrustdoc::unescaped_backticks 5132f7ab126SMiguel Ojeda 514b2aa1535SMiguel OjedaKBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) \ 515f92d19e0SLaura Abbott $(HOSTCFLAGS) -I $(srctree)/scripts/include 516f92d19e0SLaura AbbottKBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS) \ 517ceff0757SHONG Yifan -I $(srctree)/scripts/include 5181da177e4SLinus TorvaldsKBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \ 5191da177e4SLinus Torvalds -Zallow-features= 5201da177e4SLinus TorvaldsKBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS) 521a0d1c951SMasahiro YamadaKBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS) 522e9c28192SNathan ChancellorKBUILD_PROCMACROLDFLAGS := $(or $(PROCMACROLDFLAGS),$(KBUILD_HOSTLDFLAGS)) 523e9c28192SNathan Chancellor 524e9c28192SNathan Chancellor# Make variables (CC, etc...) 5253a2486ccSGary GuoCPP = $(CC) -E 526e9c28192SNathan Chancellorifneq ($(LLVM),) 527e9c28192SNathan ChancellorCC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX) 528e9c28192SNathan ChancellorLD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX) 529e9c28192SNathan ChancellorAR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX) 530e9c28192SNathan ChancellorLLVM_LINK = $(LLVM_PREFIX)llvm-link$(LLVM_SUFFIX) 5317158c5b6SNathan ChancellorNM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX) 5327158c5b6SNathan ChancellorOBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX) 5337158c5b6SNathan ChancellorOBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX) 534a0d1c951SMasahiro YamadaREADELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX) 535a0d1c951SMasahiro YamadaSTRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX) 536a0d1c951SMasahiro Yamadaifeq ($(filter -fuse-ld=% --ld-path=%,$(KBUILD_HOSTLDFLAGS)),) 5371da177e4SLinus TorvaldsKBUILD_HOSTLDFLAGS += -fuse-ld=lld 5381da177e4SLinus Torvaldsendif 5391da177e4SLinus Torvaldselse 5401da177e4SLinus TorvaldsCC = $(CROSS_COMPILE)gcc 541eefb8c12SDmitry GolovinLD = $(CROSS_COMPILE)ld 542a0d1c951SMasahiro YamadaAR = $(CROSS_COMPILE)ar 543a0d1c951SMasahiro YamadaNM = $(CROSS_COMPILE)nm 5442f7ab126SMiguel OjedaOBJCOPY = $(CROSS_COMPILE)objcopy 5452f7ab126SMiguel OjedaOBJDUMP = $(CROSS_COMPILE)objdump 5462f7ab126SMiguel OjedaREADELF = $(CROSS_COMPILE)readelf 5472f7ab126SMiguel OjedaSTRIP = $(CROSS_COMPILE)strip 5482f7ab126SMiguel Ojedaendif 549e83b9f55SAndrii NakryikoRUSTC = rustc 550c9a0f3b8SJiri OlsaRUSTDOC = rustdoc 55173a4f6dbSMasahiro YamadaRUSTFMT = rustfmt 55273a4f6dbSMasahiro YamadaCLIPPY_DRIVER = clippy-driver 5531da177e4SLinus TorvaldsBINDGEN = bindgen 554caa27b66SSam RavnborgPAHOLE = pahole 5551da177e4SLinus TorvaldsRESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids 556e9781b52SMasahiro YamadaLEX = flex 5571da177e4SLinus TorvaldsYACC = bison 558858805b3SMasahiro YamadaAWK = awk 559e4a42c82SDenis EfremovINSTALLKERNEL := installkernel 560e4a42c82SDenis EfremovPERL = perl 561e4a42c82SDenis EfremovPYTHON3 = python3 5628dfb61dcSDenis EfremovCHECK = sparse 563e397a603SParth PancholiBASH = bash 5648dfb61dcSDenis EfremovKGZIP = gzip 56548f7ddf7SNick TerrellKBZIP2 = bzip2 56673d210e9SMichał GórnyKLZOP = lzop 5678dfb61dcSDenis EfremovLZMA = lzma 56880a7d1d9SHannes EderLZ4 = lz4 5696c49f359SLuc Van OostenryckXZ = xz 5700c22be07SDouglas AndersonZSTD = zstd 5716588169dSSam RavnborgTAR = tar 5722f7ab126SMiguel Ojeda 5736588169dSSam RavnborgCHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \ 5746588169dSSam Ravnborg -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF) 5751da177e4SLinus TorvaldsNOSTDINC_FLAGS := 5762f7ab126SMiguel OjedaCFLAGS_MODULE = 5771da177e4SLinus TorvaldsRUSTFLAGS_MODULE = 5788debed3eSMasahiro YamadaAFLAGS_MODULE = 5791da177e4SLinus TorvaldsLDFLAGS_MODULE = 580abbf1590SDavid HowellsCFLAGS_KERNEL = 581abbf1590SDavid HowellsRUSTFLAGS_KERNEL = 5829d022c54SMasahiro YamadaAFLAGS_KERNEL = 5839d022c54SMasahiro YamadaLDFLAGS_vmlinux = 584abbf1590SDavid Howells 5853308b285SArnd Bergmann# Use USERINCLUDE when you must reference the UAPI directories only. 586ce6ed1c4SMasahiro YamadaUSERINCLUDE := \ 587abbf1590SDavid Howells -I$(srctree)/arch/$(SRCARCH)/include/uapi \ 588abbf1590SDavid Howells -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \ 5891da177e4SLinus Torvalds -I$(srctree)/include/uapi \ 5901da177e4SLinus Torvalds -I$(objtree)/include/generated/uapi \ 591abbf1590SDavid Howells -include $(srctree)/include/linux/compiler-version.h \ 5929d022c54SMasahiro Yamada -include $(srctree)/include/linux/kconfig.h 5939d022c54SMasahiro Yamada 59413b25489SMasahiro Yamada# Use LINUXINCLUDE when you must reference the include/ directory. 595f8224f7fSMasahiro Yamada# Needed to be compatible with the O= option 596f8224f7fSMasahiro YamadaLINUXINCLUDE := \ 5971da177e4SLinus Torvalds -I$(srctree)/arch/$(SRCARCH)/include \ 59842a92bccSMasahiro Yamada -I$(objtree)/arch/$(SRCARCH)/include/generated \ 5990817d259SAlexey Dobriyan -I$(srctree)/include \ 6000817d259SAlexey Dobriyan -I$(objtree)/include \ 6010817d259SAlexey Dobriyan $(USERINCLUDE) 6020817d259SAlexey Dobriyan 6030817d259SAlexey DobriyanKBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE 6040817d259SAlexey Dobriyan 6050817d259SAlexey DobriyanKBUILD_CFLAGS := 6060817d259SAlexey DobriyanKBUILD_CFLAGS += -fshort-wchar 607433dc2ebSMasahiro YamadaKBUILD_CFLAGS += -funsigned-char 6082f7ab126SMiguel OjedaKBUILD_CFLAGS += -fno-common 6092f7ab126SMiguel OjedaKBUILD_CFLAGS += -fno-PIE 6102f7ab126SMiguel OjedaKBUILD_CFLAGS += -fno-strict-aliasing 6112f7ab126SMiguel Ojeda 6122f7ab126SMiguel OjedaKBUILD_CPPFLAGS := -D__KERNEL__ 6132f7ab126SMiguel OjedaKBUILD_RUSTFLAGS := $(rust_common_flags) \ 614f8f88aa2SMiguel Ojeda -Cpanic=abort -Cembed-bitcode=n -Clto=n \ 6154a44b174SAlice Ryhl -Cforce-unwind-tables=n -Ccodegen-units=1 \ 6162f7ab126SMiguel Ojeda -Csymbol-mangling-version=v0 \ 61780c00ba9SSam Ravnborg -Crelocation-model=static \ 61880c00ba9SSam Ravnborg -Zfunction-sections=n \ 6192f7ab126SMiguel Ojeda -Wclippy::float_arithmetic 6206588169dSSam RavnborgKBUILD_RUSTFLAGS_OPTION_CHKS := 6216588169dSSam Ravnborg 6222f7ab126SMiguel OjedaKBUILD_AFLAGS_KERNEL := 62310df0638SMasahiro YamadaKBUILD_CFLAGS_KERNEL := 624d503ac53SMasahiro YamadaKBUILD_RUSTFLAGS_KERNEL := 6255241ab4cSMasahiro YamadaKBUILD_AFLAGS_MODULE := -DMODULE 6261da177e4SLinus TorvaldsKBUILD_CFLAGS_MODULE := -DMODULE 6272f7ab126SMiguel OjedaKBUILD_RUSTFLAGS_MODULE := --cfg MODULE 6282f7ab126SMiguel OjedaKBUILD_LDFLAGS_MODULE := 6292f7ab126SMiguel OjedaKBUILD_LDFLAGS := 6302f7ab126SMiguel OjedaCLANG_FLAGS := 6312f7ab126SMiguel Ojeda 6322f7ab126SMiguel Ojedaifeq ($(KBUILD_CLIPPY),1) 6332f7ab126SMiguel Ojeda RUSTC_OR_CLIPPY_QUIET := CLIPPY 6342f7ab126SMiguel Ojeda RUSTC_OR_CLIPPY = $(CLIPPY_DRIVER) 6352f7ab126SMiguel Ojedaelse 6362f7ab126SMiguel Ojeda RUSTC_OR_CLIPPY_QUIET := RUSTC 6372f7ab126SMiguel Ojeda RUSTC_OR_CLIPPY = $(RUSTC) 6387d56786eSMiguel Ojedaendif 6397d56786eSMiguel Ojeda 6407d56786eSMiguel Ojeda# Allows the usage of unstable features in stable compilers. 641d5ea4fecSChun-Tse Shaoexport RUSTC_BOOTSTRAP := 1 6423a2486ccSGary Guo 6432f7ab126SMiguel Ojeda# Allows finding `.clippy.toml` in out-of-srctree builds. 644d9b5665fSVasily Gorbikexport CLIPPY_CONF_DIR := $(srctree) 645d8d2d382SMasahiro Yamada 64673d210e9SMichał Górnyexport ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG 647ceff0757SHONG Yifanexport RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN LLVM_LINK 648f67695c9SElliot Bermanexport HOSTRUSTC KBUILD_HOSTRUSTFLAGS 6491da177e4SLinus Torvaldsexport CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL 650d503ac53SMasahiro Yamadaexport PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX 6510e410e15SAndrey Konovalovexport KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD TAR 6524a44b174SAlice Ryhlexport KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS KBUILD_PROCMACROLDFLAGS LDFLAGS_MODULE 653222d394dSSam Ravnborgexport KBUILD_USERCFLAGS KBUILD_USERLDFLAGS 6542f7ab126SMiguel Ojeda 6552f7ab126SMiguel Ojedaexport KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS 6561da177e4SLinus Torvaldsexport KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE 6571da177e4SLinus Torvaldsexport KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE KBUILD_RUSTFLAGS_OPTION_CHKS 6581da177e4SLinus Torvaldsexport KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE 659ae63b2d7SPrarit Bhargavaexport KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE 660ae63b2d7SPrarit Bhargavaexport KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL 661ae63b2d7SPrarit Bhargava 6621da177e4SLinus Torvalds# Files to ignore in find ... statements 6631da177e4SLinus Torvalds 6641da177e4SLinus Torvaldsexport RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \ 6651da177e4SLinus Torvalds -name CVS -o -name .pc -o -name .hg -o -name .git \) \ 666312a3d09SCao jin -prune -o 6674f193362SPaul Smith 66875f7c47cSThomas Weißschuh# =========================================================================== 66975f7c47cSThomas Weißschuh# Rules shared between *config targets and build targets 6701da177e4SLinus Torvalds 6711da177e4SLinus Torvalds# Basic helpers built in scripts/basic/ 6721da177e4SLinus TorvaldsPHONY += scripts_basic 6734f193362SPaul Smithscripts_basic: KBUILD_HOSTCFLAGS := $(KBUILD_HOSTCFLAGS) 6742728fcfaSMasahiro Yamadascripts_basic: KBUILD_HOSTLDFLAGS := $(KBUILD_HOSTLDFLAGS) 675e8e83a23SMasahiro Yamadascripts_basic: 676fd5f0cd6SJan Beulich $(Q)$(MAKE) $(build)=scripts/basic 677fd5f0cd6SJan Beulich 678fd5f0cd6SJan BeulichPHONY += outputmakefile 6793a51ff34SVladimir Kondratievifdef building_out_of_srctree 6803a51ff34SVladimir Kondratiev# Before starting out-of-tree build, make sure the source tree is clean. 6812728fcfaSMasahiro Yamada# outputmakefile generates a Makefile in the output directory, if using a 682a2a45ebeSMasahiro Yamada# separate output directory. This allows convenient use of make in the 683a2a45ebeSMasahiro Yamada# output directory. 684a2a45ebeSMasahiro Yamada# At the same time when output Makefile generated, generate .gitignore to 685a2a45ebeSMasahiro Yamada# ignore whole output directory 686a2a45ebeSMasahiro Yamada 687a2a45ebeSMasahiro Yamadaifdef KBUILD_EXTMOD 688a2a45ebeSMasahiro Yamadaprint_env_for_makefile = \ 689a2a45ebeSMasahiro Yamada echo "export KBUILD_OUTPUT = $(objtree)"; \ 690a2a45ebeSMasahiro Yamada echo "export KBUILD_EXTMOD = $(realpath $(srcroot))" ; \ 691a2a45ebeSMasahiro Yamada echo "export KBUILD_EXTMOD_OUTPUT = $(CURDIR)" 692c9bb03acSThomas Weißschuhelse 693822b11a7SMasahiro Yamadaprint_env_for_makefile = \ 694a2a45ebeSMasahiro Yamada echo "export KBUILD_OUTPUT = $(CURDIR)" 695822b11a7SMasahiro Yamadaendif 696c9bb03acSThomas Weißschuh 6972728fcfaSMasahiro Yamadafilechk_makefile = { \ 698c9bb03acSThomas Weißschuh echo "\# Automatically generated by $(abs_srctree)/Makefile: don't edit"; \ 699c9bb03acSThomas Weißschuh $(print_env_for_makefile); \ 700c9bb03acSThomas Weißschuh echo "include $(abs_srctree)/Makefile"; \ 701c9bb03acSThomas Weißschuh } 702c9bb03acSThomas Weißschuh 703c9bb03acSThomas WeißschuhPHONY += $(CURDIR)/Makefile 704c9bb03acSThomas Weißschuh$(CURDIR)/Makefile: FORCE 70511b3d517SMasahiro Yamada $(call filechk,makefile) 7064b098659SMasahiro Yamada 707e8e83a23SMasahiro Yamadaoutputmakefile: $(CURDIR)/Makefile 708e8e83a23SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),) 709e8e83a23SMasahiro Yamada @if [ -f $(srctree)/.config -o \ 710e8e83a23SMasahiro Yamada -d $(srctree)/include/config -o \ 711e8e83a23SMasahiro Yamada -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \ 712e8e83a23SMasahiro Yamada echo >&2 "***"; \ 713e8e83a23SMasahiro Yamada echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \ 714e8e83a23SMasahiro Yamada echo >&2 "*** in $(abs_srctree)";\ 71511b3d517SMasahiro Yamada echo >&2 "***"; \ 71611b3d517SMasahiro Yamada false; \ 71711b3d517SMasahiro Yamada fi 71811b3d517SMasahiro Yamadaelse 71911b3d517SMasahiro Yamada @if [ -f $(srcroot)/modules.order ]; then \ 72011b3d517SMasahiro Yamada echo >&2 "***"; \ 72111b3d517SMasahiro Yamada echo >&2 "*** The external module source tree is not clean."; \ 72211b3d517SMasahiro Yamada echo >&2 "*** Please run 'make -C $(abs_srctree) M=$(realpath $(srcroot)) clean'"; \ 72311b3d517SMasahiro Yamada echo >&2 "***"; \ 72411b3d517SMasahiro Yamada false; \ 725156e7cbbSMasahiro Yamada fi 726156e7cbbSMasahiro Yamadaendif 727fd5f0cd6SJan Beulich $(Q)ln -fsn $(srcroot) source 7281da177e4SLinus Torvalds $(Q)test -e .gitignore || \ 729db07562aSNick Desaulniers { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore 730db07562aSNick Desaulniersendif 73190e5b38aSIhor Solodrai 73290e5b38aSIhor Solodrai# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included. 73390e5b38aSIhor Solodrai# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile. 7346072b2c4SMasahiro Yamada# CC_VERSION_TEXT, RUSTC_VERSION_TEXT and PAHOLE_VERSION are referenced from 7355134a335SMiguel Ojeda# Kconfig (so they need export), and from include/config/auto.conf.cmd to 73690e5b38aSIhor Solodrai# detect the version changes between builds. 737db07562aSNick DesaulniersCC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1)) 738db07562aSNick DesaulniersRUSTC_VERSION_TEXT = $(subst $(pound),,$(shell $(RUSTC) --version 2>/dev/null)) 7396f5b41a2SNick DesaulniersPAHOLE_VERSION = $(shell $(srctree)/scripts/pahole-version.sh $(PAHOLE)) 740ae6b289aSChris Fries 741ae6b289aSChris Friesifneq ($(findstring clang,$(CC_VERSION_TEXT)),) 74257fd251cSMasahiro Yamadainclude $(srctree)/scripts/Makefile.clang 74357fd251cSMasahiro Yamadaendif 744805b2e1dSMasahiro Yamada 74557fd251cSMasahiro Yamada# Include this also for config targets because some architectures need 746805b2e1dSMasahiro Yamada# cc-cross-prefix to determine CROSS_COMPILE. 74757fd251cSMasahiro Yamadaifdef need-compiler 7482042b548SMasahiro Yamadainclude $(srctree)/scripts/Makefile.compiler 7491da177e4SLinus Torvaldsendif 7501da177e4SLinus Torvalds 7511da177e4SLinus Torvaldsifdef config-build 7521da177e4SLinus Torvalds# =========================================================================== 753766b7007SSimon Glass# *config targets only - make sure prerequisites are updated, and descend 7541da177e4SLinus Torvalds# in scripts/kconfig to make the *config target 7551da177e4SLinus Torvalds 7563204a7fbSMasahiro Yamada# Read arch-specific Makefile to set KBUILD_DEFCONFIG as needed. 75790e5b38aSIhor Solodrai# KBUILD_DEFCONFIG may point out an alternative default configuration 7581da177e4SLinus Torvalds# used for 'make defconfig' 75936de077bSMasahiro Yamadainclude $(srctree)/arch/$(SRCARCH)/Makefile 76031110ebbSSam Ravnborgexport KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT RUSTC_VERSION_TEXT PAHOLE_VERSION 76131110ebbSSam Ravnborg 76236de077bSMasahiro Yamadaconfig: outputmakefile scripts_basic FORCE 7631da177e4SLinus Torvalds $(Q)$(MAKE) $(build)=scripts/kconfig $@ 7641da177e4SLinus Torvalds 7652042b548SMasahiro Yamada%config: outputmakefile scripts_basic FORCE 7661da177e4SLinus Torvalds $(Q)$(MAKE) $(build)=scripts/kconfig $@ 767766b7007SSimon Glass 7681da177e4SLinus Torvaldselse #!config-build 7691da177e4SLinus Torvalds# =========================================================================== 7702c1f4f12SMasahiro Yamada# Build targets only - this includes vmlinux, arch-specific targets, clean 771121c2a13SMasahiro Yamada# targets and others. In general all targets except *config targets. 7722c1f4f12SMasahiro Yamada 7732c1f4f12SMasahiro Yamada# If building an external module we do not care about the all: rule 774121c2a13SMasahiro Yamada# but instead __all depend on modules 7752c1f4f12SMasahiro YamadaPHONY += all 776121c2a13SMasahiro Yamadaifeq ($(KBUILD_EXTMOD),) 7772c1f4f12SMasahiro Yamada__all: all 7782c1f4f12SMasahiro Yamadaelse 77932164845SMasahiro Yamada__all: modules 78032164845SMasahiro Yamadaendif 7812c1f4f12SMasahiro Yamada 7822c1f4f12SMasahiro Yamadatargets := 7832c1f4f12SMasahiro Yamada 7842c1f4f12SMasahiro Yamada# Decide whether to build built-in, modular, or both. 7851bf807b8SMasahiro Yamada# Normally, just do built-in. 7862c1f4f12SMasahiro Yamada 7872c1f4f12SMasahiro YamadaKBUILD_MODULES := 7882c1f4f12SMasahiro YamadaKBUILD_BUILTIN := y 7894b50c8c4SMasahiro Yamada 7902c1f4f12SMasahiro Yamada# If we have only "make modules", don't compile built-in objects. 7912c1f4f12SMasahiro Yamadaifeq ($(MAKECMDGOALS),modules) 7922c1f4f12SMasahiro Yamada KBUILD_BUILTIN := 7932c1f4f12SMasahiro Yamadaendif 7942c1f4f12SMasahiro Yamada 7952c1f4f12SMasahiro Yamada# If we have "make <whatever> modules", compile modules 796e72b635cSLuis Augenstein# in addition to whatever we do anyway. 7971bf807b8SMasahiro Yamada# Just "make" or "make all" shall build modules as well 7982c1f4f12SMasahiro Yamada 7992c1f4f12SMasahiro Yamadaifneq ($(filter all modules nsdeps compile_commands.json clang-% sbom,$(MAKECMDGOALS)),) 8002c1f4f12SMasahiro Yamada KBUILD_MODULES := y 8011bf807b8SMasahiro Yamadaendif 8022c1f4f12SMasahiro Yamada 8032c1f4f12SMasahiro Yamadaifeq ($(MAKECMDGOALS),) 8042c1f4f12SMasahiro Yamada KBUILD_MODULES := y 8052c1f4f12SMasahiro Yamadaendif 8062042b548SMasahiro Yamada 807214c0eeaSMasahiro Yamadaexport KBUILD_MODULES KBUILD_BUILTIN 808d93a18f2SMasahiro Yamada 809d93a18f2SMasahiro Yamadaifdef need-config 810ec4c2827SNathan Chancellorinclude $(objtree)/include/config/auto.conf 811ec4c2827SNathan Chancellorendif 8120d3fccf6SNathan Chancellor 813ec4c2827SNathan ChancellorCC_FLAGS_DIALECT := -std=gnu11 814ec4c2827SNathan Chancellor# Allow including a tagged struct or union anonymously in another struct/union. 815ec4c2827SNathan ChancellorCC_FLAGS_DIALECT += $(CONFIG_CC_MS_EXTENSIONS) 816ec4c2827SNathan Chancellor# Clang enables warnings about GNU and Microsoft extensions by default, disable 817ec4c2827SNathan Chancellor# them because this is expected with the above options. 818ec4c2827SNathan Chancellorifdef CONFIG_CC_IS_CLANG 819ec4c2827SNathan ChancellorCC_FLAGS_DIALECT += -Wno-gnu 820ec4c2827SNathan ChancellorCC_FLAGS_DIALECT += -Wno-microsoft-anon-tag 821ec4c2827SNathan Chancellorendif 8221da177e4SLinus Torvaldsexport CC_FLAGS_DIALECT 8231da177e4SLinus TorvaldsKBUILD_CFLAGS += $(CC_FLAGS_DIALECT) 8245750121aSMasahiro Yamada 8255750121aSMasahiro Yamadaifeq ($(KBUILD_EXTMOD),) 8261da177e4SLinus Torvalds# Objects we will link into vmlinux / subdirs we need to visit 8271da177e4SLinus Torvaldscore-y := 8281da177e4SLinus Torvaldsdrivers-y := 829315bab4eSMasahiro Yamadalibs-y := lib/ 830315bab4eSMasahiro Yamadaendif # KBUILD_EXTMOD 831315bab4eSMasahiro Yamada 832315bab4eSMasahiro Yamada# The all: target is the default when no target is given on the 833315bab4eSMasahiro Yamada# command line. 834315bab4eSMasahiro Yamada# This allow a user to issue only 'make' to build a kernel including modules 835b1f4ff74SPaulo Zanoni# Defaults to vmlinux, but the arch makefile usually adds further targets 836b1f4ff74SPaulo Zanoniall: vmlinux 837b1f4ff74SPaulo Zanoni 838b1f4ff74SPaulo Zanoni# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later. 839b1f4ff74SPaulo Zanoniifdef CONFIG_FUNCTION_TRACER 840e30f8e61SSteven Rostedt CC_FLAGS_FTRACE := -pg 841e30f8e61SSteven Rostedtendif 842e30f8e61SSteven Rostedt 843e30f8e61SSteven Rostedtifdef CONFIG_TRACEPOINTS 844e30f8e61SSteven Rostedt# To check for unused tracepoints (tracepoints that are defined but never 845e30f8e61SSteven Rostedt# called), run with: 846e30f8e61SSteven Rostedt# 847e30f8e61SSteven Rostedt# make UT=1 848e30f8e61SSteven Rostedt# 849e30f8e61SSteven Rostedt# Each unused tracepoints can take up to 5KB of memory in the running kernel. 850e30f8e61SSteven Rostedt# It is best to remove any that are not used. 851e30f8e61SSteven Rostedt# 852e30f8e61SSteven Rostedt# This command line option will be removed when all current unused 853e30f8e61SSteven Rostedt# tracepoints are removed. 854e30f8e61SSteven Rostedt 855e30f8e61SSteven Rostedtifeq ("$(origin UT)", "command line") 856e30f8e61SSteven Rostedt WARN_ON_UNUSED_TRACEPOINTS := $(UT) 857e30f8e61SSteven Rostedtendif 858e30f8e61SSteven Rostedtendif # CONFIG_TRACEPOINTS 859b2aa1535SMiguel Ojeda 860b2aa1535SMiguel Ojedaexport WARN_ON_UNUSED_TRACEPOINTS 8612e2f8b5aSMiguel Ojeda 8622e2f8b5aSMiguel Ojeda# Per-version Rust flags. These are like `rust_common_flags`, but may 8632e2f8b5aSMiguel Ojeda# depend on the Rust compiler version (e.g. using `rustc-min-version`). 8642e2f8b5aSMiguel Ojeda# 8652e2f8b5aSMiguel Ojeda# `-Aclippy::precedence`: the lint was extended in Rust 1.85.0 to 8662e2f8b5aSMiguel Ojeda# include bitmasking and shift operations. However, because it generated 8672e2f8b5aSMiguel Ojeda# many hits, in Rust 1.86.0 it was split into a new `precedence_bits` 868b2aa1535SMiguel Ojeda# lint which is not enabled by default. 869b2aa1535SMiguel Ojedarust_common_flags_per_version := \ 870b2aa1535SMiguel Ojeda $(if $(call rustc-min-version,108600),,-Aclippy::precedence) 871b2aa1535SMiguel Ojeda 872b2aa1535SMiguel Ojedarust_common_flags += $(rust_common_flags_per_version) 8733204a7fbSMasahiro YamadaKBUILD_HOSTRUSTFLAGS += $(rust_common_flags_per_version) $(HOSTRUSTFLAGS) 874315bab4eSMasahiro YamadaKBUILD_RUSTFLAGS += $(rust_common_flags_per_version) 8752042b548SMasahiro Yamada 8762042b548SMasahiro Yamadainclude $(srctree)/arch/$(SRCARCH)/Makefile 877315bab4eSMasahiro Yamada 878315bab4eSMasahiro Yamadaifdef need-config 879315bab4eSMasahiro Yamadaifdef may-sync-config 880d2f8ae0eSMasahiro Yamada# Read in dependencies to all Kconfig* files, make sure to run syncconfig if 8811da177e4SLinus Torvalds# changes are detected. This should be included after arch/$(SRCARCH)/Makefile 88205850719SMasahiro Yamada# because some architectures define CROSS_COMPILE there. 88305850719SMasahiro Yamadainclude include/config/auto.conf.cmd 88405850719SMasahiro Yamada 88505850719SMasahiro Yamada$(KCONFIG_CONFIG): 88605850719SMasahiro Yamada @echo >&2 '***' 88705850719SMasahiro Yamada @echo >&2 '*** Configuration file "$@" not found!' 88805850719SMasahiro Yamada @echo >&2 '***' 88905850719SMasahiro Yamada @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or' 8901da177e4SLinus Torvalds @echo >&2 '*** "make menuconfig" or "make xconfig").' 89161277981SUlf Magnusson @echo >&2 '***' 89261277981SUlf Magnusson @/bin/false 89361277981SUlf Magnusson 8949390dff6SMasahiro Yamada# The actual configuration files used during the build are stored in 8959390dff6SMasahiro Yamada# include/generated/ and include/config/. Update them if .config is newer than 8969390dff6SMasahiro Yamada# include/config/auto.conf (which mirrors .config). 897f463c351SMasahiro Yamada# 898d952cfafSMasahiro Yamada# This exploits the 'multi-target pattern rule' trick. 899d952cfafSMasahiro Yamada# The syncconfig should be executed only once to make all the targets. 900d952cfafSMasahiro Yamada# (Note: use the grouped target '&:' when we bump to GNU Make 4.3) 9012f7ab126SMiguel Ojeda# 902d952cfafSMasahiro Yamada# Do not use $(call cmd,...) here. That would suppress prompts from syncconfig, 903d952cfafSMasahiro Yamada# so you cannot notice that Kconfig is waiting for the user input. 9042042b548SMasahiro Yamada%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h %/generated/rustc_cfg: $(KCONFIG_CONFIG) 905d7942413SMasahiro Yamada $(Q)$(kecho) " SYNC $@" 906d7942413SMasahiro Yamada $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig 907ec873a4cSMasahiro Yamadaelse # !may-sync-config 9089ee4e336SSam Ravnborg# External modules and some install targets need include/generated/autoconf.h 909214c0eeaSMasahiro Yamada# and include/config/auto.conf but do not care if they are up-to-date. 910ec873a4cSMasahiro Yamada# Use auto.conf to show the error message 911ec873a4cSMasahiro Yamada 912ec873a4cSMasahiro Yamadachecked-configs := $(addprefix $(objtree)/, include/generated/autoconf.h include/generated/rustc_cfg include/config/auto.conf) 913214c0eeaSMasahiro Yamadamissing-configs := $(filter-out $(wildcard $(checked-configs)), $(checked-configs)) 9149ee4e336SSam Ravnborg 915214c0eeaSMasahiro Yamadaifdef missing-configs 916ec873a4cSMasahiro YamadaPHONY += $(objtree)/include/config/auto.conf 917ec873a4cSMasahiro Yamada 918ec873a4cSMasahiro Yamada$(objtree)/include/config/auto.conf: 919ec873a4cSMasahiro Yamada @echo >&2 '***' 920ec873a4cSMasahiro Yamada @echo >&2 '*** ERROR: Kernel configuration is invalid. The following files are missing:' 921ec873a4cSMasahiro Yamada @printf >&2 '*** - %s\n' $(missing-configs) 922ec873a4cSMasahiro Yamada @echo >&2 '*** Run "make oldconfig && make prepare" on kernel source to fix it.' 9239ee4e336SSam Ravnborg @echo >&2 '***' 924d7942413SMasahiro Yamada @/bin/false 9252042b548SMasahiro Yamadaendif 9261da177e4SLinus Torvalds 9277d73c3e9SNick Desaulniersendif # may-sync-config 928a1c48bb1SGeert Uytterhoevenendif # need-config 92915f5db60SMasahiro Yamada 930a0f97e06SSam RavnborgKBUILD_CFLAGS += -fno-delete-null-pointer-checks 9312f7ab126SMiguel Ojeda 93215f5db60SMasahiro Yamadaifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE 93315f5db60SMasahiro YamadaKBUILD_CFLAGS += -O2 9342f7ab126SMiguel OjedaKBUILD_RUSTFLAGS += -Copt-level=2 9351da177e4SLinus Torvaldselse ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE 9361da177e4SLinus TorvaldsKBUILD_CFLAGS += -Os 9372f7ab126SMiguel OjedaKBUILD_RUSTFLAGS += -Copt-level=s 9382f7ab126SMiguel Ojedaendif 9392f7ab126SMiguel Ojeda 9402f7ab126SMiguel Ojeda# Always set `debug-assertions` and `overflow-checks` because their default 9412f7ab126SMiguel Ojeda# depends on `opt-level` and `debug-assertions`, respectively. 94269102311SJiri KosinaKBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n) 9437d73c3e9SNick DesaulniersKBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n) 9447d73c3e9SNick Desaulniers 9457d73c3e9SNick Desaulniers# Tell gcc to never replace conditional load with a non-conditional one 94669102311SJiri Kosinaifdef CONFIG_CC_IS_GCC 947b1112139SSergei Trofimovich# gcc-10 renamed --param=allow-store-data-races=0 to 9487d73c3e9SNick Desaulniers# -fno-allow-store-data-races. 94969102311SJiri KosinaKBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0) 9501873e870SAndi KleenKBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races) 9511873e870SAndi Kleenendif 9521873e870SAndi Kleen 9531873e870SAndi Kleenifdef CONFIG_READABLE_ASM 9541873e870SAndi Kleen# Disable optimizations that make assembler listings hard to read. 9557d73c3e9SNick Desaulniers# reorder blocks reorders the control in the function 9561873e870SAndi Kleen# ipa clone creates specialized cloned functions 9571873e870SAndi Kleen# partial inlining inlines only parts of functions 958893ab004SMasahiro YamadaKBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining 959050e9baaSLinus Torvaldsendif 960050e9baaSLinus Torvalds 9612a61f474SMasahiro Yamadastackp-flags-y := -fno-stack-protector 9622a61f474SMasahiro Yamadastackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector 963e06b8b98SSam Ravnborgstackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong 9641da177e4SLinus Torvalds 965a0f97e06SSam RavnborgKBUILD_CFLAGS += $(stackp-flags-y) 9662f7ab126SMiguel Ojeda 967191f49f1SAlice Ryhlifdef CONFIG_FRAME_POINTER 968191f49f1SAlice RyhlKBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls 969191f49f1SAlice RyhlKBUILD_RUSTFLAGS += -Cforce-frame-pointers=y 9701da177e4SLinus Torvalds# Work around rustc bug on compilers without 9717e9501fdSRabin Vincent# https://github.com/rust-lang/rust/pull/156980. 9727e9501fdSRabin VincentKBUILD_RUSTFLAGS += $(if $(call rustc-min-version,109800),,-Zllvm_module_flag=frame-pointer:u32:2:max) 9737e9501fdSRabin Vincentelse 9747e9501fdSRabin Vincent# Some targets (ARM with Thumb2, for example), can't be built with frame 9757e9501fdSRabin Vincent# pointers. For those, we don't have FUNCTION_TRACER automatically 9762f7ab126SMiguel Ojeda# select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is 9772f7ab126SMiguel Ojeda# incompatible with -fomit-frame-pointer with current GCC, so we don't use 9787e9501fdSRabin Vincent# -fomit-frame-pointer with FUNCTION_TRACER. 979a0f97e06SSam Ravnborg# In the Rust target specification, "frame-pointer" is set explicitly 9801da177e4SLinus Torvalds# to "may-omit". 9817e9501fdSRabin Vincentifndef CONFIG_FUNCTION_TRACER 9821da177e4SLinus TorvaldsKBUILD_CFLAGS += -fomit-frame-pointer 983f0fe00d4Sglider@google.comendif 984f0fe00d4Sglider@google.comendif 985709a972eSKees Cook 986709a972eSKees Cook# Initialize all stack variables with a 0xAA pattern. 987709a972eSKees Cookifdef CONFIG_INIT_STACK_ALL_PATTERN 988f0fe00d4Sglider@google.comKBUILD_CFLAGS += -ftrivial-auto-var-init=pattern 989f0fe00d4Sglider@google.comendif 990f0fe00d4Sglider@google.com 991607e57c6SKees Cook# Initialize all stack variables with a zero value. 992607e57c6SKees Cookifdef CONFIG_INIT_STACK_ALL_ZERO 9934e3feaadSNathan ChancellorKBUILD_CFLAGS += -ftrivial-auto-var-init=zero 9944e3feaadSNathan Chancellorifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER 9954e3feaadSNathan Chancellor# https://github.com/llvm/llvm-project/issues/44842 996f0fe00d4Sglider@google.comCC_AUTO_VAR_INIT_ZERO_ENABLER := -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang 997f02003c8SKees Cookexport CC_AUTO_VAR_INIT_ZERO_ENABLER 998f0fe00d4Sglider@google.comKBUILD_CFLAGS += $(CC_AUTO_VAR_INIT_ZERO_ENABLER) 999feb662d9SMarco Elverendif 1000feb662d9SMarco Elverendif 1001feb662d9SMarco Elver 1002feb662d9SMarco Elverifdef CONFIG_KMALLOC_PARTITION_TYPED 1003feb662d9SMarco Elver# KMALLOC_PARTITION_CACHES_NR + 1 1004150a04d8SBill WendlingKBUILD_CFLAGS += -falloc-token-max=16 1005150a04d8SBill Wendlingendif 1006150a04d8SBill Wendling 1007150a04d8SBill Wendlingifdef CONFIG_CC_IS_CLANG 1008150a04d8SBill Wendlingifdef CONFIG_CC_HAS_COUNTED_BY_PTR 1009150a04d8SBill WendlingKBUILD_CFLAGS += -fexperimental-late-parse-attributes 1010c1525349SMasahiro Yamadaendif 1011c1525349SMasahiro Yamadaendif 1012c1525349SMasahiro Yamada 101339218ff4SKees Cook# Explicitly clear padding bits during variable initialization 101439218ff4SKees CookKBUILD_CFLAGS += $(call cc-option,-fzero-init-padding-bits=all) 101539218ff4SKees Cook 101639218ff4SKees Cook# While VLAs have been removed, GCC produces unreachable stack probes 10177454048dSKees Cook# for the randomize_kstack_offset feature. Disable it for all compilers. 10187454048dSKees CookKBUILD_CFLAGS += $(call cc-option, -fno-stack-clash-protection) 10197454048dSKees Cook 102040492775SJustin Stitt# Get details on warnings generated due to GCC value tracking. 102140492775SJustin StittKBUILD_CFLAGS += $(call cc-option, -fdiagnostics-show-context=2) 102240492775SJustin Stitt 102340492775SJustin Stitt# Show inlining notes for __attribute__((warning/error)) call chains. 1024a82adfd5SKees Cook# GCC supports this unconditionally while Clang 23+ provides a flag. 1025a82adfd5SKees CookKBUILD_CFLAGS += $(call cc-option, -fdiagnostics-show-inlining-chain) 1026a82adfd5SKees Cook 1027a82adfd5SKees Cook# Clear used registers at func exit (to reduce data lifetime and ROP gadgets). 1028a82adfd5SKees Cookifdef CONFIG_ZERO_CALL_USED_REGS 1029606576ceSSteven RostedtKBUILD_CFLAGS += -fzero-call-used-regs=used-gpr 10303b15cdc1SSami Tolvanenendif 103107d04081SVasily Gorbik 10322f4df001SVasily Gorbikifdef CONFIG_FUNCTION_TRACER 10332f4df001SVasily Gorbikifdef CONFIG_FTRACE_MCOUNT_USE_CC 10342f4df001SVasily Gorbik CC_FLAGS_FTRACE += -mrecord-mcount 10352f4df001SVasily Gorbik ifdef CONFIG_HAVE_NOP_MCOUNT 10362f4df001SVasily Gorbik ifeq ($(call cc-option-yn, -mnop-mcount),y) 10372f4df001SVasily Gorbik CC_FLAGS_FTRACE += -mnop-mcount 103807d04081SVasily Gorbik CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT 103922c8542dSSami Tolvanen endif 1040280981d6SSathvika Vasireddy endif 104122c8542dSSami Tolvanenendif 104222c8542dSSami Tolvanenifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL 1043280981d6SSathvika Vasireddy ifdef CONFIG_HAVE_OBJTOOL_NOP_MCOUNT 10443b15cdc1SSami Tolvanen CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT 10453b15cdc1SSami Tolvanen endif 10463b15cdc1SSami Tolvanenendif 10473b15cdc1SSami Tolvanenifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT 10483b15cdc1SSami Tolvanen ifdef CONFIG_HAVE_C_RECORDMCOUNT 10493b15cdc1SSami Tolvanen BUILD_C_RECORDMCOUNT := y 1050a2546faeSSteven Rostedt export BUILD_C_RECORDMCOUNT 10517d73c3e9SNick Desaulniers endif 1052f28bc3c3SVasily Gorbikendif 1053f28bc3c3SVasily Gorbikifdef CONFIG_HAVE_FENTRY 1054f28bc3c3SVasily Gorbik # s390-linux-gnu-gcc did not support -mfentry until gcc-9. 1055a2546faeSSteven Rostedt ifeq ($(call cc-option-yn, -mfentry),y) 1056f28bc3c3SVasily Gorbik CC_FLAGS_FTRACE += -mfentry 1057f28bc3c3SVasily Gorbik CC_FLAGS_USING += -DCC_USING_FENTRY 1058f28bc3c3SVasily Gorbik endif 1059f28bc3c3SVasily Gorbikendif 106016444a8aSArnaldo Carvalho de Meloexport CC_FLAGS_FTRACE 106116444a8aSArnaldo Carvalho de MeloKBUILD_CFLAGS += $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING) 106291341d4bSSam RavnborgKBUILD_AFLAGS += $(CC_FLAGS_USING) 106391341d4bSSam Ravnborgendif 10647d73c3e9SNick Desaulniers 106591341d4bSSam Ravnborg# We trigger additional mismatches with less inlining 106691341d4bSSam Ravnborgifdef CONFIG_DEBUG_SECTION_MISMATCH 10672f7ab126SMiguel OjedaKBUILD_CFLAGS += -fno-inline-functions-called-once 106890ad4052SMasahiro Yamadaendif 1069e85d1d65SMasahiro Yamada 10702f7ab126SMiguel Ojeda# `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0). 1071e85d1d65SMasahiro Yamadaifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION 107290ad4052SMasahiro YamadaKBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections 107390ad4052SMasahiro YamadaKBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y 1074d08b9f0cSSami TolvanenLDFLAGS_vmlinux += --gc-sections 10759beccca0SArd Biesheuvelendif 1076d08b9f0cSSami Tolvanen 1077d08b9f0cSSami Tolvanenifdef CONFIG_SHADOW_CALL_STACK 1078d077242dSAlice Ryhlifndef CONFIG_DYNAMIC_SCS 10799beccca0SArd BiesheuvelCC_FLAGS_SCS := -fsanitize=shadow-call-stack 1080d08b9f0cSSami TolvanenKBUILD_CFLAGS += $(CC_FLAGS_SCS) 1081d08b9f0cSSami TolvanenKBUILD_RUSTFLAGS += -Zsanitizer=shadow-call-stack 1082d08b9f0cSSami Tolvanenendif 1083dc5723b0SSami Tolvanenexport CC_FLAGS_SCS 10849f2aee8fSRong Xuendif 10852b868952SAlexander Lobakin 10869f2aee8fSRong Xuifdef CONFIG_LTO_CLANG 10879f2aee8fSRong Xuifdef CONFIG_LTO_CLANG_FULL 10889f2aee8fSRong XuCC_FLAGS_LTO := -flto 10899f2aee8fSRong Xuelse 10909f2aee8fSRong XuCC_FLAGS_LTO := -flto=thin -fsplit-lto-unit 10919f2aee8fSRong Xu 10929f2aee8fSRong Xu# These LLVM options were initially added with only in-process ThinLTO 10939f2aee8fSRong Xu# support, so avoid distributed ThinLTO support for now. 1094dc5723b0SSami Tolvanenifdef CONFIG_LTO_CLANG_THIN 1095dc5723b0SSami TolvanenKBUILD_LDFLAGS += $(call ld-option,--lto-whole-program-visibility -mllvm -always-rename-promoted-locals=false) 109622d429e7SSami Tolvanenendif 109722d429e7SSami Tolvanenendif 109822d429e7SSami TolvanenCC_FLAGS_LTO += -fvisibility=hidden 10990236526dSTor Vic 1100dc5723b0SSami Tolvanen# Limit inlining across translation units to reduce binary size 1101dc5723b0SSami TolvanenKBUILD_LDFLAGS += -mllvm -import-instr-limit=5 11025e95325fSSami Tolvanenendif 11035e95325fSSami Tolvanen 1104dc5723b0SSami Tolvanenifdef CONFIG_LTO 1105dc5723b0SSami TolvanenKBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO) 1106dc5723b0SSami TolvanenKBUILD_AFLAGS += -fno-lto 110723ef9d43SKees Cookexport CC_FLAGS_LTO 110889245600SSami Tolvanenendif 1109ce4a2620SAlice Ryhl 1110ce4a2620SAlice Ryhlifdef CONFIG_CFI 1111ce4a2620SAlice RyhlCC_FLAGS_CFI := -fsanitize=kcfi 11120c92385dSPeter Zijlstraifdef CONFIG_CFI_ICALL_NORMALIZE_INTEGERS 11130c92385dSPeter Zijlstra CC_FLAGS_CFI += -fsanitize-cfi-icall-experimental-normalize-integers 11140c92385dSPeter Zijlstraendif 1115ca627e63SMatthew Maurerifdef CONFIG_FINEIBT_BHI 1116ca627e63SMatthew Maurer CC_FLAGS_CFI += -fsanitize-kcfi-arity 1117ca627e63SMatthew Maurerendif 1118ca627e63SMatthew Maurerifdef CONFIG_RUST 1119ca627e63SMatthew Maurer # Always pass -Zsanitizer-cfi-normalize-integers as CONFIG_RUST selects 1120ca627e63SMatthew Maurer # CONFIG_CFI_ICALL_NORMALIZE_INTEGERS. 1121ca627e63SMatthew Maurer RUSTC_FLAGS_CFI := -Zsanitizer=kcfi -Zsanitizer-cfi-normalize-integers 1122cf68fffbSSami Tolvanen KBUILD_RUSTFLAGS += $(RUSTC_FLAGS_CFI) 1123cf68fffbSSami Tolvanen export RUSTC_FLAGS_CFI 1124cf68fffbSSami Tolvanenendif 1125cf68fffbSSami TolvanenKBUILD_CFLAGS += $(CC_FLAGS_CFI) 11266cbd1d6dSSamuel Hollandexport CC_FLAGS_CFI 11276cbd1d6dSSamuel Hollandendif 11286cbd1d6dSSamuel Holland 11296cbd1d6dSSamuel Holland# Architectures can define flags to add/remove for floating-point support 11306cbd1d6dSSamuel HollandCC_FLAGS_FPU += -D_LINUX_FPU_COMPILATION_UNIT 1131d49a0626SPeter Zijlstraexport CC_FLAGS_FPU 11325270316cSPetr Pavluexport CC_FLAGS_NO_FPU 11335270316cSPetr Pavlu 11345270316cSPetr Pavluifneq ($(CONFIG_FUNCTION_ALIGNMENT),0) 11355270316cSPetr Pavlu# Set the minimal function alignment. Use the newer GCC option 11365270316cSPetr Pavlu# -fmin-function-alignment if it is available, or fall back to -falign-funtions. 11375270316cSPetr Pavlu# See also CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT. 1138d49a0626SPeter Zijlstraifdef CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT 113909c60546SFeng TangKBUILD_CFLAGS += -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT) 11405270316cSPetr Pavluelse 114109c60546SFeng TangKBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT) 1142e8e69931SSam Ravnborgendif 114304e85bbfSAlexey Dobriyanendif 1144e8e69931SSam Ravnborg 1145df8fc4e9SKees Cook# arch Makefile may override CC so keep this after arch Makefile is included 1146df8fc4e9SKees CookNOSTDINC_FLAGS += -nostdinc 1147df8fc4e9SKees Cook 1148df8fc4e9SKees Cook# To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE, 1149df8fc4e9SKees Cook# the kernel uses only C99 flexible arrays for dynamically sized trailing 1150df8fc4e9SKees Cook# arrays. Enforce this for everything that may examine structure sizes and 1151fe8d0a41SKirill Smelkov# perform bounds checking. 11528b42cf2fSMasahiro YamadaKBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3) 1153d0115552SLinus Torvalds 11543ce120b1SLinus Torvalds# disable invalid "can't wrap" optimizations for signed / pointers 11557d4eb0d8SMasahiro YamadaKBUILD_CFLAGS += -fno-strict-overflow 11563ce120b1SLinus Torvalds 11578f7f5c9fSAndi Kleen# Make sure -fstack-check isn't enabled (like gentoo apparently did) 11587d73c3e9SNick DesaulniersKBUILD_CFLAGS += -fno-stack-check 11597d73c3e9SNick Desaulniers 11607d73c3e9SNick Desaulniers# conserve stack if available 11618f7f5c9fSAndi Kleenifdef CONFIG_CC_IS_GCC 116284ffc79bSNathan ChancellorKBUILD_CFLAGS += -fconserve-stack 116384ffc79bSNathan Chancellorendif 116484ffc79bSNathan Chancellor 116556cb9b7dSKonstantin Khorenko# Ensure compilers do not transform certain loops into calls to wcslen() 116656cb9b7dSKonstantin KhorenkoKBUILD_CFLAGS += -fno-builtin-wcslen 116756cb9b7dSKonstantin Khorenko 116856cb9b7dSKonstantin KhorenkoCFLAGS_GCOV := -fprofile-arcs -ftest-coverage 116956cb9b7dSKonstantin Khorenkoifdef CONFIG_CC_IS_GCC 117056cb9b7dSKonstantin KhorenkoCFLAGS_GCOV += -fno-tree-loop-im 117156cb9b7dSKonstantin Khorenko# Use atomic counter updates to avoid concurrent-access crashes in GCOV. 117256cb9b7dSKonstantin Khorenko# Only enable if -fprofile-update=prefer-atomic does not introduce new 117356cb9b7dSKonstantin Khorenko# undefined symbols (e.g. libatomic calls that the kernel cannot link). 117456cb9b7dSKonstantin KhorenkoCFLAGS_GCOV += $(call try-run,\ 117556cb9b7dSKonstantin Khorenko echo 'long long x; void f(void){x++;}' | \ 117656cb9b7dSKonstantin Khorenko $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -w -fprofile-arcs \ 117756cb9b7dSKonstantin Khorenko -ftest-coverage -x c - -c -o "$$TMP.base" && \ 117856cb9b7dSKonstantin Khorenko echo 'long long x; void f(void){x++;}' | \ 117956cb9b7dSKonstantin Khorenko $(CC) $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS) -w -fprofile-arcs \ 118056cb9b7dSKonstantin Khorenko -ftest-coverage -fprofile-update=prefer-atomic \ 118156cb9b7dSKonstantin Khorenko -x c - -c -o "$$TMP" && \ 118256cb9b7dSKonstantin Khorenko $(NM) "$$TMP.base" | grep ' U ' > "$$TMP.ubase" || true ; \ 118356cb9b7dSKonstantin Khorenko $(NM) "$$TMP" | grep ' U ' > "$$TMP.utest" || true ; \ 118456cb9b7dSKonstantin Khorenko cmp -s "$$TMP.ubase" "$$TMP.utest",\ 118556cb9b7dSKonstantin Khorenko -fprofile-update=prefer-atomic) 11861d3730f0SMasahiro Yamadaendif 11871d3730f0SMasahiro Yamadaexport CFLAGS_GCOV 1188379b749aSThomas Weißschuh 1189dda13507SGary Guo# change __FILE__ to the relative path to the source directory 1190dda13507SGary Guoifdef building_out_of_srctree 1191dda13507SGary GuoKBUILD_CPPFLAGS += -fmacro-prefix-map=$(srcroot)/= 11921d3730f0SMasahiro Yamadaifeq ($(call rustc-option-yn, --remap-path-scope=macro),y) 1193a73619a8SMasahiro YamadaKBUILD_RUSTFLAGS += --remap-path-prefix=$(srcroot)/= --remap-path-scope=macro 1194e0fe0bbeSMasahiro Yamadaendif 11957319256dSNathan Chancellorendif 11966947fd96SMasahiro Yamada 119772d09184SMasahiro Yamada# include additional Makefiles when needed 1198e0fe0bbeSMasahiro Yamadainclude-y := scripts/Makefile.warn 1199e0fe0bbeSMasahiro Yamadainclude-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug 1200f80be457SAlexander Potapenkoinclude-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf 1201e0fe0bbeSMasahiro Yamadainclude-$(CONFIG_KASAN) += scripts/Makefile.kasan 1202e0fe0bbeSMasahiro Yamadainclude-$(CONFIG_KCSAN) += scripts/Makefile.kcsan 1203613f4b3eSKees Cookinclude-$(CONFIG_KMSAN) += scripts/Makefile.kmsan 120476261fc7SKees Cookinclude-$(CONFIG_UBSAN) += scripts/Makefile.ubsan 1205315ad878SRong Xuinclude-$(CONFIG_KCOV) += scripts/Makefile.kcov 1206d5dc9583SRong Xuinclude-$(CONFIG_RANDSTRUCT) += scripts/Makefile.randstruct 12073269701cSMarco Elverinclude-$(CONFIG_KSTACK_ERASE) += scripts/Makefile.kstack_erase 1208e0fe0bbeSMasahiro Yamadainclude-$(CONFIG_AUTOFDO_CLANG) += scripts/Makefile.autofdo 1209e0fe0bbeSMasahiro Yamadainclude-$(CONFIG_PROPELLER_CLANG) += scripts/Makefile.propeller 1210e0fe0bbeSMasahiro Yamadainclude-$(CONFIG_WARN_CONTEXT_ANALYSIS) += scripts/Makefile.context-analysis 1211a86fe353SMasahiro Yamadainclude-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins 1212132305b3SMasahiro Yamada 1213132305b3SMasahiro Yamadainclude $(addprefix $(srctree)/, $(include-y)) 1214132305b3SMasahiro Yamada 1215bf5438fcSJason Baron# scripts/Makefile.gcc-plugins is intentionally included last. 12162f7ab126SMiguel Ojeda# Do not add $(call cc-option,...) below this line. When you build the kernel 12178cc7af75SMasahiro Yamada# from the clean source tree, the GCC plugins do not exist at this point. 12188cc7af75SMasahiro Yamada 12198cc7af75SMasahiro Yamada# Add user supplied CPPFLAGS, AFLAGS, CFLAGS and RUSTFLAGS as the last assignments 12202f7ab126SMiguel OjedaKBUILD_CPPFLAGS += $(KCPPFLAGS) 122152bcc330SSam RavnborgKBUILD_AFLAGS += $(KAFLAGS) 1222a9684337SBill WendlingKBUILD_CFLAGS += $(KCFLAGS) 1223a9684337SBill WendlingKBUILD_RUSTFLAGS += $(KRUSTFLAGS) 122418991197SRoland McGrath 12250d362be5SNick DesaulniersKBUILD_LDFLAGS_MODULE += --build-id=sha1 12260d362be5SNick DesaulniersLDFLAGS_vmlinux += --build-id=sha1 12270d362be5SNick Desaulniers 12280d362be5SNick Desaulniers# Specific code, such as outlined KASAN checks, may be placed in 12290d362be5SNick Desaulniers# COMDAT-deduplicated sections. Use --force-group-allocation to resolve these 12305d7d18f5SDavid Howells# groups when linking modules. The option is available from ld.bfd 2.29 and 12310f1fe9d6SMasahiro Yamada# ld.lld 19.1.0. 12325d7d18f5SDavid HowellsKBUILD_LDFLAGS_MODULE += $(call ld-option,--force-group-allocation) 12335d7d18f5SDavid Howells 12345cf896fbSPeter CollingbourneKBUILD_LDFLAGS += -z noexecstack 1235ccb2d173SFangrui Songifeq ($(CONFIG_LD_IS_BFD),y) 1236ccb2d173SFangrui SongKBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments) 12375cf896fbSPeter Collingbourneendif 12385cf896fbSPeter Collingbourne 123959612b24SNathan Chancellorifeq ($(CONFIG_STRIP_ASM_SYMS),y) 124059612b24SNathan ChancellorLDFLAGS_vmlinux += -X 124159612b24SNathan Chancellorendif 1242e1789d7cSXin Li 124359612b24SNathan Chancellorifeq ($(CONFIG_RELR),y) 124459612b24SNathan Chancellor# ld.lld before 15 did not support -z pack-relative-relocs. 12459b400d17SArd BiesheuvelLDFLAGS_vmlinux += $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs) 12469b400d17SArd Biesheuvelendif 12479b400d17SArd Biesheuvel 12489b400d17SArd Biesheuvel# We never want expected sections to be placed heuristically by the 1249deab487eSThomas Weißschuh# linker. All sections should be explicitly named in the linker script. 1250deab487eSThomas Weißschuhifdef CONFIG_LD_ORPHAN_WARN 1251deab487eSThomas WeißschuhLDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL) 1252deab487eSThomas Weißschuhendif 1253deab487eSThomas Weißschuh 1254deab487eSThomas Weißschuhifneq ($(CONFIG_ARCH_VMLINUX_NEEDS_RELOCS),) 1255deab487eSThomas WeißschuhLDFLAGS_vmlinux += --emit-relocs --discard-none 1256deab487eSThomas Weißschuhendif 1257deab487eSThomas Weißschuh 1258deab487eSThomas Weißschuh# Align the architecture of userspace programs with the kernel 1259deab487eSThomas WeißschuhUSERFLAGS_FROM_KERNEL := --target=% 12602d0ec4a9SThomas Weißschuh 12612d0ec4a9SThomas Weißschuhifdef CONFIG_ARCH_USERFLAGS 12627f3a59dbSMasahiro YamadaKBUILD_USERCFLAGS += $(CONFIG_ARCH_USERFLAGS) 1263dfc1b168SThomas WeißschuhKBUILD_USERLDFLAGS += $(CONFIG_ARCH_USERFLAGS) 1264936599caSThomas Weißschuhelse 1265dfc1b168SThomas Weißschuh# If not overridden also inherit the bit size 1266dfc1b168SThomas WeißschuhUSERFLAGS_FROM_KERNEL += -m32 -m64 1267dfc1b168SThomas Weißschuhendif 126880591e61SLuc Van Oostenryck 126980591e61SLuc Van OostenryckKBUILD_USERCFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)) 127080591e61SLuc Van OostenryckKBUILD_USERLDFLAGS += $(filter $(USERFLAGS_FROM_KERNEL), $(KBUILD_CPPFLAGS) $(KBUILD_CFLAGS)) 127114516765SLuc Van Oostenryck 127214516765SLuc Van Oostenryck# userspace programs are linked via the compiler, use the correct linker 127314516765SLuc Van Oostenryckifdef CONFIG_CC_IS_CLANG 12741f2f01b1SLuc Van OostenryckKBUILD_USERLDFLAGS += --ld-path=$(LD) 12751f2f01b1SLuc Van Oostenryckendif 12761f2f01b1SLuc Van Oostenryck 1277fd69b2f7SPeter Zijlstra# make the checker run with the right architecture 1278fd69b2f7SPeter ZijlstraCHECKFLAGS += --arch=$(ARCH) 1279fd69b2f7SPeter Zijlstra 1280fd69b2f7SPeter Zijlstra# insure the checker run with the right endianness 1281fd69b2f7SPeter ZijlstraCHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian) 1282fd69b2f7SPeter Zijlstra 1283fd69b2f7SPeter Zijlstra# the checker needs the correct machine size 1284fd69b2f7SPeter ZijlstraCHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32) 12851da177e4SLinus Torvalds 12861da177e4SLinus Torvalds# Validate the checker is available and functional 12871da177e4SLinus Torvaldsifneq ($(KBUILD_CHECKSRC), 0) 12881da177e4SLinus Torvalds ifneq ($(shell $(srctree)/scripts/checker-valid.sh $(CHECK) $(CHECKFLAGS)), 1) 12891da177e4SLinus Torvalds $(warning C=$(KBUILD_CHECKSRC) specified, but $(CHECK) is not available or not up to date) 12901da177e4SLinus Torvalds KBUILD_CHECKSRC = 0 12911da177e4SLinus Torvalds endif 12921da177e4SLinus Torvaldsendif 12931da177e4SLinus Torvalds 12941da177e4SLinus Torvalds# Default kernel image to build when no specific target is given. 12951da177e4SLinus Torvalds# KBUILD_IMAGE may be overruled on the command line or 12961da177e4SLinus Torvalds# set in the environment 12971da177e4SLinus Torvalds# Also any assignments in arch/$(ARCH)/Makefile take precedence over 1298f4d4ffc0SJason Cooper# this default value 1299f4d4ffc0SJason Cooperexport KBUILD_IMAGE ?= vmlinux 1300f4d4ffc0SJason Cooper 1301f4d4ffc0SJason Cooper# 1302f4d4ffc0SJason Cooper# INSTALL_PATH specifies where to place the updated kernel and system map 1303f4d4ffc0SJason Cooper# images. Default is /boot, but you can set it to other values 1304f4d4ffc0SJason Cooperexport INSTALL_PATH ?= /boot 13051da177e4SLinus Torvalds 13061da177e4SLinus Torvalds# 1307070b98bfSSam Ravnborg# INSTALL_DTBS_PATH specifies a prefix for relocations required by build roots. 13081da177e4SLinus Torvalds# Like INSTALL_MOD_PATH, it isn't defined in the Makefile, but can be passed as 13091da177e4SLinus Torvalds# an argument if needed. Otherwise it defaults to the kernel install path 1310df9df036SSam Ravnborg# 13111da177e4SLinus Torvaldsexport INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE) 13121da177e4SLinus Torvalds 1313e00d8880SMasahiro Yamada# 1314e2a666d5SRusty Russell# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory 13151da177e4SLinus Torvalds# relocations required by build roots. This is not defined in the 13161da177e4SLinus Torvalds# makefile but the argument can be passed to make if needed. 13175750121aSMasahiro Yamada# 13185750121aSMasahiro Yamada 131923febe37SMasahiro YamadaMODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE) 132095fb6317SMasahiro Yamadaexport MODLIB 13211da177e4SLinus Torvalds 13225750121aSMasahiro YamadaPHONY += prepare0 13235750121aSMasahiro Yamada 13245750121aSMasahiro Yamadaifeq ($(KBUILD_EXTMOD),) 13251f2bfbd0SSam Ravnborg 13265750121aSMasahiro Yamadabuild-dir := . 132741a77d43SMasahiro Yamadaclean-dirs := $(sort . Documentation \ 1328f0d50ca0SMasahiro Yamada $(patsubst %/,%,$(filter %/, $(core-) \ 1329f0d50ca0SMasahiro Yamada $(drivers-) $(libs-)))) 13309c72d26eSMasahiro Yamada 133195698570SSam Ravnborgexport ARCH_CORE := $(core-y) 13321da177e4SLinus Torvaldsexport ARCH_LIB := $(filter %/, $(libs-y)) 13332441e78bSNicolas Pitreexport ARCH_DRIVERS := $(drivers-y) $(drivers-m) 13341f50b80aSMasahiro Yamada# Externally visible symbols (used by link-vmlinux.sh) 13351f50b80aSMasahiro Yamada 13361bf807b8SMasahiro YamadaKBUILD_VMLINUX_OBJS := built-in.a $(patsubst %/, %/lib.a, $(filter %/, $(libs-y))) 13371f50b80aSMasahiro YamadaKBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y)) 13381f50b80aSMasahiro Yamada 13399c72d26eSMasahiro Yamadaexport KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS 13409c72d26eSMasahiro Yamadaexport KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds 13419c72d26eSMasahiro Yamada 1342fbe6e37dSNicholas Pigginifdef CONFIG_TRIM_UNUSED_KSYMS 13439c72d26eSMasahiro Yamada# For the kernel to actually contain only the needed exported symbols, 13449c72d26eSMasahiro Yamada# we have to build modules as well to determine what those symbols are. 13452441e78bSNicolas PitreKBUILD_MODULES := y 13467a342e6cSMasahiro Yamadaendif 13477a342e6cSMasahiro Yamada 13489c5a0ac3SMasahiro YamadaPHONY += vmlinux_a 1349741f98feSSam Ravnborgvmlinux_a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE 13507a342e6cSMasahiro Yamada $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_a 13517a342e6cSMasahiro Yamada 13527a342e6cSMasahiro Yamadavmlinux.a: vmlinux_a 13535d4aeffbSMasahiro Yamada @: 13548debed3eSMasahiro Yamada 13558debed3eSMasahiro YamadaPHONY += vmlinux_o 13568debed3eSMasahiro Yamadavmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS) 13578debed3eSMasahiro Yamada $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_o 13588debed3eSMasahiro Yamada 13598debed3eSMasahiro Yamadavmlinux.o: vmlinux_o 13608debed3eSMasahiro Yamada @: 13618debed3eSMasahiro Yamada 13628debed3eSMasahiro YamadaPHONY += vmlinux 13638debed3eSMasahiro Yamada# LDFLAGS_vmlinux in the top Makefile defines linker flags for the top vmlinux, 13648debed3eSMasahiro Yamada# not for decompressors. LDFLAGS_vmlinux in arch/*/boot/compressed/Makefile is 13658debed3eSMasahiro Yamada# unrelated; the decompressors just happen to have the same base name, 13665d4aeffbSMasahiro Yamada# arch/*/boot/compressed/vmlinux. 13675d4aeffbSMasahiro Yamada# Export LDFLAGS_vmlinux only to scripts/Makefile.vmlinux. 1368392885eeSMasahiro Yamada# 13691da177e4SLinus Torvalds# _LDFLAGS_vmlinux is a workaround for the 'private export' bug: 13701da177e4SLinus Torvalds# https://savannah.gnu.org/bugs/?61463 13719c5a0ac3SMasahiro Yamada# For Make > 4.4, the following simple code will work: 13721da177e4SLinus Torvalds# vmlinux: private export LDFLAGS_vmlinux := $(LDFLAGS_vmlinux) 13731cb86b6cSMasahiro Yamadavmlinux: private _LDFLAGS_vmlinux := $(LDFLAGS_vmlinux) 1374ec31f868SMasahiro Yamadavmlinux: export LDFLAGS_vmlinux = $(_LDFLAGS_vmlinux) 13751cb86b6cSMasahiro Yamadavmlinux: vmlinux.o $(KBUILD_LDS) modpost 13761cb86b6cSMasahiro Yamada $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux 13771cb86b6cSMasahiro Yamada 13780d0e7718SMichal Marek# The actual objects are generated when descending, 137983a35e36SGeert Uytterhoeven# make sure no implicit rule kicks in 138024512795SMasahiro Yamada$(sort $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)): . ; 13810d0e7718SMichal Marek 1382cb58455cSSam Ravnborgifeq ($(origin KERNELRELEASE),file) 1383d8821622SMasahiro Yamadafilechk_kernel.release = $(srctree)/scripts/setlocalversion $(srctree) 1384d8821622SMasahiro Yamadaelse 1385d8821622SMasahiro Yamadafilechk_kernel.release = echo $(KERNELRELEASE) 1386d8821622SMasahiro Yamadaendif 138760df1aeeSMasahiro Yamada 1388d8821622SMasahiro Yamada# Store (new) KERNELRELEASE string in include/config/kernel.release 1389cb58455cSSam Ravnborginclude/config/kernel.release: FORCE 13901da177e4SLinus Torvalds $(call filechk,kernel.release) 13915bb78269SSam Ravnborg 13925bb78269SSam Ravnborg# Additional helpers built in scripts/ 13935bb78269SSam Ravnborg# Carefully list dependencies so we do not try to build scripts twice 13945bb78269SSam Ravnborg# in parallel 13951da177e4SLinus TorvaldsPHONY += scripts 1396a5139fb3SMasahiro Yamadascripts: scripts_basic scripts_dtc 13975bb78269SSam Ravnborg $(Q)$(MAKE) $(build)=$(@) 139836de077bSMasahiro Yamada 13995e9e95ccSMasahiro Yamada# Things we need to do before we recursively start building the kernel 1400985d6cccSMasahiro Yamada# or the modules are listed in "prepare". 1401985d6cccSMasahiro Yamada# A multi level approach is used. prepareN is processed before prepareN-1. 14025bb78269SSam Ravnborg# archprepare is used in arch Makefiles and when processed asm symlink, 140365bba042SMasahiro Yamada# version.h and scripts_basic is processed / created. 140460df1aeeSMasahiro Yamada 1405ed7ceac1SMasahiro YamadaPHONY += prepare archprepare 140686feeaa8SSam Ravnborg 14071da177e4SLinus Torvaldsarchprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \ 14080d989ac2SMasahiro Yamada asm-generic $(version_h) include/generated/utsrelease.h \ 14092f7ab126SMiguel Ojeda include/generated/compile.h include/generated/autoconf.h \ 1410ecab4115SMiguel Ojeda include/generated/rustc_cfg remove-stale-files 14112f7ab126SMiguel Ojeda 14122f7ab126SMiguel Ojedaprepare0: archprepare 1413b9ab5ebbSJosh Poimboeuf $(Q)$(MAKE) $(build)=scripts/mod 14141476fee5SMasahiro Yamada $(Q)$(MAKE) $(build)=. prepare 14151476fee5SMasahiro Yamada 14161476fee5SMasahiro Yamada# All the preparing.. 14171476fee5SMasahiro Yamadaprepare: prepare0 14182c1f4f12SMasahiro Yamadaifdef CONFIG_RUST 1419fbb5c060SArnd Bergmann +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh 14207d0e5c20SMasahiro Yamada $(Q)$(MAKE) $(build)=rust 14212c1f4f12SMasahiro Yamadaendif 14222c1f4f12SMasahiro Yamada 1423037fc336SMasahiro YamadaPHONY += remove-stale-files 1424037fc336SMasahiro Yamadaremove-stale-files: 14252c1f4f12SMasahiro Yamada $(Q)$(srctree)/scripts/remove-stale-files 1426037fc336SMasahiro Yamada 1427037fc336SMasahiro Yamada# Support for using generic headers in asm-generic 14282c1f4f12SMasahiro Yamadaasm-generic := -f $(srctree)/scripts/Makefile.asm-headers obj 14291da177e4SLinus Torvalds 14301da177e4SLinus TorvaldsPHONY += asm-generic uapi-asm-generic 14311da177e4SLinus Torvaldsasm-generic: uapi-asm-generic 14321da177e4SLinus Torvalds $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \ 14331da177e4SLinus Torvalds generic=include/asm-generic 14341da177e4SLinus Torvaldsuapi-asm-generic: 14351da177e4SLinus Torvalds $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \ 143663104eecSSam Ravnborg generic=include/uapi/asm-generic 14371da177e4SLinus Torvalds 14381da177e4SLinus Torvalds# Generate some files 14391da177e4SLinus Torvalds# --------------------------------------------------------------------------- 14401da177e4SLinus Torvalds 1441ad774086SMasahiro Yamada# KERNELRELEASE can change from a few different places, meaning version.h 14421da177e4SLinus Torvalds# needs to be updated, so this check is forced on all builds 14431da177e4SLinus Torvalds 144463104eecSSam Ravnborguts_len := 64 14459b82f13eSSasha Levindefine filechk_utsrelease.h 1446ad774086SMasahiro Yamada if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \ 1447207da4c8SMasahiro Yamada echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \ 14489b82f13eSSasha Levin exit 1; \ 14499b82f13eSSasha Levin fi; \ 1450207da4c8SMasahiro Yamada echo \#define UTS_RELEASE \"$(KERNELRELEASE)\" 14519b82f13eSSasha Levinendef 14529b82f13eSSasha Levin 145388a68672SSasha Levindefine filechk_version.h 145488a68672SSasha Levin if [ $(SUBLEVEL) -gt 255 ]; then \ 145588a68672SSasha Levin echo \#define LINUX_VERSION_CODE $(shell \ 145688a68672SSasha Levin expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + 255); \ 145763104eecSSam Ravnborg else \ 145863104eecSSam Ravnborg echo \#define LINUX_VERSION_CODE $(shell \ 1459d98dba88SMasahiro Yamada expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \ 1460d98dba88SMasahiro Yamada fi; \ 146143fee2b2SMasahiro Yamada echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \ 14621da177e4SLinus Torvalds ((c) > 255 ? 255 : (c)))'; \ 14631da177e4SLinus Torvalds echo \#define LINUX_VERSION_MAJOR $(VERSION); \ 1464273b281fSSam Ravnborg echo \#define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL); \ 146563104eecSSam Ravnborg echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL) 146663104eecSSam Ravnborgendef 1467a55f283eSMasahiro Yamada 1468a55f283eSMasahiro Yamada$(version_h): private PATCHLEVEL := $(or $(PATCHLEVEL), 0) 1469a55f283eSMasahiro Yamada$(version_h): private SUBLEVEL := $(or $(SUBLEVEL), 0) 1470a55f283eSMasahiro Yamada$(version_h): FORCE 1471a55f283eSMasahiro Yamada $(call filechk,version.h) 1472a55f283eSMasahiro Yamada 1473179efcb4SVegard Nossuminclude/generated/utsrelease.h: include/config/kernel.release FORCE 1474179efcb4SVegard Nossum $(call filechk,utsrelease.h) 14759663d989SPeter Foley 14769663d989SPeter Foleyfilechk_compile.h = $(srctree)/scripts/mkcompile_h \ 1477179efcb4SVegard Nossum "$(UTS_MACHINE)" "$(CONFIG_CC_VERSION_TEXT)" "$(LD)" 14781da177e4SLinus Torvalds 14798d730cfbSDavid Woodhouseinclude/generated/compile.h: FORCE 14808d730cfbSDavid Woodhouse $(call filechk,compile.h) 1481e6883b18SSam Ravnborg 1482e6883b18SSam RavnborgPHONY += headerdep 1483e6883b18SSam Ravnborgheaderdep: 148459b2bd05SMasahiro Yamada $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \ 148559b2bd05SMasahiro Yamada $(srctree)/scripts/headerdep.pl -I$(srctree)/include 148659b2bd05SMasahiro Yamada 148759b2bd05SMasahiro Yamada# --------------------------------------------------------------------------- 148859b2bd05SMasahiro Yamada# Kernel headers 14896d716275SDavid Woodhouse 14908d730cfbSDavid Woodhouse#Default location for installed headers 149159b2bd05SMasahiro Yamadaexport INSTALL_HDR_PATH = $(objtree)/usr 149259b2bd05SMasahiro Yamada 14934f193362SPaul Smithquiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include 14941da177e4SLinus Torvalds cmd_headers_install = \ 14951da177e4SLinus Torvalds mkdir -p $(INSTALL_HDR_PATH); \ 1496a5bae54cSMasahiro Yamada rsync -mrl --include='*/' --include='*\.h' --exclude='*' \ 14971da177e4SLinus Torvalds usr/include $(INSTALL_HDR_PATH) 149859b2bd05SMasahiro Yamada 14992adde2ebSHenrik LindströmPHONY += headers_install 1500268d191aSThomas Weißschuhheaders_install: headers 1501268d191aSThomas Weißschuh $(call cmd,headers_install) 1502268d191aSThomas Weißschuh 1503d5470d14SMasahiro YamadaPHONY += archheaders archscripts 1504d5470d14SMasahiro Yamada 1505268d191aSThomas Weißschuhhdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj 15061f85712eSMike Frysinger 1507e949f4c2SMasahiro YamadaPHONY += headers 150859b2bd05SMasahiro Yamadaheaders: $(version_h) scripts_unifdef uapi-asm-generic archheaders 1509e949f4c2SMasahiro Yamadaifdef HEADER_ARCH 151068475359SDavid Woodhouse $(Q)$(MAKE) -f $(srctree)/Makefile HEADER_ARCH= SRCARCH=$(HEADER_ARCH) headers 1511f8e05c10SNicolas Schierelse 1512f8e05c10SNicolas Schier $(Q)$(MAKE) $(hdr-inst)=include/uapi 1513f8e05c10SNicolas Schier $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi 1514f8e05c10SNicolas Schierendif 1515bdd7714bSMasahiro Yamada 1516bdd7714bSMasahiro Yamadaifdef CONFIG_HEADERS_INSTALL 1517bdd7714bSMasahiro Yamadaprepare: headers 1518bdd7714bSMasahiro Yamadaendif 151941d7ea30SVladimir Oltean 152041d7ea30SVladimir OlteanPHONY += usr_gen_init_cpio 152141d7ea30SVladimir Olteanusr_gen_init_cpio: scripts_basic 152241d7ea30SVladimir Oltean $(Q)$(MAKE) $(build)=usr usr/gen_init_cpio 15238d730cfbSDavid Woodhouse 152414ccc638SMasahiro YamadaPHONY += scripts_unifdef 152514ccc638SMasahiro Yamadascripts_unifdef: scripts_basic 152614ccc638SMasahiro Yamada $(Q)$(MAKE) $(build)=scripts scripts/unifdef 152775ef3122SRandy Dunlap 152875ef3122SRandy DunlapPHONY += scripts_gen_packed_field_checks 152914ccc638SMasahiro Yamadascripts_gen_packed_field_checks: scripts_basic 153014ccc638SMasahiro Yamada $(Q)$(MAKE) $(build)=scripts scripts/gen_packed_field_checks 1531f774f5bbSMasahiro Yamada 1532f774f5bbSMasahiro Yamada# --------------------------------------------------------------------------- 153314ccc638SMasahiro Yamada# Install 153414ccc638SMasahiro Yamada 153556769ba4SMasahiro Yamada# Many distributions have the custom install script, /sbin/installkernel. 153656769ba4SMasahiro Yamada# If DKMS is installed, 'make install' will eventually recurse back 153756769ba4SMasahiro Yamada# to this Makefile to build and install external modules. 153856769ba4SMasahiro Yamada# Cancel sub_make_done so that options such as M=, V=, etc. are parsed. 153956769ba4SMasahiro Yamada 154056769ba4SMasahiro Yamadaquiet_cmd_install = INSTALL $(INSTALL_PATH) 154156769ba4SMasahiro Yamada cmd_install = unset sub_make_done; $(srctree)/scripts/install.sh 154256769ba4SMasahiro Yamada 15431bb0b18aSMasahiro Yamada# --------------------------------------------------------------------------- 15441bb0b18aSMasahiro Yamada# vDSO install 154503f16cd0SJosh Poimboeuf 15460d989ac2SMasahiro YamadaPHONY += vdso_install 15470d989ac2SMasahiro Yamadavdso_install: export INSTALL_FILES = $(vdso-install-y) 15480d989ac2SMasahiro Yamadavdso_install: 15490d989ac2SMasahiro Yamada $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vdsoinst 15500d989ac2SMasahiro Yamada 15510d989ac2SMasahiro Yamada# --------------------------------------------------------------------------- 15520d989ac2SMasahiro Yamada# Tools 15530d989ac2SMasahiro Yamada 15540d989ac2SMasahiro Yamadaifdef CONFIG_OBJTOOL 15556e6ef2daSMasahiro Yamadaprepare: tools/objtool 15566e6ef2daSMasahiro Yamadaendif 15576e6ef2daSMasahiro Yamada 15586e6ef2daSMasahiro Yamadaifdef CONFIG_BPF 15596e6ef2daSMasahiro Yamadaifdef CONFIG_DEBUG_INFO_BTF 15606e6ef2daSMasahiro Yamadaprepare: tools/bpf/resolve_btfids 15610d989ac2SMasahiro Yamadaendif 15620d989ac2SMasahiro Yamadaendif 15630d989ac2SMasahiro Yamada 15640d989ac2SMasahiro Yamada# The tools build system is not a part of Kbuild and tends to introduce 15650d989ac2SMasahiro Yamada# its own unique issues. If you need to integrate a new tool into Kbuild, 15660d989ac2SMasahiro Yamada# please consider locating that tool outside the tools/ tree and using the 15670d989ac2SMasahiro Yamada# standard Kbuild "hostprogs" syntax instead of adding a new tools/* entry 15680d989ac2SMasahiro Yamada# here. See Documentation/kbuild/makefiles.rst for details. 15690d989ac2SMasahiro Yamada 15700d989ac2SMasahiro YamadaPHONY += resolve_btfids_clean 15710d989ac2SMasahiro Yamada 1572fdb12c8aSNathan Chancellorresolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids 157368b4fe32SJosh Poimboeuf 157468b4fe32SJosh Poimboeuf# tools/bpf/resolve_btfids directory might not exist 157568b4fe32SJosh Poimboeuf# in output directory, skip its clean in that case 1576fdb12c8aSNathan Chancellorresolve_btfids_clean: 157768b4fe32SJosh Poimboeufifneq ($(wildcard $(resolve_btfids_O)),) 1578fdb12c8aSNathan Chancellor $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean 157968b4fe32SJosh Poimboeufendif 158068b4fe32SJosh Poimboeuf 15811bb0b18aSMasahiro YamadaPHONY += objtool_clean objtool_mrproper 15821bb0b18aSMasahiro Yamada 1583ee916dccSLinus Torvaldsobjtool_O = $(abspath $(objtree))/tools/objtool 15841bb0b18aSMasahiro Yamada 15851bb0b18aSMasahiro Yamadaobjtool_clean objtool_mrproper: 15861bb0b18aSMasahiro Yamadaifneq ($(wildcard $(objtool_O)),) 1587ee916dccSLinus Torvalds $(Q)$(MAKE) -sC $(abs_srctree)/tools/objtool O=$(objtool_O) srctree=$(abs_srctree) $(patsubst objtool_%,%,$@) 15881bb0b18aSMasahiro Yamadaendif 15891bb0b18aSMasahiro Yamada 15905a5da78bSShuah Khantools/: FORCE 15915a5da78bSShuah Khan $(Q)mkdir -p $(objtree)/tools 15925a5da78bSShuah Khan $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ 15934062eba9SGuillaume Tucker 15942bc84526SShuah Khantools/%: FORCE 15955a5da78bSShuah Khan $(Q)mkdir -p $(objtree)/tools 15964062eba9SGuillaume Tucker $(Q)$(MAKE) O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $* 159717eac6c2SShuah Khan 1598dcb825a9SWang Long# --------------------------------------------------------------------------- 15993d6dee7aSBamvor Jian Zhang# Kernel selftest 16003d6dee7aSBamvor Jian Zhang 16013d6dee7aSBamvor Jian ZhangPHONY += kselftest 160237013b55SBjörn Töpelkselftest: headers 16036d3d638dSBjörn Töpel $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests run_tests 16043e4c6948SMasahiro Yamada 16053d6dee7aSBamvor Jian Zhangkselftest-%: headers FORCE 16065a5da78bSShuah Khan $(Q)unset sub_make_done; $(MAKE) -C $(srctree)/tools/testing/selftests $* 160737c8a5faSRob Herring 160837c8a5faSRob HerringPHONY += kselftest-merge 160937c8a5faSRob Herringkselftest-merge: 161037c8a5faSRob Herring $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!)) 161137c8a5faSRob Herring $(Q)find $(srctree)/tools/testing/selftests -name config -o -name config.$(UTS_MACHINE) | \ 161237c8a5faSRob Herring xargs $(srctree)/scripts/kconfig/merge_config.sh -y -m $(objtree)/.config 1613400fbf4bSRob Herring (Arm) $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig 1614400fbf4bSRob Herring (Arm) 1615400fbf4bSRob Herring (Arm)# --------------------------------------------------------------------------- 1616400fbf4bSRob Herring (Arm)# Devicetree files 1617400fbf4bSRob Herring (Arm) 1618400fbf4bSRob Herring (Arm)ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),) 161937c8a5faSRob Herringdtstree := arch/$(SRCARCH)/boot/dts 162037c8a5faSRob Herringendif 1621ee476203SMasahiro Yamada 162275e89534SRob Herringdtbindingtree := Documentation/devicetree/bindings 162337c8a5faSRob Herring 1624ee476203SMasahiro Yamada%.yaml: dtbs_prepare 162575e89534SRob Herring $(Q)$(MAKE) $(build)=$(dtbindingtree) \ 1626ce88c9c7SViresh Kumar $(dtbindingtree)/$(patsubst %.yaml,%.example.dtb,$@) dt_binding_check_one 1627ee476203SMasahiro Yamada 1628ee476203SMasahiro Yamadaifneq ($(dtstree),) 162924507871SMasahiro Yamada 163037c8a5faSRob Herring%.dtb: dtbs_prepare 1631ee476203SMasahiro Yamada $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@ 1632ee476203SMasahiro Yamada 1633ee476203SMasahiro Yamada%.dtbo: dtbs_prepare 1634ee476203SMasahiro Yamada $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@ 1635ee476203SMasahiro Yamada 1636400fbf4bSRob Herring (Arm)PHONY += dtbs dtbs_prepare dtbs_install dtbs_check 1637e10c4321SMasahiro Yamadadtbs: dtbs_prepare 1638ec201955SRob Herring $(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1 1639ec201955SRob Herring 1640ec201955SRob Herring# include/config/kernel.release is actually needed when installing DTBs because 1641604a57baSRob Herring# INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make 1642b5154bf6SMasahiro Yamada# dtbs_install depend on it as dtbs_install may run as root. 1643b5154bf6SMasahiro Yamadadtbs_prepare: include/config/kernel.release scripts_dtc 1644b5154bf6SMasahiro Yamada 16454f0e3a57SRob Herringifneq ($(filter dtbs_check %.yaml, $(MAKECMDGOALS)),) 164637c8a5faSRob Herringexport CHECK_DTBS=y 16478f66864cSMasahiro Yamadaendif 164837c8a5faSRob Herring 164937c8a5faSRob Herringifneq ($(CHECK_DTBS),) 165037c8a5faSRob Herringdtbs_prepare: dt_binding_schemas 165137c8a5faSRob Herringendif 165237c8a5faSRob Herring 1653654102dfSMasahiro Yamadadtbs_check: dtbs 1654654102dfSMasahiro Yamada 1655654102dfSMasahiro Yamadadtbs_install: 1656654102dfSMasahiro Yamada $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree) 165737c8a5faSRob Herring 165837c8a5faSRob Herringifdef CONFIG_OF_EARLY_FLATTREE 165937c8a5faSRob Herringall: dtbs 166037c8a5faSRob Herringendif 166137c8a5faSRob Herring 166237c8a5faSRob Herringifdef CONFIG_GENERIC_BUILTIN_DTB 1663e10c4321SMasahiro Yamadavmlinux: dtbs 1664604a57baSRob Herringendif 1665e10c4321SMasahiro Yamada 1666e10c4321SMasahiro Yamadaendif 1667604a57baSRob Herring 1668604a57baSRob HerringPHONY += scripts_dtc 1669400fbf4bSRob Herring (Arm)scripts_dtc: scripts_basic 1670604a57baSRob Herring $(Q)$(MAKE) $(build)=scripts/dtc 1671604a57baSRob Herring 1672400fbf4bSRob Herring (Arm)ifneq ($(filter dt_binding_check, $(MAKECMDGOALS)),) 16734f0e3a57SRob Herringexport CHECK_DTBS=y 1674b6acf807SRob Herringendif 1675604a57baSRob Herring 1676400fbf4bSRob Herring (Arm)PHONY += dt_binding_check dt_binding_schemas 1677b6acf807SRob Herringdt_binding_check: dt_binding_schemas scripts_dtc 1678efb6347dSDaniel Golle $(Q)$(MAKE) $(build)=$(dtbindingtree) $@ 1679efb6347dSDaniel Golle 1680efb6347dSDaniel Golledt_binding_schemas: 1681efb6347dSDaniel Golle $(Q)$(MAKE) $(build)=$(dtbindingtree) 168237c8a5faSRob Herring 16831da177e4SLinus TorvaldsPHONY += dt_compatible_check 16841da177e4SLinus Torvaldsdt_compatible_check: dt_binding_schemas 16851da177e4SLinus Torvalds $(Q)$(MAKE) $(build)=$(dtbindingtree) $@ 16861da177e4SLinus Torvalds 16871da177e4SLinus TorvaldsPHONY += dt_style_selftest 16881da177e4SLinus Torvaldsdt_style_selftest: 168973d1393eSMichal Marek $(Q)$(srctree)/scripts/dtc/dt-style-selftest/run.sh 16901da177e4SLinus Torvalds 16914b50c8c4SMasahiro Yamada# --------------------------------------------------------------------------- 16924b50c8c4SMasahiro Yamada# Modules 16934b50c8c4SMasahiro Yamada 16944b50c8c4SMasahiro Yamadaifdef CONFIG_MODULES 16951bf807b8SMasahiro Yamada 16964b50c8c4SMasahiro Yamada# By default, build modules as well 16974b50c8c4SMasahiro Yamada 16981da177e4SLinus Torvaldsall: modules 1699551559e1STejun Heo 17001da177e4SLinus Torvalds# When we're building modules with modversions, we need to consider 1701feb113adSCarlos Llamas# the built-in objects during the descend as well, in order to 1702f73edc89SMasahiro Yamada# make sure the checksums are up to date before we record them. 1703f73edc89SMasahiro Yamadaifdef CONFIG_MODVERSIONS 17041bf807b8SMasahiro Yamada KBUILD_BUILTIN := y 1705f73edc89SMasahiro Yamadaendif 1706f73edc89SMasahiro Yamada 17071da177e4SLinus Torvalds# Build modules 1708f73edc89SMasahiro Yamada# 1709a6c36632SMichal Marek 17101da177e4SLinus Torvalds# *.ko are usually independent of vmlinux, but CONFIG_DEBUG_INFO_BTF_MODULES 1711059bc9fcSMasahiro Yamada# is an exception. 1712596b0474SMasahiro Yamadaifdef CONFIG_DEBUG_INFO_BTF_MODULES 17131da177e4SLinus TorvaldsKBUILD_BUILTIN := y 17148ae071fcSMasahiro Yamadamodules: vmlinux 17158ae071fcSMasahiro Yamadaendif 17161da177e4SLinus Torvalds 17171da177e4SLinus Torvaldsmodules: modules_prepare 17181da177e4SLinus Torvalds 17191da177e4SLinus Torvalds# Target to prepare building external modules 17201da177e4SLinus Torvaldsmodules_prepare: prepare 17211da177e4SLinus Torvalds $(Q)$(MAKE) $(build)=scripts scripts/module.lds 17221da177e4SLinus Torvalds 17231da177e4SLinus Torvaldsendif # CONFIG_MODULES 17241fdd7290SMasahiro Yamada 17253d32285fSMasahiro Yamada### 1726ac4f0678SArd Biesheuvel# Cleaning is done on three levels. 17279f2aee8fSRong Xu# make clean Delete most generated files 1728aba09154SNathan Chancellor# Leave enough to build external modules 1729654102dfSMasahiro Yamada# make mrproper Delete the current configuration, and all generated files 1730e72b635cSLuis Augenstein# make distclean Remove editor backup files, patch leftover files and the like 17311da177e4SLinus Torvalds 17321da177e4SLinus Torvalds# Directories & files removed with 'make clean' 17330663c68cSMasahiro YamadaCLEAN_FILES += vmlinux.symvers modules-only.symvers \ 1734b0d6207bSMasahiro Yamada modules.builtin modules.builtin.modinfo modules.nsdeps \ 1735c8578539SThomas Weißschuh modules.builtin.ranges vmlinux.o.map vmlinux.unstripped \ 17360663c68cSMasahiro Yamada vmlinux.thinlto-index builtin.order \ 173746457133SMasahiro Yamada compile_commands.json rust/test \ 17385cca3606SMasahiro Yamada rust-project.json .vmlinux.objs .vmlinux.export.c \ 1739b31f2a49SNayna Jain .builtin-dtbs-list .builtin-dtbs.S sbom-*.spdx.json 1740b31f2a49SNayna Jain 1741ffa46bbcSMasahiro Yamada# Directories & files removed with 'make mrproper' 1742a44bfed9SChen MiaoMRPROPER_FILES += include/config include/generated \ 17438b6bdbd7SMiguel Ojeda arch/$(SRCARCH)/include/generated .objdiff \ 17448b6bdbd7SMiguel Ojeda debian snap tar-install PKGBUILD pacman \ 17451da177e4SLinus Torvalds .config .config.old .version \ 17461da177e4SLinus Torvalds Module.symvers \ 17471da177e4SLinus Torvalds certs/signing_key.pem \ 1748d98dba88SMasahiro Yamada certs/x509.genkey \ 17491da177e4SLinus Torvalds vmlinux-gdb.py \ 175076cd306dSMasahiro Yamada rpmbuild \ 17511da177e4SLinus Torvalds rust/libmacros.so rust/libmacros.dylib \ 1752bd1ee804SPawel Moll rust/libpin_init_internal.so rust/libpin_init_internal.dylib \ 1753bd1ee804SPawel Moll rust/libzerocopy_derive.so rust/libzerocopy_derive.dylib 1754fbe6e37dSNicholas Piggin 1755bd1ee804SPawel Moll# clean - Delete most, but leave enough to build external modules 175668b4fe32SJosh Poimboeuf# 17571da177e4SLinus Torvaldsclean: private rm-files := $(CLEAN_FILES) 17581da177e4SLinus Torvalds 17591da177e4SLinus TorvaldsPHONY += archclean vmlinuxclean 1760d98dba88SMasahiro Yamada 1761cb43fb57SMauro Carvalho Chehabvmlinuxclean: 17621da177e4SLinus Torvalds $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean 1763b421b8a6SMasahiro Yamada $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean) 17641da177e4SLinus Torvalds 17651da177e4SLinus Torvaldsclean: archclean vmlinuxclean resolve_btfids_clean objtool_clean 17661da177e4SLinus Torvalds 1767fdb12c8aSNathan Chancellor# mrproper - Delete all generated files, including .config 17681da177e4SLinus Torvalds# 17692f7ab126SMiguel Ojedamrproper: private rm-files := $(MRPROPER_FILES) 17702f7ab126SMiguel Ojedamrproper-dirs := $(addprefix _mrproper_,scripts) 17712f7ab126SMiguel Ojeda 17721da177e4SLinus TorvaldsPHONY += $(mrproper-dirs) mrproper 17731da177e4SLinus Torvalds$(mrproper-dirs): 17741da177e4SLinus Torvalds $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@) 17754f193362SPaul Smith 17761da177e4SLinus Torvaldsmrproper: clean objtool_mrproper $(mrproper-dirs) 17771da177e4SLinus Torvalds $(call cmd,rmfiles) 177819c8d912SMasahiro Yamada @find . $(RCS_FIND_IGNORE) \ 17791da177e4SLinus Torvalds \( -name '*.rmeta' \) \ 1780f78271dfSMasahiro Yamada -type f -print | xargs rm -f 17817a02cec5SMasahiro Yamada 17827a02cec5SMasahiro Yamada# distclean 17831da177e4SLinus Torvalds# 17841da177e4SLinus TorvaldsPHONY += distclean 17851da177e4SLinus Torvalds 17861da177e4SLinus Torvaldsdistclean: mrproper 17871da177e4SLinus Torvalds @find . $(RCS_FIND_IGNORE) \ 17881da177e4SLinus Torvalds \( -name '*.orig' -o -name '*.rej' -o -name '*~' \ 1789f8e05c10SNicolas Schier -o -name '*.bak' -o -name '#*#' -o -name '*%' \ 1790f8e05c10SNicolas Schier -o -name 'core' -o -name tags -o -name TAGS -o -name 'cscope*' \ 1791bafb6747SArnaldo Carvalho de Melo -o -name GPATH -o -name GRTAGS -o -name GSYMS -o -name GTAGS \) \ 1792000ec95fSMasahiro Yamada -type f -print | xargs rm -f 1793031ecc6dSZach Brown 1794000ec95fSMasahiro Yamada 17951da177e4SLinus Torvalds# Packaging of the kernel to various formats 17961da177e4SLinus Torvalds# --------------------------------------------------------------------------- 17971da177e4SLinus Torvalds 17981da177e4SLinus Torvaldsmodules-cpio-pkg: usr_gen_init_cpio 17995dffbe81SSegher Boessenkool 1800a1e7b7bbSKonstantin Khlebnikov%src-pkg: FORCE 18015dffbe81SSegher Boessenkool $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ 18025dffbe81SSegher Boessenkool%pkg: include/config/kernel.release FORCE 18031da177e4SLinus Torvalds $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@ 1804fe69b420SMasahiro Yamada 18051da177e4SLinus Torvalds# Brief documentation of the typical targets used 18061da177e4SLinus Torvalds# --------------------------------------------------------------------------- 18075ea084efSSamuel Tardieu 18085cc8d246SJesper Juhlboards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig) 18095ea084efSSamuel Tardieuboards := $(sort $(notdir $(boards))) 18105cc8d246SJesper Juhlboard-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig)) 18111da177e4SLinus Torvaldsboard-dirs := $(sort $(notdir $(board-dirs:/=))) 18121da177e4SLinus Torvalds 18131da177e4SLinus TorvaldsPHONY += help 18141da177e4SLinus Torvaldshelp: 18151da177e4SLinus Torvalds @echo 'Cleaning targets:' 18161da177e4SLinus Torvalds @echo ' clean - Remove most generated files but keep the config and' 18171da177e4SLinus Torvalds @echo ' enough build support to build external modules' 18189cc5d74cSBodo Eggert @echo ' mrproper - Remove all generated files + config + various backup files' 181956769ba4SMasahiro Yamada @echo ' distclean - mrproper + remove editor backup and patch files' 18201da177e4SLinus Torvalds @echo '' 182140ab87a4SWang YanQing @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help 1822433db3e2SVinícius Tinti @echo '' 1823433db3e2SVinícius Tinti @echo 'Other generic targets:' 182462718979SJoe Perches @echo ' all - Build all targets marked with [*]' 182562718979SJoe Perches @echo '* vmlinux - Build the bare kernel' 1826155ad605SSam Ravnborg @echo '* modules - Build all modules' 1827c4d5ee67SRobert P. J. Day @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)' 18281da177e4SLinus Torvalds @echo ' vdso_install - Install unstripped vdso to INSTALL_MOD_PATH (default: /)' 18291da177e4SLinus Torvalds @echo ' dir/ - Build all files in dir and below' 1830f4ed1009SJianbin Kang @echo ' dir/file.[ois] - Build specified target only' 18313f1d9a6cSMichal Marek @echo ' dir/file.ll - Build the LLVM assembly file' 18323f1d9a6cSMichal Marek @echo ' (requires compiler support for LLVM assembly generation)' 18333f1d9a6cSMichal Marek @echo ' dir/file.lst - Build specified mixed source/assembly target only' 183400e81f4fSXin Li (Intel) @echo ' (requires a recent binutils and recent build (System.map))' 183500e81f4fSXin Li (Intel) @echo ' dir/file.ko - Build module including final link' 183659df3230SGeert Uytterhoeven @echo ' modules_prepare - Set up for building external modules' 18372fb9b1bdSSam Ravnborg @echo ' tags/TAGS - Generate tags file for editors' 183831b8cc80SRandy Dunlap @echo ' cscope - Generate cscope index' 183966242cfaSHeiko Carstens @echo ' gtags - Generate GNU GLOBAL index' 184066242cfaSHeiko Carstens @echo ' kernelrelease - Output the release version string (use with make -s)' 1841aa025e7dSSam Ravnborg @echo ' kernelversion - Output the version stored in Makefile (use with make -s)' 1842ec2d987fSRandy Dunlap @echo ' image_name - Output the image name (use with make -s)' 184374425eeeSNicolas Palix @echo ' headers - Build ready-to-install UAPI headers in usr/include' 18447f855fc8SMasahiro Yamada @echo ' headers_install - Install sanitised kernel UAPI headers to INSTALL_HDR_PATH'; \ 1845f58316a4SAndrew Jones echo ' (default: $(INSTALL_HDR_PATH))'; \ 18466ad7cbc0SNathan Huckleberry echo '' 18476ad7cbc0SNathan Huckleberry @echo 'Static analysers:' 184874425eeeSNicolas Palix @echo ' checkstack - Generate a list of stack hogs and consider all functions' 1849eb8305aeSMatthias Maennich @echo ' with a stack size larger than MINSTACKSIZE (default: 100)' 1850eb8305aeSMatthias Maennich @echo ' versioncheck - Sanity check on version.h usage' 1851e72b635cSLuis Augenstein @echo ' includecheck - Check for duplicate included header files' 1852eb8305aeSMatthias Maennich @echo ' headerdep - Detect inclusion cycles in headers' 185331b8cc80SRandy Dunlap @echo ' coccicheck - Check with Coccinelle' 1854e51d8dacSShuah Khan @echo ' kconfig-sym-check - Check for dangling Kconfig symbol references' 18555a5da78bSShuah Khan @echo ' clang-analyzer - Check with clang static analyzer' 18565a5da78bSShuah Khan @echo ' clang-tidy - Check with clang-tidy' 1857e51d8dacSShuah Khan @echo '' 1858e51d8dacSShuah Khan @echo 'Tools:' 1859e51d8dacSShuah Khan @echo ' nsdeps - Generate missing symbol namespace dependencies' 1860dcb825a9SWang Long @echo ' sbom - Generate Software Bill of Materials' 1861e51d8dacSShuah Khan @echo '' 1862e51d8dacSShuah Khan @echo 'Kernel selftest:' 18635a5da78bSShuah Khan @echo ' kselftest - Build and run kernel selftest' 18642f7ab126SMiguel Ojeda @echo ' Build, install, and boot kernel before' 18652f7ab126SMiguel Ojeda @echo ' running kselftest on it' 18662f7ab126SMiguel Ojeda @echo ' Run as root for full coverage' 18672f7ab126SMiguel Ojeda @echo ' kselftest-all - Build kernel selftest' 18682f7ab126SMiguel Ojeda @echo ' kselftest-install - Build and install kernel selftest' 18692f7ab126SMiguel Ojeda @echo ' kselftest-clean - Remove all generated kselftest files' 18702f7ab126SMiguel Ojeda @echo ' kselftest-merge - Merge all the config dependencies of' 18712f7ab126SMiguel Ojeda @echo ' kselftest to existing .config.' 18722f7ab126SMiguel Ojeda @echo '' 18732f7ab126SMiguel Ojeda @echo 'Rust targets:' 18742f7ab126SMiguel Ojeda @echo ' rustavailable - Checks whether the Rust toolchain is' 18752f7ab126SMiguel Ojeda @echo ' available and, if not, explains why.' 18762f7ab126SMiguel Ojeda @echo ' rustfmt - Reformat all the Rust code in the kernel' 18772f7ab126SMiguel Ojeda @echo ' rustfmtcheck - Checks if all the Rust code in the kernel' 18782f7ab126SMiguel Ojeda @echo ' is formatted, printing a diff otherwise.' 18792f7ab126SMiguel Ojeda @echo ' rustdoc - Generate Rust documentation' 18802f7ab126SMiguel Ojeda @echo ' (requires kernel .config)' 18812f7ab126SMiguel Ojeda @echo ' rusttest - Runs the Rust tests' 188237c8a5faSRob Herring @echo ' (requires kernel .config; downloads external repos)' 188337c8a5faSRob Herring @echo ' rust-analyzer - Generate rust-project.json rust-analyzer support file' 188437c8a5faSRob Herring @echo ' (requires kernel .config)' 188537c8a5faSRob Herring @echo ' dir/file.[os] - Build specified target only' 1886604a57baSRob Herring @echo ' dir/file.rsi - Build macro expanded source, similar to C preprocessing.' 1887d939881aSXu Yang @echo ' Run with RUSTFMT=n to skip reformatting if needed.' 1888efb6347dSDaniel Golle @echo ' The output is not intended to be compilable.' 18897aa8dd91SStephen Boyd @echo ' dir/file.ll - Build the LLVM assembly file' 189037c8a5faSRob Herring @echo '' 189137c8a5faSRob Herring @$(if $(dtstree), \ 189231b8cc80SRandy Dunlap echo 'Devicetree:'; \ 189331b8cc80SRandy Dunlap echo '* dtbs - Build device tree blobs for enabled boards'; \ 189431b8cc80SRandy Dunlap echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \ 189531b8cc80SRandy Dunlap echo ' dt_binding_check - Validate device tree binding documents and examples'; \ 18961da177e4SLinus Torvalds echo ' dt_binding_schemas - Build processed device tree binding schemas'; \ 1897000ec95fSMasahiro Yamada echo ' dt_style_selftest - Run dt-check-style fixture tests'; \ 18981da177e4SLinus Torvalds echo ' dtbs_check - Validate device tree source files';\ 18991da177e4SLinus Torvalds echo '') 1900cb43fb57SMauro Carvalho Chehab 19011da177e4SLinus Torvalds @echo 'Userspace tools targets:' 1902766b7007SSimon Glass @echo ' use "make tools/help"' 19035c816641SMasahiro Yamada @echo ' or "cd tools; make help"' 1904766b7007SSimon Glass @echo '' 19051da177e4SLinus Torvalds @echo 'Kernel packaging:' 19061da177e4SLinus Torvalds @$(MAKE) -f $(srctree)/scripts/Makefile.package help 19071da177e4SLinus Torvalds @echo '' 19084234448bSGeert Uytterhoeven @echo 'Documentation targets:' 19091da177e4SLinus Torvalds @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp 19105dffbe81SSegher Boessenkool @echo '' 19115dffbe81SSegher Boessenkool @echo 'Architecture-specific targets ($(SRCARCH)):' 19125dffbe81SSegher Boessenkool @$(or $(archhelp),\ 19135dffbe81SSegher Boessenkool echo ' No architecture-specific help defined for $(SRCARCH)') 19145dffbe81SSegher Boessenkool @echo '' 19151da177e4SLinus Torvalds @$(if $(boards), \ 191683d98d73SMasahiro Yamada $(foreach b, $(boards), \ 19176ae4b986SMasahiro Yamada printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \ 19186ae4b986SMasahiro Yamada echo '') 19191da177e4SLinus Torvalds @$(if $(board-dirs), \ 1920a64c0440SGeert Uytterhoeven $(foreach b, $(board-dirs), \ 1921a64c0440SGeert Uytterhoeven printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \ 1922701842e3SDustin Kirkland printf " %-16s - Show all of the above\\n" help-boards; \ 1923af07ce3eSIngo Molnar echo '') 192489876175SMasahiro Yamada 192528bc20dcSSam Ravnborg @echo ' make V=n [targets] 1: verbose build' 192628bc20dcSSam Ravnborg @echo ' 2: give reason for rebuild of target' 192728bc20dcSSam Ravnborg @echo ' V=1 and V=2 can be combined with V=12' 192892ef432fSMasahiro Yamada @echo ' make O=dir [targets] Locate all output files in "dir", including .config' 1929c77d06e7SYann Droneaud @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK' 1930a6de553dSMichal Marek @echo ' (sparse by default)' 1931e30f8e61SSteven Rostedt @echo ' make C=2 [targets] Force check of all c source with $$CHECK' 1932e30f8e61SSteven Rostedt @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections' 1933ec201955SRob Herring @echo ' make W=n [targets] Enable extra build checks, n=1,2,3,c,e where' 1934ec201955SRob Herring @echo ' 1: warnings which may be relevant and do not occur too often' 1935ec201955SRob Herring @echo ' 2: warnings which occur quite often but may still be relevant' 1936ec201955SRob Herring @echo ' 3: more obscure warnings, can most likely be ignored' 19371da177e4SLinus Torvalds @echo ' c: extra checks in the configuration stage (Kconfig)' 19381da177e4SLinus Torvalds @echo ' e: warnings are being treated as errors' 19391da177e4SLinus Torvalds @echo ' Multiple levels can be combined with W=12 or W=123' 19401da177e4SLinus Torvalds @echo ' make UT=1 [targets] Warn if a tracepoint is defined but not used.' 19411da177e4SLinus Torvalds @echo ' [ This will be removed when all current unused tracepoints are eliminated. ]' 19425dffbe81SSegher Boessenkool @$(if $(dtstree), \ 19435dffbe81SSegher Boessenkool echo ' make CHECK_DTBS=1 [targets] Check all generated dtb files against schema'; \ 19445dffbe81SSegher Boessenkool echo ' This can be applied both to "dtbs" and to individual "foo.dtb" targets' ; \ 19455dffbe81SSegher Boessenkool ) 1946fbae4d58SMichal Marek @echo '' 19475dffbe81SSegher Boessenkool @echo 'Execute "make" or "make all" to build all targets marked with [*] ' 19485dffbe81SSegher Boessenkool @echo 'For further info see the ./README file' 1949766b7007SSimon Glass 19505dffbe81SSegher Boessenkool 19515dffbe81SSegher Boessenkoolhelp-board-dirs := $(addprefix help-,$(board-dirs)) 19525dffbe81SSegher Boessenkool 19535dffbe81SSegher Boessenkoolhelp-boards: $(help-board-dirs) 19545dffbe81SSegher Boessenkool 19555dffbe81SSegher Boessenkoolboards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig))) 19561da177e4SLinus Torvalds 19571da177e4SLinus Torvalds$(help-board-dirs): help-%: 19587e8a8143SMauro Carvalho Chehab @echo 'Architecture-specific targets ($(SRCARCH) $*):' 19597e8a8143SMauro Carvalho Chehab @$(if $(boards-per-dir), \ 19607e8a8143SMauro Carvalho Chehab $(foreach b, $(boards-per-dir), \ 19617e8a8143SMauro Carvalho Chehab printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \ 196222cba31bSJani Nikula echo '') 1963bc7b752aSMasahiro Yamada 1964cb43fb57SMauro Carvalho Chehab 19651da177e4SLinus Torvalds# Documentation targets 19662f7ab126SMiguel Ojeda# --------------------------------------------------------------------------- 19672f7ab126SMiguel OjedaDOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \ 19682f7ab126SMiguel Ojeda linkcheckdocs dochelp refcheckdocs texinfodocs infodocs mandocs \ 19692f7ab126SMiguel Ojeda htmldocs-redirects 19702f7ab126SMiguel Ojeda 19712f7ab126SMiguel OjedaPHONY += $(DOC_TARGETS) 19722f7ab126SMiguel Ojeda$(DOC_TARGETS): 1973ecab4115SMiguel Ojeda $(Q)$(MAKE) $(build)=Documentation $@ 19742f7ab126SMiguel Ojeda 19752f7ab126SMiguel Ojeda 19762f7ab126SMiguel Ojeda# Rust targets 19772f7ab126SMiguel Ojeda# --------------------------------------------------------------------------- 19782f7ab126SMiguel Ojeda 19792f7ab126SMiguel Ojeda# "Is Rust available?" target 19802f7ab126SMiguel OjedaPHONY += rustavailable 19812f7ab126SMiguel Ojedarustavailable: 19822f7ab126SMiguel Ojeda +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh && echo "Rust is available!" 19832f7ab126SMiguel Ojeda 19842f7ab126SMiguel Ojeda# Documentation target 19852f7ab126SMiguel Ojeda# 19862f7ab126SMiguel Ojeda# Using the singular to avoid running afoul of `no-dot-config-targets`. 19872f7ab126SMiguel OjedaPHONY += rustdoc 1988158a3b72SMiguel Ojedarustdoc: prepare 1989158a3b72SMiguel Ojeda $(Q)$(MAKE) $(build)=rust $@ 19902f7ab126SMiguel Ojeda 19912f7ab126SMiguel Ojeda# Testing target 19922f7ab126SMiguel OjedaPHONY += rusttest 1993397a479bSMasahiro Yamadarusttest: prepare 1994158a3b72SMiguel Ojeda $(Q)$(MAKE) $(build)=rust $@ 1995158a3b72SMiguel Ojeda 199688de91ccSMiguel Ojeda# Formatting targets 199773740175SMiguel Ojeda# 199856762152SMiguel Ojeda# Generated files as well as vendored crates are skipped. 199950605498SMiguel OjedaPHONY += rustfmt rustfmtcheck 2000158a3b72SMiguel Ojeda 2001397a479bSMasahiro Yamadarustfmt: 20022f7ab126SMiguel Ojeda $(Q)find $(srctree) $(RCS_FIND_IGNORE) \ 20032f7ab126SMiguel Ojeda \( \ 20042f7ab126SMiguel Ojeda -path $(srctree)/rust/proc-macro2 \ 20052f7ab126SMiguel Ojeda -o -path $(srctree)/rust/quote \ 20062f7ab126SMiguel Ojeda -o -path $(srctree)/rust/syn \ 200767274c08SMasahiro Yamada -o -path $(srctree)/rust/zerocopy \ 200867274c08SMasahiro Yamada -o -path $(srctree)/rust/zerocopy-derive \ 200967274c08SMasahiro Yamada \) -prune -o \ 201091ecf7ffSMasahiro Yamada -type f -a -name '*.rs' -a ! -name '*generated*' -print \ 201191ecf7ffSMasahiro Yamada | xargs $(RUSTFMT) $(rustfmt_flags) 201291ecf7ffSMasahiro Yamada 201391ecf7ffSMasahiro Yamadarustfmtcheck: rustfmt_flags = --check 201491ecf7ffSMasahiro Yamadarustfmtcheck: rustfmt 201591ecf7ffSMasahiro Yamada 201667274c08SMasahiro Yamada# Misc 20177a739ce5SMasahiro Yamada# --------------------------------------------------------------------------- 20181e5ff84fSMasahiro Yamada 20198d2e5200SMasahiro YamadaPHONY += misc-check 202067274c08SMasahiro Yamadamisc-check: 202167274c08SMasahiro Yamada $(Q)$(srctree)/scripts/misc-check 202267274c08SMasahiro Yamada 202367274c08SMasahiro Yamadaall: misc-check 202467274c08SMasahiro Yamada 20251da177e4SLinus TorvaldsPHONY += scripts_gdb 20261da177e4SLinus Torvaldsscripts_gdb: prepare0 2027c753ccb2STzafrir Cohen $(Q)$(MAKE) $(build)=scripts/gdb 2028c753ccb2STzafrir Cohen $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py) 20291da177e4SLinus Torvalds 20301da177e4SLinus Torvaldsifdef CONFIG_GDB_SCRIPTS 20311da177e4SLinus Torvaldsall: scripts_gdb 20321da177e4SLinus Torvaldsendif 20331da177e4SLinus Torvalds 203411122b86SMasahiro Yamadaelse # KBUILD_EXTMOD 20351da177e4SLinus Torvalds 20366212804fSMasahiro Yamadafilechk_kernel.release = echo $(KERNELRELEASE) 20376212804fSMasahiro Yamada 20381bf807b8SMasahiro Yamada### 20391da177e4SLinus Torvalds# External module support. 204013b25489SMasahiro Yamada# When building external modules the kernel used as basis is considered 20413d32285fSMasahiro Yamada# read-only, and no consistency checks are made and the make 204213b25489SMasahiro Yamada# system is not used on the basis kernel. If updates are required 204313b25489SMasahiro Yamada# in the basis kernel ordinary make commands (without M=...) must be used. 20441da177e4SLinus Torvalds 20456072b2c4SMasahiro Yamada# We are always building only modules. 20466072b2c4SMasahiro YamadaKBUILD_BUILTIN := 20476072b2c4SMasahiro YamadaKBUILD_MODULES := y 204890e5b38aSIhor Solodrai 20496072b2c4SMasahiro Yamadabuild-dir := . 2050129ab0d2SMasahiro Yamada 20516072b2c4SMasahiro Yamadaclean-dirs := . 2052129ab0d2SMasahiro Yamadaclean: private rm-files := Module.symvers modules.nsdeps compile_commands.json 20536072b2c4SMasahiro Yamada 20546072b2c4SMasahiro YamadaPHONY += prepare 205590e5b38aSIhor Solodrai# now expand this into a simple variable to reduce the cost of shell evaluations 205690e5b38aSIhor Solodraiprepare: CC_VERSION_TEXT := $(CC_VERSION_TEXT) 205790e5b38aSIhor Solodraiprepare: PAHOLE_VERSION := $(PAHOLE_VERSION) 205890e5b38aSIhor Solodraiprepare: 205990e5b38aSIhor Solodrai @if [ "$(CC_VERSION_TEXT)" != "$(CONFIG_CC_VERSION_TEXT)" ]; then \ 20606072b2c4SMasahiro Yamada echo >&2 "warning: the compiler differs from the one used to build the kernel"; \ 2061fe69b420SMasahiro Yamada echo >&2 " The kernel was built by: $(CONFIG_CC_VERSION_TEXT)"; \ 20621da177e4SLinus Torvalds echo >&2 " You are using: $(CC_VERSION_TEXT)"; \ 20631da177e4SLinus Torvalds fi 20641da177e4SLinus Torvalds @if [ "$(PAHOLE_VERSION)" != "$(CONFIG_PAHOLE_VERSION)" ]; then \ 20651da177e4SLinus Torvalds echo >&2 "warning: pahole version differs from the one used to build the kernel"; \ 20661da177e4SLinus Torvalds echo >&2 " The kernel was built with: $(CONFIG_PAHOLE_VERSION)"; \ 20671da177e4SLinus Torvalds echo >&2 " You are using: $(PAHOLE_VERSION)"; \ 20681da177e4SLinus Torvalds fi 206949a9ef76SVinay Varma 20701da177e4SLinus TorvaldsPHONY += help 207106300b21SSam Ravnborghelp: 20725e02797bSMasahiro Yamada @echo ' Building external modules.' 20735e02797bSMasahiro Yamada @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target' 20748ae071fcSMasahiro Yamada @echo '' 20758ae071fcSMasahiro Yamada @echo ' modules - default target, build the module(s)' 20768ae071fcSMasahiro Yamada @echo ' modules_install - install the module' 20778ae071fcSMasahiro Yamada @echo ' clean - remove generated files in module directory only' 20788ae071fcSMasahiro Yamada @echo ' rust-analyzer - generate rust-project.json rust-analyzer support file' 20798ae071fcSMasahiro Yamada @echo '' 20805e02797bSMasahiro Yamada 20818ae071fcSMasahiro Yamadaifndef CONFIG_MODULES 20821da177e4SLinus Torvaldsmodules modules_install: __external_modules_error 20831da177e4SLinus Torvalds__external_modules_error: 20843e3005dfSMasahiro Yamada @echo >&2 '***' 20853e3005dfSMasahiro Yamada @echo >&2 '*** The present kernel disabled CONFIG_MODULES.' 20863e3005dfSMasahiro Yamada @echo >&2 '*** You cannot build or install external modules.' 2087151aeca2SMasahiro Yamada @echo >&2 '***' 20883e3005dfSMasahiro Yamada @false 20895e02797bSMasahiro Yamadaendif 2090151aeca2SMasahiro Yamada 2091151aeca2SMasahiro Yamadaendif # KBUILD_EXTMOD 2092151aeca2SMasahiro Yamada 2093151aeca2SMasahiro Yamada# --------------------------------------------------------------------------- 2094151aeca2SMasahiro Yamada# Modules 2095151aeca2SMasahiro Yamada 2096151aeca2SMasahiro YamadaPHONY += modules modules_install modules_sign modules_prepare 2097151aeca2SMasahiro Yamada 2098151aeca2SMasahiro Yamadamodules_install: 2099151aeca2SMasahiro Yamada $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst \ 2100151aeca2SMasahiro Yamada sign-only=$(if $(filter modules_install,$(MAKECMDGOALS)),,y) 2101151aeca2SMasahiro Yamada 2102151aeca2SMasahiro Yamadaifeq ($(CONFIG_MODULE_SIG),y) 2103151aeca2SMasahiro Yamada# modules_sign is a subset of modules_install. 2104151aeca2SMasahiro Yamada# 'make modules_install modules_sign' is equivalent to 'make modules_install'. 21053e3005dfSMasahiro Yamadamodules_sign: modules_install 21063e3005dfSMasahiro Yamada @: 21073e3005dfSMasahiro Yamadaelse 2108bad6beb2SMasahiro Yamadamodules_sign: 21095750121aSMasahiro Yamada @echo >&2 '***' 21105750121aSMasahiro Yamada @echo >&2 '*** CONFIG_MODULE_SIG is disabled. You cannot sign modules.' 2111f73edc89SMasahiro Yamada @echo >&2 '***' 2112f73edc89SMasahiro Yamada @false 2113f73edc89SMasahiro Yamadaendif 2114f73edc89SMasahiro Yamada 2115f73edc89SMasahiro Yamadaifdef CONFIG_MODULES 2116f73edc89SMasahiro Yamada 21173e3005dfSMasahiro Yamadamodules.order: $(build-dir) 21181a998be6SMasahiro Yamada @: 2119bad6beb2SMasahiro Yamada 21201a998be6SMasahiro Yamada# KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules. 21211a998be6SMasahiro Yamada# This is solely useful to speed up test compiles. 21223e3005dfSMasahiro Yamadamodules: modpost 21233e3005dfSMasahiro Yamadaifneq ($(KBUILD_MODPOST_NOFINAL),1) 21245e02797bSMasahiro Yamada $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal 21258ae071fcSMasahiro Yamadaendif 21263e3005dfSMasahiro Yamada 2127f110e5a2SMasahiro YamadaPHONY += modules_check 2128f110e5a2SMasahiro Yamadamodules_check: modules.order 21293e3005dfSMasahiro Yamada $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $< 21303e3005dfSMasahiro Yamada 2131f73edc89SMasahiro Yamadaelse # CONFIG_MODULES 2132f73edc89SMasahiro Yamada 2133f73edc89SMasahiro Yamadamodules: 2134f73edc89SMasahiro Yamada @: 2135f73edc89SMasahiro Yamada 2136b1fbfcb4SMasahiro YamadaKBUILD_MODULES := 2137b1fbfcb4SMasahiro Yamada 2138b1fbfcb4SMasahiro Yamadaendif # CONFIG_MODULES 2139b1fbfcb4SMasahiro Yamada 2140b1fbfcb4SMasahiro YamadaPHONY += modpost 2141b1fbfcb4SMasahiro Yamadamodpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \ 2142b1fbfcb4SMasahiro Yamada $(if $(KBUILD_MODULES), modules_check) 2143b1fbfcb4SMasahiro Yamada $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 2144b1fbfcb4SMasahiro Yamada 2145b1fbfcb4SMasahiro Yamada# Single targets 2146b1fbfcb4SMasahiro Yamada# --------------------------------------------------------------------------- 2147b1fbfcb4SMasahiro Yamada# To build individual files in subdirectories, you can do like this: 2148b1fbfcb4SMasahiro Yamada# 2149b1fbfcb4SMasahiro Yamada# make foo/bar/baz.s 2150b1fbfcb4SMasahiro Yamada# 2151b1fbfcb4SMasahiro Yamada# The supported suffixes for single-target are listed in 'single-targets' 2152fc93a4cdSMasahiro Yamada# 2153fc93a4cdSMasahiro Yamada# To build only under specific subdirectories, you can do like this: 2154b1fbfcb4SMasahiro Yamada# 2155f73edc89SMasahiro Yamada# make foo/bar/baz/ 2156b1fbfcb4SMasahiro Yamada 21575750121aSMasahiro Yamadaifdef single-build 2158b1fbfcb4SMasahiro Yamada 2159b1fbfcb4SMasahiro Yamada# .ko is special because modpost is needed 2160bad6beb2SMasahiro Yamadasingle-ko := $(sort $(filter %.ko, $(MAKECMDGOALS))) 2161f73edc89SMasahiro Yamadasingle-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \ 2162f73edc89SMasahiro Yamada $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko))) 2163bad6beb2SMasahiro Yamada 2164b1fbfcb4SMasahiro Yamada$(single-ko): single_modules 2165f73edc89SMasahiro Yamada @: 2166f73edc89SMasahiro Yamada$(single-no-ko): $(build-dir) 2167f73edc89SMasahiro Yamada @: 2168bad6beb2SMasahiro Yamada 2169b1fbfcb4SMasahiro Yamada# Remove modules.order when done because it is not the real one. 21705750121aSMasahiro YamadaPHONY += single_modules 2171b1fbfcb4SMasahiro Yamadasingle_modules: $(single-no-ko) modules_prepare 21721bf807b8SMasahiro Yamada $(Q){ $(foreach m, $(single-ko), echo $(m:%.ko=%.o);) } > modules.order 21733753af77SMasahiro Yamada $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost 2174b1fbfcb4SMasahiro Yamadaifneq ($(KBUILD_MODPOST_NOFINAL),1) 2175b1fbfcb4SMasahiro Yamada $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal 217611b3d517SMasahiro Yamadaendif 217711b3d517SMasahiro Yamada $(Q)rm -f modules.order 2178c99f3918SMasahiro Yamada 2179c99f3918SMasahiro Yamadasingle-goals := $(addprefix $(build-dir)/, $(single-no-ko)) 2180c99f3918SMasahiro Yamada 2181c99f3918SMasahiro YamadaKBUILD_MODULES := y 21825750121aSMasahiro Yamada 21835750121aSMasahiro Yamadaendif 21845750121aSMasahiro Yamada 2185c99f3918SMasahiro Yamadaprepare: outputmakefile 218676cd306dSMasahiro Yamada 218776cd306dSMasahiro Yamada# Preset locale variables to speed up the build process. Limit locale 218876cd306dSMasahiro Yamada# tweaks to this spot to avoid wrong language settings when running 218976cd306dSMasahiro Yamada# make menuconfig etc. 219076cd306dSMasahiro Yamada# Error messages still appears in the original language 219188d7be03SMichal MarekPHONY += $(build-dir) 219288d7be03SMichal Marek$(build-dir): prepare 219313b25489SMasahiro Yamada $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals) 21942f7ab126SMiguel Ojeda 21959f2aee8fSRong Xuclean-dirs := $(addprefix _clean_, $(clean-dirs)) 2196dcad240cSAndrew DavisPHONY += $(clean-dirs) clean 2197dcad240cSAndrew Davis$(clean-dirs): 219824507871SMasahiro Yamada $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@) 2199ef46d9b3SMasahiro Yamada 22005e9e95ccSMasahiro Yamadaclean: $(clean-dirs) 220188d7be03SMichal Marek $(call cmd,rmfiles) 22029a8dfb39SMasahiro Yamada @find . $(RCS_FIND_IGNORE) \ 22034fa8bc94SMasahiro Yamada \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \ 220488d7be03SMichal Marek -o -name '*.ko.*' -o -name '*.o.thinlto.bc' \ 22056b90bd4bSEmese Revfy -o -name '*.dtb' -o -name '*.dtbo' \ 2206433db3e2SVinícius Tinti -o -name '*.dtb.S' -o -name '*.dtbo.S' \ 220738e89184SSami Tolvanen -o -name '*.dt.yaml' -o -name 'dtbs-list' \ 2208025fd4b4SJoel Kamminga -o -name '*.dwo' -o -name '*.lst' \ 220987af9388SMasahiro Yamada -o -name '*.su' -o -name '*.mod' \ 22109c73bcfaSThomas Weißschuh -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \ 22119c73bcfaSThomas Weißschuh -o -name '*.lex.c' -o -name '*.tab.[ch]' \ 221288d7be03SMichal Marek -o -name '*.asn1.[ch]' \ 22131da177e4SLinus Torvalds -o -name '*.symtypes' -o -name 'modules.order' \ 22141da177e4SLinus Torvalds -o -name '*.c.[012]*.*' \ 2215a680eedcSSam Ravnborg -o -name '*.ll' \ 2216858805b3SMasahiro Yamada -o -name '*.gcno' \ 22171da177e4SLinus Torvalds -o -name '*.long-type-*.txt' \ 2218f4ed1009SJianbin Kang \) -type f -print \ 22191da177e4SLinus Torvalds -o -name '.tmp_*' -print \ 22201da177e4SLinus Torvalds | xargs rm -rf 22215045b460SJohn Hubbard 22225045b460SJohn Hubbard# Generate tags for editors 22235045b460SJohn Hubbard# --------------------------------------------------------------------------- 222449a9ef76SVinay Varmaquiet_cmd_tags = GEN $@ 222549a9ef76SVinay Varma cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@ 2226d734422bSMiguel Ojeda 222713b25489SMasahiro Yamadatags TAGS cscope gtags: FORCE 222813b25489SMasahiro Yamada $(call cmd,tags) 222913b25489SMasahiro Yamada 223013b25489SMasahiro Yamada# Generate rust-project.json (a file that describes the structure of non-Cargo 223149a9ef76SVinay Varma# Rust projects) for rust-analyzer (an implementation of the Language Server 223213b25489SMasahiro Yamada# Protocol). 223349a9ef76SVinay VarmaPHONY += rust-analyzer 2234eb8305aeSMatthias Maennichrust-analyzer: 2235eb8305aeSMatthias Maennich +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh 2236eb8305aeSMatthias Maennichifdef KBUILD_EXTMOD 2237eb8305aeSMatthias Maennich# FIXME: external modules must not descend into a sub-directory of the kernel 2238bff9c62bSMasahiro Yamada $(Q)$(MAKE) $(build)=$(objtree)/rust src=$(srctree)/rust $@ 2239eb8305aeSMatthias Maennichelse 2240bff9c62bSMasahiro Yamada $(Q)$(MAKE) $(build)=rust $@ 2241eb8305aeSMatthias Maennichendif 2242e72b635cSLuis Augenstein 2243e72b635cSLuis Augenstein# Script to generate missing namespace dependencies 2244e72b635cSLuis Augenstein# --------------------------------------------------------------------------- 2245e72b635cSLuis Augenstein 2246e72b635cSLuis AugensteinPHONY += nsdeps 2247e72b635cSLuis Augensteinnsdeps: export KBUILD_NSDEPS=1 2248e72b635cSLuis Augensteinnsdeps: modules 2249e72b635cSLuis Augenstein $(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps 2250e72b635cSLuis Augenstein 2251e72b635cSLuis Augenstein# Script to generate .spdx.json SBOM documents describing the build 22529c16c1eaSLuis Augenstein# --------------------------------------------------------------------------- 22539c16c1eaSLuis Augenstein 22549c16c1eaSLuis Augensteinifdef building_out_of_srctree 22559c16c1eaSLuis Augensteinsbom_targets := sbom-source.spdx.json 2256a68a29a1SLuis Augensteinendif 2257b0191211SLuis Augensteinsbom_targets += sbom-build.spdx.json sbom-output.spdx.json 2258b0191211SLuis Augensteinquiet_cmd_sbom = GEN $(sbom_targets) 2259b0191211SLuis Augenstein cmd_sbom = printf "%s\n" "$(KBUILD_IMAGE)" >"$(tmp-target)"; \ 2260b0191211SLuis Augenstein $(if $(CONFIG_MODULES),sed 's/\.o$$/.ko/' $(objtree)/modules.order >> "$(tmp-target)";) \ 2261e72b635cSLuis Augenstein $(PYTHON3) $(srctree)/scripts/sbom/sbom.py \ 2262e72b635cSLuis Augenstein --src-tree $(abspath $(srctree)) \ 2263e72b635cSLuis Augenstein --obj-tree $(abspath $(objtree)) \ 2264e72b635cSLuis Augenstein --roots-file "$(tmp-target)" \ 22653d32285fSMasahiro Yamada --output-directory $(abspath $(objtree)) \ 22663d32285fSMasahiro Yamada --generate-spdx \ 22673d32285fSMasahiro Yamada --package-license "GPL-2.0 WITH Linux-syscall-note" \ 22683d32285fSMasahiro Yamada --package-version "$(KERNELVERSION)" \ 22693d32285fSMasahiro Yamada --write-output-on-error; 22703d32285fSMasahiro YamadaPHONY += sbom 2271bad6beb2SMasahiro Yamadasbom: $(notdir $(KBUILD_IMAGE)) include/generated/autoconf.h $(if $(CONFIG_MODULES),modules modules.order) 227232164845SMasahiro Yamada $(call cmd,sbom) 2273bad6beb2SMasahiro Yamada 22743d32285fSMasahiro Yamada# Clang Tooling 22753d32285fSMasahiro Yamada# --------------------------------------------------------------------------- 2276bad6beb2SMasahiro Yamada 22773d32285fSMasahiro Yamadaquiet_cmd_gen_compile_commands = GEN $@ 22786ad7cbc0SNathan Huckleberry cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs)) 22796ad7cbc0SNathan Huckleberry 22806ad7cbc0SNathan Huckleberrycompile_commands.json: $(srctree)/scripts/clang-tools/gen_compile_commands.py \ 22816ad7cbc0SNathan Huckleberry $(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \ 22826ad7cbc0SNathan Huckleberry $(if $(CONFIG_MODULES), modules.order) FORCE 22836ad7cbc0SNathan Huckleberry $(call if_changed,gen_compile_commands) 2284bad6beb2SMasahiro Yamada 22856ad7cbc0SNathan Huckleberrytargets += compile_commands.json 22866ad7cbc0SNathan Huckleberry 22876ad7cbc0SNathan HuckleberryPHONY += clang-tidy clang-analyzer 22886ad7cbc0SNathan Huckleberry 22896ad7cbc0SNathan Huckleberryifdef CONFIG_CC_IS_CLANG 22906ad7cbc0SNathan Huckleberryquiet_cmd_clang_tools = CHECK $< 22916ad7cbc0SNathan Huckleberry cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $< 22921da177e4SLinus Torvalds 22931da177e4SLinus Torvaldsclang-tidy clang-analyzer: compile_commands.json 22941da177e4SLinus Torvalds $(call cmd,clang_tools) 2295f58316a4SAndrew Joneselse 2296279f3dd3SPeter Foleyclang-tidy clang-analyzer: 22971da177e4SLinus Torvalds @echo "$@ requires CC=clang" >&2 2298436f876cSPeter Foley @false 22991da177e4SLinus Torvaldsendif 230080007434SGeert Uytterhoeven 23011da177e4SLinus Torvalds# Scripts to check various things for consistency 23021da177e4SLinus Torvalds# --------------------------------------------------------------------------- 23032ee2d292SPeter Foley 23041da177e4SLinus TorvaldsPHONY += includecheck versioncheck coccicheck kconfig-sym-check 230580007434SGeert Uytterhoeven 23061da177e4SLinus Torvaldsincludecheck: 230774425eeeSNicolas Palix find $(srctree)/* $(RCS_FIND_IGNORE) \ 2308858805b3SMasahiro Yamada -name '*.[hcS]' -type f -print | sort \ 230974425eeeSNicolas Palix | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl 2310f58316a4SAndrew Jones 2311f58316a4SAndrew Jonesversioncheck: 2312f58316a4SAndrew Jones find $(srctree)/* $(RCS_FIND_IGNORE) \ 2313c398ff00SMike Marciniszyn -name '*.[hcS]' -type f -print | sort \ 2314e3ccf6e3SJeff Dike | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl 2315011e3a9aSJeff Dike 2316011e3a9aSJeff Dikecoccicheck: 2317011e3a9aSJeff Dike $(Q)$(BASH) $(srctree)/scripts/$@ 2318011e3a9aSJeff Dike 2319011e3a9aSJeff Dikekconfig-sym-check: 2320011e3a9aSJeff Dike $(Q)$(PERL) $(srctree)/scripts/kconfig/kconfig-sym-check.pl $(srctree) $(KCONFIG_SYM_CHECK_EXCLUDES) 2321011e3a9aSJeff Dike 2322011e3a9aSJeff DikePHONY += checkstack kernelrelease kernelversion image_name 2323011e3a9aSJeff Dike 232466242cfaSHeiko Carstens# UML needs a little special treatment here. It wants to use the host 23251da177e4SLinus Torvalds# toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone 23261da177e4SLinus Torvalds# else wants $(ARCH), including people doing cross-builds, which means 232766242cfaSHeiko Carstens# that $(SUBARCH) doesn't work here. 23281da177e4SLinus Torvaldsifeq ($(ARCH), um) 23297b8ea53dSAmerigo WangCHECKSTACK_ARCH := $(SUBARCH) 23301cb86b6cSMasahiro Yamadaelse 233101ab1788SAmerigo WangCHECKSTACK_ARCH := $(ARCH) 2332cb58455cSSam Ravnborgendif 23332244cbd8SSam RavnborgMINSTACKSIZE ?= 100 23341da177e4SLinus Torvaldscheckstack: 2335c398ff00SMike Marciniszyn $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \ 2336c398ff00SMike Marciniszyn $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH) $(MINSTACKSIZE) 2337c398ff00SMike Marciniszyn 233876a48b8fSMasahiro Yamadakernelrelease: 233976a48b8fSMasahiro Yamada @$(filechk_kernel.release) 234076a48b8fSMasahiro Yamada 234176a48b8fSMasahiro Yamadakernelversion: 23421da177e4SLinus Torvalds @echo $(KERNELVERSION) 23430663c68cSMasahiro Yamada 23441da177e4SLinus Torvaldsimage_name: 2345392885eeSMasahiro Yamada @echo $(KBUILD_IMAGE) 2346392885eeSMasahiro Yamada 23471da177e4SLinus TorvaldsPHONY += run-command 2348b999923cSMasahiro Yamadarun-command: 23491da177e4SLinus Torvalds $(Q)$(KBUILD_RUN_COMMAND) 235046b7c492SSZ Lin (林上智) 23512042b548SMasahiro Yamadaquiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files))) 2352688931a5SMasahiro Yamada cmd_rmfiles = rm -rf $(rm-files) 23531da177e4SLinus Torvalds 23544f193362SPaul Smith# read saved command lines for existing targets 23551da177e4SLinus Torvaldsexisting-targets := $(wildcard $(sort $(targets))) 23564f193362SPaul Smith 2357bd412d81SUlf Magnusson-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd) 2358fe8d0a41SKirill Smelkov 23594f193362SPaul Smithendif # config-build 2360endif # mixed-build 2361endif # need-sub-make 2362 2363PHONY += FORCE 2364FORCE: 2365 2366# Declare the contents of the PHONY variable as phony. We keep that 2367# information in a variable so we can use it in if_changed and friends. 2368.PHONY: $(PHONY) 2369