blob: f975b639632809e8599b4b131f2c2e56ebf8f186 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Linus Torvalds568035b2022-08-14 15:50:18 -07002VERSION = 6
Linus Torvalds1613e602024-05-26 15:20:12 -07003PATCHLEVEL = 10
Linus Torvalds55922c92011-05-29 17:43:36 -07004SUBLEVEL = 0
Linus Torvalds1613e602024-05-26 15:20:12 -07005EXTRAVERSION = -rc1
6NAME = Baby Opossum Posse
Linus Torvalds1da177e2005-04-16 15:20:36 -07007
8# *DOCUMENTATION*
9# To see a list of typical targets execute "make help"
10# More info can be located in ./README
11# Comments in this file are targeted only to the developer, do not
12# expect to learn how to build the kernel reading this file.
13
Masahiro Yamada87d599f2022-12-13 20:24:20 +090014ifeq ($(filter undefine,$(.FEATURES)),)
15$(error GNU Make >= 3.82 is required. Your Make version is $(MAKE_VERSION))
16endif
17
Masahiro Yamada121c2a12020-05-11 12:50:13 +090018$(if $(filter __%, $(MAKECMDGOALS)), \
19 $(error targets prefixed with '__' are only for internal use))
20
Masahiro Yamadaba634ec2017-10-04 12:56:05 +090021# That's our default target when none is given on the command line
Masahiro Yamada121c2a12020-05-11 12:50:13 +090022PHONY := __all
23__all:
Masahiro Yamadaba634ec2017-10-04 12:56:05 +090024
Linus Torvalds1da177e2005-04-16 15:20:36 -070025# We are using a recursive build, so we need to do a little thinking
26# to get the ordering right.
27#
28# Most importantly: sub-Makefiles should only ever modify files in
29# their own directory. If in some directory we have a dependency on
30# a file in another dir (which doesn't happen often, but it's often
Nicholas Pigginf49821e2018-02-11 00:25:04 +100031# unavoidable when linking the built-in.a targets which finally
Linus Torvalds1da177e2005-04-16 15:20:36 -070032# turn into vmlinux), we will call a sub make in that other dir, and
33# after that we are sure that everything which is in that other dir
34# is now up to date.
35#
36# The only cases where we need to modify files which have global
37# effects are thus separated out and done before the recursive
38# descending is started. They are now explicitly listed as the
39# prepare rule.
40
Masahiro Yamada5fa94ce2023-06-27 08:30:12 +090041this-makefile := $(lastword $(MAKEFILE_LIST))
Masahiro Yamadae2bad142024-03-06 19:42:22 +090042abs_srctree := $(realpath $(dir $(this-makefile)))
43abs_objtree := $(CURDIR)
Masahiro Yamada5fa94ce2023-06-27 08:30:12 +090044
Masahiro Yamada221cc2d2019-03-26 13:02:19 +090045ifneq ($(sub_make_done),1)
Masahiro Yamada3812b8c2019-02-22 16:40:07 +090046
47# Do not use make's built-in rules and variables
48# (this increases performance and avoids hard-to-debug behaviour)
49MAKEFLAGS += -rR
50
51# Avoid funny character set dependencies
52unexport LC_ALL
53LC_COLLATE=C
54LC_NUMERIC=C
55export LC_COLLATE LC_NUMERIC
56
57# Avoid interference with shell env settings
58unexport GREP_OPTIONS
59
Michal Marek066b7ed2014-07-04 14:29:30 +020060# Beautify output
61# ---------------------------------------------------------------------------
62#
Masahiro Yamada8962b6b2022-12-23 01:25:32 +090063# Most of build commands in Kbuild start with "cmd_". You can optionally define
64# "quiet_cmd_*". If defined, the short log is printed. Otherwise, no log from
65# that command is printed by default.
Michal Marek066b7ed2014-07-04 14:29:30 +020066#
Masahiro Yamada8962b6b2022-12-23 01:25:32 +090067# e.g.)
68# quiet_cmd_depmod = DEPMOD $(MODLIB)
69# cmd_depmod = $(srctree)/scripts/depmod.sh $(DEPMOD) $(KERNELRELEASE)
Michal Marek066b7ed2014-07-04 14:29:30 +020070#
71# A simple variant is to prefix commands with $(Q) - that's useful
72# for commands that shall be hidden in non-verbose mode.
73#
Masahiro Yamada8962b6b2022-12-23 01:25:32 +090074# $(Q)$(MAKE) $(build)=scripts/basic
Michal Marek066b7ed2014-07-04 14:29:30 +020075#
Masahiro Yamada6ae4b982022-12-23 01:25:34 +090076# If KBUILD_VERBOSE contains 1, the whole command is echoed.
77# If KBUILD_VERBOSE contains 2, the reason for rebuilding is printed.
Michal Marek066b7ed2014-07-04 14:29:30 +020078#
Linus Torvalds1da177e2005-04-16 15:20:36 -070079# To put more focus on warnings, be less verbose as default
80# Use 'make V=1' to see the full commands
81
Cheng Renquanb8b06182009-05-26 16:03:07 +080082ifeq ("$(origin V)", "command line")
83 KBUILD_VERBOSE = $(V)
Linus Torvalds1da177e2005-04-16 15:20:36 -070084endif
Linus Torvalds1da177e2005-04-16 15:20:36 -070085
Masahiro Yamada6ae4b982022-12-23 01:25:34 +090086quiet = quiet_
87Q = @
88
89ifneq ($(findstring 1, $(KBUILD_VERBOSE)),)
Michal Marek066b7ed2014-07-04 14:29:30 +020090 quiet =
91 Q =
Michal Marek066b7ed2014-07-04 14:29:30 +020092endif
93
94# If the user is running make -s (silent mode), suppress echoing of
95# commands
Dmitry Goncharov4bf73582022-12-05 16:48:19 -050096# make-4.0 (and later) keep single letter options in the 1st word of MAKEFLAGS.
Michal Marek066b7ed2014-07-04 14:29:30 +020097
Dmitry Goncharov4bf73582022-12-05 16:48:19 -050098ifeq ($(filter 3.%,$(MAKE_VERSION)),)
Masahiro Yamadafc5d57a2022-12-23 01:25:31 +090099short-opts := $(firstword -$(MAKEFLAGS))
Dmitry Goncharov4bf73582022-12-05 16:48:19 -0500100else
Masahiro Yamadafc5d57a2022-12-23 01:25:31 +0900101short-opts := $(filter-out --%,$(MAKEFLAGS))
Dmitry Goncharov4bf73582022-12-05 16:48:19 -0500102endif
103
Masahiro Yamadafc5d57a2022-12-23 01:25:31 +0900104ifneq ($(findstring s,$(short-opts)),)
Dmitry Goncharov4bf73582022-12-05 16:48:19 -0500105quiet=silent_
Masahiro Yamada83d98d72022-12-23 01:25:35 +0900106override KBUILD_VERBOSE :=
Michal Marek066b7ed2014-07-04 14:29:30 +0200107endif
Michal Marek066b7ed2014-07-04 14:29:30 +0200108
109export quiet Q KBUILD_VERBOSE
110
Masahiro Yamadabcf637f2021-02-22 01:53:06 +0900111# Call a source code checker (by default, "sparse") as part of the
112# C compilation.
113#
114# Use 'make C=1' to enable checking of only re-compiled files.
115# Use 'make C=2' to enable checking of *all* source files, regardless
116# of whether they are re-compiled or not.
117#
118# See the file "Documentation/dev-tools/sparse.rst" for more details,
119# including where to get the "sparse" utility.
120
121ifeq ("$(origin C)", "command line")
122 KBUILD_CHECKSRC = $(C)
123endif
124ifndef KBUILD_CHECKSRC
125 KBUILD_CHECKSRC = 0
126endif
127
128export KBUILD_CHECKSRC
129
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200130# Enable "clippy" (a linter) as part of the Rust compilation.
131#
132# Use 'make CLIPPY=1' to enable it.
133ifeq ("$(origin CLIPPY)", "command line")
134 KBUILD_CLIPPY := $(CLIPPY)
135endif
136
137export KBUILD_CLIPPY
138
Masahiro Yamadabcf637f2021-02-22 01:53:06 +0900139# Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the
140# directory of external module to build. Setting M= takes precedence.
141ifeq ("$(origin M)", "command line")
142 KBUILD_EXTMOD := $(M)
143endif
144
145$(if $(word 2, $(KBUILD_EXTMOD)), \
146 $(error building multiple external modules is not supported))
147
Masahiro Yamada9a68fd72022-07-14 14:02:42 +0900148$(foreach x, % :, $(if $(findstring $x, $(KBUILD_EXTMOD)), \
149 $(error module directory path cannot contain '$x')))
150
Masahiro Yamada74ee5852021-06-02 23:02:13 +0900151# Remove trailing slashes
152ifneq ($(filter %/, $(KBUILD_EXTMOD)),)
153KBUILD_EXTMOD := $(shell dirname $(KBUILD_EXTMOD).)
154endif
155
Masahiro Yamadabcf637f2021-02-22 01:53:06 +0900156export KBUILD_EXTMOD
157
Masahiro Yamada92ef4322023-11-23 18:05:40 +0900158# backward compatibility
159KBUILD_EXTRA_WARN ?= $(KBUILD_ENABLE_EXTRA_GCC_CHECKS)
160
161ifeq ("$(origin W)", "command line")
162 KBUILD_EXTRA_WARN := $(W)
163endif
164
165export KBUILD_EXTRA_WARN
166
Masahiro Yamada25b146c52019-03-30 21:04:14 +0900167# Kbuild will save output files in the current working directory.
168# This does not need to match to the root of the kernel source tree.
169#
170# For example, you can do this:
171#
172# cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile
173#
174# If you want to save output files in a different location, there are
175# two syntaxes to specify it.
176#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700177# 1) O=
178# Use "make O=dir/to/store/output/files/"
Sam Ravnborg070b98b2006-06-25 00:07:55 +0200179#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700180# 2) Set KBUILD_OUTPUT
Masahiro Yamada25b146c52019-03-30 21:04:14 +0900181# Set the environment variable KBUILD_OUTPUT to point to the output directory.
182# export KBUILD_OUTPUT=dir/to/store/output/files/; make
Linus Torvalds1da177e2005-04-16 15:20:36 -0700183#
184# The O= assignment takes precedence over the KBUILD_OUTPUT environment
185# variable.
186
Masahiro Yamada25b146c52019-03-30 21:04:14 +0900187# Do we want to change the working directory?
Cheng Renquanb8b06182009-05-26 16:03:07 +0800188ifeq ("$(origin O)", "command line")
189 KBUILD_OUTPUT := $(O)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190endif
191
Masahiro Yamada25b146c52019-03-30 21:04:14 +0900192ifneq ($(KBUILD_OUTPUT),)
Masahiro Yamada7beba042023-12-16 01:06:37 +0900193# $(realpath ...) gets empty if the path does not exist. Run 'mkdir -p' first.
194$(shell mkdir -p "$(KBUILD_OUTPUT)")
Masahiro Yamada25b146c52019-03-30 21:04:14 +0900195# $(realpath ...) resolves symlinks
Masahiro Yamada7beba042023-12-16 01:06:37 +0900196abs_objtree := $(realpath $(KBUILD_OUTPUT))
197$(if $(abs_objtree),,$(error failed to create output directory "$(KBUILD_OUTPUT)"))
Masahiro Yamada25b146c52019-03-30 21:04:14 +0900198endif # ifneq ($(KBUILD_OUTPUT),)
199
Masahiro Yamada25b146c52019-03-30 21:04:14 +0900200ifneq ($(words $(subst :, ,$(abs_srctree))), 1)
201$(error source directory cannot contain spaces or colons)
202endif
203
Masahiro Yamada688931a2019-03-19 13:02:36 +0900204ifneq ($(filter 3.%,$(MAKE_VERSION)),)
205# 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x
206# We need to invoke sub-make to avoid implicit rules in the top Makefile.
207need-sub-make := 1
208# Cancel implicit rules for this Makefile.
Masahiro Yamada93fdddf2020-05-11 12:50:12 +0900209$(this-makefile): ;
Masahiro Yamada688931a2019-03-19 13:02:36 +0900210endif
211
Masahiro Yamada221cc2d2019-03-26 13:02:19 +0900212export sub_make_done := 1
213
Masahiro Yamada5fc10e72023-06-27 08:30:13 +0900214endif # sub_make_done
215
216ifeq ($(abs_objtree),$(CURDIR))
217# Suppress "Entering directory ..." if we are at the final work directory.
218no-print-directory := --no-print-directory
219else
220# Recursion to show "Entering directory ..."
221need-sub-make := 1
222endif
223
224ifeq ($(filter --no-print-directory, $(MAKEFLAGS)),)
225# If --no-print-directory is unset, recurse once again to set it.
226# You may end up recursing into __sub-make twice. This is needed due to the
227# behavior change in GNU Make 4.4.1.
228need-sub-make := 1
229endif
230
Masahiro Yamada688931a2019-03-19 13:02:36 +0900231ifeq ($(need-sub-make),1)
232
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900233PHONY += $(MAKECMDGOALS) __sub-make
Milton Miller0b357862007-09-21 18:09:02 -0500234
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900235$(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
Charles Keepax16f89092012-10-15 13:49:12 +0100236 @:
Milton Miller0b357862007-09-21 18:09:02 -0500237
Cao jinc4e6fff2017-06-30 10:45:43 +0800238# Invoke a second make in the output directory, passing relevant variables
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900239__sub-make:
Masahiro Yamada5fc10e72023-06-27 08:30:13 +0900240 $(Q)$(MAKE) $(no-print-directory) -C $(abs_objtree) \
241 -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242
Masahiro Yamada5fc10e72023-06-27 08:30:13 +0900243else # need-sub-make
Masahiro Yamada688931a2019-03-19 13:02:36 +0900244
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245# We process the rest of the Makefile if this is the final invocation of make
Masahiro Yamada7ff52572014-09-09 20:02:22 +0900246
Masahiro Yamada25b146c52019-03-30 21:04:14 +0900247ifeq ($(abs_srctree),$(abs_objtree))
Michal Marek9da07632014-04-25 23:25:18 +0200248 # building in the source tree
249 srctree := .
Masahiro Yamada051f2782019-07-06 12:07:12 +0900250 building_out_of_srctree :=
Michal Marek9da07632014-04-25 23:25:18 +0200251else
Masahiro Yamada25b146c52019-03-30 21:04:14 +0900252 ifeq ($(abs_srctree)/,$(dir $(abs_objtree)))
Michal Marek9da07632014-04-25 23:25:18 +0200253 # building in a subdirectory of the source tree
254 srctree := ..
255 else
Masahiro Yamada25b146c52019-03-30 21:04:14 +0900256 srctree := $(abs_srctree)
Michal Marek9da07632014-04-25 23:25:18 +0200257 endif
Masahiro Yamada051f2782019-07-06 12:07:12 +0900258 building_out_of_srctree := 1
Michal Marek9da07632014-04-25 23:25:18 +0200259endif
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900260
Masahiro Yamada95fd3f82019-07-06 12:07:13 +0900261ifneq ($(KBUILD_ABS_SRCTREE),)
262srctree := $(abs_srctree)
263endif
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900264
Michal Marek7e1c0472014-04-25 17:29:45 +0200265objtree := .
Masahiro Yamadab1992c32024-04-27 23:55:02 +0900266
267VPATH :=
268
269ifeq ($(KBUILD_EXTMOD),)
270ifdef building_out_of_srctree
Masahiro Yamada6b12de62019-02-22 16:40:09 +0900271VPATH := $(srctree)
Masahiro Yamadab1992c32024-04-27 23:55:02 +0900272endif
273endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700274
Masahiro Yamada051f2782019-07-06 12:07:12 +0900275export building_out_of_srctree srctree objtree VPATH
Linus Torvalds1da177e2005-04-16 15:20:36 -0700276
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900277# To make sure we do not include .config for any of the *config targets
278# catch them early, and hand them over to scripts/kconfig/Makefile
279# It is allowed to specify more targets when calling make, including
280# mixing *config targets and build targets.
281# For example 'make oldconfig all'.
282# Detect when mixed targets is specified, and make a second invocation
283# of make so .config is not included in this case either (for *config).
284
285version_h := include/generated/uapi/linux/version.h
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900286
Masahiro Yamada22340a02018-02-11 17:40:29 +0900287clean-targets := %clean mrproper cleandocs
288no-dot-config-targets := $(clean-targets) \
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900289 cscope gtags TAGS tags help% %docs check% coccicheck \
Masahiro Yamada59b2bd02019-06-04 19:14:02 +0900290 $(version_h) headers headers_% archheaders archscripts \
David Engraf46239802020-03-26 20:29:33 +0100291 %asm-generic kernelversion %src-pkg dt_binding_check \
Masahiro Yamada05e96e92023-03-16 00:50:18 +0900292 outputmakefile rustavailable rustfmt rustfmtcheck
Masahiro Yamadaeb931e12023-08-23 20:50:42 +0900293no-sync-config-targets := $(no-dot-config-targets) %install modules_sign kernelrelease \
Masahiro Yamada993bdde2021-02-28 15:10:25 +0900294 image_name
Masahiro Yamadaaa4847d2022-12-29 21:16:42 +0900295single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.rsi %.s %.symtypes %/
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900296
Masahiro Yamada2042b542019-08-11 00:53:03 +0900297config-build :=
298mixed-build :=
299need-config := 1
300may-sync-config := 1
Masahiro Yamada394053f2019-08-15 00:19:18 +0900301single-build :=
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900302
303ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
Masahiro Yamada3b9ab242024-02-02 10:31:42 +0900304 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
Masahiro Yamada50a33992024-03-01 20:21:07 +0900305 need-config :=
Masahiro Yamada3b9ab242024-02-02 10:31:42 +0900306 endif
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900307endif
308
Masahiro Yamadad7942412018-07-20 16:46:34 +0900309ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
Masahiro Yamada3b9ab242024-02-02 10:31:42 +0900310 ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
Masahiro Yamada50a33992024-03-01 20:21:07 +0900311 may-sync-config :=
Masahiro Yamada3b9ab242024-02-02 10:31:42 +0900312 endif
Masahiro Yamadad7942412018-07-20 16:46:34 +0900313endif
314
Masahiro Yamada9d361172023-10-14 19:54:36 +0900315need-compiler := $(may-sync-config)
316
Masahiro Yamadad7942412018-07-20 16:46:34 +0900317ifneq ($(KBUILD_EXTMOD),)
Masahiro Yamada50a33992024-03-01 20:21:07 +0900318 may-sync-config :=
Masahiro Yamadad7942412018-07-20 16:46:34 +0900319endif
320
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900321ifeq ($(KBUILD_EXTMOD),)
Masahiro Yamada50a33992024-03-01 20:21:07 +0900322 ifneq ($(filter %config,$(MAKECMDGOALS)),)
323 config-build := 1
324 ifneq ($(words $(MAKECMDGOALS)),1)
325 mixed-build := 1
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900326 endif
Masahiro Yamada50a33992024-03-01 20:21:07 +0900327 endif
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900328endif
Masahiro Yamada22340a02018-02-11 17:40:29 +0900329
Masahiro Yamada394053f2019-08-15 00:19:18 +0900330# We cannot build single targets and the others at the same time
331ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),)
Masahiro Yamada50a33992024-03-01 20:21:07 +0900332 single-build := 1
Masahiro Yamada3b9ab242024-02-02 10:31:42 +0900333 ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),)
Masahiro Yamada50a33992024-03-01 20:21:07 +0900334 mixed-build := 1
Masahiro Yamada3b9ab242024-02-02 10:31:42 +0900335 endif
Masahiro Yamada394053f2019-08-15 00:19:18 +0900336endif
337
Masahiro Yamada22340a02018-02-11 17:40:29 +0900338# For "make -j clean all", "make -j mrproper defconfig all", etc.
339ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
Masahiro Yamada50a33992024-03-01 20:21:07 +0900340 ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
341 mixed-build := 1
342 endif
Masahiro Yamada22340a02018-02-11 17:40:29 +0900343endif
344
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900345# install and modules_install need also be processed one by one
346ifneq ($(filter install,$(MAKECMDGOALS)),)
Masahiro Yamada50a33992024-03-01 20:21:07 +0900347 ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
348 mixed-build := 1
349 endif
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900350endif
351
Masahiro Yamada2042b542019-08-11 00:53:03 +0900352ifdef mixed-build
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900353# ===========================================================================
354# We're called with mixed targets (*config and build targets).
355# Handle them one by one.
356
357PHONY += $(MAKECMDGOALS) __build_one_by_one
358
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900359$(MAKECMDGOALS): __build_one_by_one
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900360 @:
361
362__build_one_by_one:
363 $(Q)set -e; \
364 for i in $(MAKECMDGOALS); do \
365 $(MAKE) -f $(srctree)/Makefile $$i; \
366 done
367
Masahiro Yamada2042b542019-08-11 00:53:03 +0900368else # !mixed-build
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900369
Masahiro Yamada3204a7f2021-02-28 15:10:26 +0900370include $(srctree)/scripts/Kbuild.include
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900371
372# Read KERNELRELEASE from include/config/kernel.release (if it exists)
Masahiro Yamada6768fa42022-12-11 11:54:47 +0900373KERNELRELEASE = $(call read-file, include/config/kernel.release)
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900374KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
375export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
376
Masahiro Yamada3204a7f2021-02-28 15:10:26 +0900377include $(srctree)/scripts/subarch.include
Linus Torvalds1da177e2005-04-16 15:20:36 -0700378
379# Cross compiling and selecting different set of gcc/bin-utils
380# ---------------------------------------------------------------------------
381#
382# When performing cross compilation for other architectures ARCH shall be set
383# to the target architecture. (See arch/* for the possibilities).
384# ARCH can be set during invocation of make:
Ard Biesheuvel94483492023-01-13 18:32:57 +0100385# make ARCH=arm64
Linus Torvalds1da177e2005-04-16 15:20:36 -0700386# Another way is to have ARCH set in the environment.
387# The default ARCH is the host where make is executed.
388
389# CROSS_COMPILE specify the prefix used for all executables used
390# during compilation. Only gcc and related bin-utils executables
391# are prefixed with $(CROSS_COMPILE).
392# CROSS_COMPILE can be set on the command line
Ard Biesheuvel94483492023-01-13 18:32:57 +0100393# make CROSS_COMPILE=aarch64-linux-gnu-
Linus Torvalds1da177e2005-04-16 15:20:36 -0700394# Alternatively CROSS_COMPILE can be set in the environment.
395# Default value for CROSS_COMPILE is not to prefix executables
396# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
Sam Ravnborg2331d1a2009-10-11 23:22:58 +0200397ARCH ?= $(SUBARCH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398
399# Architecture as present in compile.h
Thomas Gleixner6752ed92007-10-11 11:11:36 +0200400UTS_MACHINE := $(ARCH)
401SRCARCH := $(ARCH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402
Sam Ravnborgd746d642007-11-12 20:14:19 +0100403# Additional ARCH settings for x86
404ifeq ($(ARCH),i386)
405 SRCARCH := x86
406endif
407ifeq ($(ARCH),x86_64)
408 SRCARCH := x86
409endif
Sam Ravnborg74b469f2007-10-25 19:42:04 +0200410
Sam Ravnborg5e538792008-12-02 23:17:12 -0800411# Additional ARCH settings for sparc
Namhyung Kime69f58c2010-10-25 05:48:23 +0000412ifeq ($(ARCH),sparc32)
413 SRCARCH := sparc
414endif
Sam Ravnborga439fe52008-07-27 23:00:59 +0200415ifeq ($(ARCH),sparc64)
Sam Ravnborg5e538792008-12-02 23:17:12 -0800416 SRCARCH := sparc
Sam Ravnborga439fe52008-07-27 23:00:59 +0200417endif
Sam Ravnborg2fb9b1b2008-06-21 00:24:17 +0200418
Masahiro Yamada5f6e0fe02021-06-10 11:03:31 +0900419# Additional ARCH settings for parisc
420ifeq ($(ARCH),parisc64)
421 SRCARCH := parisc
422endif
423
Masahiro Yamadaf02aa482021-04-10 23:31:58 +0900424export cross_compiling :=
425ifneq ($(SRCARCH),$(SUBARCH))
426cross_compiling := 1
427endif
428
Roman Zippel14cdd3c2006-06-08 22:12:51 -0700429KCONFIG_CONFIG ?= .config
Ben Gardiner41263fc2010-12-14 11:39:44 -0500430export KCONFIG_CONFIG
Roman Zippel14cdd3c2006-06-08 22:12:51 -0700431
Linus Torvalds1da177e2005-04-16 15:20:36 -0700432# SHELL used by kbuild
Masahiro Yamada858805b2019-08-25 22:28:37 +0900433CONFIG_SHELL := sh
Linus Torvalds1da177e2005-04-16 15:20:36 -0700434
Masahiro Yamada6d79a7b2018-07-12 19:38:36 +0900435HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
436HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
437HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
Uwe Kleine-Königd7f14c62017-07-09 20:02:36 +0200438
Masahiro Yamadaa0d1c952020-04-08 10:36:23 +0900439ifneq ($(LLVM),)
Nathan Chancellore9c28192022-03-04 10:08:14 -0700440ifneq ($(filter %/,$(LLVM)),)
441LLVM_PREFIX := $(LLVM)
442else ifneq ($(filter -%,$(LLVM)),)
443LLVM_SUFFIX := $(LLVM)
444endif
445
446HOSTCC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
447HOSTCXX = $(LLVM_PREFIX)clang++$(LLVM_SUFFIX)
Masahiro Yamadaa0d1c952020-04-08 10:36:23 +0900448else
449HOSTCC = gcc
450HOSTCXX = g++
451endif
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200452HOSTRUSTC = rustc
Chun-Tse Shaod5ea4fe2022-04-01 23:18:02 +0000453HOSTPKG_CONFIG = pkg-config
Masahiro Yamada7f3a59d2020-04-29 12:45:14 +0900454
Elliot Bermanf67695c92022-02-01 13:35:42 -0800455KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
Peter Zijlstrab5ec6fd2023-06-09 11:28:30 +0200456 -O2 -fomit-frame-pointer -std=gnu11
Elliot Bermanf67695c92022-02-01 13:35:42 -0800457KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
458KBUILD_USERLDFLAGS := $(USERLDFLAGS)
Masahiro Yamada7f3a59d2020-04-29 12:45:14 +0900459
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200460# These flags apply to all Rust code in the tree, including the kernel and
461# host programs.
462export rust_common_flags := --edition=2021 \
463 -Zbinary_dep_depinfo=y \
464 -Dunsafe_op_in_unsafe_fn -Drust_2018_idioms \
465 -Dunreachable_pub -Dnon_ascii_idents \
466 -Wmissing_docs \
467 -Drustdoc::missing_crate_level_docs \
468 -Dclippy::correctness -Dclippy::style \
469 -Dclippy::suspicious -Dclippy::complexity \
470 -Dclippy::perf \
471 -Dclippy::let_unit_value -Dclippy::mut_mut \
472 -Dclippy::needless_bitwise_bool \
473 -Dclippy::needless_continue \
Miguel Ojeda9418e682023-07-30 00:03:17 +0200474 -Dclippy::no_mangle_with_rust_abi \
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200475 -Wclippy::dbg_macro
476
Elliot Bermanf67695c92022-02-01 13:35:42 -0800477KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
Masahiro Yamada735aab12020-03-25 12:14:32 +0900478KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200479KBUILD_HOSTRUSTFLAGS := $(rust_common_flags) -O -Cstrip=debuginfo \
480 -Zallow-features= $(HOSTRUSTFLAGS)
Laura Abbottf92d19e2018-07-09 17:46:02 -0700481KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
482KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484# Make variables (CC, etc...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485CPP = $(CC) -E
Masahiro Yamadaa0d1c952020-04-08 10:36:23 +0900486ifneq ($(LLVM),)
Nathan Chancellore9c28192022-03-04 10:08:14 -0700487CC = $(LLVM_PREFIX)clang$(LLVM_SUFFIX)
488LD = $(LLVM_PREFIX)ld.lld$(LLVM_SUFFIX)
489AR = $(LLVM_PREFIX)llvm-ar$(LLVM_SUFFIX)
490NM = $(LLVM_PREFIX)llvm-nm$(LLVM_SUFFIX)
491OBJCOPY = $(LLVM_PREFIX)llvm-objcopy$(LLVM_SUFFIX)
492OBJDUMP = $(LLVM_PREFIX)llvm-objdump$(LLVM_SUFFIX)
493READELF = $(LLVM_PREFIX)llvm-readelf$(LLVM_SUFFIX)
494STRIP = $(LLVM_PREFIX)llvm-strip$(LLVM_SUFFIX)
Masahiro Yamadaa0d1c952020-04-08 10:36:23 +0900495else
496CC = $(CROSS_COMPILE)gcc
497LD = $(CROSS_COMPILE)ld
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498AR = $(CROSS_COMPILE)ar
499NM = $(CROSS_COMPILE)nm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500OBJCOPY = $(CROSS_COMPILE)objcopy
501OBJDUMP = $(CROSS_COMPILE)objdump
Dmitry Golovineefb8c12019-12-05 00:54:41 +0200502READELF = $(CROSS_COMPILE)readelf
Masahiro Yamadaa0d1c952020-04-08 10:36:23 +0900503STRIP = $(CROSS_COMPILE)strip
504endif
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200505RUSTC = rustc
506RUSTDOC = rustdoc
507RUSTFMT = rustfmt
508CLIPPY_DRIVER = clippy-driver
509BINDGEN = bindgen
510CARGO = cargo
Andrii Nakryikoe83b9f52019-04-02 09:49:50 -0700511PAHOLE = pahole
Jiri Olsac9a0f3b2020-07-11 23:53:24 +0200512RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
Masahiro Yamada73a4f6d2017-12-10 01:02:28 +0900513LEX = flex
514YACC = bison
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515AWK = awk
Sam Ravnborgcaa27b62009-07-20 21:37:11 +0200516INSTALLKERNEL := installkernel
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517PERL = perl
Masahiro Yamadae9781b52018-03-13 18:12:02 +0900518PYTHON3 = python3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700519CHECK = sparse
Masahiro Yamada858805b2019-08-25 22:28:37 +0900520BASH = bash
Denis Efremove4a42c82020-06-08 12:59:44 +0300521KGZIP = gzip
522KBZIP2 = bzip2
523KLZOP = lzop
Denis Efremov8dfb61d2020-06-05 10:39:55 +0300524LZMA = lzma
525LZ4 = lz4c
526XZ = xz
Nick Terrell48f7ddf2020-07-30 12:08:36 -0700527ZSTD = zstd
Denis Efremov8dfb61d2020-06-05 10:39:55 +0300528
Hannes Eder80a7d1d2008-12-27 22:38:44 +0100529CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
Luc Van Oostenryck6c49f352018-02-15 22:07:50 +0100530 -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
Douglas Anderson0c22be02019-03-14 16:41:59 -0700531NOSTDINC_FLAGS :=
Sam Ravnborg65881692010-07-28 17:33:09 +0200532CFLAGS_MODULE =
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200533RUSTFLAGS_MODULE =
Sam Ravnborg65881692010-07-28 17:33:09 +0200534AFLAGS_MODULE =
535LDFLAGS_MODULE =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536CFLAGS_KERNEL =
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200537RUSTFLAGS_KERNEL =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700538AFLAGS_KERNEL =
Masahiro Yamada8debed32023-01-09 04:23:17 +0900539LDFLAGS_vmlinux =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700540
David Howellsabbf1592012-10-02 18:01:26 +0100541# Use USERINCLUDE when you must reference the UAPI directories only.
542USERINCLUDE := \
Masahiro Yamada9d022c52017-10-04 12:56:04 +0900543 -I$(srctree)/arch/$(SRCARCH)/include/uapi \
544 -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
David Howellsabbf1592012-10-02 18:01:26 +0100545 -I$(srctree)/include/uapi \
Arnd Bergmann3308b282016-06-15 17:45:45 +0200546 -I$(objtree)/include/generated/uapi \
Masahiro Yamadace6ed1c2021-03-04 20:37:08 +0900547 -include $(srctree)/include/linux/compiler-version.h \
David Howellsabbf1592012-10-02 18:01:26 +0100548 -include $(srctree)/include/linux/kconfig.h
549
Linus Torvalds1da177e2005-04-16 15:20:36 -0700550# Use LINUXINCLUDE when you must reference the include/ directory.
551# Needed to be compatible with the O= option
David Howellsabbf1592012-10-02 18:01:26 +0100552LINUXINCLUDE := \
Masahiro Yamada9d022c52017-10-04 12:56:04 +0900553 -I$(srctree)/arch/$(SRCARCH)/include \
554 -I$(objtree)/arch/$(SRCARCH)/include/generated \
Masahiro Yamada051f2782019-07-06 12:07:12 +0900555 $(if $(building_out_of_srctree),-I$(srctree)/include) \
Masahiro Yamadaf8224f72017-06-06 16:15:28 +0900556 -I$(objtree)/include \
557 $(USERINCLUDE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
Masahiro Yamada42a92bc2018-12-14 17:05:37 +0900559KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
Alexey Dobriyan0817d252023-07-13 21:52:28 +0300560
561KBUILD_CFLAGS :=
562KBUILD_CFLAGS += -std=gnu11
563KBUILD_CFLAGS += -fshort-wchar
564KBUILD_CFLAGS += -funsigned-char
565KBUILD_CFLAGS += -fno-common
566KBUILD_CFLAGS += -fno-PIE
567KBUILD_CFLAGS += -fno-strict-aliasing
Alexey Dobriyan0817d252023-07-13 21:52:28 +0300568
Masahiro Yamada433dc2e2017-10-12 18:22:25 +0900569KBUILD_CPPFLAGS := -D__KERNEL__
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200570KBUILD_RUSTFLAGS := $(rust_common_flags) \
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200571 -Cpanic=abort -Cembed-bitcode=n -Clto=n \
572 -Cforce-unwind-tables=n -Ccodegen-units=1 \
573 -Csymbol-mangling-version=v0 \
574 -Crelocation-model=static \
575 -Zfunction-sections=n \
576 -Dclippy::float_arithmetic
577
Sam Ravnborg80c00ba2010-07-28 19:11:27 +0200578KBUILD_AFLAGS_KERNEL :=
579KBUILD_CFLAGS_KERNEL :=
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200580KBUILD_RUSTFLAGS_KERNEL :=
Sam Ravnborg65881692010-07-28 17:33:09 +0200581KBUILD_AFLAGS_MODULE := -DMODULE
582KBUILD_CFLAGS_MODULE := -DMODULE
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200583KBUILD_RUSTFLAGS_MODULE := --cfg MODULE
Masahiro Yamada10df0632019-08-15 01:06:22 +0900584KBUILD_LDFLAGS_MODULE :=
Masahiro Yamadad503ac52018-08-24 08:20:39 +0900585KBUILD_LDFLAGS :=
Masahiro Yamada5241ab4c2019-07-29 18:15:17 +0900586CLANG_FLAGS :=
Linus Torvalds1da177e2005-04-16 15:20:36 -0700587
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200588ifeq ($(KBUILD_CLIPPY),1)
589 RUSTC_OR_CLIPPY_QUIET := CLIPPY
590 RUSTC_OR_CLIPPY = $(CLIPPY_DRIVER)
591else
592 RUSTC_OR_CLIPPY_QUIET := RUSTC
593 RUSTC_OR_CLIPPY = $(RUSTC)
594endif
595
596ifdef RUST_LIB_SRC
597 export RUST_LIB_SRC
598endif
599
600# Allows the usage of unstable features in stable compilers.
601export RUSTC_BOOTSTRAP := 1
602
Chun-Tse Shaod5ea4fe2022-04-01 23:18:02 +0000603export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC HOSTPKG_CONFIG
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200604export RUSTC RUSTDOC RUSTFMT RUSTC_OR_CLIPPY_QUIET RUSTC_OR_CLIPPY BINDGEN CARGO
605export HOSTRUSTC KBUILD_HOSTRUSTFLAGS
Vasily Gorbikd9b56652020-10-23 13:57:32 +0200606export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
Masahiro Yamadad8d2d382021-02-01 10:00:24 +0900607export PERL PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
Nick Terrell48f7ddf2020-07-30 12:08:36 -0700608export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD
Vasily Gorbik7bac9872019-01-21 13:54:39 +0100609export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
Elliot Bermanf67695c92022-02-01 13:35:42 -0800610export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611
Masahiro Yamadad503ac52018-08-24 08:20:39 +0900612export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
Andrey Konovalov0e410e12018-02-06 15:36:00 -0800613export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200614export KBUILD_RUSTFLAGS RUSTFLAGS_KERNEL RUSTFLAGS_MODULE
Sam Ravnborg222d3942007-10-15 21:59:31 +0200615export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200616export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_RUSTFLAGS_MODULE KBUILD_LDFLAGS_MODULE
617export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL KBUILD_RUSTFLAGS_KERNEL
Linus Torvalds1da177e2005-04-16 15:20:36 -0700618
Linus Torvalds1da177e2005-04-16 15:20:36 -0700619# Files to ignore in find ... statements
620
Prarit Bhargavaae63b2d2014-02-06 07:51:42 -0500621export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \
622 -name CVS -o -name .pc -o -name .hg -o -name .git \) \
623 -prune -o
Linus Torvalds1da177e2005-04-16 15:20:36 -0700624
625# ===========================================================================
626# Rules shared between *config targets and build targets
627
Cao jin312a3d02017-08-02 10:31:06 +0800628# Basic helpers built in scripts/basic/
Paul Smith4f193362006-03-05 17:14:10 -0500629PHONY += scripts_basic
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630scripts_basic:
631 $(Q)$(MAKE) $(build)=scripts/basic
632
Paul Smith4f193362006-03-05 17:14:10 -0500633PHONY += outputmakefile
Masahiro Yamada2728fcf2021-05-17 16:03:11 +0900634ifdef building_out_of_srctree
Masahiro Yamadae8e83a22019-08-22 13:46:11 +0900635# Before starting out-of-tree build, make sure the source tree is clean.
Jan Beulichfd5f0cd2006-05-02 12:33:20 +0200636# outputmakefile generates a Makefile in the output directory, if using a
637# separate output directory. This allows convenient use of make in the
638# output directory.
Vladimir Kondratiev3a51ff32019-02-03 10:48:40 +0200639# At the same time when output Makefile generated, generate .gitignore to
640# ignore whole output directory
Masahiro Yamada2728fcf2021-05-17 16:03:11 +0900641
642quiet_cmd_makefile = GEN Makefile
643 cmd_makefile = { \
644 echo "\# Automatically generated by $(srctree)/Makefile: don't edit"; \
645 echo "include $(srctree)/Makefile"; \
646 } > Makefile
647
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648outputmakefile:
Masahiro Yamada4b098652022-09-24 17:24:25 +0900649 @if [ -f $(srctree)/.config -o \
Masahiro Yamadae8e83a22019-08-22 13:46:11 +0900650 -d $(srctree)/include/config -o \
651 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
652 echo >&2 "***"; \
653 echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
654 echo >&2 "*** in $(abs_srctree)";\
655 echo >&2 "***"; \
656 false; \
657 fi
Andi Kleen92979992009-01-10 04:56:13 +0100658 $(Q)ln -fsn $(srctree) source
Masahiro Yamada2728fcf2021-05-17 16:03:11 +0900659 $(call cmd,makefile)
Masahiro Yamada156e7cb2019-03-26 13:26:58 +0900660 $(Q)test -e .gitignore || \
661 { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
Jan Beulichfd5f0cd2006-05-02 12:33:20 +0200662endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
Nick Desaulniersdb075622021-02-05 14:01:25 -0800664# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
665# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
666# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
667# and from include/config/auto.conf.cmd to detect the compiler upgrade.
Masahiro Yamada6072b2c2021-08-01 11:53:46 +0900668CC_VERSION_TEXT = $(subst $(pound),,$(shell LC_ALL=C $(CC) --version 2>/dev/null | head -n 1))
Nick Desaulniersdb075622021-02-05 14:01:25 -0800669
670ifneq ($(findstring clang,$(CC_VERSION_TEXT)),)
Nick Desaulniers6f5b41a2021-08-02 11:39:08 -0700671include $(srctree)/scripts/Makefile.clang
Chris Friesae6b2892017-11-07 11:46:13 -0800672endif
673
Masahiro Yamada57fd2512021-02-28 15:10:27 +0900674# Include this also for config targets because some architectures need
675# cc-cross-prefix to determine CROSS_COMPILE.
Masahiro Yamada805b2e12021-02-28 15:10:28 +0900676ifdef need-compiler
Masahiro Yamada57fd2512021-02-28 15:10:27 +0900677include $(srctree)/scripts/Makefile.compiler
Masahiro Yamada805b2e12021-02-28 15:10:28 +0900678endif
Masahiro Yamada57fd2512021-02-28 15:10:27 +0900679
Masahiro Yamada2042b542019-08-11 00:53:03 +0900680ifdef config-build
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681# ===========================================================================
682# *config targets only - make sure prerequisites are updated, and descend
683# in scripts/kconfig to make the *config target
684
Simon Glass766b7002023-10-26 20:26:23 +1300685# Read arch-specific Makefile to set KBUILD_DEFCONFIG as needed.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686# KBUILD_DEFCONFIG may point out an alternative default configuration
687# used for 'make defconfig'
Masahiro Yamada3204a7f2021-02-28 15:10:26 +0900688include $(srctree)/arch/$(SRCARCH)/Makefile
Masahiro Yamada315bab42018-06-08 09:21:43 +0900689export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690
Masahiro Yamada36de0772019-08-22 13:46:13 +0900691config: outputmakefile scripts_basic FORCE
Sam Ravnborg31110eb2008-12-13 23:00:45 +0100692 $(Q)$(MAKE) $(build)=scripts/kconfig $@
693
Masahiro Yamada36de0772019-08-22 13:46:13 +0900694%config: outputmakefile scripts_basic FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695 $(Q)$(MAKE) $(build)=scripts/kconfig $@
696
Masahiro Yamada2042b542019-08-11 00:53:03 +0900697else #!config-build
Linus Torvalds1da177e2005-04-16 15:20:36 -0700698# ===========================================================================
Simon Glass766b7002023-10-26 20:26:23 +1300699# Build targets only - this includes vmlinux, arch-specific targets, clean
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700# targets and others. In general all targets except *config targets.
701
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900702# If building an external module we do not care about the all: rule
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900703# but instead __all depend on modules
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900704PHONY += all
705ifeq ($(KBUILD_EXTMOD),)
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900706__all: all
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900707else
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900708__all: modules
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900709endif
710
Masahiro Yamada32164842022-09-25 03:19:14 +0900711targets :=
712
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900713# Decide whether to build built-in, modular, or both.
714# Normally, just do built-in.
715
716KBUILD_MODULES :=
717KBUILD_BUILTIN := 1
718
719# If we have only "make modules", don't compile built-in objects.
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900720ifeq ($(MAKECMDGOALS),modules)
Masahiro Yamada4b50c8c2020-05-31 17:47:06 +0900721 KBUILD_BUILTIN :=
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900722endif
723
724# If we have "make <whatever> modules", compile modules
725# in addition to whatever we do anyway.
726# Just "make" or "make all" shall build modules as well
727
Nathan Huckleberry6ad7cbc2020-08-22 23:56:18 +0900728ifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECMDGOALS)),)
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900729 KBUILD_MODULES := 1
730endif
731
732ifeq ($(MAKECMDGOALS),)
733 KBUILD_MODULES := 1
734endif
735
736export KBUILD_MODULES KBUILD_BUILTIN
737
Masahiro Yamada2042b542019-08-11 00:53:03 +0900738ifdef need-config
Masahiro Yamadad93a18f2019-04-27 12:33:36 +0900739include include/config/auto.conf
740endif
741
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742ifeq ($(KBUILD_EXTMOD),)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743# Objects we will link into vmlinux / subdirs we need to visit
Masahiro Yamada57501212022-09-25 03:19:10 +0900744core-y :=
745drivers-y :=
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746libs-y := lib/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700747endif # KBUILD_EXTMOD
748
Masahiro Yamada315bab42018-06-08 09:21:43 +0900749# The all: target is the default when no target is given on the
750# command line.
751# This allow a user to issue only 'make' to build a kernel including modules
752# Defaults to vmlinux, but the arch makefile usually adds further targets
753all: vmlinux
754
Nick Desaulniers7d73c3e2021-08-16 13:25:01 -0700755CFLAGS_GCOV := -fprofile-arcs -ftest-coverage
756ifdef CONFIG_CC_IS_GCC
757CFLAGS_GCOV += -fno-tree-loop-im
758endif
Masahiro Yamada5aadfde2018-05-28 18:22:04 +0900759export CFLAGS_GCOV
Masahiro Yamada315bab42018-06-08 09:21:43 +0900760
Paulo Zanonib1f4ff72018-09-10 10:59:56 -0700761# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
762ifdef CONFIG_FUNCTION_TRACER
763 CC_FLAGS_FTRACE := -pg
764endif
765
Masahiro Yamada3204a7f2021-02-28 15:10:26 +0900766include $(srctree)/arch/$(SRCARCH)/Makefile
Masahiro Yamada315bab42018-06-08 09:21:43 +0900767
Masahiro Yamada2042b542019-08-11 00:53:03 +0900768ifdef need-config
769ifdef may-sync-config
Masahiro Yamada315bab42018-06-08 09:21:43 +0900770# Read in dependencies to all Kconfig* files, make sure to run syncconfig if
771# changes are detected. This should be included after arch/$(SRCARCH)/Makefile
772# because some architectures define CROSS_COMPILE there.
Masahiro Yamadad2f8ae02019-05-12 11:13:48 +0900773include include/config/auto.conf.cmd
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774
Masahiro Yamada05850712019-02-22 16:40:11 +0900775$(KCONFIG_CONFIG):
776 @echo >&2 '***'
777 @echo >&2 '*** Configuration file "$@" not found!'
778 @echo >&2 '***'
779 @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or'
780 @echo >&2 '*** "make menuconfig" or "make xconfig").'
781 @echo >&2 '***'
782 @/bin/false
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783
Ulf Magnusson61277982018-02-13 08:58:20 +0100784# The actual configuration files used during the build are stored in
785# include/generated/ and include/config/. Update them if .config is newer than
786# include/config/auto.conf (which mirrors .config).
Masahiro Yamada9390dff2019-02-22 16:40:10 +0900787#
788# This exploits the 'multi-target pattern rule' trick.
789# The syncconfig should be executed only once to make all the targets.
Masahiro Yamadaf463c352020-03-25 12:16:30 +0900790# (Note: use the grouped target '&:' when we bump to GNU Make 4.3)
Masahiro Yamadad952cfa2021-07-14 13:23:49 +0900791#
792# Do not use $(call cmd,...) here. That would suppress prompts from syncconfig,
793# so you cannot notice that Kconfig is waiting for the user input.
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200794%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h %/generated/rustc_cfg: $(KCONFIG_CONFIG)
Masahiro Yamadad952cfa2021-07-14 13:23:49 +0900795 $(Q)$(kecho) " SYNC $@"
796 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
Masahiro Yamada2042b542019-08-11 00:53:03 +0900797else # !may-sync-config
Masahiro Yamadad7942412018-07-20 16:46:34 +0900798# External modules and some install targets need include/generated/autoconf.h
799# and include/config/auto.conf but do not care if they are up-to-date.
800# Use auto.conf to trigger the test
Sam Ravnborg9ee4e332006-08-07 21:01:36 +0200801PHONY += include/config/auto.conf
802
803include/config/auto.conf:
Masahiro Yamada4b098652022-09-24 17:24:25 +0900804 @test -e include/generated/autoconf.h -a -e $@ || ( \
Michal Marek5369f552012-07-07 23:04:40 +0200805 echo >&2; \
806 echo >&2 " ERROR: Kernel configuration is invalid."; \
807 echo >&2 " include/generated/autoconf.h or $@ are missing.";\
808 echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
809 echo >&2 ; \
Sam Ravnborg9ee4e332006-08-07 21:01:36 +0200810 /bin/false)
811
Masahiro Yamadad7942412018-07-20 16:46:34 +0900812endif # may-sync-config
Masahiro Yamada2042b542019-08-11 00:53:03 +0900813endif # need-config
Linus Torvalds1da177e2005-04-16 15:20:36 -0700814
Nick Desaulniers7d73c3e2021-08-16 13:25:01 -0700815KBUILD_CFLAGS += -fno-delete-null-pointer-checks
Geert Uytterhoevena1c48bb2014-05-27 09:54:12 +0200816
Masahiro Yamada15f5db62019-08-21 02:09:40 +0900817ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
818KBUILD_CFLAGS += -O2
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200819KBUILD_RUSTFLAGS += -Copt-level=2
Masahiro Yamada15f5db62019-08-21 02:09:40 +0900820else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
821KBUILD_CFLAGS += -Os
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200822KBUILD_RUSTFLAGS += -Copt-level=s
Arnd Bergmann815eb712016-04-25 17:35:28 +0200823endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700824
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200825# Always set `debug-assertions` and `overflow-checks` because their default
826# depends on `opt-level` and `debug-assertions`, respectively.
827KBUILD_RUSTFLAGS += -Cdebug-assertions=$(if $(CONFIG_RUST_DEBUG_ASSERTIONS),y,n)
828KBUILD_RUSTFLAGS += -Coverflow-checks=$(if $(CONFIG_RUST_OVERFLOW_CHECKS),y,n)
829
Jiri Kosina69102312014-08-06 16:08:43 -0700830# Tell gcc to never replace conditional load with a non-conditional one
Nick Desaulniers7d73c3e2021-08-16 13:25:01 -0700831ifdef CONFIG_CC_IS_GCC
832# gcc-10 renamed --param=allow-store-data-races=0 to
833# -fno-allow-store-data-races.
Jiri Kosina69102312014-08-06 16:08:43 -0700834KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
Sergei Trofimovichb1112132020-03-17 00:07:18 +0000835KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races)
Nick Desaulniers7d73c3e2021-08-16 13:25:01 -0700836endif
Jiri Kosina69102312014-08-06 16:08:43 -0700837
Andi Kleen1873e872012-03-28 11:51:18 -0700838ifdef CONFIG_READABLE_ASM
839# Disable optimizations that make assembler listings hard to read.
840# reorder blocks reorders the control in the function
841# ipa clone creates specialized cloned functions
842# partial inlining inlines only parts of functions
Nick Desaulniers7d73c3e2021-08-16 13:25:01 -0700843KBUILD_CFLAGS += -fno-reorder-blocks -fno-ipa-cp-clone -fno-partial-inlining
Andi Kleen1873e872012-03-28 11:51:18 -0700844endif
845
Masahiro Yamada893ab0042020-06-27 03:59:12 +0900846stackp-flags-y := -fno-stack-protector
Linus Torvalds050e9ba2018-06-14 12:21:18 +0900847stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector
848stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
Masahiro Yamada2a61f472018-05-28 18:22:00 +0900849
850KBUILD_CFLAGS += $(stackp-flags-y)
Sam Ravnborge06b8b92008-02-13 22:43:28 +0100851
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200852KBUILD_RUSTFLAGS-$(CONFIG_WERROR) += -Dwarnings
853KBUILD_RUSTFLAGS += $(KBUILD_RUSTFLAGS-y)
854
Linus Torvalds1da177e2005-04-16 15:20:36 -0700855ifdef CONFIG_FRAME_POINTER
Sam Ravnborga0f97e02007-10-14 22:21:35 +0200856KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200857KBUILD_RUSTFLAGS += -Cforce-frame-pointers=y
Linus Torvalds1da177e2005-04-16 15:20:36 -0700858else
Rabin Vincent7e9501f2010-08-10 19:20:53 +0100859# Some targets (ARM with Thumb2, for example), can't be built with frame
860# pointers. For those, we don't have FUNCTION_TRACER automatically
861# select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is
862# incompatible with -fomit-frame-pointer with current GCC, so we don't use
863# -fomit-frame-pointer with FUNCTION_TRACER.
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200864# In the Rust target specification, "frame-pointer" is set explicitly
865# to "may-omit".
Rabin Vincent7e9501f2010-08-10 19:20:53 +0100866ifndef CONFIG_FUNCTION_TRACER
Sam Ravnborga0f97e02007-10-14 22:21:35 +0200867KBUILD_CFLAGS += -fomit-frame-pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868endif
Rabin Vincent7e9501f2010-08-10 19:20:53 +0100869endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870
glider@google.comf0fe00d2020-06-16 10:34:35 +0200871# Initialize all stack variables with a 0xAA pattern.
872ifdef CONFIG_INIT_STACK_ALL_PATTERN
Kees Cook709a9722019-04-10 08:48:31 -0700873KBUILD_CFLAGS += -ftrivial-auto-var-init=pattern
874endif
875
glider@google.comf0fe00d2020-06-16 10:34:35 +0200876# Initialize all stack variables with a zero value.
877ifdef CONFIG_INIT_STACK_ALL_ZERO
glider@google.comf0fe00d2020-06-16 10:34:35 +0200878KBUILD_CFLAGS += -ftrivial-auto-var-init=zero
Kees Cook607e57c2022-09-29 22:57:43 -0700879ifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER
880# https://github.com/llvm/llvm-project/issues/44842
Nathan Chancellor4e3feaa2023-01-24 09:19:28 -0700881CC_AUTO_VAR_INIT_ZERO_ENABLER := -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
882export CC_AUTO_VAR_INIT_ZERO_ENABLER
883KBUILD_CFLAGS += $(CC_AUTO_VAR_INIT_ZERO_ENABLER)
glider@google.comf0fe00d2020-06-16 10:34:35 +0200884endif
Kees Cookf02003c2021-09-14 12:49:03 -0700885endif
glider@google.comf0fe00d2020-06-16 10:34:35 +0200886
Kees Cook39218ff2021-04-01 16:23:44 -0700887# While VLAs have been removed, GCC produces unreachable stack probes
888# for the randomize_kstack_offset feature. Disable it for all compilers.
889KBUILD_CFLAGS += $(call cc-option, -fno-stack-clash-protection)
890
Kees Cooka82adfd2021-04-12 19:56:54 -0700891# Clear used registers at func exit (to reduce data lifetime and ROP gadgets).
892ifdef CONFIG_ZERO_CALL_USED_REGS
893KBUILD_CFLAGS += -fzero-call-used-regs=used-gpr
894endif
895
Steven Rostedt606576c2008-10-06 19:06:12 -0400896ifdef CONFIG_FUNCTION_TRACER
Sami Tolvanen3b15cdc12020-12-11 10:46:18 -0800897ifdef CONFIG_FTRACE_MCOUNT_USE_CC
898 CC_FLAGS_FTRACE += -mrecord-mcount
Vasily Gorbik2f4df002018-08-06 15:17:46 +0200899 ifdef CONFIG_HAVE_NOP_MCOUNT
900 ifeq ($(call cc-option-yn, -mnop-mcount),y)
901 CC_FLAGS_FTRACE += -mnop-mcount
902 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
903 endif
904 endif
Steven Rostedta2546fa2011-02-09 13:15:59 -0500905endif
Sami Tolvanen22c85422020-09-25 16:43:53 -0700906ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
Sathvika Vasireddy280981d2022-11-14 23:27:49 +0530907 ifdef CONFIG_HAVE_OBJTOOL_NOP_MCOUNT
908 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
909 endif
Sami Tolvanen22c85422020-09-25 16:43:53 -0700910endif
Sami Tolvanen3b15cdc12020-12-11 10:46:18 -0800911ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
912 ifdef CONFIG_HAVE_C_RECORDMCOUNT
913 BUILD_C_RECORDMCOUNT := y
914 export BUILD_C_RECORDMCOUNT
915 endif
916endif
Steven Rostedta2546fa2011-02-09 13:15:59 -0500917ifdef CONFIG_HAVE_FENTRY
Nick Desaulniers7d73c3e2021-08-16 13:25:01 -0700918 # s390-linux-gnu-gcc did not support -mfentry until gcc-9.
Vasily Gorbikf28bc3c2018-08-06 15:17:42 +0200919 ifeq ($(call cc-option-yn, -mfentry),y)
920 CC_FLAGS_FTRACE += -mfentry
921 CC_FLAGS_USING += -DCC_USING_FENTRY
922 endif
Steven Rostedta2546fa2011-02-09 13:15:59 -0500923endif
Vasily Gorbikf28bc3c2018-08-06 15:17:42 +0200924export CC_FLAGS_FTRACE
925KBUILD_CFLAGS += $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING)
926KBUILD_AFLAGS += $(CC_FLAGS_USING)
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200927endif
928
Sam Ravnborg91341d42008-01-21 21:31:44 +0100929# We trigger additional mismatches with less inlining
930ifdef CONFIG_DEBUG_SECTION_MISMATCH
Nick Desaulniers7d73c3e2021-08-16 13:25:01 -0700931KBUILD_CFLAGS += -fno-inline-functions-called-once
Sam Ravnborg91341d42008-01-21 21:31:44 +0100932endif
933
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200934# `rustc`'s `-Zfunction-sections` applies to data too (as of 1.59.0).
Masahiro Yamada90ad4052017-04-14 15:17:26 +0900935ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
Masahiro Yamadae85d1d62018-08-22 22:51:09 +0900936KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
Miguel Ojeda2f7ab122021-07-03 16:42:57 +0200937KBUILD_RUSTFLAGS_KERNEL += -Zfunction-sections=y
Masahiro Yamadae85d1d62018-08-22 22:51:09 +0900938LDFLAGS_vmlinux += --gc-sections
Masahiro Yamada90ad4052017-04-14 15:17:26 +0900939endif
940
Sami Tolvanend08b9f02020-04-27 09:00:07 -0700941ifdef CONFIG_SHADOW_CALL_STACK
Ard Biesheuvel9beccca2022-10-27 17:59:07 +0200942ifndef CONFIG_DYNAMIC_SCS
Sami Tolvanend08b9f02020-04-27 09:00:07 -0700943CC_FLAGS_SCS := -fsanitize=shadow-call-stack
944KBUILD_CFLAGS += $(CC_FLAGS_SCS)
Ard Biesheuvel9beccca2022-10-27 17:59:07 +0200945endif
Sami Tolvanend08b9f02020-04-27 09:00:07 -0700946export CC_FLAGS_SCS
947endif
948
Sami Tolvanendc5723b2020-12-11 10:46:19 -0800949ifdef CONFIG_LTO_CLANG
950ifdef CONFIG_LTO_CLANG_THIN
Alexander Lobakin2b868952021-01-21 18:45:55 +0000951CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit
Sami Tolvanendc5723b2020-12-11 10:46:19 -0800952else
Alexander Lobakin2b868952021-01-21 18:45:55 +0000953CC_FLAGS_LTO := -flto
Sami Tolvanendc5723b2020-12-11 10:46:19 -0800954endif
955CC_FLAGS_LTO += -fvisibility=hidden
Sami Tolvanen22d429e2020-12-11 10:46:21 -0800956
957# Limit inlining across translation units to reduce binary size
958KBUILD_LDFLAGS += -mllvm -import-instr-limit=5
Tor Vic02365262021-06-13 13:07:49 +0000959endif
Sami Tolvanendc5723b2020-12-11 10:46:19 -0800960
961ifdef CONFIG_LTO
Sami Tolvanen5e953252021-02-23 13:59:52 -0800962KBUILD_CFLAGS += -fno-lto $(CC_FLAGS_LTO)
963KBUILD_AFLAGS += -fno-lto
Sami Tolvanendc5723b2020-12-11 10:46:19 -0800964export CC_FLAGS_LTO
965endif
966
Sami Tolvanencf68fff2021-04-08 11:28:26 -0700967ifdef CONFIG_CFI_CLANG
Sami Tolvanen89245602022-09-08 14:54:47 -0700968CC_FLAGS_CFI := -fsanitize=kcfi
Sami Tolvanencf68fff2021-04-08 11:28:26 -0700969KBUILD_CFLAGS += $(CC_FLAGS_CFI)
970export CC_FLAGS_CFI
971endif
972
Samuel Holland6cbd1d62024-03-29 00:18:16 -0700973# Architectures can define flags to add/remove for floating-point support
974CC_FLAGS_FPU += -D_LINUX_FPU_COMPILATION_UNIT
975export CC_FLAGS_FPU
976export CC_FLAGS_NO_FPU
977
Peter Zijlstrad49a0622022-09-15 13:10:47 +0200978ifneq ($(CONFIG_FUNCTION_ALIGNMENT),0)
Petr Pavlu52703162024-02-22 14:35:00 +0100979# Set the minimal function alignment. Use the newer GCC option
980# -fmin-function-alignment if it is available, or fall back to -falign-funtions.
981# See also CONFIG_CC_HAS_SANE_FUNCTION_ALIGNMENT.
982ifdef CONFIG_CC_HAS_MIN_FUNCTION_ALIGNMENT
983KBUILD_CFLAGS += -fmin-function-alignment=$(CONFIG_FUNCTION_ALIGNMENT)
984else
Peter Zijlstrad49a0622022-09-15 13:10:47 +0200985KBUILD_CFLAGS += -falign-functions=$(CONFIG_FUNCTION_ALIGNMENT)
Feng Tang09c60542020-08-11 18:34:13 -0700986endif
Petr Pavlu52703162024-02-22 14:35:00 +0100987endif
Feng Tang09c60542020-08-11 18:34:13 -0700988
Sam Ravnborge8e69932005-04-30 16:51:42 -0700989# arch Makefile may override CC so keep this after arch Makefile is included
Alexey Dobriyan04e85bb2021-08-02 23:43:15 +0300990NOSTDINC_FLAGS += -nostdinc
Sam Ravnborge8e69932005-04-30 16:51:42 -0700991
Kees Cookdf8fc4e2023-05-17 16:18:11 -0700992# To gain proper coverage for CONFIG_UBSAN_BOUNDS and CONFIG_FORTIFY_SOURCE,
993# the kernel uses only C99 flexible arrays for dynamically sized trailing
994# arrays. Enforce this for everything that may examine structure sizes and
995# perform bounds checking.
996KBUILD_CFLAGS += $(call cc-option, -fstrict-flex-arrays=3)
997
Gustavo A. R. Silvaa5e0ace02023-11-30 14:29:34 -0600998#Currently, disable -Wstringop-overflow for GCC 11, globally.
999KBUILD_CFLAGS-$(CONFIG_CC_NO_STRINGOP_OVERFLOW) += $(call cc-option, -Wno-stringop-overflow)
1000KBUILD_CFLAGS-$(CONFIG_CC_STRINGOP_OVERFLOW) += $(call cc-option, -Wstringop-overflow)
Gustavo A. R. Silva113a6182023-10-31 17:50:11 -06001001
Kirill Smelkovfe8d0a42009-04-09 15:34:34 +04001002# disable invalid "can't wrap" optimizations for signed / pointers
Masahiro Yamada8b42cf22020-09-10 22:51:17 +09001003KBUILD_CFLAGS += -fno-strict-overflow
Linus Torvaldsd0115552009-03-19 15:53:19 -07001004
Linus Torvalds3ce120b2017-12-29 17:34:43 -08001005# Make sure -fstack-check isn't enabled (like gentoo apparently did)
Masahiro Yamada7d4eb0d2020-09-10 22:51:19 +09001006KBUILD_CFLAGS += -fno-stack-check
Linus Torvalds3ce120b2017-12-29 17:34:43 -08001007
Andi Kleen8f7f5c92009-09-18 12:49:37 -07001008# conserve stack if available
Nick Desaulniers7d73c3e2021-08-16 13:25:01 -07001009ifdef CONFIG_CC_IS_GCC
1010KBUILD_CFLAGS += -fconserve-stack
1011endif
Andi Kleen8f7f5c92009-09-18 12:49:37 -07001012
Masahiro Yamadaa73619a2018-03-30 13:15:26 +09001013# change __FILE__ to the relative path from the srctree
Denys Zagoruia716bd72020-11-02 04:08:53 -08001014KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
Masahiro Yamadaa73619a2018-03-30 13:15:26 +09001015
Masahiro Yamadae0fe0bb2020-08-02 00:00:49 +09001016# include additional Makefiles when needed
1017include-y := scripts/Makefile.extrawarn
Masahiro Yamada6947fd92021-10-12 12:25:03 +09001018include-$(CONFIG_DEBUG_INFO) += scripts/Makefile.debug
Masahiro Yamada72d09182023-10-19 00:19:48 +09001019include-$(CONFIG_DEBUG_INFO_BTF)+= scripts/Makefile.btf
Masahiro Yamadae0fe0bb2020-08-02 00:00:49 +09001020include-$(CONFIG_KASAN) += scripts/Makefile.kasan
1021include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan
Alexander Potapenkof80be452022-09-15 17:03:45 +02001022include-$(CONFIG_KMSAN) += scripts/Makefile.kmsan
Masahiro Yamadae0fe0bb2020-08-02 00:00:49 +09001023include-$(CONFIG_UBSAN) += scripts/Makefile.ubsan
1024include-$(CONFIG_KCOV) += scripts/Makefile.kcov
Kees Cook613f4b3e2022-05-03 13:55:01 -07001025include-$(CONFIG_RANDSTRUCT) += scripts/Makefile.randstruct
Masahiro Yamadae0fe0bb2020-08-02 00:00:49 +09001026include-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins
1027
1028include $(addprefix $(srctree)/, $(include-y))
Masahiro Yamadaa86fe352014-04-14 18:27:10 +09001029
Masahiro Yamada132305b2020-08-02 00:00:50 +09001030# scripts/Makefile.gcc-plugins is intentionally included last.
1031# Do not add $(call cc-option,...) below this line. When you build the kernel
1032# from the clean source tree, the GCC plugins do not exist at this point.
Jason Baronbf5438fc2010-09-17 11:09:00 -04001033
Miguel Ojeda2f7ab122021-07-03 16:42:57 +02001034# Add user supplied CPPFLAGS, AFLAGS, CFLAGS and RUSTFLAGS as the last assignments
Masahiro Yamada8cc7af72019-08-21 02:09:41 +09001035KBUILD_CPPFLAGS += $(KCPPFLAGS)
1036KBUILD_AFLAGS += $(KAFLAGS)
1037KBUILD_CFLAGS += $(KCFLAGS)
Miguel Ojeda2f7ab122021-07-03 16:42:57 +02001038KBUILD_RUSTFLAGS += $(KRUSTFLAGS)
Sam Ravnborg52bcc332007-10-15 22:03:58 +02001039
Bill Wendlinga9684332020-09-22 16:21:40 -07001040KBUILD_LDFLAGS_MODULE += --build-id=sha1
1041LDFLAGS_vmlinux += --build-id=sha1
Roland McGrath18991192007-07-19 01:48:40 -07001042
Nick Desaulniers0d362be2022-08-10 15:24:40 -07001043KBUILD_LDFLAGS += -z noexecstack
1044ifeq ($(CONFIG_LD_IS_BFD),y)
1045KBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments)
1046endif
1047
David Howells5d7d18f2009-03-04 11:59:07 -08001048ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
Masahiro Yamada0f1fe9d2022-09-30 03:12:23 +09001049LDFLAGS_vmlinux += -X
David Howells5d7d18f2009-03-04 11:59:07 -08001050endif
1051
Peter Collingbourne5cf896fb62019-07-31 18:18:42 -07001052ifeq ($(CONFIG_RELR),y)
Fangrui Songccb2d172023-04-11 20:09:44 +00001053# ld.lld before 15 did not support -z pack-relative-relocs.
1054LDFLAGS_vmlinux += $(call ld-option,--pack-dyn-relocs=relr,-z pack-relative-relocs)
Peter Collingbourne5cf896fb62019-07-31 18:18:42 -07001055endif
1056
Nathan Chancellor59612b22020-11-19 13:46:56 -07001057# We never want expected sections to be placed heuristically by the
1058# linker. All sections should be explicitly named in the linker script.
1059ifdef CONFIG_LD_ORPHAN_WARN
Xin Lie1789d72022-10-25 00:30:23 -07001060LDFLAGS_vmlinux += --orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL)
Nathan Chancellor59612b22020-11-19 13:46:56 -07001061endif
1062
Masahiro Yamada7f3a59d2020-04-29 12:45:14 +09001063# Align the bit size of userspace programs with the kernel
Masahiro Yamada7f58b482020-07-01 00:06:25 +09001064KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
1065KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
Masahiro Yamada7f3a59d2020-04-29 12:45:14 +09001066
Luc Van Oostenryck80591e62019-11-09 13:12:16 +01001067# make the checker run with the right architecture
1068CHECKFLAGS += --arch=$(ARCH)
1069
Luc Van Oostenryck145167652018-05-28 20:27:35 +02001070# insure the checker run with the right endianness
1071CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
1072
Luc Van Oostenryck1f2f01b2018-05-30 22:48:38 +02001073# the checker needs the correct machine size
1074CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
1075
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076# Default kernel image to build when no specific target is given.
Sam Ravnborg070b98b2006-06-25 00:07:55 +02001077# KBUILD_IMAGE may be overruled on the command line or
Linus Torvalds1da177e2005-04-16 15:20:36 -07001078# set in the environment
1079# Also any assignments in arch/$(ARCH)/Makefile take precedence over
1080# this default value
1081export KBUILD_IMAGE ?= vmlinux
1082
1083#
1084# INSTALL_PATH specifies where to place the updated kernel and system map
1085# images. Default is /boot, but you can set it to other values
1086export INSTALL_PATH ?= /boot
1087
1088#
Jason Cooperf4d4ffc2013-12-01 23:56:28 +00001089# INSTALL_DTBS_PATH specifies a prefix for relocations required by build roots.
1090# Like INSTALL_MOD_PATH, it isn't defined in the Makefile, but can be passed as
1091# an argument if needed. Otherwise it defaults to the kernel install path
1092#
1093export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE)
1094
1095#
Linus Torvalds1da177e2005-04-16 15:20:36 -07001096# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
1097# relocations required by build roots. This is not defined in the
Sam Ravnborg070b98b2006-06-25 00:07:55 +02001098# makefile but the argument can be passed to make if needed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001099#
1100
Sam Ravnborgdf9df032006-01-16 12:46:07 +01001101MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001102export MODLIB
1103
Masahiro Yamadae00d8882019-01-15 16:19:00 +09001104PHONY += prepare0
Rusty Russelle2a666d2012-10-19 11:53:15 +10301105
Masahiro Yamadaccae4cf2021-03-31 22:38:07 +09001106export extmod_prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)
Masahiro Yamada7f691802021-03-31 22:38:06 +09001107export MODORDER := $(extmod_prefix)modules.order
1108export MODULES_NSDEPS := $(extmod_prefix)modules.nsdeps
Masahiro Yamada47801c92019-08-02 19:23:58 +09001109
Linus Torvalds1da177e2005-04-16 15:20:36 -07001110ifeq ($(KBUILD_EXTMOD),)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001111
Masahiro Yamada57501212022-09-25 03:19:10 +09001112build-dir := .
1113clean-dirs := $(sort . Documentation \
Masahiro Yamada23febe32020-06-01 14:56:57 +09001114 $(patsubst %/,%,$(filter %/, $(core-) \
Masahiro Yamada95fb6312020-06-01 14:56:58 +09001115 $(drivers-) $(libs-))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001116
Masahiro Yamada57501212022-09-25 03:19:10 +09001117export ARCH_CORE := $(core-y)
1118export ARCH_LIB := $(filter %/, $(libs-y))
1119export ARCH_DRIVERS := $(drivers-y) $(drivers-m)
Sam Ravnborg1f2bfbd2012-05-05 10:18:41 +02001120# Externally visible symbols (used by link-vmlinux.sh)
Masahiro Yamada57501212022-09-25 03:19:10 +09001121
Masahiro Yamada32164842022-09-25 03:19:14 +09001122KBUILD_VMLINUX_OBJS := ./built-in.a
Masahiro Yamadaf0d50ca2020-06-01 14:56:59 +09001123ifdef CONFIG_MODULES
1124KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
1125KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
1126else
1127KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
1128endif
Masahiro Yamadaf0d50ca2020-06-01 14:56:59 +09001129
Masahiro Yamada32164842022-09-25 03:19:14 +09001130export KBUILD_VMLINUX_LIBS
Sam Ravnborg95698572012-05-05 10:18:40 +02001131export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001132
Nicolas Pitre2441e782016-04-22 15:25:00 -04001133ifdef CONFIG_TRIM_UNUSED_KSYMS
Masahiro Yamada1f50b802018-03-16 16:37:13 +09001134# For the kernel to actually contain only the needed exported symbols,
1135# we have to build modules as well to determine what those symbols are.
Masahiro Yamadafb2d99b2020-05-31 19:11:39 +09001136KBUILD_MODULES := 1
Masahiro Yamada1f50b802018-03-16 16:37:13 +09001137endif
1138
Masahiro Yamada32164842022-09-25 03:19:14 +09001139# '$(AR) mPi' needs 'T' to workaround the bug of llvm-ar <= 14
1140quiet_cmd_ar_vmlinux.a = AR $@
1141 cmd_ar_vmlinux.a = \
1142 rm -f $@; \
1143 $(AR) cDPrST $@ $(KBUILD_VMLINUX_OBJS); \
Masahiro Yamadafb3041d2022-10-28 01:28:39 +09001144 $(AR) mPiT $$($(AR) t $@ | sed -n 1p) $@ $$($(AR) t $@ | grep -F -f $(srctree)/scripts/head-object-list.txt)
Nicholas Pigginfbe6e372016-08-24 22:29:21 +10001145
Masahiro Yamada32164842022-09-25 03:19:14 +09001146targets += vmlinux.a
Masahiro Yamada5e9e95cc92023-06-12 00:50:57 +09001147vmlinux.a: $(KBUILD_VMLINUX_OBJS) scripts/head-object-list.txt FORCE
Masahiro Yamada32164842022-09-25 03:19:14 +09001148 $(call if_changed,ar_vmlinux.a)
Nicolas Pitre2441e782016-04-22 15:25:00 -04001149
Masahiro Yamada7a342e62022-09-28 15:39:40 +09001150PHONY += vmlinux_o
1151vmlinux_o: vmlinux.a $(KBUILD_VMLINUX_LIBS)
Masahiro Yamada9c5a0ac2022-09-25 03:19:12 +09001152 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux_o
Sam Ravnborg741f98f2007-07-17 10:54:06 +02001153
Masahiro Yamada7a342e62022-09-28 15:39:40 +09001154vmlinux.o modules.builtin.modinfo modules.builtin: vmlinux_o
1155 @:
1156
Masahiro Yamada5d4aeff2022-09-28 15:39:41 +09001157PHONY += vmlinux
Masahiro Yamada8debed32023-01-09 04:23:17 +09001158# LDFLAGS_vmlinux in the top Makefile defines linker flags for the top vmlinux,
1159# not for decompressors. LDFLAGS_vmlinux in arch/*/boot/compressed/Makefile is
1160# unrelated; the decompressors just happen to have the same base name,
1161# arch/*/boot/compressed/vmlinux.
1162# Export LDFLAGS_vmlinux only to scripts/Makefile.vmlinux.
1163#
1164# _LDFLAGS_vmlinux is a workaround for the 'private export' bug:
1165# https://savannah.gnu.org/bugs/?61463
1166# For Make > 4.4, the following simple code will work:
1167# vmlinux: private export LDFLAGS_vmlinux := $(LDFLAGS_vmlinux)
1168vmlinux: private _LDFLAGS_vmlinux := $(LDFLAGS_vmlinux)
1169vmlinux: export LDFLAGS_vmlinux = $(_LDFLAGS_vmlinux)
Masahiro Yamada5d4aeff2022-09-28 15:39:41 +09001170vmlinux: vmlinux.o $(KBUILD_LDS) modpost
1171 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vmlinux
Masahiro Yamada392885e2018-11-30 10:05:22 +09001172
Masahiro Yamada38385f82014-04-28 16:26:18 +09001173# The actual objects are generated when descending,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174# make sure no implicit rule kicks in
Masahiro Yamada9c5a0ac2022-09-25 03:19:12 +09001175$(sort $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)): . ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001176
Masahiro Yamada1cb86b62023-01-28 01:19:42 +09001177ifeq ($(origin KERNELRELEASE),file)
Masahiro Yamadaec31f862023-01-22 23:14:25 +09001178filechk_kernel.release = $(srctree)/scripts/setlocalversion $(srctree)
Masahiro Yamada1cb86b62023-01-28 01:19:42 +09001179else
1180filechk_kernel.release = echo $(KERNELRELEASE)
1181endif
Michal Marek0d0e7712013-07-11 15:34:51 +02001182
Geert Uytterhoeven83a35e32013-06-28 11:27:31 +02001183# Store (new) KERNELRELEASE string in include/config/kernel.release
Masahiro Yamada24512792019-04-07 19:03:18 +09001184include/config/kernel.release: FORCE
Michal Marek0d0e7712013-07-11 15:34:51 +02001185 $(call filechk,kernel.release)
Sam Ravnborgcb584552006-01-09 21:20:34 +01001186
Masahiro Yamadad8821622018-03-16 16:37:11 +09001187# Additional helpers built in scripts/
1188# Carefully list dependencies so we do not try to build scripts twice
1189# in parallel
1190PHONY += scripts
Masahiro Yamada60df1ae2018-11-29 12:13:24 +09001191scripts: scripts_basic scripts_dtc
Masahiro Yamadad8821622018-03-16 16:37:11 +09001192 $(Q)$(MAKE) $(build)=$(@)
Sam Ravnborgcb584552006-01-09 21:20:34 +01001193
Linus Torvalds1da177e2005-04-16 15:20:36 -07001194# Things we need to do before we recursively start building the kernel
Sam Ravnborg5bb78262005-09-11 22:30:22 +02001195# or the modules are listed in "prepare".
1196# A multi level approach is used. prepareN is processed before prepareN-1.
1197# archprepare is used in arch Makefiles and when processed asm symlink,
1198# version.h and scripts_basic is processed / created.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001199
Masahiro Yamadaa5139fb2019-08-22 13:46:12 +09001200PHONY += prepare archprepare
Sam Ravnborg5bb78262005-09-11 22:30:22 +02001201
Masahiro Yamada36de0772019-08-22 13:46:13 +09001202archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \
Masahiro Yamada5e9e95cc92023-06-12 00:50:57 +09001203 asm-generic $(version_h) include/generated/utsrelease.h \
Masahiro Yamadaa55f2832022-08-28 11:39:54 +09001204 include/generated/compile.h include/generated/autoconf.h remove-stale-files
Sam Ravnborg5bb78262005-09-11 22:30:22 +02001205
Masahiro Yamada65bba042018-11-29 11:58:50 +09001206prepare0: archprepare
Masahiro Yamada60df1ae2018-11-29 12:13:24 +09001207 $(Q)$(MAKE) $(build)=scripts/mod
Masahiro Yamadaed7ceac2022-08-20 18:15:28 +09001208 $(Q)$(MAKE) $(build)=. prepare
Sam Ravnborg86feeaa2005-09-09 19:28:28 +02001209
Linus Torvalds1da177e2005-04-16 15:20:36 -07001210# All the preparing..
Masahiro Yamada0d989ac2021-05-12 15:52:01 +09001211prepare: prepare0
Miguel Ojeda2f7ab122021-07-03 16:42:57 +02001212ifdef CONFIG_RUST
Miguel Ojedaecab4112024-02-17 01:26:37 +01001213 +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh
Miguel Ojeda2f7ab122021-07-03 16:42:57 +02001214 $(Q)$(MAKE) $(build)=rust
1215endif
Josh Poimboeufb9ab5eb2016-02-28 22:22:42 -06001216
Masahiro Yamada1476fee2021-04-25 16:07:12 +09001217PHONY += remove-stale-files
1218remove-stale-files:
1219 $(Q)$(srctree)/scripts/remove-stale-files
1220
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +09001221# Support for using generic headers in asm-generic
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +09001222asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj
1223
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +09001224PHONY += asm-generic uapi-asm-generic
1225asm-generic: uapi-asm-generic
Masahiro Yamada037fc332019-03-17 11:01:09 +09001226 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \
1227 generic=include/asm-generic
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +09001228uapi-asm-generic:
Masahiro Yamada037fc332019-03-17 11:01:09 +09001229 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \
1230 generic=include/uapi/asm-generic
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +09001231
Linus Torvalds1da177e2005-04-16 15:20:36 -07001232# Generate some files
1233# ---------------------------------------------------------------------------
1234
1235# KERNELRELEASE can change from a few different places, meaning version.h
1236# needs to be updated, so this check is forced on all builds
1237
1238uts_len := 64
Sam Ravnborg63104ee2006-07-03 23:30:54 +02001239define filechk_utsrelease.h
Linus Torvalds1da177e2005-04-16 15:20:36 -07001240 if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
Sam Ravnborg63104ee2006-07-03 23:30:54 +02001241 echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
1242 exit 1; \
1243 fi; \
Masahiro Yamadaad774082018-12-31 17:24:09 +09001244 echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245endef
1246
Sam Ravnborg63104ee2006-07-03 23:30:54 +02001247define filechk_version.h
Sasha Levin9b82f132021-02-05 22:50:32 -05001248 if [ $(SUBLEVEL) -gt 255 ]; then \
1249 echo \#define LINUX_VERSION_CODE $(shell \
Masahiro Yamada207da4c2021-02-27 23:20:23 +09001250 expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + 255); \
Sasha Levin9b82f132021-02-05 22:50:32 -05001251 else \
1252 echo \#define LINUX_VERSION_CODE $(shell \
Masahiro Yamada207da4c2021-02-27 23:20:23 +09001253 expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \
Sasha Levin9b82f132021-02-05 22:50:32 -05001254 fi; \
1255 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \
Sasha Levin88a68672021-02-12 11:29:24 -05001256 ((c) > 255 ? 255 : (c)))'; \
1257 echo \#define LINUX_VERSION_MAJOR $(VERSION); \
1258 echo \#define LINUX_VERSION_PATCHLEVEL $(PATCHLEVEL); \
1259 echo \#define LINUX_VERSION_SUBLEVEL $(SUBLEVEL)
Sam Ravnborg63104ee2006-07-03 23:30:54 +02001260endef
1261
Masahiro Yamadad98dba82024-04-28 00:32:53 +09001262$(version_h): private PATCHLEVEL := $(or $(PATCHLEVEL), 0)
1263$(version_h): private SUBLEVEL := $(or $(SUBLEVEL), 0)
Masahiro Yamada43fee2b2018-07-25 14:16:11 +09001264$(version_h): FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001265 $(call filechk,version.h)
1266
Sam Ravnborg273b2812009-10-18 00:52:28 +02001267include/generated/utsrelease.h: include/config/kernel.release FORCE
Sam Ravnborg63104ee2006-07-03 23:30:54 +02001268 $(call filechk,utsrelease.h)
1269
Masahiro Yamadaa55f2832022-08-28 11:39:54 +09001270filechk_compile.h = $(srctree)/scripts/mkcompile_h \
1271 "$(UTS_MACHINE)" "$(CONFIG_CC_VERSION_TEXT)" "$(LD)"
1272
1273include/generated/compile.h: FORCE
1274 $(call filechk,compile.h)
1275
Vegard Nossum179efcb2008-12-16 12:33:43 +01001276PHONY += headerdep
1277headerdep:
Peter Foley9663d982011-04-26 17:17:11 -04001278 $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \
1279 $(srctree)/scripts/headerdep.pl -I$(srctree)/include
Vegard Nossum179efcb2008-12-16 12:33:43 +01001280
Linus Torvalds1da177e2005-04-16 15:20:36 -07001281# ---------------------------------------------------------------------------
David Woodhouse8d730cf2006-06-18 11:58:39 +01001282# Kernel headers
David Woodhouse8d730cf2006-06-18 11:58:39 +01001283
Sam Ravnborge6883b12008-06-05 16:43:46 +02001284#Default location for installed headers
1285export INSTALL_HDR_PATH = $(objtree)/usr
1286
Masahiro Yamada59b2bd02019-06-04 19:14:02 +09001287quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include
1288 cmd_headers_install = \
1289 mkdir -p $(INSTALL_HDR_PATH); \
1290 rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
1291 usr/include $(INSTALL_HDR_PATH)
David Woodhouse6d716272006-09-24 22:16:03 +01001292
David Woodhouse8d730cf2006-06-18 11:58:39 +01001293PHONY += headers_install
Masahiro Yamada59b2bd02019-06-04 19:14:02 +09001294headers_install: headers
1295 $(call cmd,headers_install)
Paul Smith4f193362006-03-05 17:14:10 -05001296
Linus Torvalds1da177e2005-04-16 15:20:36 -07001297PHONY += archheaders archscripts
1298
Masahiro Yamadaa5bae542019-06-04 19:14:04 +09001299hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
Linus Torvalds1da177e2005-04-16 15:20:36 -07001300
Masahiro Yamada59b2bd02019-06-04 19:14:02 +09001301PHONY += headers
1302headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
Masahiro Yamada1b620d52022-09-01 10:12:52 +09001303 $(if $(filter um, $(SRCARCH)), $(error Headers not exportable for UML))
Masahiro Yamadad5470d12019-06-04 19:14:03 +09001304 $(Q)$(MAKE) $(hdr-inst)=include/uapi
1305 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi
Mike Frysinger1f857122007-02-14 00:33:02 -08001306
Masahiro Yamadae949f4c2019-06-04 19:13:59 +09001307ifdef CONFIG_HEADERS_INSTALL
Masahiro Yamada59b2bd02019-06-04 19:14:02 +09001308prepare: headers
Masahiro Yamadae949f4c2019-06-04 19:13:59 +09001309endif
David Woodhouse68475352006-06-18 12:02:10 +01001310
Masahiro Yamadabdd77142019-06-04 19:14:01 +09001311PHONY += scripts_unifdef
1312scripts_unifdef: scripts_basic
1313 $(Q)$(MAKE) $(build)=scripts scripts/unifdef
1314
David Woodhouse8d730cf2006-06-18 11:58:39 +01001315# ---------------------------------------------------------------------------
Masahiro Yamada14ccc632021-07-29 09:12:54 +09001316# Install
1317
1318# Many distributions have the custom install script, /sbin/installkernel.
Randy Dunlap75ef3122022-04-25 20:53:18 -07001319# If DKMS is installed, 'make install' will eventually recurse back
1320# to this Makefile to build and install external modules.
Masahiro Yamada14ccc632021-07-29 09:12:54 +09001321# Cancel sub_make_done so that options such as M=, V=, etc. are parsed.
1322
Masahiro Yamadaf774f5b2022-05-03 11:47:16 +09001323quiet_cmd_install = INSTALL $(INSTALL_PATH)
1324 cmd_install = unset sub_make_done; $(srctree)/scripts/install.sh
Masahiro Yamada14ccc632021-07-29 09:12:54 +09001325
1326# ---------------------------------------------------------------------------
Masahiro Yamada56769ba2023-10-14 19:54:35 +09001327# vDSO install
1328
1329PHONY += vdso_install
1330vdso_install: export INSTALL_FILES = $(vdso-install-y)
1331vdso_install:
1332 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.vdsoinst
1333
1334# ---------------------------------------------------------------------------
Masahiro Yamada1bb0b182021-05-12 15:52:00 +09001335# Tools
1336
Josh Poimboeuf03f16cd2022-04-18 09:50:36 -07001337ifdef CONFIG_OBJTOOL
Masahiro Yamada0d989ac2021-05-12 15:52:01 +09001338prepare: tools/objtool
1339endif
1340
1341ifdef CONFIG_BPF
1342ifdef CONFIG_DEBUG_INFO_BTF
1343prepare: tools/bpf/resolve_btfids
1344endif
1345endif
1346
1347PHONY += resolve_btfids_clean
1348
1349resolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids
1350
1351# tools/bpf/resolve_btfids directory might not exist
1352# in output directory, skip its clean in that case
1353resolve_btfids_clean:
1354ifneq ($(wildcard $(resolve_btfids_O)),)
1355 $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean
1356endif
1357
Masahiro Yamada1bb0b182021-05-12 15:52:00 +09001358# Clear a bunch of variables before executing the submake
1359ifeq ($(quiet),silent_)
1360tools_silent=s
1361endif
1362
1363tools/: FORCE
1364 $(Q)mkdir -p $(objtree)/tools
1365 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
1366
1367tools/%: FORCE
1368 $(Q)mkdir -p $(objtree)/tools
1369 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
1370
1371# ---------------------------------------------------------------------------
Shuah Khan5a5da782014-08-07 13:07:46 -06001372# Kernel selftest
1373
1374PHONY += kselftest
Guillaume Tucker4062eba2022-07-13 08:33:43 +02001375kselftest: headers
Shuah Khan2bc84522017-09-06 16:44:35 -06001376 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests
Shuah Khan5a5da782014-08-07 13:07:46 -06001377
Guillaume Tucker4062eba2022-07-13 08:33:43 +02001378kselftest-%: headers FORCE
Shuah Khan17eac6c2019-09-26 16:40:14 -06001379 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
Wang Longdcb825a2015-10-08 02:41:18 +00001380
Bamvor Jian Zhang3d6dee72016-01-08 15:27:34 +08001381PHONY += kselftest-merge
1382kselftest-merge:
1383 $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!))
Björn Töpel37013b52023-10-04 14:48:37 +02001384 $(Q)find $(srctree)/tools/testing/selftests -name config -o -name config.$(UTS_MACHINE) | \
Björn Töpel6d3d6382023-10-04 14:48:36 +02001385 xargs $(srctree)/scripts/kconfig/merge_config.sh -y -m $(objtree)/.config
Masahiro Yamada3e4c6942019-08-21 16:03:48 +09001386 $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
Bamvor Jian Zhang3d6dee72016-01-08 15:27:34 +08001387
Shuah Khan5a5da782014-08-07 13:07:46 -06001388# ---------------------------------------------------------------------------
Rob Herring37c8a5f2018-01-10 15:19:37 -06001389# Devicetree files
1390
1391ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)
1392dtstree := arch/$(SRCARCH)/boot/dts
1393endif
1394
1395ifneq ($(dtstree),)
1396
Masahiro Yamadaee476202022-07-24 18:59:19 +09001397%.dtb: dtbs_prepare
Rob Herring75e89532021-12-08 15:39:16 -06001398 $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
Rob Herring37c8a5f2018-01-10 15:19:37 -06001399
Masahiro Yamadaee476202022-07-24 18:59:19 +09001400%.dtbo: dtbs_prepare
Rob Herring75e89532021-12-08 15:39:16 -06001401 $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
Viresh Kumarce88c9c2021-01-29 12:54:08 +05301402
Masahiro Yamadaee476202022-07-24 18:59:19 +09001403PHONY += dtbs dtbs_prepare dtbs_install dtbs_check
1404dtbs: dtbs_prepare
Masahiro Yamada24507872024-01-09 21:07:34 +09001405 $(Q)$(MAKE) $(build)=$(dtstree) need-dtbslist=1
Rob Herring37c8a5f2018-01-10 15:19:37 -06001406
Masahiro Yamadaee476202022-07-24 18:59:19 +09001407# include/config/kernel.release is actually needed when installing DTBs because
1408# INSTALL_DTBS_PATH contains $(KERNELRELEASE). However, we do not want to make
1409# dtbs_install depend on it as dtbs_install may run as root.
1410dtbs_prepare: include/config/kernel.release scripts_dtc
1411
Rob Herring75e89532021-12-08 15:39:16 -06001412ifneq ($(filter dtbs_check, $(MAKECMDGOALS)),)
Masahiro Yamadae10c4322020-03-04 12:20:37 +09001413export CHECK_DTBS=y
Rob Herringec201952022-12-19 19:32:33 -06001414endif
1415
1416ifneq ($(CHECK_DTBS),)
Rob Herring604a57b2024-04-05 17:56:03 -05001417dtbs_prepare: dt_binding_schemas
Masahiro Yamadab5154bf2020-03-04 12:20:36 +09001418endif
1419
Masahiro Yamadab5154bf2020-03-04 12:20:36 +09001420dtbs_check: dtbs
Rob Herring4f0e3a52018-09-06 13:26:07 -05001421
Rob Herring37c8a5f2018-01-10 15:19:37 -06001422dtbs_install:
Masahiro Yamada8f668642024-01-09 21:07:35 +09001423 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.dtbinst obj=$(dtstree)
Rob Herring37c8a5f2018-01-10 15:19:37 -06001424
1425ifdef CONFIG_OF_EARLY_FLATTREE
1426all: dtbs
1427endif
1428
1429endif
1430
1431PHONY += scripts_dtc
1432scripts_dtc: scripts_basic
1433 $(Q)$(MAKE) $(build)=scripts/dtc
1434
Masahiro Yamadae10c4322020-03-04 12:20:37 +09001435ifneq ($(filter dt_binding_check, $(MAKECMDGOALS)),)
Rob Herring604a57b2024-04-05 17:56:03 -05001436export CHECK_DTBS=y
Masahiro Yamadae10c4322020-03-04 12:20:37 +09001437endif
1438
Rob Herring604a57b2024-04-05 17:56:03 -05001439PHONY += dt_binding_check dt_binding_schemas
1440dt_binding_check: dt_binding_schemas scripts_dtc
1441 $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings $@
1442
1443dt_binding_schemas:
Rob Herring4f0e3a52018-09-06 13:26:07 -05001444 $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings
1445
Rob Herringb6acf802022-06-30 15:37:22 -06001446PHONY += dt_compatible_check
Rob Herring604a57b2024-04-05 17:56:03 -05001447dt_compatible_check: dt_binding_schemas
Rob Herringb6acf802022-06-30 15:37:22 -06001448 $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings $@
1449
Rob Herring37c8a5f2018-01-10 15:19:37 -06001450# ---------------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -07001451# Modules
1452
1453ifdef CONFIG_MODULES
1454
Sam Ravnborg070b98b2006-06-25 00:07:55 +02001455# By default, build modules as well
Linus Torvalds1da177e2005-04-16 15:20:36 -07001456
Michal Marek73d13932010-03-10 12:28:58 +01001457all: modules
Linus Torvalds1da177e2005-04-16 15:20:36 -07001458
Masahiro Yamada4b50c8c2020-05-31 17:47:06 +09001459# When we're building modules with modversions, we need to consider
1460# the built-in objects during the descend as well, in order to
1461# make sure the checksums are up to date before we record them.
1462ifdef CONFIG_MODVERSIONS
1463 KBUILD_BUILTIN := 1
1464endif
1465
Masahiro Yamada3fbb43d2014-04-28 16:32:43 +09001466# Build modules
Tejun Heo551559e2007-12-07 21:04:30 +09001467#
Linus Torvalds1da177e2005-04-16 15:20:36 -07001468
Carlos Llamasfeb113a2023-01-25 18:30:47 +00001469# *.ko are usually independent of vmlinux, but CONFIG_DEBUG_INFO_BTF_MODULES
Masahiro Yamadaf73edc82022-09-25 03:19:13 +09001470# is an exception.
1471ifdef CONFIG_DEBUG_INFO_BTF_MODULES
Masahiro Yamada74d33202023-01-10 14:48:00 +09001472KBUILD_BUILTIN := 1
Masahiro Yamadaf73edc82022-09-25 03:19:13 +09001473modules: vmlinux
1474endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001475
Masahiro Yamadaf73edc82022-09-25 03:19:13 +09001476modules: modules_prepare
Michal Mareka6c36632010-03-08 10:07:12 +01001477
Linus Torvalds1da177e2005-04-16 15:20:36 -07001478# Target to prepare building external modules
Masahiro Yamada059bc9fc2018-11-29 12:56:30 +09001479modules_prepare: prepare
Masahiro Yamada596b0472020-09-08 13:27:08 +09001480 $(Q)$(MAKE) $(build)=scripts scripts/module.lds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001481
Masahiro Yamada8ae071f2023-06-15 20:17:43 +09001482endif # CONFIG_MODULES
1483
Linus Torvalds1da177e2005-04-16 15:20:36 -07001484###
1485# Cleaning is done on three levels.
1486# make clean Delete most generated files
1487# Leave enough to build external modules
1488# make mrproper Delete the current configuration, and all generated files
1489# make distclean Remove editor backup files, patch leftover files and the like
1490
1491# Directories & files removed with 'make clean'
Masahiro Yamada1fdd7292023-08-19 20:43:01 +09001492CLEAN_FILES += vmlinux.symvers modules-only.symvers \
Masahiro Yamada3d322852020-08-22 23:56:16 +09001493 modules.builtin modules.builtin.modinfo modules.nsdeps \
Nathan Chancelloraba09152024-05-01 15:55:25 -07001494 compile_commands.json rust/test \
Maíra Canal7ea01d32023-02-03 14:37:04 -03001495 rust-project.json .vmlinux.objs .vmlinux.export.c
Linus Torvalds1da177e2005-04-16 15:20:36 -07001496
1497# Directories & files removed with 'make mrproper'
Masahiro Yamada0663c682020-05-04 17:08:07 +09001498MRPROPER_FILES += include/config include/generated \
Masahiro Yamadab0d62072022-05-29 00:47:02 +09001499 arch/$(SRCARCH)/include/generated .objdiff \
Masahiro Yamada0663c682020-05-04 17:08:07 +09001500 debian snap tar-install \
1501 .config .config.old .version \
Masahiro Yamada46457132019-07-15 23:01:49 +09001502 Module.symvers \
Masahiro Yamada5cca3602021-12-14 11:53:48 +09001503 certs/signing_key.pem \
Nayna Jainb31f2a42021-04-09 10:35:05 -04001504 certs/x509.genkey \
1505 vmlinux-gdb.py \
Masahiro Yamadaffa46bb2023-09-30 19:38:47 +09001506 rpmbuild \
Masahiro Yamadac83b16c2023-01-07 18:45:45 +09001507 rust/libmacros.so
Linus Torvalds1da177e2005-04-16 15:20:36 -07001508
1509# clean - Delete most, but leave enough to build external modules
1510#
Masahiro Yamadad98dba82024-04-28 00:32:53 +09001511clean: private rm-files := $(CLEAN_FILES)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512
Masahiro Yamada76cd3062019-08-11 00:53:05 +09001513PHONY += archclean vmlinuxclean
Linus Torvalds1da177e2005-04-16 15:20:36 -07001514
Pawel Mollbd1ee802012-10-29 11:23:02 +00001515vmlinuxclean:
1516 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
Nicholas Pigginfbe6e372016-08-24 22:29:21 +10001517 $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
Pawel Mollbd1ee802012-10-29 11:23:02 +00001518
Jiri Olsa50d3a3f2021-02-05 13:40:20 +01001519clean: archclean vmlinuxclean resolve_btfids_clean
Linus Torvalds1da177e2005-04-16 15:20:36 -07001520
1521# mrproper - Delete all generated files, including .config
1522#
Masahiro Yamadad98dba82024-04-28 00:32:53 +09001523mrproper: private rm-files := $(MRPROPER_FILES)
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -03001524mrproper-dirs := $(addprefix _mrproper_,scripts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001525
Masahiro Yamadab421b8a2019-01-14 17:29:29 +09001526PHONY += $(mrproper-dirs) mrproper
Linus Torvalds1da177e2005-04-16 15:20:36 -07001527$(mrproper-dirs):
1528 $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
1529
Masahiro Yamadab421b8a2019-01-14 17:29:29 +09001530mrproper: clean $(mrproper-dirs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001531 $(call cmd,rmfiles)
Miguel Ojeda2f7ab122021-07-03 16:42:57 +02001532 @find . $(RCS_FIND_IGNORE) \
1533 \( -name '*.rmeta' \) \
1534 -type f -print | xargs rm -f
Linus Torvalds1da177e2005-04-16 15:20:36 -07001535
1536# distclean
1537#
Paul Smith4f193362006-03-05 17:14:10 -05001538PHONY += distclean
Linus Torvalds1da177e2005-04-16 15:20:36 -07001539
1540distclean: mrproper
Masahiro Yamada19c8d9122021-05-04 19:10:56 +09001541 @find . $(RCS_FIND_IGNORE) \
Sam Ravnborg070b98b2006-06-25 00:07:55 +02001542 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
Masahiro Yamadaf78271d2017-01-22 23:02:32 +09001543 -o -name '*.bak' -o -name '#*#' -o -name '*%' \
Masahiro Yamada7a02cec2021-05-04 19:10:57 +09001544 -o -name 'core' -o -name tags -o -name TAGS -o -name 'cscope*' \
1545 -o -name GPATH -o -name GRTAGS -o -name GSYMS -o -name GTAGS \) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546 -type f -print | xargs rm -f
1547
1548
1549# Packaging of the kernel to various formats
1550# ---------------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -07001551
Arnaldo Carvalho de Melobafb6742010-06-07 07:44:25 -03001552%src-pkg: FORCE
Masahiro Yamada000ec952019-08-21 16:02:04 +09001553 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
Zach Brown031ecc62006-06-08 22:12:37 -07001554%pkg: include/config/kernel.release FORCE
Masahiro Yamada000ec952019-08-21 16:02:04 +09001555 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556
1557# Brief documentation of the typical targets used
1558# ---------------------------------------------------------------------------
1559
Segher Boessenkool5dffbe82008-04-06 22:16:07 +02001560boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig)
Konstantin Khlebnikova1e7b7b2014-10-28 17:18:20 +04001561boards := $(sort $(notdir $(boards)))
Segher Boessenkool5dffbe82008-04-06 22:16:07 +02001562board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
1563board-dirs := $(sort $(notdir $(board-dirs:/=)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001564
Masahiro Yamadafe69b422016-03-13 09:39:55 +09001565PHONY += help
Linus Torvalds1da177e2005-04-16 15:20:36 -07001566help:
1567 @echo 'Cleaning targets:'
Samuel Tardieu5ea084e2006-12-12 19:09:40 +01001568 @echo ' clean - Remove most generated files but keep the config and'
Jesper Juhl5cc8d242006-09-24 14:01:08 +02001569 @echo ' enough build support to build external modules'
Samuel Tardieu5ea084e2006-12-12 19:09:40 +01001570 @echo ' mrproper - Remove all generated files + config + various backup files'
Jesper Juhl5cc8d242006-09-24 14:01:08 +02001571 @echo ' distclean - mrproper + remove editor backup and patch files'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001572 @echo ''
Linus Torvalds1da177e2005-04-16 15:20:36 -07001573 @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
1574 @echo ''
1575 @echo 'Other generic targets:'
1576 @echo ' all - Build all targets marked with [*]'
1577 @echo '* vmlinux - Build the bare kernel'
1578 @echo '* modules - Build all modules'
Bodo Eggert9cc5d742005-11-23 20:11:34 +01001579 @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
Masahiro Yamada56769ba2023-10-14 19:54:35 +09001580 @echo ' vdso_install - Install unstripped vdso to INSTALL_MOD_PATH (default: /)'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001581 @echo ' dir/ - Build all files in dir and below'
Wang YanQing40ab87a42015-12-11 00:35:19 +08001582 @echo ' dir/file.[ois] - Build specified target only'
Vinícius Tinti433db3e2017-04-24 13:04:58 -07001583 @echo ' dir/file.ll - Build the LLVM assembly file'
1584 @echo ' (requires compiler support for LLVM assembly generation)'
Joe Perches62718972010-01-13 09:31:44 -08001585 @echo ' dir/file.lst - Build specified mixed source/assembly target only'
1586 @echo ' (requires a recent binutils and recent build (System.map))'
Sam Ravnborg155ad602005-07-07 17:56:08 -07001587 @echo ' dir/file.ko - Build module including final link'
Robert P. J. Dayc4d5ee62009-04-24 12:35:23 -04001588 @echo ' modules_prepare - Set up for building external modules'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001589 @echo ' tags/TAGS - Generate tags file for editors'
1590 @echo ' cscope - Generate cscope index'
Jianbin Kangf4ed1002011-01-14 20:07:05 +08001591 @echo ' gtags - Generate GNU GLOBAL index'
Michal Marek3f1d9a62014-07-11 15:57:24 +02001592 @echo ' kernelrelease - Output the release version string (use with make -s)'
1593 @echo ' kernelversion - Output the version stored in Makefile (use with make -s)'
1594 @echo ' image_name - Output the image name (use with make -s)'
Sam Ravnborg2fb9b1b2008-06-21 00:24:17 +02001595 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
Geert Uytterhoeven59df3232007-01-29 13:47:01 +01001596 echo ' (default: $(INSTALL_HDR_PATH))'; \
Sam Ravnborg2fb9b1b2008-06-21 00:24:17 +02001597 echo ''
Randy Dunlap31b8cc82017-05-08 15:55:08 -07001598 @echo 'Static analysers:'
Heiko Carstens66242cf2023-11-20 19:37:19 +01001599 @echo ' checkstack - Generate a list of stack hogs and consider all functions'
1600 @echo ' with a stack size larger than MINSTACKSIZE (default: 100)'
Sam Ravnborgaa025e72007-11-14 21:34:55 +01001601 @echo ' versioncheck - Sanity check on version.h usage'
Randy Dunlapec2d9872007-11-04 12:01:55 -08001602 @echo ' includecheck - Check for duplicate included header files'
Adrian Bunk295ac052007-08-24 23:04:56 +02001603 @echo ' export_report - List the usages of all exported symbols'
Nicolas Palix74425ee2010-06-06 17:15:01 +02001604 @echo ' headerdep - Detect inclusion cycles in headers'
Masahiro Yamada7f855fc82017-11-14 18:47:20 +09001605 @echo ' coccicheck - Check with Coccinelle'
Nathan Huckleberry6ad7cbc2020-08-22 23:56:18 +09001606 @echo ' clang-analyzer - Check with clang static analyzer'
1607 @echo ' clang-tidy - Check with clang-tidy'
Nicolas Palix74425ee2010-06-06 17:15:01 +02001608 @echo ''
Matthias Maennicheb8305a2019-09-06 11:32:32 +01001609 @echo 'Tools:'
1610 @echo ' nsdeps - Generate missing symbol namespace dependencies'
1611 @echo ''
Randy Dunlap31b8cc82017-05-08 15:55:08 -07001612 @echo 'Kernel selftest:'
Shuah Khane51d8da2020-03-30 12:07:11 -06001613 @echo ' kselftest - Build and run kernel selftest'
1614 @echo ' Build, install, and boot kernel before'
1615 @echo ' running kselftest on it'
1616 @echo ' Run as root for full coverage'
1617 @echo ' kselftest-all - Build kernel selftest'
1618 @echo ' kselftest-install - Build and install kernel selftest'
1619 @echo ' kselftest-clean - Remove all generated kselftest files'
1620 @echo ' kselftest-merge - Merge all the config dependencies of'
1621 @echo ' kselftest to existing .config.'
Shuah Khan5a5da782014-08-07 13:07:46 -06001622 @echo ''
Miguel Ojeda2f7ab122021-07-03 16:42:57 +02001623 @echo 'Rust targets:'
1624 @echo ' rustavailable - Checks whether the Rust toolchain is'
1625 @echo ' available and, if not, explains why.'
1626 @echo ' rustfmt - Reformat all the Rust code in the kernel'
1627 @echo ' rustfmtcheck - Checks if all the Rust code in the kernel'
1628 @echo ' is formatted, printing a diff otherwise.'
1629 @echo ' rustdoc - Generate Rust documentation'
1630 @echo ' (requires kernel .config)'
1631 @echo ' rusttest - Runs the Rust tests'
1632 @echo ' (requires kernel .config; downloads external repos)'
1633 @echo ' rust-analyzer - Generate rust-project.json rust-analyzer support file'
1634 @echo ' (requires kernel .config)'
1635 @echo ' dir/file.[os] - Build specified target only'
1636 @echo ' dir/file.rsi - Build macro expanded source, similar to C preprocessing.'
1637 @echo ' Run with RUSTFMT=n to skip reformatting if needed.'
1638 @echo ' The output is not intended to be compilable.'
1639 @echo ' dir/file.ll - Build the LLVM assembly file'
1640 @echo ''
Rob Herring37c8a5f2018-01-10 15:19:37 -06001641 @$(if $(dtstree), \
1642 echo 'Devicetree:'; \
Rob Herring604a57b2024-04-05 17:56:03 -05001643 echo '* dtbs - Build device tree blobs for enabled boards'; \
1644 echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \
1645 echo ' dt_binding_check - Validate device tree binding documents and examples'; \
1646 echo ' dt_binding_schema - Build processed device tree binding schemas'; \
1647 echo ' dtbs_check - Validate device tree source files';\
Rob Herring37c8a5f2018-01-10 15:19:37 -06001648 echo '')
1649
Randy Dunlap31b8cc82017-05-08 15:55:08 -07001650 @echo 'Userspace tools targets:'
1651 @echo ' use "make tools/help"'
1652 @echo ' or "cd tools; make help"'
1653 @echo ''
Linus Torvalds1da177e2005-04-16 15:20:36 -07001654 @echo 'Kernel packaging:'
Masahiro Yamada000ec952019-08-21 16:02:04 +09001655 @$(MAKE) -f $(srctree)/scripts/Makefile.package help
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656 @echo ''
1657 @echo 'Documentation targets:'
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -03001658 @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
Linus Torvalds1da177e2005-04-16 15:20:36 -07001659 @echo ''
Simon Glass766b7002023-10-26 20:26:23 +13001660 @echo 'Architecture-specific targets ($(SRCARCH)):'
Masahiro Yamada5c816642022-02-11 14:14:11 +09001661 @$(or $(archhelp),\
Simon Glass766b7002023-10-26 20:26:23 +13001662 echo ' No architecture-specific help defined for $(SRCARCH)')
Linus Torvalds1da177e2005-04-16 15:20:36 -07001663 @echo ''
1664 @$(if $(boards), \
1665 $(foreach b, $(boards), \
Geert Uytterhoeven42344482019-10-25 13:53:05 +02001666 printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001667 echo '')
Segher Boessenkool5dffbe82008-04-06 22:16:07 +02001668 @$(if $(board-dirs), \
1669 $(foreach b, $(board-dirs), \
1670 printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
1671 printf " %-16s - Show all of the above\\n" help-boards; \
1672 echo '')
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673
Masahiro Yamada83d98d72022-12-23 01:25:35 +09001674 @echo ' make V=n [targets] 1: verbose build'
Masahiro Yamada6ae4b982022-12-23 01:25:34 +09001675 @echo ' 2: give reason for rebuild of target'
1676 @echo ' V=1 and V=2 can be combined with V=12'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677 @echo ' make O=dir [targets] Locate all output files in "dir", including .config'
Geert Uytterhoevena64c0442019-10-25 13:52:32 +02001678 @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK'
1679 @echo ' (sparse by default)'
Dustin Kirkland701842e2006-05-23 15:57:23 -05001680 @echo ' make C=2 [targets] Force check of all c source with $$CHECK'
Ingo Molnaraf07ce32011-06-16 13:26:23 +02001681 @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections'
Masahiro Yamada89876172024-01-20 17:32:55 +09001682 @echo ' make W=n [targets] Enable extra build checks, n=1,2,3,c,e where'
Sam Ravnborg28bc20d2011-04-27 22:15:27 +02001683 @echo ' 1: warnings which may be relevant and do not occur too often'
1684 @echo ' 2: warnings which occur quite often but may still be relevant'
1685 @echo ' 3: more obscure warnings, can most likely be ignored'
Masahiro Yamada92ef4322023-11-23 18:05:40 +09001686 @echo ' c: extra checks in the configuration stage (Kconfig)'
Yann Droneaudc77d06e2022-04-08 10:46:07 +02001687 @echo ' e: warnings are being treated as errors'
Michal Mareka6de5532011-04-29 14:45:31 +02001688 @echo ' Multiple levels can be combined with W=12 or W=123'
Rob Herringec201952022-12-19 19:32:33 -06001689 @$(if $(dtstree), \
1690 echo ' make CHECK_DTBS=1 [targets] Check all generated dtb files against schema'; \
1691 echo ' This can be applied both to "dtbs" and to individual "foo.dtb" targets' ; \
1692 )
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693 @echo ''
1694 @echo 'Execute "make" or "make all" to build all targets marked with [*] '
1695 @echo 'For further info see the ./README file'
1696
1697
Segher Boessenkool5dffbe82008-04-06 22:16:07 +02001698help-board-dirs := $(addprefix help-,$(board-dirs))
1699
1700help-boards: $(help-board-dirs)
1701
Michal Marekfbae4d52014-11-28 13:31:43 +01001702boards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)))
Segher Boessenkool5dffbe82008-04-06 22:16:07 +02001703
1704$(help-board-dirs): help-%:
Simon Glass766b7002023-10-26 20:26:23 +13001705 @echo 'Architecture-specific targets ($(SRCARCH) $*):'
Segher Boessenkool5dffbe82008-04-06 22:16:07 +02001706 @$(if $(boards-per-dir), \
1707 $(foreach b, $(boards-per-dir), \
1708 printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
1709 echo '')
1710
1711
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712# Documentation targets
1713# ---------------------------------------------------------------------------
Jani Nikulae8939222017-10-09 18:26:15 +03001714DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \
Maxim Cournoyer1f050e92022-11-16 14:02:09 -05001715 linkcheckdocs dochelp refcheckdocs texinfodocs infodocs
Jani Nikula22cba312016-05-19 15:14:05 +03001716PHONY += $(DOC_TARGETS)
Masahiro Yamadabc7b752a2019-08-22 02:33:21 +09001717$(DOC_TARGETS):
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -03001718 $(Q)$(MAKE) $(build)=Documentation $@
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719
Miguel Ojeda2f7ab122021-07-03 16:42:57 +02001720
1721# Rust targets
1722# ---------------------------------------------------------------------------
1723
1724# "Is Rust available?" target
1725PHONY += rustavailable
1726rustavailable:
Miguel Ojedaecab4112024-02-17 01:26:37 +01001727 +$(Q)$(CONFIG_SHELL) $(srctree)/scripts/rust_is_available.sh && echo "Rust is available!"
Miguel Ojeda2f7ab122021-07-03 16:42:57 +02001728
1729# Documentation target
1730#
1731# Using the singular to avoid running afoul of `no-dot-config-targets`.
1732PHONY += rustdoc
1733rustdoc: prepare
1734 $(Q)$(MAKE) $(build)=rust $@
1735
1736# Testing target
1737PHONY += rusttest
1738rusttest: prepare
1739 $(Q)$(MAKE) $(build)=rust $@
1740
1741# Formatting targets
1742PHONY += rustfmt rustfmtcheck
1743
1744# We skip `rust/alloc` since we want to minimize the diff w.r.t. upstream.
1745#
1746# We match using absolute paths since `find` does not resolve them
1747# when matching, which is a problem when e.g. `srctree` is `..`.
1748# We `grep` afterwards in order to remove the directory entry itself.
1749rustfmt:
1750 $(Q)find $(abs_srctree) -type f -name '*.rs' \
1751 -o -path $(abs_srctree)/rust/alloc -prune \
1752 -o -path $(abs_objtree)/rust/test -prune \
1753 | grep -Fv $(abs_srctree)/rust/alloc \
1754 | grep -Fv $(abs_objtree)/rust/test \
1755 | grep -Fv generated \
1756 | xargs $(RUSTFMT) $(rustfmt_flags)
1757
1758rustfmtcheck: rustfmt_flags = --check
1759rustfmtcheck: rustfmt
1760
Masahiro Yamada67274c02019-02-19 18:33:02 +09001761# Misc
1762# ---------------------------------------------------------------------------
1763
Masahiro Yamada91ecf7f2022-12-29 16:43:10 +09001764PHONY += misc-check
1765misc-check:
1766 $(Q)$(srctree)/scripts/misc-check
1767
1768all: misc-check
1769
Masahiro Yamada67274c02019-02-19 18:33:02 +09001770PHONY += scripts_gdb
Masahiro Yamada7a739ce2019-06-04 19:13:57 +09001771scripts_gdb: prepare0
Masahiro Yamada1e5ff842019-02-19 18:33:04 +09001772 $(Q)$(MAKE) $(build)=scripts/gdb
Masahiro Yamada8d2e5202019-02-19 18:33:05 +09001773 $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
Masahiro Yamada67274c02019-02-19 18:33:02 +09001774
1775ifdef CONFIG_GDB_SCRIPTS
1776all: scripts_gdb
1777endif
1778
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779else # KBUILD_EXTMOD
1780
Tzafrir Cohenc753ccb2023-03-14 15:02:48 +02001781filechk_kernel.release = echo $(KERNELRELEASE)
1782
Linus Torvalds1da177e2005-04-16 15:20:36 -07001783###
1784# External module support.
1785# When building external modules the kernel used as basis is considered
1786# read-only, and no consistency checks are made and the make
1787# system is not used on the basis kernel. If updates are required
Masahiro Yamada11122b82021-05-04 19:10:58 +09001788# in the basis kernel ordinary make commands (without M=...) must be used.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001789
Masahiro Yamada62128042020-09-09 05:55:57 +09001790# We are always building only modules.
1791KBUILD_BUILTIN :=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001792KBUILD_MODULES := 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001793
Masahiro Yamada57501212022-09-25 03:19:10 +09001794build-dir := $(KBUILD_EXTMOD)
Masahiro Yamada3d322852020-08-22 23:56:16 +09001795
Masahiro Yamada7f691802021-03-31 22:38:06 +09001796compile_commands.json: $(extmod_prefix)compile_commands.json
Masahiro Yamada3d322852020-08-22 23:56:16 +09001797PHONY += compile_commands.json
1798
Masahiro Yamada76cd3062019-08-11 00:53:05 +09001799clean-dirs := $(KBUILD_EXTMOD)
Masahiro Yamadad98dba82024-04-28 00:32:53 +09001800clean: private rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \
Nathan Chancelloraba09152024-05-01 15:55:25 -07001801 $(KBUILD_EXTMOD)/compile_commands.json
Linus Torvalds1da177e2005-04-16 15:20:36 -07001802
Masahiro Yamada6072b2c2021-08-01 11:53:46 +09001803PHONY += prepare
1804# now expand this into a simple variable to reduce the cost of shell evaluations
1805prepare: CC_VERSION_TEXT := $(CC_VERSION_TEXT)
1806prepare:
Masahiro Yamada129ab0d2021-12-14 11:53:53 +09001807 @if [ "$(CC_VERSION_TEXT)" != "$(CONFIG_CC_VERSION_TEXT)" ]; then \
Masahiro Yamada6072b2c2021-08-01 11:53:46 +09001808 echo >&2 "warning: the compiler differs from the one used to build the kernel"; \
Masahiro Yamada129ab0d2021-12-14 11:53:53 +09001809 echo >&2 " The kernel was built by: $(CONFIG_CC_VERSION_TEXT)"; \
Masahiro Yamada6072b2c2021-08-01 11:53:46 +09001810 echo >&2 " You are using: $(CC_VERSION_TEXT)"; \
1811 fi
1812
Masahiro Yamadafe69b422016-03-13 09:39:55 +09001813PHONY += help
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814help:
1815 @echo ' Building external modules.'
1816 @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target'
1817 @echo ''
1818 @echo ' modules - default target, build the module(s)'
1819 @echo ' modules_install - install the module'
1820 @echo ' clean - remove generated files in module directory only'
Vinay Varma49a9ef72023-04-11 17:17:15 +08001821 @echo ' rust-analyzer - generate rust-project.json rust-analyzer support file'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001822 @echo ''
Sam Ravnborg06300b22006-01-25 07:13:18 +01001823
Masahiro Yamada5e027972023-08-23 20:50:46 +09001824ifndef CONFIG_MODULES
1825modules modules_install: __external_modules_error
Masahiro Yamada8ae071f2023-06-15 20:17:43 +09001826__external_modules_error:
1827 @echo >&2 '***'
1828 @echo >&2 '*** The present kernel disabled CONFIG_MODULES.'
1829 @echo >&2 '*** You cannot build or install external modules.'
1830 @echo >&2 '***'
1831 @false
Masahiro Yamada5e027972023-08-23 20:50:46 +09001832endif
Masahiro Yamada8ae071f2023-06-15 20:17:43 +09001833
Linus Torvalds1da177e2005-04-16 15:20:36 -07001834endif # KBUILD_EXTMOD
1835
Masahiro Yamada3e3005d2021-03-31 22:38:03 +09001836# ---------------------------------------------------------------------------
1837# Modules
1838
Masahiro Yamada151aeca2023-08-23 20:50:48 +09001839PHONY += modules modules_install modules_sign modules_prepare
Masahiro Yamada3e3005d2021-03-31 22:38:03 +09001840
Masahiro Yamada5e027972023-08-23 20:50:46 +09001841modules_install:
Masahiro Yamada151aeca2023-08-23 20:50:48 +09001842 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst \
1843 sign-only=$(if $(filter modules_install,$(MAKECMDGOALS)),,y)
1844
1845ifeq ($(CONFIG_MODULE_SIG),y)
1846# modules_sign is a subset of modules_install.
1847# 'make modules_install modules_sign' is equivalent to 'make modules_install'.
1848modules_sign: modules_install
1849 @:
1850else
1851modules_sign:
1852 @echo >&2 '***'
1853 @echo >&2 '*** CONFIG_MODULE_SIG is disabled. You cannot sign modules.'
1854 @echo >&2 '***'
1855 @false
1856endif
Masahiro Yamada3e3005d2021-03-31 22:38:03 +09001857
1858ifdef CONFIG_MODULES
1859
Masahiro Yamada57501212022-09-25 03:19:10 +09001860$(MODORDER): $(build-dir)
1861 @:
1862
Masahiro Yamadaf73edc82022-09-25 03:19:13 +09001863# KBUILD_MODPOST_NOFINAL can be set to skip the final link of modules.
1864# This is solely useful to speed up test compiles.
1865modules: modpost
1866ifneq ($(KBUILD_MODPOST_NOFINAL),1)
1867 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
1868endif
Masahiro Yamada3e3005d2021-03-31 22:38:03 +09001869
Masahiro Yamada1a998be2021-03-31 22:38:05 +09001870PHONY += modules_check
1871modules_check: $(MODORDER)
1872 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
1873
Masahiro Yamada3e3005d2021-03-31 22:38:03 +09001874else # CONFIG_MODULES
1875
Masahiro Yamada5e027972023-08-23 20:50:46 +09001876modules:
Masahiro Yamada8ae071f2023-06-15 20:17:43 +09001877 @:
Masahiro Yamada3e3005d2021-03-31 22:38:03 +09001878
Masahiro Yamadaf110e5a2022-08-28 11:39:50 +09001879KBUILD_MODULES :=
1880
Masahiro Yamada3e3005d2021-03-31 22:38:03 +09001881endif # CONFIG_MODULES
1882
Masahiro Yamadaf73edc82022-09-25 03:19:13 +09001883PHONY += modpost
1884modpost: $(if $(single-build),, $(if $(KBUILD_BUILTIN), vmlinux.o)) \
1885 $(if $(KBUILD_MODULES), modules_check)
1886 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1887
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001888# Single targets
1889# ---------------------------------------------------------------------------
1890# To build individual files in subdirectories, you can do like this:
1891#
1892# make foo/bar/baz.s
1893#
1894# The supported suffixes for single-target are listed in 'single-targets'
1895#
1896# To build only under specific subdirectories, you can do like this:
1897#
1898# make foo/bar/baz/
1899
1900ifdef single-build
1901
1902# .ko is special because modpost is needed
1903single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
Masahiro Yamadafc93a4c2022-04-07 00:30:22 +09001904single-no-ko := $(filter-out $(single-ko), $(MAKECMDGOALS)) \
1905 $(foreach x, o mod, $(patsubst %.ko, %.$x, $(single-ko)))
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001906
Masahiro Yamadaf73edc82022-09-25 03:19:13 +09001907$(single-ko): single_modules
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001908 @:
Masahiro Yamada57501212022-09-25 03:19:10 +09001909$(single-no-ko): $(build-dir)
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001910 @:
1911
Masahiro Yamadaf110e5a2022-08-28 11:39:50 +09001912# Remove MODORDER when done because it is not the real one.
Masahiro Yamadaf73edc82022-09-25 03:19:13 +09001913PHONY += single_modules
1914single_modules: $(single-no-ko) modules_prepare
Masahiro Yamadaa53da432023-01-01 15:07:09 +09001915 $(Q){ $(foreach m, $(single-ko), echo $(extmod_prefix)$(m:%.ko=%.o);) } > $(MODORDER)
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001916 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
Masahiro Yamadaf73edc82022-09-25 03:19:13 +09001917ifneq ($(KBUILD_MODPOST_NOFINAL),1)
1918 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modfinal
1919endif
Masahiro Yamadaf110e5a2022-08-28 11:39:50 +09001920 $(Q)rm -f $(MODORDER)
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001921
Masahiro Yamada57501212022-09-25 03:19:10 +09001922single-goals := $(addprefix $(build-dir)/, $(single-no-ko))
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001923
Masahiro Yamada3753af72022-10-15 05:18:11 +09001924KBUILD_MODULES := 1
1925
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001926endif
1927
Masahiro Yamadac99f3912019-08-11 00:53:04 +09001928# Preset locale variables to speed up the build process. Limit locale
1929# tweaks to this spot to avoid wrong language settings when running
1930# make menuconfig etc.
1931# Error messages still appears in the original language
Masahiro Yamada57501212022-09-25 03:19:10 +09001932PHONY += $(build-dir)
1933$(build-dir): prepare
1934 $(Q)$(MAKE) $(build)=$@ need-builtin=1 need-modorder=1 $(single-goals)
Masahiro Yamadac99f3912019-08-11 00:53:04 +09001935
Masahiro Yamada76cd3062019-08-11 00:53:05 +09001936clean-dirs := $(addprefix _clean_, $(clean-dirs))
1937PHONY += $(clean-dirs) clean
1938$(clean-dirs):
1939 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1940
Michal Marek88d7be02010-09-06 12:00:08 +02001941clean: $(clean-dirs)
Michal Marek88d7be02010-09-06 12:00:08 +02001942 $(call cmd,rmfiles)
Masahiro Yamada5c816642022-02-11 14:14:11 +09001943 @find $(or $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
Miguel Ojeda2f7ab122021-07-03 16:42:57 +02001944 \( -name '*.[aios]' -o -name '*.rsi' -o -name '*.ko' -o -name '.*.cmd' \
Rob Herring4f0e3a52018-09-06 13:26:07 -05001945 -o -name '*.ko.*' \
Andrew Davisdcad2402022-11-14 14:59:39 -06001946 -o -name '*.dtb' -o -name '*.dtbo' \
1947 -o -name '*.dtb.S' -o -name '*.dtbo.S' \
Masahiro Yamada24507872024-01-09 21:07:34 +09001948 -o -name '*.dt.yaml' -o -name 'dtbs-list' \
Masahiro Yamadaef46d9b2017-11-17 01:49:13 +09001949 -o -name '*.dwo' -o -name '*.lst' \
Masahiro Yamada5e9e95cc92023-06-12 00:50:57 +09001950 -o -name '*.su' -o -name '*.mod' \
Michal Marek88d7be02010-09-06 12:00:08 +02001951 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
Masahiro Yamada9a8dfb32018-03-23 22:04:31 +09001952 -o -name '*.lex.c' -o -name '*.tab.[ch]' \
Masahiro Yamada4fa8bc92018-03-23 22:04:37 +09001953 -o -name '*.asn1.[ch]' \
Michal Marek88d7be02010-09-06 12:00:08 +02001954 -o -name '*.symtypes' -o -name 'modules.order' \
Emese Revfy6b90bd42016-05-24 00:09:38 +02001955 -o -name '*.c.[012]*.*' \
Vinícius Tinti433db3e2017-04-24 13:04:58 -07001956 -o -name '*.ll' \
Sami Tolvanen38e89182020-12-11 10:46:20 -08001957 -o -name '*.gcno' \
Thomas Weißschuh9c73bcf2023-01-18 05:05:34 +00001958 -o -name '*.*.symversions' \) -type f -print \
1959 -o -name '.tmp_*' -print \
1960 | xargs rm -rf
Michal Marek88d7be02010-09-06 12:00:08 +02001961
Linus Torvalds1da177e2005-04-16 15:20:36 -07001962# Generate tags for editors
1963# ---------------------------------------------------------------------------
Sam Ravnborga680eed2008-12-03 22:24:13 +01001964quiet_cmd_tags = GEN $@
Masahiro Yamada858805b2019-08-25 22:28:37 +09001965 cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@
Linus Torvalds1da177e2005-04-16 15:20:36 -07001966
Jianbin Kangf4ed1002011-01-14 20:07:05 +08001967tags TAGS cscope gtags: FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001968 $(call cmd,tags)
1969
Vinay Varma49a9ef72023-04-11 17:17:15 +08001970# IDE support targets
1971PHONY += rust-analyzer
1972rust-analyzer:
1973 $(Q)$(MAKE) $(build)=rust $@
1974
Matthias Maennicheb8305a2019-09-06 11:32:32 +01001975# Script to generate missing namespace dependencies
1976# ---------------------------------------------------------------------------
1977
1978PHONY += nsdeps
Masahiro Yamadabff9c622019-10-29 21:38:06 +09001979nsdeps: export KBUILD_NSDEPS=1
Matthias Maennicheb8305a2019-09-06 11:32:32 +01001980nsdeps: modules
Masahiro Yamadabff9c622019-10-29 21:38:06 +09001981 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps
Matthias Maennicheb8305a2019-09-06 11:32:32 +01001982
Masahiro Yamada3d322852020-08-22 23:56:16 +09001983# Clang Tooling
1984# ---------------------------------------------------------------------------
1985
1986quiet_cmd_gen_compile_commands = GEN $@
1987 cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
1988
Masahiro Yamada7f691802021-03-31 22:38:06 +09001989$(extmod_prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \
Masahiro Yamada32164842022-09-25 03:19:14 +09001990 $(if $(KBUILD_EXTMOD),, vmlinux.a $(KBUILD_VMLINUX_LIBS)) \
Masahiro Yamada3d322852020-08-22 23:56:16 +09001991 $(if $(CONFIG_MODULES), $(MODORDER)) FORCE
1992 $(call if_changed,gen_compile_commands)
1993
Masahiro Yamada7f691802021-03-31 22:38:06 +09001994targets += $(extmod_prefix)compile_commands.json
Masahiro Yamada3d322852020-08-22 23:56:16 +09001995
Nathan Huckleberry6ad7cbc2020-08-22 23:56:18 +09001996PHONY += clang-tidy clang-analyzer
1997
1998ifdef CONFIG_CC_IS_CLANG
1999quiet_cmd_clang_tools = CHECK $<
2000 cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $<
2001
Masahiro Yamada7f691802021-03-31 22:38:06 +09002002clang-tidy clang-analyzer: $(extmod_prefix)compile_commands.json
Nathan Huckleberry6ad7cbc2020-08-22 23:56:18 +09002003 $(call cmd,clang_tools)
2004else
2005clang-tidy clang-analyzer:
2006 @echo "$@ requires CC=clang" >&2
2007 @false
2008endif
2009
Linus Torvalds1da177e2005-04-16 15:20:36 -07002010# Scripts to check various things for consistency
2011# ---------------------------------------------------------------------------
2012
Jacob Keller7dfbea42020-10-09 17:18:44 -07002013PHONY += includecheck versioncheck coccicheck export_report
Peter Foley279f3dd2011-04-26 17:15:01 -04002014
Linus Torvalds1da177e2005-04-16 15:20:36 -07002015includecheck:
Peter Foley436f8762011-04-26 17:18:29 -04002016 find $(srctree)/* $(RCS_FIND_IGNORE) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002017 -name '*.[hcS]' -type f -print | sort \
Geert Uytterhoeven80007432007-11-05 11:51:44 +01002018 | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019
2020versioncheck:
Peter Foley2ee2d292011-04-26 17:19:28 -04002021 find $(srctree)/* $(RCS_FIND_IGNORE) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002022 -name '*.[hcS]' -type f -print | sort \
Geert Uytterhoeven80007432007-11-05 11:51:44 +01002023 | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
Linus Torvalds1da177e2005-04-16 15:20:36 -07002024
Nicolas Palix74425ee2010-06-06 17:15:01 +02002025coccicheck:
Masahiro Yamada858805b2019-08-25 22:28:37 +09002026 $(Q)$(BASH) $(srctree)/scripts/$@
Nicolas Palix74425ee2010-06-06 17:15:01 +02002027
Adrian Bunk295ac052007-08-24 23:04:56 +02002028export_report:
2029 $(PERL) $(srctree)/scripts/export_report.pl
2030
Mike Marciniszync398ff02013-06-24 08:48:37 -04002031PHONY += checkstack kernelrelease kernelversion image_name
Jeff Dikee3ccf6e2006-09-27 01:50:37 -07002032
Jeff Dike011e3a92006-12-13 00:34:12 -08002033# UML needs a little special treatment here. It wants to use the host
2034# toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone
2035# else wants $(ARCH), including people doing cross-builds, which means
2036# that $(SUBARCH) doesn't work here.
2037ifeq ($(ARCH), um)
2038CHECKSTACK_ARCH := $(SUBARCH)
2039else
2040CHECKSTACK_ARCH := $(ARCH)
2041endif
Heiko Carstens66242cf2023-11-20 19:37:19 +01002042MINSTACKSIZE ?= 100
Linus Torvalds1da177e2005-04-16 15:20:36 -07002043checkstack:
2044 $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
Heiko Carstens66242cf2023-11-20 19:37:19 +01002045 $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH) $(MINSTACKSIZE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
Amerigo Wang7b8ea532010-08-20 05:36:06 -04002047kernelrelease:
Masahiro Yamada1cb86b62023-01-28 01:19:42 +09002048 @$(filechk_kernel.release)
Amerigo Wang01ab1782010-06-28 10:45:21 +08002049
Sam Ravnborgcb584552006-01-09 21:20:34 +01002050kernelversion:
Sam Ravnborg2244cbd2006-01-16 12:12:12 +01002051 @echo $(KERNELVERSION)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
Mike Marciniszync398ff02013-06-24 08:48:37 -04002053image_name:
2054 @echo $(KBUILD_IMAGE)
2055
Masahiro Yamada76a48b82023-07-22 13:47:55 +09002056PHONY += run-command
2057run-command:
2058 $(Q)$(KBUILD_RUN_COMMAND)
2059
Linus Torvalds1da177e2005-04-16 15:20:36 -07002060quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
Masahiro Yamada0663c682020-05-04 17:08:07 +09002061 cmd_rmfiles = rm -rf $(rm-files)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002062
Masahiro Yamada392885e2018-11-30 10:05:22 +09002063# read saved command lines for existing targets
2064existing-targets := $(wildcard $(sort $(targets)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07002065
Masahiro Yamadab9999232019-02-22 16:40:08 +09002066-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002067
SZ Lin (林上智)46b7c492020-03-01 00:09:58 +08002068endif # config-build
Masahiro Yamada2042b542019-08-11 00:53:03 +09002069endif # mixed-build
2070endif # need-sub-make
Linus Torvalds1da177e2005-04-16 15:20:36 -07002071
Paul Smith4f193362006-03-05 17:14:10 -05002072PHONY += FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -07002073FORCE:
Paul Smith4f193362006-03-05 17:14:10 -05002074
Ulf Magnussonbd412d82018-07-05 12:33:07 +09002075# Declare the contents of the PHONY variable as phony. We keep that
Kirill Smelkovfe8d0a42009-04-09 15:34:34 +04002076# information in a variable so we can use it in if_changed and friends.
Paul Smith4f193362006-03-05 17:14:10 -05002077.PHONY: $(PHONY)