blob: a8b4d45eb790f952fcb690829365ecdf31009501 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001# SPDX-License-Identifier: GPL-2.0
Linus Torvaldsbfeffd12019-01-06 17:08:20 -08002VERSION = 5
Linus Torvalds3650b222020-10-25 15:14:11 -07003PATCHLEVEL = 10
Greg Kroah-Hartmana8d81222023-10-10 21:53:40 +02004SUBLEVEL = 198
Linus Torvalds2c85ebc2020-12-13 14:41:30 -08005EXTRAVERSION =
Greg Kroah-Hartman7b43ec82021-02-26 10:13:02 +01006NAME = Dare mighty things
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 Yamada121c2a12020-05-11 12:50:13 +090014$(if $(filter __%, $(MAKECMDGOALS)), \
15 $(error targets prefixed with '__' are only for internal use))
16
Masahiro Yamadaba634ec2017-10-04 12:56:05 +090017# That's our default target when none is given on the command line
Masahiro Yamada121c2a12020-05-11 12:50:13 +090018PHONY := __all
19__all:
Masahiro Yamadaba634ec2017-10-04 12:56:05 +090020
Linus Torvalds1da177e2005-04-16 15:20:36 -070021# We are using a recursive build, so we need to do a little thinking
22# to get the ordering right.
23#
24# Most importantly: sub-Makefiles should only ever modify files in
25# their own directory. If in some directory we have a dependency on
26# a file in another dir (which doesn't happen often, but it's often
Nicholas Pigginf49821e2018-02-11 00:25:04 +100027# unavoidable when linking the built-in.a targets which finally
Linus Torvalds1da177e2005-04-16 15:20:36 -070028# turn into vmlinux), we will call a sub make in that other dir, and
29# after that we are sure that everything which is in that other dir
30# is now up to date.
31#
32# The only cases where we need to modify files which have global
33# effects are thus separated out and done before the recursive
34# descending is started. They are now explicitly listed as the
35# prepare rule.
36
Masahiro Yamada221cc2d2019-03-26 13:02:19 +090037ifneq ($(sub_make_done),1)
Masahiro Yamada3812b8c2019-02-22 16:40:07 +090038
39# Do not use make's built-in rules and variables
40# (this increases performance and avoids hard-to-debug behaviour)
41MAKEFLAGS += -rR
42
43# Avoid funny character set dependencies
44unexport LC_ALL
45LC_COLLATE=C
46LC_NUMERIC=C
47export LC_COLLATE LC_NUMERIC
48
49# Avoid interference with shell env settings
50unexport GREP_OPTIONS
51
Michal Marek066b7ed2014-07-04 14:29:30 +020052# Beautify output
53# ---------------------------------------------------------------------------
54#
55# Normally, we echo the whole command before executing it. By making
56# that echo $($(quiet)$(cmd)), we now have the possibility to set
57# $(quiet) to choose other forms of output instead, e.g.
58#
59# quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
60# cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
61#
62# If $(quiet) is empty, the whole command will be printed.
63# If it is set to "quiet_", only the short version will be printed.
64# If it is set to "silent_", nothing will be printed at all, since
65# the variable $(silent_cmd_cc_o_c) doesn't exist.
66#
67# A simple variant is to prefix commands with $(Q) - that's useful
68# for commands that shall be hidden in non-verbose mode.
69#
70# $(Q)ln $@ :<
71#
72# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
73# If KBUILD_VERBOSE equals 1 then the above command is displayed.
Randy Dunlap505b12b2020-02-12 20:40:57 -080074# If KBUILD_VERBOSE equals 2 then give the reason why each target is rebuilt.
Michal Marek066b7ed2014-07-04 14:29:30 +020075#
Linus Torvalds1da177e2005-04-16 15:20:36 -070076# To put more focus on warnings, be less verbose as default
77# Use 'make V=1' to see the full commands
78
Cheng Renquanb8b06182009-05-26 16:03:07 +080079ifeq ("$(origin V)", "command line")
80 KBUILD_VERBOSE = $(V)
Linus Torvalds1da177e2005-04-16 15:20:36 -070081endif
82ifndef KBUILD_VERBOSE
83 KBUILD_VERBOSE = 0
84endif
85
Michal Marek066b7ed2014-07-04 14:29:30 +020086ifeq ($(KBUILD_VERBOSE),1)
87 quiet =
88 Q =
89else
90 quiet=quiet_
91 Q = @
92endif
93
94# If the user is running make -s (silent mode), suppress echoing of
95# commands
Dmitry Goncharov322df542022-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 Goncharov322df542022-12-05 16:48:19 -050098ifeq ($(filter 3.%,$(MAKE_VERSION)),)
99silence:=$(findstring s,$(firstword -$(MAKEFLAGS)))
100else
101silence:=$(findstring s,$(filter-out --%,$(MAKEFLAGS)))
102endif
103
104ifeq ($(silence),s)
105quiet=silent_
Michal Marek066b7ed2014-07-04 14:29:30 +0200106endif
Michal Marek066b7ed2014-07-04 14:29:30 +0200107
108export quiet Q KBUILD_VERBOSE
109
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900110# Kbuild will save output files in the current working directory.
111# This does not need to match to the root of the kernel source tree.
112#
113# For example, you can do this:
114#
115# cd /dir/to/store/output/files; make -f /dir/to/kernel/source/Makefile
116#
117# If you want to save output files in a different location, there are
118# two syntaxes to specify it.
119#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120# 1) O=
121# Use "make O=dir/to/store/output/files/"
Sam Ravnborg070b98b2006-06-25 00:07:55 +0200122#
Linus Torvalds1da177e2005-04-16 15:20:36 -0700123# 2) Set KBUILD_OUTPUT
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900124# Set the environment variable KBUILD_OUTPUT to point to the output directory.
125# export KBUILD_OUTPUT=dir/to/store/output/files/; make
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126#
127# The O= assignment takes precedence over the KBUILD_OUTPUT environment
128# variable.
129
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900130# Do we want to change the working directory?
Cheng Renquanb8b06182009-05-26 16:03:07 +0800131ifeq ("$(origin O)", "command line")
132 KBUILD_OUTPUT := $(O)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700133endif
134
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900135ifneq ($(KBUILD_OUTPUT),)
136# Make's built-in functions such as $(abspath ...), $(realpath ...) cannot
137# expand a shell special character '~'. We use a somewhat tedious way here.
138abs_objtree := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) && pwd)
139$(if $(abs_objtree),, \
140 $(error failed to create output directory "$(KBUILD_OUTPUT)"))
141
142# $(realpath ...) resolves symlinks
143abs_objtree := $(realpath $(abs_objtree))
144else
145abs_objtree := $(CURDIR)
146endif # ifneq ($(KBUILD_OUTPUT),)
147
148ifeq ($(abs_objtree),$(CURDIR))
149# Suppress "Entering directory ..." unless we are changing the work directory.
150MAKEFLAGS += --no-print-directory
151else
152need-sub-make := 1
Robert Jarzmik51193b72016-04-02 21:38:53 +0200153endif
154
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900155abs_srctree := $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900157ifneq ($(words $(subst :, ,$(abs_srctree))), 1)
158$(error source directory cannot contain spaces or colons)
159endif
160
161ifneq ($(abs_srctree),$(abs_objtree))
Masahiro Yamada80463f12018-09-14 15:33:23 +0900162# Look for make include files relative to root of kernel src
163#
164# This does not become effective immediately because MAKEFLAGS is re-parsed
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900165# once after the Makefile is read. We need to invoke sub-make.
166MAKEFLAGS += --include-dir=$(abs_srctree)
Masahiro Yamada688931a2019-03-19 13:02:36 +0900167need-sub-make := 1
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900168endif
Masahiro Yamada3812b8c2019-02-22 16:40:07 +0900169
Masahiro Yamada93fdddf2020-05-11 12:50:12 +0900170this-makefile := $(lastword $(MAKEFILE_LIST))
171
Masahiro Yamada688931a2019-03-19 13:02:36 +0900172ifneq ($(filter 3.%,$(MAKE_VERSION)),)
173# 'MAKEFLAGS += -rR' does not immediately become effective for GNU Make 3.x
174# We need to invoke sub-make to avoid implicit rules in the top Makefile.
175need-sub-make := 1
176# Cancel implicit rules for this Makefile.
Masahiro Yamada93fdddf2020-05-11 12:50:12 +0900177$(this-makefile): ;
Masahiro Yamada688931a2019-03-19 13:02:36 +0900178endif
179
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900180export abs_srctree abs_objtree
Masahiro Yamada221cc2d2019-03-26 13:02:19 +0900181export sub_make_done := 1
182
Masahiro Yamada688931a2019-03-19 13:02:36 +0900183ifeq ($(need-sub-make),1)
184
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900185PHONY += $(MAKECMDGOALS) __sub-make
Milton Miller0b357862007-09-21 18:09:02 -0500186
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900187$(filter-out $(this-makefile), $(MAKECMDGOALS)) __all: __sub-make
Charles Keepax16f89092012-10-15 13:49:12 +0100188 @:
Milton Miller0b357862007-09-21 18:09:02 -0500189
Cao jinc4e6fff2017-06-30 10:45:43 +0800190# Invoke a second make in the output directory, passing relevant variables
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900191__sub-make:
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900192 $(Q)$(MAKE) -C $(abs_objtree) -f $(abs_srctree)/Makefile $(MAKECMDGOALS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Masahiro Yamada688931a2019-03-19 13:02:36 +0900194endif # need-sub-make
Masahiro Yamada221cc2d2019-03-26 13:02:19 +0900195endif # sub_make_done
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
197# We process the rest of the Makefile if this is the final invocation of make
Masahiro Yamada688931a2019-03-19 13:02:36 +0900198ifeq ($(need-sub-make),)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199
Masahiro Yamada7ff52572014-09-09 20:02:22 +0900200# Do not print "Entering directory ...",
201# but we want to display it when entering to the output directory
202# so that IDEs/editors are able to understand relative filenames.
203MAKEFLAGS += --no-print-directory
204
Masahiro Yamadaaa55c8e2014-09-09 20:02:24 +0900205# Call a source code checker (by default, "sparse") as part of the
206# C compilation.
207#
208# Use 'make C=1' to enable checking of only re-compiled files.
209# Use 'make C=2' to enable checking of *all* source files, regardless
210# of whether they are re-compiled or not.
211#
Cao jin036db112017-03-24 17:03:17 +0800212# See the file "Documentation/dev-tools/sparse.rst" for more details,
213# including where to get the "sparse" utility.
Masahiro Yamadaaa55c8e2014-09-09 20:02:24 +0900214
215ifeq ("$(origin C)", "command line")
216 KBUILD_CHECKSRC = $(C)
217endif
218ifndef KBUILD_CHECKSRC
219 KBUILD_CHECKSRC = 0
220endif
221
Masahiro Yamada7e35b422019-09-21 16:05:41 +0900222# Use make M=dir or set the environment variable KBUILD_EXTMOD to specify the
223# directory of external module to build. Setting M= takes precedence.
Masahiro Yamadaaa55c8e2014-09-09 20:02:24 +0900224ifeq ("$(origin M)", "command line")
225 KBUILD_EXTMOD := $(M)
226endif
227
Masahiro Yamadae9e81b62020-05-25 00:42:15 +0900228$(if $(word 2, $(KBUILD_EXTMOD)), \
229 $(error building multiple external modules is not supported))
230
Masahiro Yamada051f2782019-07-06 12:07:12 +0900231export KBUILD_CHECKSRC KBUILD_EXTMOD
232
Masahiro Yamada394053f2019-08-15 00:19:18 +0900233extmod-prefix = $(if $(KBUILD_EXTMOD),$(KBUILD_EXTMOD)/)
234
Elliot Berman7d5e1de2021-04-07 08:03:11 -0700235# ANDROID: set up mixed-build support. mixed-build allows device kernel modules
236# to be compiled against a GKI kernel. This approach still uses the headers and
237# Kbuild from device kernel, so care must be taken to ensure that those headers match.
238ifdef KBUILD_MIXED_TREE
239# Need vmlinux.symvers for modpost and System.map for depmod, check whether they exist in KBUILD_MIXED_TREE
240required_mixed_files=vmlinux.symvers System.map
241$(if $(filter-out $(words $(required_mixed_files)), \
242 $(words $(wildcard $(add-prefix $(KBUILD_MIXED_TREE)/,$(required_mixed_files))))),,\
243 $(error KBUILD_MIXED_TREE=$(KBUILD_MIXED_TREE) doesn't contain $(required_mixed_files)))
244endif
245
246mixed-build-prefix = $(if $(KBUILD_MIXED_TREE),$(KBUILD_MIXED_TREE)/)
247export KBUILD_MIXED_TREE
248
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900249ifeq ($(abs_srctree),$(abs_objtree))
Michal Marek9da07632014-04-25 23:25:18 +0200250 # building in the source tree
251 srctree := .
Masahiro Yamada051f2782019-07-06 12:07:12 +0900252 building_out_of_srctree :=
Michal Marek9da07632014-04-25 23:25:18 +0200253else
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900254 ifeq ($(abs_srctree)/,$(dir $(abs_objtree)))
Michal Marek9da07632014-04-25 23:25:18 +0200255 # building in a subdirectory of the source tree
256 srctree := ..
257 else
Masahiro Yamada25b146c2019-03-30 21:04:14 +0900258 srctree := $(abs_srctree)
Michal Marek9da07632014-04-25 23:25:18 +0200259 endif
Masahiro Yamada051f2782019-07-06 12:07:12 +0900260 building_out_of_srctree := 1
Michal Marek9da07632014-04-25 23:25:18 +0200261endif
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900262
Masahiro Yamada95fd3f82019-07-06 12:07:13 +0900263ifneq ($(KBUILD_ABS_SRCTREE),)
264srctree := $(abs_srctree)
265endif
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900266
Michal Marek7e1c0472014-04-25 17:29:45 +0200267objtree := .
Masahiro Yamada6b12de62019-02-22 16:40:09 +0900268VPATH := $(srctree)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700269
Masahiro Yamada051f2782019-07-06 12:07:12 +0900270export building_out_of_srctree srctree objtree VPATH
Linus Torvalds1da177e2005-04-16 15:20:36 -0700271
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900272# To make sure we do not include .config for any of the *config targets
273# catch them early, and hand them over to scripts/kconfig/Makefile
274# It is allowed to specify more targets when calling make, including
275# mixing *config targets and build targets.
276# For example 'make oldconfig all'.
277# Detect when mixed targets is specified, and make a second invocation
278# of make so .config is not included in this case either (for *config).
279
280version_h := include/generated/uapi/linux/version.h
281old_version_h := include/linux/version.h
282
Masahiro Yamada22340a02018-02-11 17:40:29 +0900283clean-targets := %clean mrproper cleandocs
284no-dot-config-targets := $(clean-targets) \
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900285 cscope gtags TAGS tags help% %docs check% coccicheck \
Masahiro Yamada59b2bd02019-06-04 19:14:02 +0900286 $(version_h) headers headers_% archheaders archscripts \
David Engraf46239802020-03-26 20:29:33 +0100287 %asm-generic kernelversion %src-pkg dt_binding_check \
288 outputmakefile
Masahiro Yamadaede8be32021-02-28 15:10:25 +0900289no-sync-config-targets := $(no-dot-config-targets) %install kernelrelease \
290 image_name
Masahiro Yamada394053f2019-08-15 00:19:18 +0900291single-targets := %.a %.i %.ko %.lds %.ll %.lst %.mod %.o %.s %.symtypes %/
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900292
Masahiro Yamada2042b542019-08-11 00:53:03 +0900293config-build :=
294mixed-build :=
295need-config := 1
296may-sync-config := 1
Masahiro Yamada394053f2019-08-15 00:19:18 +0900297single-build :=
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900298
299ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
300 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
Masahiro Yamada2042b542019-08-11 00:53:03 +0900301 need-config :=
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900302 endif
303endif
304
Masahiro Yamadad7942412018-07-20 16:46:34 +0900305ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
306 ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
Masahiro Yamada2042b542019-08-11 00:53:03 +0900307 may-sync-config :=
Masahiro Yamadad7942412018-07-20 16:46:34 +0900308 endif
309endif
310
311ifneq ($(KBUILD_EXTMOD),)
Masahiro Yamada2042b542019-08-11 00:53:03 +0900312 may-sync-config :=
Masahiro Yamadad7942412018-07-20 16:46:34 +0900313endif
314
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900315ifeq ($(KBUILD_EXTMOD),)
Masahiro Yamadaefbf9722020-08-12 23:49:23 +0900316 ifneq ($(filter %config,$(MAKECMDGOALS)),)
Masahiro Yamada2042b542019-08-11 00:53:03 +0900317 config-build := 1
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900318 ifneq ($(words $(MAKECMDGOALS)),1)
Masahiro Yamada2042b542019-08-11 00:53:03 +0900319 mixed-build := 1
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900320 endif
321 endif
322endif
Masahiro Yamada22340a02018-02-11 17:40:29 +0900323
Masahiro Yamada394053f2019-08-15 00:19:18 +0900324# We cannot build single targets and the others at the same time
325ifneq ($(filter $(single-targets), $(MAKECMDGOALS)),)
326 single-build := 1
327 ifneq ($(filter-out $(single-targets), $(MAKECMDGOALS)),)
328 mixed-build := 1
329 endif
330endif
331
Masahiro Yamada22340a02018-02-11 17:40:29 +0900332# For "make -j clean all", "make -j mrproper defconfig all", etc.
333ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
334 ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
Masahiro Yamada2042b542019-08-11 00:53:03 +0900335 mixed-build := 1
Masahiro Yamada22340a02018-02-11 17:40:29 +0900336 endif
337endif
338
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900339# install and modules_install need also be processed one by one
340ifneq ($(filter install,$(MAKECMDGOALS)),)
341 ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
Masahiro Yamada2042b542019-08-11 00:53:03 +0900342 mixed-build := 1
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900343 endif
344endif
345
Masahiro Yamada2042b542019-08-11 00:53:03 +0900346ifdef mixed-build
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900347# ===========================================================================
348# We're called with mixed targets (*config and build targets).
349# Handle them one by one.
350
351PHONY += $(MAKECMDGOALS) __build_one_by_one
352
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900353$(MAKECMDGOALS): __build_one_by_one
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900354 @:
355
356__build_one_by_one:
357 $(Q)set -e; \
358 for i in $(MAKECMDGOALS); do \
359 $(MAKE) -f $(srctree)/Makefile $$i; \
360 done
361
Masahiro Yamada2042b542019-08-11 00:53:03 +0900362else # !mixed-build
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900363
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900364include scripts/Kbuild.include
365
366# Read KERNELRELEASE from include/config/kernel.release (if it exists)
367KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
368KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
369export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
370
Anders Roxellb2d35fa2018-09-04 12:47:21 +0200371include scripts/subarch.include
Linus Torvalds1da177e2005-04-16 15:20:36 -0700372
373# Cross compiling and selecting different set of gcc/bin-utils
374# ---------------------------------------------------------------------------
375#
376# When performing cross compilation for other architectures ARCH shall be set
377# to the target architecture. (See arch/* for the possibilities).
378# ARCH can be set during invocation of make:
379# make ARCH=ia64
380# Another way is to have ARCH set in the environment.
381# The default ARCH is the host where make is executed.
382
383# CROSS_COMPILE specify the prefix used for all executables used
384# during compilation. Only gcc and related bin-utils executables
385# are prefixed with $(CROSS_COMPILE).
386# CROSS_COMPILE can be set on the command line
387# make CROSS_COMPILE=ia64-linux-
388# Alternatively CROSS_COMPILE can be set in the environment.
389# Default value for CROSS_COMPILE is not to prefix executables
390# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
Sam Ravnborg2331d1a2009-10-11 23:22:58 +0200391ARCH ?= $(SUBARCH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700392
393# Architecture as present in compile.h
Thomas Gleixner6752ed92007-10-11 11:11:36 +0200394UTS_MACHINE := $(ARCH)
395SRCARCH := $(ARCH)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700396
Sam Ravnborgd746d642007-11-12 20:14:19 +0100397# Additional ARCH settings for x86
398ifeq ($(ARCH),i386)
399 SRCARCH := x86
400endif
401ifeq ($(ARCH),x86_64)
402 SRCARCH := x86
403endif
Sam Ravnborg74b469f2007-10-25 19:42:04 +0200404
Sam Ravnborg5e538792008-12-02 23:17:12 -0800405# Additional ARCH settings for sparc
Namhyung Kime69f58c2010-10-25 05:48:23 +0000406ifeq ($(ARCH),sparc32)
407 SRCARCH := sparc
408endif
Sam Ravnborga439fe52008-07-27 23:00:59 +0200409ifeq ($(ARCH),sparc64)
Sam Ravnborg5e538792008-12-02 23:17:12 -0800410 SRCARCH := sparc
Sam Ravnborga439fe52008-07-27 23:00:59 +0200411endif
Sam Ravnborg2fb9b1b2008-06-21 00:24:17 +0200412
Paul Mundt3cc000b2009-04-11 08:39:27 +0900413# Additional ARCH settings for sh
414ifeq ($(ARCH),sh64)
415 SRCARCH := sh
416endif
417
Roman Zippel14cdd3c2006-06-08 22:12:51 -0700418KCONFIG_CONFIG ?= .config
Ben Gardiner41263fc2010-12-14 11:39:44 -0500419export KCONFIG_CONFIG
Roman Zippel14cdd3c2006-06-08 22:12:51 -0700420
Masahiro Yamada2a86f662020-02-28 12:46:40 +0900421# Default file for 'make defconfig'. This may be overridden by arch-Makefile.
422export KBUILD_DEFCONFIG := defconfig
423
Linus Torvalds1da177e2005-04-16 15:20:36 -0700424# SHELL used by kbuild
Masahiro Yamada858805b2019-08-25 22:28:37 +0900425CONFIG_SHELL := sh
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426
Masahiro Yamada6d79a7b2018-07-12 19:38:36 +0900427HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
428HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
429HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
Uwe Kleine-Königd7f14c62017-07-09 20:02:36 +0200430
Masahiro Yamadaa0d1c952020-04-08 10:36:23 +0900431ifneq ($(LLVM),)
432HOSTCC = clang
433HOSTCXX = clang++
434else
435HOSTCC = gcc
436HOSTCXX = g++
437endif
Masahiro Yamada7f3a59d2020-04-29 12:45:14 +0900438
Elliot Berman3172c952022-01-12 12:14:58 -0800439KBUILD_USERHOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes \
440 -O2 -fomit-frame-pointer -std=gnu89
441KBUILD_USERCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(USERCFLAGS)
442KBUILD_USERLDFLAGS := $(USERLDFLAGS)
Masahiro Yamada7f3a59d2020-04-29 12:45:14 +0900443
Elliot Berman3172c952022-01-12 12:14:58 -0800444KBUILD_HOSTCFLAGS := $(KBUILD_USERHOSTCFLAGS) $(HOST_LFS_CFLAGS) $(HOSTCFLAGS)
Masahiro Yamada735aab12020-03-25 12:14:32 +0900445KBUILD_HOSTCXXFLAGS := -Wall -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
Laura Abbottf92d19e2018-07-09 17:46:02 -0700446KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
447KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700448
Linus Torvalds1da177e2005-04-16 15:20:36 -0700449# Make variables (CC, etc...)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450CPP = $(CC) -E
Masahiro Yamadaa0d1c952020-04-08 10:36:23 +0900451ifneq ($(LLVM),)
452CC = clang
453LD = ld.lld
454AR = llvm-ar
455NM = llvm-nm
456OBJCOPY = llvm-objcopy
457OBJDUMP = llvm-objdump
458READELF = llvm-readelf
Masahiro Yamadaa0d1c952020-04-08 10:36:23 +0900459STRIP = llvm-strip
460else
461CC = $(CROSS_COMPILE)gcc
462LD = $(CROSS_COMPILE)ld
Linus Torvalds1da177e2005-04-16 15:20:36 -0700463AR = $(CROSS_COMPILE)ar
464NM = $(CROSS_COMPILE)nm
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465OBJCOPY = $(CROSS_COMPILE)objcopy
466OBJDUMP = $(CROSS_COMPILE)objdump
Dmitry Golovineefb8c12019-12-05 00:54:41 +0200467READELF = $(CROSS_COMPILE)readelf
Masahiro Yamadaa0d1c952020-04-08 10:36:23 +0900468STRIP = $(CROSS_COMPILE)strip
469endif
Andrii Nakryikoe83b9f52019-04-02 09:49:50 -0700470PAHOLE = pahole
Jiri Olsac9a0f3b2020-07-11 23:53:24 +0200471RESOLVE_BTFIDS = $(objtree)/tools/bpf/resolve_btfids/resolve_btfids
Masahiro Yamada73a4f6d2017-12-10 01:02:28 +0900472LEX = flex
473YACC = bison
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474AWK = awk
Sam Ravnborgcaa27b62009-07-20 21:37:11 +0200475INSTALLKERNEL := installkernel
Dominique Martinet3ca42582020-12-01 14:17:30 +0100476DEPMOD = depmod
Linus Torvalds1da177e2005-04-16 15:20:36 -0700477PERL = perl
Masahiro Yamada011bf122014-07-18 13:40:11 +0900478PYTHON = python
Masahiro Yamadae9781b52018-03-13 18:12:02 +0900479PYTHON3 = python3
Linus Torvalds1da177e2005-04-16 15:20:36 -0700480CHECK = sparse
Masahiro Yamada858805b2019-08-25 22:28:37 +0900481BASH = bash
Denis Efremove4a42c82020-06-08 12:59:44 +0300482KGZIP = gzip
483KBZIP2 = bzip2
484KLZOP = lzop
Denis Efremov8dfb61d2020-06-05 10:39:55 +0300485LZMA = lzma
Alistair Delva76a0d392020-06-17 21:55:14 -0700486LZ4 = lz4
Denis Efremov8dfb61d2020-06-05 10:39:55 +0300487XZ = xz
Nick Terrell48f7ddf2020-07-30 12:08:36 -0700488ZSTD = zstd
Denis Efremov8dfb61d2020-06-05 10:39:55 +0300489
Tao Huangc2482142015-11-21 19:40:34 +0800490# Use the wrapper for the compiler. This wrapper scans for new
491# warnings and causes the build to stop upon encountering them.
492ifeq ($(CC),$(CROSS_COMPILE)gcc)
493ifneq ($(wildcard $(srctree)/scripts/gcc-wrapper.py),)
Tao Huang18f2a772022-07-14 19:35:55 +0800494CC = $(abspath $(srctree)/scripts/gcc-wrapper.py) $(CROSS_COMPILE)gcc
Tao Huangc2482142015-11-21 19:40:34 +0800495endif
496endif
497
Jiri Olsac5006ab2022-10-19 10:56:03 +0200498PAHOLE_FLAGS = $(shell PAHOLE=$(PAHOLE) $(srctree)/scripts/pahole-flags.sh)
499
Hannes Eder80a7d1d2008-12-27 22:38:44 +0100500CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
Luc Van Oostenryck6c49f352018-02-15 22:07:50 +0100501 -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
Douglas Anderson0c22be02019-03-14 16:41:59 -0700502NOSTDINC_FLAGS :=
Sam Ravnborg65881692010-07-28 17:33:09 +0200503CFLAGS_MODULE =
504AFLAGS_MODULE =
505LDFLAGS_MODULE =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700506CFLAGS_KERNEL =
507AFLAGS_KERNEL =
Michal Marekb36fad62016-06-07 11:57:02 +0200508LDFLAGS_vmlinux =
Linus Torvalds1da177e2005-04-16 15:20:36 -0700509
David Howellsabbf1592012-10-02 18:01:26 +0100510# Use USERINCLUDE when you must reference the UAPI directories only.
511USERINCLUDE := \
Masahiro Yamada9d022c52017-10-04 12:56:04 +0900512 -I$(srctree)/arch/$(SRCARCH)/include/uapi \
513 -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
David Howellsabbf1592012-10-02 18:01:26 +0100514 -I$(srctree)/include/uapi \
Arnd Bergmann3308b282016-06-15 17:45:45 +0200515 -I$(objtree)/include/generated/uapi \
David Howellsabbf1592012-10-02 18:01:26 +0100516 -include $(srctree)/include/linux/kconfig.h
517
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518# Use LINUXINCLUDE when you must reference the include/ directory.
519# Needed to be compatible with the O= option
David Howellsabbf1592012-10-02 18:01:26 +0100520LINUXINCLUDE := \
Masahiro Yamada9d022c52017-10-04 12:56:04 +0900521 -I$(srctree)/arch/$(SRCARCH)/include \
522 -I$(objtree)/arch/$(SRCARCH)/include/generated \
Masahiro Yamada051f2782019-07-06 12:07:12 +0900523 $(if $(building_out_of_srctree),-I$(srctree)/include) \
Masahiro Yamadaf8224f72017-06-06 16:15:28 +0900524 -I$(objtree)/include \
525 $(USERINCLUDE)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Masahiro Yamada42a92bc2018-12-14 17:05:37 +0900527KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
Masahiro Yamadaeeb56872018-12-14 17:05:38 +0900528KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
Masahiro Yamada42a92bc2018-12-14 17:05:37 +0900529 -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
Luc Van Oostenryckb89f25e2019-03-04 13:55:20 +0100530 -Werror=implicit-function-declaration -Werror=implicit-int \
Olaf Hering172aad81a2020-10-11 20:54:31 +0200531 -Werror=return-type -Wno-format-security \
Masahiro Yamada433dc2e2017-10-12 18:22:25 +0900532 -std=gnu89
533KBUILD_CPPFLAGS := -D__KERNEL__
Sam Ravnborg80c00ba2010-07-28 19:11:27 +0200534KBUILD_AFLAGS_KERNEL :=
535KBUILD_CFLAGS_KERNEL :=
Sam Ravnborg65881692010-07-28 17:33:09 +0200536KBUILD_AFLAGS_MODULE := -DMODULE
537KBUILD_CFLAGS_MODULE := -DMODULE
Masahiro Yamada10df0632019-08-15 01:06:22 +0900538KBUILD_LDFLAGS_MODULE :=
Masahiro Yamadad503ac52018-08-24 08:20:39 +0900539KBUILD_LDFLAGS :=
Masahiro Yamada5241ab4c2019-07-29 18:15:17 +0900540CLANG_FLAGS :=
Linus Torvalds1da177e2005-04-16 15:20:36 -0700541
Masahiro Yamadaaa824e02020-03-26 14:57:18 +0900542export ARCH SRCARCH CONFIG_SHELL BASH HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE LD CC
Vasily Gorbikd9b56652020-10-23 13:57:32 +0200543export CPP AR NM STRIP OBJCOPY OBJDUMP READELF PAHOLE RESOLVE_BTFIDS LEX YACC AWK INSTALLKERNEL
Masahiro Yamada94f73452020-01-06 17:36:28 +0900544export PERL PYTHON PYTHON3 CHECK CHECKFLAGS MAKE UTS_MACHINE HOSTCXX
Nick Terrell48f7ddf2020-07-30 12:08:36 -0700545export KGZIP KBZIP2 KLZOP LZMA LZ4 XZ ZSTD
Vasily Gorbik7bac9872019-01-21 13:54:39 +0100546export KBUILD_HOSTCXXFLAGS KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS LDFLAGS_MODULE
Elliot Berman3172c952022-01-12 12:14:58 -0800547export KBUILD_USERCFLAGS KBUILD_USERLDFLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700548
Masahiro Yamadad503ac52018-08-24 08:20:39 +0900549export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
Andrey Konovalov0e410e12018-02-06 15:36:00 -0800550export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
Sam Ravnborg222d3942007-10-15 21:59:31 +0200551export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
Sam Ravnborg65881692010-07-28 17:33:09 +0200552export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
Sam Ravnborg80c00ba2010-07-28 19:11:27 +0200553export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
Jiri Olsac5006ab2022-10-19 10:56:03 +0200554export PAHOLE_FLAGS
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555
Linus Torvalds1da177e2005-04-16 15:20:36 -0700556# Files to ignore in find ... statements
557
Prarit Bhargavaae63b2d2014-02-06 07:51:42 -0500558export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \
559 -name CVS -o -name .pc -o -name .hg -o -name .git \) \
560 -prune -o
Jesper Juhl450c6072012-02-16 22:49:15 +0100561export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
562 --exclude CVS --exclude .pc --exclude .hg --exclude .git
Linus Torvalds1da177e2005-04-16 15:20:36 -0700563
564# ===========================================================================
565# Rules shared between *config targets and build targets
566
Cao jin312a3d02017-08-02 10:31:06 +0800567# Basic helpers built in scripts/basic/
Paul Smith4f193362006-03-05 17:14:10 -0500568PHONY += scripts_basic
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569scripts_basic:
570 $(Q)$(MAKE) $(build)=scripts/basic
Steven Rostedt638adb02009-11-17 10:48:25 -0500571 $(Q)rm -f .tmp_quiet_recordmcount
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
Paul Smith4f193362006-03-05 17:14:10 -0500573PHONY += outputmakefile
Masahiro Yamadae8e83a22019-08-22 13:46:11 +0900574# Before starting out-of-tree build, make sure the source tree is clean.
Jan Beulichfd5f0cd2006-05-02 12:33:20 +0200575# outputmakefile generates a Makefile in the output directory, if using a
576# separate output directory. This allows convenient use of make in the
577# output directory.
Vladimir Kondratiev3a51ff32019-02-03 10:48:40 +0200578# At the same time when output Makefile generated, generate .gitignore to
579# ignore whole output directory
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580outputmakefile:
Masahiro Yamada051f2782019-07-06 12:07:12 +0900581ifdef building_out_of_srctree
Masahiro Yamadae8e83a22019-08-22 13:46:11 +0900582 $(Q)if [ -f $(srctree)/.config -o \
583 -d $(srctree)/include/config -o \
584 -d $(srctree)/arch/$(SRCARCH)/include/generated ]; then \
585 echo >&2 "***"; \
586 echo >&2 "*** The source tree is not clean, please run 'make$(if $(findstring command line, $(origin ARCH)), ARCH=$(ARCH)) mrproper'"; \
587 echo >&2 "*** in $(abs_srctree)";\
588 echo >&2 "***"; \
589 false; \
590 fi
Andi Kleen92979992009-01-10 04:56:13 +0100591 $(Q)ln -fsn $(srctree) source
Masahiro Yamada4fd61272018-09-18 17:45:53 +0900592 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
Masahiro Yamada156e7cb2019-03-26 13:26:58 +0900593 $(Q)test -e .gitignore || \
594 { echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
Jan Beulichfd5f0cd2006-05-02 12:33:20 +0200595endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700596
Masahiro Yamada99516742018-10-30 22:26:34 +0900597ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
Chris Friesae6b2892017-11-07 11:46:13 -0800598ifneq ($(CROSS_COMPILE),)
Nick Desaulniers2c7167392020-11-09 10:48:31 -0800599CLANG_FLAGS += --target=$(notdir $(CROSS_COMPILE:%-=%))
Alistair Strachanb318f052019-05-14 17:23:12 -0700600GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
Fangrui Songca9b31f2020-07-21 10:31:23 -0700601CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)$(notdir $(CROSS_COMPILE))
Stefan Agneref8c4ed2018-09-17 19:31:57 -0700602GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
Chris Friesae6b2892017-11-07 11:46:13 -0800603endif
604ifneq ($(GCC_TOOLCHAIN),)
Masahiro Yamada238bcbc2018-11-06 12:04:55 +0900605CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
Chris Friesae6b2892017-11-07 11:46:13 -0800606endif
Masahiro Yamada83f55e62023-03-28 17:08:29 -0700607ifeq ($(LLVM_IAS),1)
Nathan Chancellord5f67f62023-03-28 17:08:30 -0700608CLANG_FLAGS += -fintegrated-as
Masahiro Yamada83f55e62023-03-28 17:08:29 -0700609else
Nathan Chancellord5f67f62023-03-28 17:08:30 -0700610CLANG_FLAGS += -fno-integrated-as
Nathan Chancellor876a0602019-06-27 12:14:48 -0700611endif
Nathan Chancellor589834b2019-06-11 11:43:31 -0700612CLANG_FLAGS += -Werror=unknown-warning-option
Masahiro Yamada238bcbc2018-11-06 12:04:55 +0900613KBUILD_CFLAGS += $(CLANG_FLAGS)
614KBUILD_AFLAGS += $(CLANG_FLAGS)
Joel Stanley3bd98052018-11-12 14:51:15 +1030615export CLANG_FLAGS
Chris Friesae6b2892017-11-07 11:46:13 -0800616endif
617
Masahiro Yamada315bab42018-06-08 09:21:43 +0900618# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
619# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
620# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
621# and from include/config/auto.conf.cmd to detect the compiler upgrade.
Masahiro Yamada902a6892019-05-09 16:35:55 +0900622CC_VERSION_TEXT = $(shell $(CC) --version 2>/dev/null | head -n 1)
Masahiro Yamada315bab42018-06-08 09:21:43 +0900623
Masahiro Yamada2042b542019-08-11 00:53:03 +0900624ifdef config-build
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625# ===========================================================================
626# *config targets only - make sure prerequisites are updated, and descend
627# in scripts/kconfig to make the *config target
628
629# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
630# KBUILD_DEFCONFIG may point out an alternative default configuration
631# used for 'make defconfig'
Masahiro Yamadaa436bb72015-03-27 20:43:36 +0900632include arch/$(SRCARCH)/Makefile
Masahiro Yamada315bab42018-06-08 09:21:43 +0900633export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Masahiro Yamada36de0772019-08-22 13:46:13 +0900635config: outputmakefile scripts_basic FORCE
Sam Ravnborg31110eb2008-12-13 23:00:45 +0100636 $(Q)$(MAKE) $(build)=scripts/kconfig $@
637
Masahiro Yamada36de0772019-08-22 13:46:13 +0900638%config: outputmakefile scripts_basic FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639 $(Q)$(MAKE) $(build)=scripts/kconfig $@
640
Masahiro Yamada2042b542019-08-11 00:53:03 +0900641else #!config-build
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642# ===========================================================================
643# Build targets only - this includes vmlinux, arch specific targets, clean
644# targets and others. In general all targets except *config targets.
645
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900646# If building an external module we do not care about the all: rule
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900647# but instead __all depend on modules
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900648PHONY += all
649ifeq ($(KBUILD_EXTMOD),)
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900650__all: all
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900651else
Masahiro Yamada121c2a12020-05-11 12:50:13 +0900652__all: modules
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900653endif
654
655# Decide whether to build built-in, modular, or both.
656# Normally, just do built-in.
657
658KBUILD_MODULES :=
659KBUILD_BUILTIN := 1
660
661# If we have only "make modules", don't compile built-in objects.
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900662ifeq ($(MAKECMDGOALS),modules)
Masahiro Yamada4b50c8c2020-05-31 17:47:06 +0900663 KBUILD_BUILTIN :=
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900664endif
665
666# If we have "make <whatever> modules", compile modules
667# in addition to whatever we do anyway.
668# Just "make" or "make all" shall build modules as well
669
Nathan Huckleberry6ad7cbc2020-08-22 23:56:18 +0900670ifneq ($(filter all modules nsdeps %compile_commands.json clang-%,$(MAKECMDGOALS)),)
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +0900671 KBUILD_MODULES := 1
672endif
673
674ifeq ($(MAKECMDGOALS),)
675 KBUILD_MODULES := 1
676endif
677
678export KBUILD_MODULES KBUILD_BUILTIN
679
Masahiro Yamada2042b542019-08-11 00:53:03 +0900680ifdef need-config
Masahiro Yamadad93a18f2019-04-27 12:33:36 +0900681include include/config/auto.conf
682endif
683
Linus Torvalds1da177e2005-04-16 15:20:36 -0700684ifeq ($(KBUILD_EXTMOD),)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685# Objects we will link into vmlinux / subdirs we need to visit
Masahiro Yamada23febe32020-06-01 14:56:57 +0900686core-y := init/ usr/
Masahiro Yamadaf96182e2019-01-11 18:52:00 +0900687drivers-y := drivers/ sound/
Masahiro Yamadad93a18f2019-04-27 12:33:36 +0900688drivers-$(CONFIG_SAMPLES) += samples/
Masahiro Yamada95fb6312020-06-01 14:56:58 +0900689drivers-y += net/ virt/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690libs-y := lib/
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691endif # KBUILD_EXTMOD
692
Elliot Berman7d5e1de2021-04-07 08:03:11 -0700693ifndef KBUILD_MIXED_TREE
Masahiro Yamada315bab42018-06-08 09:21:43 +0900694# The all: target is the default when no target is given on the
695# command line.
696# This allow a user to issue only 'make' to build a kernel including modules
697# Defaults to vmlinux, but the arch makefile usually adds further targets
698all: vmlinux
Elliot Berman7d5e1de2021-04-07 08:03:11 -0700699endif
Masahiro Yamada315bab42018-06-08 09:21:43 +0900700
701CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
702 $(call cc-option,-fno-tree-loop-im) \
703 $(call cc-disable-warning,maybe-uninitialized,)
Masahiro Yamada5aadfde2018-05-28 18:22:04 +0900704export CFLAGS_GCOV
Masahiro Yamada315bab42018-06-08 09:21:43 +0900705
Paulo Zanonib1f4ff72018-09-10 10:59:56 -0700706# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
707ifdef CONFIG_FUNCTION_TRACER
708 CC_FLAGS_FTRACE := -pg
709endif
710
Ben Hutchings37b9bb02022-07-11 00:31:38 +0200711ifdef CONFIG_CC_IS_GCC
712RETPOLINE_CFLAGS := $(call cc-option,-mindirect-branch=thunk-extern -mindirect-branch-register)
Peter Zijlstra6849ed82021-11-19 17:50:25 +0100713RETPOLINE_CFLAGS += $(call cc-option,-mindirect-branch-cs-prefix)
Ben Hutchings37b9bb02022-07-11 00:31:38 +0200714RETPOLINE_VDSO_CFLAGS := $(call cc-option,-mindirect-branch=thunk-inline -mindirect-branch-register)
715endif
716ifdef CONFIG_CC_IS_CLANG
717RETPOLINE_CFLAGS := -mretpoline-external-thunk
718RETPOLINE_VDSO_CFLAGS := -mretpoline
719endif
Peter Zijlstrab24fdd02022-06-27 22:21:17 +0000720
721ifdef CONFIG_RETHUNK
722RETHUNK_CFLAGS := -mfunction-return=thunk-extern
723RETPOLINE_CFLAGS += $(RETHUNK_CFLAGS)
724endif
725
Masahiro Yamada669e06b2019-03-26 15:11:12 +0900726export RETPOLINE_CFLAGS
727export RETPOLINE_VDSO_CFLAGS
728
Masahiro Yamada315bab42018-06-08 09:21:43 +0900729include arch/$(SRCARCH)/Makefile
730
Masahiro Yamada2042b542019-08-11 00:53:03 +0900731ifdef need-config
732ifdef may-sync-config
Masahiro Yamada315bab42018-06-08 09:21:43 +0900733# Read in dependencies to all Kconfig* files, make sure to run syncconfig if
734# changes are detected. This should be included after arch/$(SRCARCH)/Makefile
735# because some architectures define CROSS_COMPILE there.
Masahiro Yamadad2f8ae02019-05-12 11:13:48 +0900736include include/config/auto.conf.cmd
Linus Torvalds1da177e2005-04-16 15:20:36 -0700737
Masahiro Yamada05850712019-02-22 16:40:11 +0900738$(KCONFIG_CONFIG):
739 @echo >&2 '***'
740 @echo >&2 '*** Configuration file "$@" not found!'
741 @echo >&2 '***'
742 @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or'
743 @echo >&2 '*** "make menuconfig" or "make xconfig").'
744 @echo >&2 '***'
745 @/bin/false
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Ulf Magnusson61277982018-02-13 08:58:20 +0100747# The actual configuration files used during the build are stored in
748# include/generated/ and include/config/. Update them if .config is newer than
749# include/config/auto.conf (which mirrors .config).
Masahiro Yamada9390dff2019-02-22 16:40:10 +0900750#
751# This exploits the 'multi-target pattern rule' trick.
752# The syncconfig should be executed only once to make all the targets.
Masahiro Yamadaf463c352020-03-25 12:16:30 +0900753# (Note: use the grouped target '&:' when we bump to GNU Make 4.3)
Masahiro Yamadaff4b8f32021-07-14 13:23:49 +0900754#
755# Do not use $(call cmd,...) here. That would suppress prompts from syncconfig,
756# so you cannot notice that Kconfig is waiting for the user input.
Masahiro Yamada3044dd02020-05-01 15:01:41 +0900757%/config/auto.conf %/config/auto.conf.cmd %/generated/autoconf.h: $(KCONFIG_CONFIG)
Masahiro Yamadaff4b8f32021-07-14 13:23:49 +0900758 $(Q)$(kecho) " SYNC $@"
759 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
Masahiro Yamada2042b542019-08-11 00:53:03 +0900760else # !may-sync-config
Masahiro Yamadad7942412018-07-20 16:46:34 +0900761# External modules and some install targets need include/generated/autoconf.h
762# and include/config/auto.conf but do not care if they are up-to-date.
763# Use auto.conf to trigger the test
Sam Ravnborg9ee4e332006-08-07 21:01:36 +0200764PHONY += include/config/auto.conf
765
766include/config/auto.conf:
Sam Ravnborg264a2682009-10-18 00:49:24 +0200767 $(Q)test -e include/generated/autoconf.h -a -e $@ || ( \
Michal Marek5369f552012-07-07 23:04:40 +0200768 echo >&2; \
769 echo >&2 " ERROR: Kernel configuration is invalid."; \
770 echo >&2 " include/generated/autoconf.h or $@ are missing.";\
771 echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
772 echo >&2 ; \
Sam Ravnborg9ee4e332006-08-07 21:01:36 +0200773 /bin/false)
774
Masahiro Yamadad7942412018-07-20 16:46:34 +0900775endif # may-sync-config
Masahiro Yamada2042b542019-08-11 00:53:03 +0900776endif # need-config
Linus Torvalds1da177e2005-04-16 15:20:36 -0700777
Geert Uytterhoevena1c48bb2014-05-27 09:54:12 +0200778KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,)
Linus Torvaldsef6000b2016-10-12 10:23:41 -0700779KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
Linus Torvaldsbd664f62017-07-12 19:25:47 -0700780KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
781KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
Linus Torvalds6f303d62019-05-01 11:05:41 -0700782KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
Geert Uytterhoevena1c48bb2014-05-27 09:54:12 +0200783
Masahiro Yamada15f5db62019-08-21 02:09:40 +0900784ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE
785KBUILD_CFLAGS += -O2
786else ifdef CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE_O3
787KBUILD_CFLAGS += -O3
788else ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
789KBUILD_CFLAGS += -Os
Arnd Bergmann815eb712016-04-25 17:35:28 +0200790endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700791
Jiri Kosina69102312014-08-06 16:08:43 -0700792# Tell gcc to never replace conditional load with a non-conditional one
793KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
Sergei Trofimovichb1112132020-03-17 00:07:18 +0000794KBUILD_CFLAGS += $(call cc-option,-fno-allow-store-data-races)
Jiri Kosina69102312014-08-06 16:08:43 -0700795
Andi Kleen1873e872012-03-28 11:51:18 -0700796ifdef CONFIG_READABLE_ASM
797# Disable optimizations that make assembler listings hard to read.
798# reorder blocks reorders the control in the function
799# ipa clone creates specialized cloned functions
800# partial inlining inlines only parts of functions
801KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
802 $(call cc-option,-fno-ipa-cp-clone,) \
803 $(call cc-option,-fno-partial-inlining)
804endif
805
Mike Frysinger08f67462009-06-04 16:29:08 -0700806ifneq ($(CONFIG_FRAME_WARN),0)
Masahiro Yamadaa83e4ca2020-02-17 00:19:36 +0900807KBUILD_CFLAGS += -Wframe-larger-than=$(CONFIG_FRAME_WARN)
Andi Kleen35bb5b12008-02-22 15:15:03 +0100808endif
809
Masahiro Yamada893ab002020-06-27 03:59:12 +0900810stackp-flags-y := -fno-stack-protector
Linus Torvalds050e9ba2018-06-14 12:21:18 +0900811stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector
812stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
Masahiro Yamada2a61f472018-05-28 18:22:00 +0900813
814KBUILD_CFLAGS += $(stackp-flags-y)
Sam Ravnborge06b8b92008-02-13 22:43:28 +0100815
Linus Torvalds824c5552021-09-05 11:24:05 -0700816KBUILD_CFLAGS-$(CONFIG_WERROR) += -Werror
817KBUILD_CFLAGS += $(KBUILD_CFLAGS-y)
818
Masahiro Yamada076f4212018-10-30 22:26:33 +0900819ifdef CONFIG_CC_IS_CLANG
Masahiro Yamadaa1494302019-05-10 23:10:09 +0900820KBUILD_CPPFLAGS += -Qunused-arguments
821KBUILD_CFLAGS += -Wno-format-invalid-specifier
822KBUILD_CFLAGS += -Wno-gnu
Masahiro Yamadacfe17c92017-11-27 21:15:13 +0900823# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
824# source of a reference will be _MergedGlobals and not on of the whitelisted names.
825# See modpost pattern 2
Masahiro Yamadaa1494302019-05-10 23:10:09 +0900826KBUILD_CFLAGS += -mno-global-merge
Masahiro Yamadacfe17c92017-11-27 21:15:13 +0900827else
828
Nathan Chancellore2079e92019-08-26 17:41:55 -0700829# Warn about unmarked fall-throughs in switch statement.
830# Disabled for clang while comment to attribute conversion happens and
831# https://github.com/ClangBuiltLinux/linux/issues/636 is discussed.
832KBUILD_CFLAGS += $(call cc-option,-Wimplicit-fallthrough,)
Masahiro Yamadacfe17c92017-11-27 21:15:13 +0900833endif
834
Nathan Chancellordc4b67b2021-04-28 18:23:50 -0700835# These warnings generated too much noise in a regular build.
836# Use make W=1 to enable them (see scripts/Makefile.extrawarn)
837KBUILD_CFLAGS += $(call cc-disable-warning, unused-but-set-variable)
838
Sodagudi Prasad0a5f4172018-02-06 15:46:51 -0800839KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
Linus Torvalds1d869332022-06-09 09:41:42 -0700840
841# These result in bogus false positives
842KBUILD_CFLAGS += $(call cc-disable-warning, dangling-pointer)
843
Linus Torvalds1da177e2005-04-16 15:20:36 -0700844ifdef CONFIG_FRAME_POINTER
Sam Ravnborga0f97e02007-10-14 22:21:35 +0200845KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
Linus Torvalds1da177e2005-04-16 15:20:36 -0700846else
Rabin Vincent7e9501f2010-08-10 19:20:53 +0100847# Some targets (ARM with Thumb2, for example), can't be built with frame
848# pointers. For those, we don't have FUNCTION_TRACER automatically
849# select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is
850# incompatible with -fomit-frame-pointer with current GCC, so we don't use
851# -fomit-frame-pointer with FUNCTION_TRACER.
852ifndef CONFIG_FUNCTION_TRACER
Sam Ravnborga0f97e02007-10-14 22:21:35 +0200853KBUILD_CFLAGS += -fomit-frame-pointer
Linus Torvalds1da177e2005-04-16 15:20:36 -0700854endif
Rabin Vincent7e9501f2010-08-10 19:20:53 +0100855endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856
glider@google.comf0fe00d2020-06-16 10:34:35 +0200857# Initialize all stack variables with a 0xAA pattern.
858ifdef CONFIG_INIT_STACK_ALL_PATTERN
Kees Cook709a9722019-04-10 08:48:31 -0700859KBUILD_CFLAGS += -ftrivial-auto-var-init=pattern
860endif
861
glider@google.comf0fe00d2020-06-16 10:34:35 +0200862# Initialize all stack variables with a zero value.
863ifdef CONFIG_INIT_STACK_ALL_ZERO
glider@google.comf0fe00d2020-06-16 10:34:35 +0200864KBUILD_CFLAGS += -ftrivial-auto-var-init=zero
Kees Cookba52e682022-09-29 22:57:43 -0700865ifdef CONFIG_CC_HAS_AUTO_VAR_INIT_ZERO_ENABLER
866# https://github.com/llvm/llvm-project/issues/44842
glider@google.comf0fe00d2020-06-16 10:34:35 +0200867KBUILD_CFLAGS += -enable-trivial-auto-var-init-zero-knowing-it-will-be-removed-from-clang
868endif
Kees Cookbdcb1d72021-09-14 12:49:03 -0700869endif
glider@google.comf0fe00d2020-06-16 10:34:35 +0200870
Masahiro Yamada19155472021-02-03 16:52:39 +0900871DEBUG_CFLAGS :=
872
Mark Wielaard121c5d02020-10-17 14:01:35 +0200873# Workaround for GCC versions < 5.0
874# https://gcc.gnu.org/bugzilla/show_bug.cgi?id=61801
875ifdef CONFIG_CC_IS_GCC
Masahiro Yamada19155472021-02-03 16:52:39 +0900876DEBUG_CFLAGS += $(call cc-ifversion, -lt, 0500, $(call cc-option, -fno-var-tracking-assignments))
Mark Wielaard121c5d02020-10-17 14:01:35 +0200877endif
Linus Torvalds2062afb2014-07-26 14:52:01 -0700878
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879ifdef CONFIG_DEBUG_INFO
Sedat Dilek695afd32020-08-16 14:32:44 +0200880
Andi Kleen866ced92014-07-30 20:50:18 +0200881ifdef CONFIG_DEBUG_INFO_SPLIT
Masahiro Yamada9d937442019-02-22 16:56:09 +0900882DEBUG_CFLAGS += -gsplit-dwarf
Andi Kleen866ced92014-07-30 20:50:18 +0200883else
Masahiro Yamada1e88e412019-02-10 15:51:00 +0900884DEBUG_CFLAGS += -g
Andi Kleen866ced92014-07-30 20:50:18 +0200885endif
Sedat Dilek695afd32020-08-16 14:32:44 +0200886
Masahiro Yamadac36a2512023-03-28 17:08:31 -0700887ifdef CONFIG_AS_IS_LLVM
Nick Desaulniers3a260e92022-10-24 13:34:14 -0700888KBUILD_AFLAGS += -g
889else
Behan Webster22883282014-02-14 15:19:17 -0800890KBUILD_AFLAGS += -Wa,-gdwarf-2
Nick Desaulniers62015d12020-11-09 10:35:28 -0800891endif
Sedat Dilek695afd32020-08-16 14:32:44 +0200892
Andi Kleenbfaf2dd2014-07-30 20:50:19 +0200893ifdef CONFIG_DEBUG_INFO_DWARF4
Masahiro Yamada9d937442019-02-22 16:56:09 +0900894DEBUG_CFLAGS += -gdwarf-4
Andi Kleenbfaf2dd2014-07-30 20:50:19 +0200895endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896
Andi Kleend6f4ceb2010-07-14 15:43:52 +0200897ifdef CONFIG_DEBUG_INFO_REDUCED
Masahiro Yamada1e88e412019-02-10 15:51:00 +0900898DEBUG_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \
Andi Kleene82c4bb2013-02-07 13:58:40 -0800899 $(call cc-option,-fno-var-tracking)
Andi Kleend6f4ceb2010-07-14 15:43:52 +0200900endif
901
Nick Desaulniers10e68b022020-05-26 10:18:29 -0700902ifdef CONFIG_DEBUG_INFO_COMPRESSED
903DEBUG_CFLAGS += -gz=zlib
Arvind Sankar7b169942020-06-11 18:03:39 -0400904KBUILD_AFLAGS += -gz=zlib
Nick Desaulniers10e68b022020-05-26 10:18:29 -0700905KBUILD_LDFLAGS += --compress-debug-sections=zlib
906endif
907
Sedat Dilek695afd32020-08-16 14:32:44 +0200908endif # CONFIG_DEBUG_INFO
909
Masahiro Yamada1e88e412019-02-10 15:51:00 +0900910KBUILD_CFLAGS += $(DEBUG_CFLAGS)
911export DEBUG_CFLAGS
912
Steven Rostedt606576c2008-10-06 19:06:12 -0400913ifdef CONFIG_FUNCTION_TRACER
Sami Tolvanen45078822020-09-25 16:36:45 -0700914ifdef CONFIG_FTRACE_MCOUNT_USE_CC
915 CC_FLAGS_FTRACE += -mrecord-mcount
Vasily Gorbik2f4df002018-08-06 15:17:46 +0200916 ifdef CONFIG_HAVE_NOP_MCOUNT
917 ifeq ($(call cc-option-yn, -mnop-mcount),y)
918 CC_FLAGS_FTRACE += -mnop-mcount
919 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
920 endif
921 endif
Steven Rostedta2546fa2011-02-09 13:15:59 -0500922endif
Sami Tolvanen195bcf12020-09-25 16:43:53 -0700923ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
924 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
925endif
Sami Tolvanen45078822020-09-25 16:36:45 -0700926ifdef CONFIG_FTRACE_MCOUNT_USE_RECORDMCOUNT
927 ifdef CONFIG_HAVE_C_RECORDMCOUNT
928 BUILD_C_RECORDMCOUNT := y
929 export BUILD_C_RECORDMCOUNT
930 endif
931endif
Steven Rostedta2546fa2011-02-09 13:15:59 -0500932ifdef CONFIG_HAVE_FENTRY
Vasily Gorbikf28bc3c2018-08-06 15:17:42 +0200933 ifeq ($(call cc-option-yn, -mfentry),y)
934 CC_FLAGS_FTRACE += -mfentry
935 CC_FLAGS_USING += -DCC_USING_FENTRY
936 endif
Steven Rostedta2546fa2011-02-09 13:15:59 -0500937endif
Vasily Gorbikf28bc3c2018-08-06 15:17:42 +0200938export CC_FLAGS_FTRACE
939KBUILD_CFLAGS += $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING)
940KBUILD_AFLAGS += $(CC_FLAGS_USING)
Arnaldo Carvalho de Melo16444a82008-05-12 21:20:42 +0200941endif
942
Sam Ravnborg91341d42008-01-21 21:31:44 +0100943# We trigger additional mismatches with less inlining
944ifdef CONFIG_DEBUG_SECTION_MISMATCH
945KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
946endif
947
Masahiro Yamada90ad4052017-04-14 15:17:26 +0900948ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
Masahiro Yamadae85d1d62018-08-22 22:51:09 +0900949KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
950LDFLAGS_vmlinux += --gc-sections
Masahiro Yamada90ad4052017-04-14 15:17:26 +0900951endif
952
Sami Tolvanend08b9f02020-04-27 09:00:07 -0700953ifdef CONFIG_SHADOW_CALL_STACK
954CC_FLAGS_SCS := -fsanitize=shadow-call-stack
955KBUILD_CFLAGS += $(CC_FLAGS_SCS)
956export CC_FLAGS_SCS
957endif
958
Sami Tolvanenba01e932020-03-06 14:14:03 -0800959ifdef CONFIG_LTO_CLANG
960ifdef CONFIG_LTO_CLANG_THIN
Alexander Lobakine11b3232021-01-21 18:45:55 +0000961CC_FLAGS_LTO := -flto=thin -fsplit-lto-unit
Sami Tolvanenba01e932020-03-06 14:14:03 -0800962KBUILD_LDFLAGS += --thinlto-cache-dir=$(extmod-prefix).thinlto-cache
963else
Alexander Lobakine11b3232021-01-21 18:45:55 +0000964CC_FLAGS_LTO := -flto
Sami Tolvanenba01e932020-03-06 14:14:03 -0800965endif
Giuliano Procidabe409db2021-03-12 09:19:08 +0000966
967ifeq ($(SRCARCH),x86)
Giuliano Procida90d03f62021-03-12 17:36:13 +0000968# TODO(b/182572011): Revert workaround for compiler / linker bug.
Sami Tolvanenba01e932020-03-06 14:14:03 -0800969CC_FLAGS_LTO += -fvisibility=hidden
Giuliano Procidabe409db2021-03-12 09:19:08 +0000970else
971CC_FLAGS_LTO += -fvisibility=default
972endif
Sami Tolvanen819ae9e2019-12-04 15:57:39 -0800973
974# Limit inlining across translation units to reduce binary size
975KBUILD_LDFLAGS += -mllvm -import-instr-limit=5
Sami Tolvanenba01e932020-03-06 14:14:03 -0800976endif
977
978ifdef CONFIG_LTO
979KBUILD_CFLAGS += $(CC_FLAGS_LTO)
980export CC_FLAGS_LTO
981endif
982
Sami Tolvanen2c351bb2019-04-25 16:09:05 -0700983ifdef CONFIG_CFI_CLANG
984CC_FLAGS_CFI := -fsanitize=cfi \
985 -fsanitize-cfi-cross-dso \
986 -fno-sanitize-cfi-canonical-jump-tables \
987 -fno-sanitize-blacklist
988
989ifdef CONFIG_CFI_PERMISSIVE
990CC_FLAGS_CFI += -fsanitize-recover=cfi \
991 -fno-sanitize-trap=cfi
992else
993ifndef CONFIG_UBSAN_TRAP
994CC_FLAGS_CFI += -ftrap-function=__ubsan_handle_cfi_check_fail_abort
995endif
996endif
997
998# If LTO flags are filtered out, we must also filter out CFI.
999CC_FLAGS_LTO += $(CC_FLAGS_CFI)
1000KBUILD_CFLAGS += $(CC_FLAGS_CFI)
1001export CC_FLAGS_CFI
1002endif
1003
Feng Tang09c60542020-08-11 18:34:13 -07001004ifdef CONFIG_DEBUG_FORCE_FUNCTION_ALIGN_32B
1005KBUILD_CFLAGS += -falign-functions=32
1006endif
1007
Sam Ravnborge8e69932005-04-30 16:51:42 -07001008# arch Makefile may override CC so keep this after arch Makefile is included
Masahiro Yamadae08d6de2018-05-28 18:21:38 +09001009NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
Sam Ravnborge8e69932005-04-30 16:51:42 -07001010
Linus Torvalds1da177e2005-04-16 15:20:36 -07001011# warn about C99 declaration after statement
Masahiro Yamadaa33e7ae2018-10-01 18:44:37 +09001012KBUILD_CFLAGS += -Wdeclaration-after-statement
Linus Torvalds1da177e2005-04-16 15:20:36 -07001013
Kees Cook0bb95f82018-06-25 15:59:34 -07001014# Variable Length Arrays (VLAs) should not be used anywhere in the kernel
Masahiro Yamada8289f912019-05-09 15:45:49 +09001015KBUILD_CFLAGS += -Wvla
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
Sam Ravnborg070b98b2006-06-25 00:07:55 +02001017# disable pointer signed / unsigned warnings in gcc 4.0
Masahiro Yamadafb073a42018-10-01 18:44:36 +09001018KBUILD_CFLAGS += -Wno-pointer-sign
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
Stephen Rothwell217c3e02018-08-31 07:47:28 +10001020# disable stringop warnings in gcc 8+
1021KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
1022
Linus Torvalds5c45de22020-05-09 14:30:29 -07001023# We'll want to enable this eventually, but it's not going away for 5.7 at least
1024KBUILD_CFLAGS += $(call cc-disable-warning, zero-length-bounds)
Linus Torvalds44720992020-05-09 14:52:44 -07001025KBUILD_CFLAGS += $(call cc-disable-warning, array-bounds)
Linus Torvalds5a760212020-05-09 15:40:52 -07001026KBUILD_CFLAGS += $(call cc-disable-warning, stringop-overflow)
Linus Torvalds5c45de22020-05-09 14:30:29 -07001027
Linus Torvaldsadc71922020-05-09 15:45:21 -07001028# Another good warning that we'll want to enable eventually
1029KBUILD_CFLAGS += $(call cc-disable-warning, restrict)
1030
Linus Torvalds78a52552020-05-09 13:57:10 -07001031# Enabled with W=2, disabled by default as noisy
1032KBUILD_CFLAGS += $(call cc-disable-warning, maybe-uninitialized)
1033
Kirill Smelkovfe8d0a42009-04-09 15:34:34 +04001034# disable invalid "can't wrap" optimizations for signed / pointers
Masahiro Yamada8b42cf22020-09-10 22:51:17 +09001035KBUILD_CFLAGS += -fno-strict-overflow
Linus Torvaldsd0115552009-03-19 15:53:19 -07001036
Linus Torvalds3ce120b2017-12-29 17:34:43 -08001037# Make sure -fstack-check isn't enabled (like gentoo apparently did)
Masahiro Yamada7d4eb0d2020-09-10 22:51:19 +09001038KBUILD_CFLAGS += -fno-stack-check
Linus Torvalds3ce120b2017-12-29 17:34:43 -08001039
Andi Kleen8f7f5c92009-09-18 12:49:37 -07001040# conserve stack if available
1041KBUILD_CFLAGS += $(call cc-option,-fconserve-stack)
1042
Josh Triplettfe7c36c2013-12-23 13:56:06 -08001043# Prohibit date/time macros, which would make the build non-deterministic
Masahiro Yamada87de84c2020-09-10 22:51:20 +09001044KBUILD_CFLAGS += -Werror=date-time
Josh Triplettfe7c36c2013-12-23 13:56:06 -08001045
Daniel Wagnerea8daa72016-03-08 09:29:09 +01001046# enforce correct pointer usage
1047KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
1048
Kees Cookc834f0e2017-03-20 17:14:11 -07001049# Require designated initializers for all marked structures
1050KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
1051
Masahiro Yamadaa73619a2018-03-30 13:15:26 +09001052# change __FILE__ to the relative path from the srctree
Denys Zagoruia716bd72020-11-02 04:08:53 -08001053KBUILD_CPPFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
Masahiro Yamadaa73619a2018-03-30 13:15:26 +09001054
Masahiro Yamadae0fe0bb2020-08-02 00:00:49 +09001055# include additional Makefiles when needed
1056include-y := scripts/Makefile.extrawarn
1057include-$(CONFIG_KASAN) += scripts/Makefile.kasan
1058include-$(CONFIG_KCSAN) += scripts/Makefile.kcsan
1059include-$(CONFIG_UBSAN) += scripts/Makefile.ubsan
1060include-$(CONFIG_KCOV) += scripts/Makefile.kcov
1061include-$(CONFIG_GCC_PLUGINS) += scripts/Makefile.gcc-plugins
1062
1063include $(addprefix $(srctree)/, $(include-y))
Masahiro Yamadaa86fe352014-04-14 18:27:10 +09001064
Masahiro Yamada132305b2020-08-02 00:00:50 +09001065# scripts/Makefile.gcc-plugins is intentionally included last.
1066# Do not add $(call cc-option,...) below this line. When you build the kernel
1067# from the clean source tree, the GCC plugins do not exist at this point.
Jason Baronbf5438fc2010-09-17 11:09:00 -04001068
Masahiro Yamada8cc7af72019-08-21 02:09:41 +09001069# Add user supplied CPPFLAGS, AFLAGS and CFLAGS as the last assignments
1070KBUILD_CPPFLAGS += $(KCPPFLAGS)
1071KBUILD_AFLAGS += $(KAFLAGS)
1072KBUILD_CFLAGS += $(KCFLAGS)
Sam Ravnborg52bcc332007-10-15 22:03:58 +02001073
Bill Wendlinga9684332020-09-22 16:21:40 -07001074KBUILD_LDFLAGS_MODULE += --build-id=sha1
1075LDFLAGS_vmlinux += --build-id=sha1
Roland McGrath18991192007-07-19 01:48:40 -07001076
Nick Desaulniers8f4f2c92022-08-10 15:24:40 -07001077KBUILD_LDFLAGS += -z noexecstack
1078KBUILD_LDFLAGS += $(call ld-option,--no-warn-rwx-segments)
1079
David Howells5d7d18f2009-03-04 11:59:07 -08001080ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
Andi Kleend79a2712009-09-16 22:36:55 +02001081LDFLAGS_vmlinux += $(call ld-option, -X,)
David Howells5d7d18f2009-03-04 11:59:07 -08001082endif
1083
Peter Collingbourne5cf896f2019-07-31 18:18:42 -07001084ifeq ($(CONFIG_RELR),y)
Nick Desaulniersdcf38272021-03-18 17:07:06 -07001085LDFLAGS_vmlinux += --pack-dyn-relocs=relr --use-android-relr-tags
Peter Collingbourne5cf896f2019-07-31 18:18:42 -07001086endif
1087
Nathan Chancellor59612b22020-11-19 13:46:56 -07001088# We never want expected sections to be placed heuristically by the
1089# linker. All sections should be explicitly named in the linker script.
1090ifdef CONFIG_LD_ORPHAN_WARN
1091LDFLAGS_vmlinux += --orphan-handling=warn
1092endif
1093
Masahiro Yamada7f3a59d2020-04-29 12:45:14 +09001094# Align the bit size of userspace programs with the kernel
Masahiro Yamada7f58b482020-07-01 00:06:25 +09001095KBUILD_USERCFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
1096KBUILD_USERLDFLAGS += $(filter -m32 -m64 --target=%, $(KBUILD_CFLAGS))
Masahiro Yamada7f3a59d2020-04-29 12:45:14 +09001097
Luc Van Oostenryck80591e62019-11-09 13:12:16 +01001098# make the checker run with the right architecture
1099CHECKFLAGS += --arch=$(ARCH)
1100
Luc Van Oostenryck145167652018-05-28 20:27:35 +02001101# insure the checker run with the right endianness
1102CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
1103
Luc Van Oostenryck1f2f01b2018-05-30 22:48:38 +02001104# the checker needs the correct machine size
1105CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
1106
Linus Torvalds1da177e2005-04-16 15:20:36 -07001107# Default kernel image to build when no specific target is given.
Sam Ravnborg070b98b2006-06-25 00:07:55 +02001108# KBUILD_IMAGE may be overruled on the command line or
Linus Torvalds1da177e2005-04-16 15:20:36 -07001109# set in the environment
1110# Also any assignments in arch/$(ARCH)/Makefile take precedence over
1111# this default value
1112export KBUILD_IMAGE ?= vmlinux
1113
1114#
1115# INSTALL_PATH specifies where to place the updated kernel and system map
1116# images. Default is /boot, but you can set it to other values
1117export INSTALL_PATH ?= /boot
1118
1119#
Jason Cooperf4d4ffc2013-12-01 23:56:28 +00001120# INSTALL_DTBS_PATH specifies a prefix for relocations required by build roots.
1121# Like INSTALL_MOD_PATH, it isn't defined in the Makefile, but can be passed as
1122# an argument if needed. Otherwise it defaults to the kernel install path
1123#
1124export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE)
1125
1126#
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
1128# relocations required by build roots. This is not defined in the
Sam Ravnborg070b98b2006-06-25 00:07:55 +02001129# makefile but the argument can be passed to make if needed.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001130#
1131
Sam Ravnborgdf9df032006-01-16 12:46:07 +01001132MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001133export MODLIB
1134
Theodore Ts'oac031f22006-06-21 20:53:09 -04001135#
Masahiro Yamada3fbb43d2014-04-28 16:32:43 +09001136# INSTALL_MOD_STRIP, if defined, will cause modules to be
1137# stripped after they are installed. If INSTALL_MOD_STRIP is '1', then
1138# the default option --strip-debug will be used. Otherwise,
1139# INSTALL_MOD_STRIP value will be used as the options to the strip command.
Sam Ravnborg2ea03892009-01-14 21:38:20 +01001140
Theodore Ts'oac031f22006-06-21 20:53:09 -04001141ifdef INSTALL_MOD_STRIP
1142ifeq ($(INSTALL_MOD_STRIP),1)
Sam Ravnborg2ea03892009-01-14 21:38:20 +01001143mod_strip_cmd = $(STRIP) --strip-debug
Theodore Ts'oac031f22006-06-21 20:53:09 -04001144else
Sam Ravnborg2ea03892009-01-14 21:38:20 +01001145mod_strip_cmd = $(STRIP) $(INSTALL_MOD_STRIP)
Theodore Ts'oac031f22006-06-21 20:53:09 -04001146endif # INSTALL_MOD_STRIP=1
1147else
Sam Ravnborg2ea03892009-01-14 21:38:20 +01001148mod_strip_cmd = true
Theodore Ts'oac031f22006-06-21 20:53:09 -04001149endif # INSTALL_MOD_STRIP
1150export mod_strip_cmd
1151
Bertrand Jacquinbeb50df2014-08-27 20:31:56 +09301152# CONFIG_MODULE_COMPRESS, if defined, will cause module to be compressed
1153# after they are installed in agreement with CONFIG_MODULE_COMPRESS_GZIP
1154# or CONFIG_MODULE_COMPRESS_XZ.
1155
1156mod_compress_cmd = true
1157ifdef CONFIG_MODULE_COMPRESS
1158 ifdef CONFIG_MODULE_COMPRESS_GZIP
Denis Efremove4a42c82020-06-08 12:59:44 +03001159 mod_compress_cmd = $(KGZIP) -n -f
Bertrand Jacquinbeb50df2014-08-27 20:31:56 +09301160 endif # CONFIG_MODULE_COMPRESS_GZIP
1161 ifdef CONFIG_MODULE_COMPRESS_XZ
Denis Efremov8dfb61d2020-06-05 10:39:55 +03001162 mod_compress_cmd = $(XZ) -f
Bertrand Jacquinbeb50df2014-08-27 20:31:56 +09301163 endif # CONFIG_MODULE_COMPRESS_XZ
1164endif # CONFIG_MODULE_COMPRESS
1165export mod_compress_cmd
1166
Michal Marekd9d8d7e2013-01-25 13:41:31 +10301167ifdef CONFIG_MODULE_SIG_ALL
David Woodhouse3ee550f2015-08-14 16:17:16 +01001168$(eval $(call config_filename,MODULE_SIG_KEY))
1169
1170mod_sign_cmd = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY) certs/signing_key.x509
Rusty Russelle2a666d2012-10-19 11:53:15 +10301171else
1172mod_sign_cmd = true
1173endif
1174export mod_sign_cmd
1175
Rolf Eike Beer056d28d2019-03-26 12:48:39 -05001176HOST_LIBELF_LIBS = $(shell pkg-config libelf --libs 2>/dev/null || echo -lelf)
1177
Alistair Delvad728c7f2021-01-11 12:04:38 -08001178has_libelf := $(call try-run,\
1179 echo "int main() {}" | \
1180 $(HOSTCC) $(KBUILD_HOSTCFLAGS) -xc -o /dev/null $(KBUILD_HOSTLDFLAGS) $(HOST_LIBELF_LIBS) -,1,0)
Jiri Olsa33a57ce2020-07-11 23:53:22 +02001181
Josh Poimboeuf9f0c18a2017-02-15 12:21:17 -06001182ifdef CONFIG_STACK_VALIDATION
Josh Poimboeuf9f0c18a2017-02-15 12:21:17 -06001183 ifeq ($(has_libelf),1)
1184 objtool_target := tools/objtool FORCE
1185 else
Josh Poimboeuf9f0c18a2017-02-15 12:21:17 -06001186 SKIP_STACK_VALIDATION := 1
1187 export SKIP_STACK_VALIDATION
1188 endif
1189endif
1190
Jiri Olsa0945d672021-02-05 13:40:20 +01001191PHONY += resolve_btfids_clean
1192
Jiri Olsa76983e22021-02-11 13:40:04 +01001193resolve_btfids_O = $(abspath $(objtree))/tools/bpf/resolve_btfids
1194
1195# tools/bpf/resolve_btfids directory might not exist
1196# in output directory, skip its clean in that case
Jiri Olsa0945d672021-02-05 13:40:20 +01001197resolve_btfids_clean:
Jiri Olsa76983e22021-02-11 13:40:04 +01001198ifneq ($(wildcard $(resolve_btfids_O)),)
1199 $(Q)$(MAKE) -sC $(srctree)/tools/bpf/resolve_btfids O=$(resolve_btfids_O) clean
1200endif
Jiri Olsa0945d672021-02-05 13:40:20 +01001201
Jiri Olsa017dab32020-09-23 20:57:34 +02001202ifdef CONFIG_BPF
Jiri Olsa33a57ce2020-07-11 23:53:22 +02001203ifdef CONFIG_DEBUG_INFO_BTF
1204 ifeq ($(has_libelf),1)
1205 resolve_btfids_target := tools/bpf/resolve_btfids FORCE
1206 else
1207 ERROR_RESOLVE_BTFIDS := 1
1208 endif
Jiri Olsa017dab32020-09-23 20:57:34 +02001209endif # CONFIG_DEBUG_INFO_BTF
1210endif # CONFIG_BPF
Jiri Olsa33a57ce2020-07-11 23:53:22 +02001211
Masahiro Yamadae00d8882019-01-15 16:19:00 +09001212PHONY += prepare0
Rusty Russelle2a666d2012-10-19 11:53:15 +10301213
Masahiro Yamada394053f2019-08-15 00:19:18 +09001214export MODORDER := $(extmod-prefix)modules.order
Masahiro Yamadabc35d4b2019-10-29 21:38:08 +09001215export MODULES_NSDEPS := $(extmod-prefix)modules.nsdeps
Masahiro Yamada47801c92019-08-02 19:23:58 +09001216
Elliot Berman280812b2020-07-24 18:12:48 -07001217# ---------------------------------------------------------------------------
1218# Kernel headers
1219
1220PHONY += headers
1221
1222#Default location for installed headers
1223ifeq ($(KBUILD_EXTMOD),)
1224PHONY += archheaders archscripts
1225hdr-inst := -f $(srctree)/scripts/Makefile.headersinst obj
1226headers: $(version_h) scripts_unifdef uapi-asm-generic archheaders archscripts
1227else
1228hdr-prefix = $(KBUILD_EXTMOD)/
1229hdr-inst := -f $(srctree)/scripts/Makefile.headersinst dst=$(KBUILD_EXTMOD)/usr/include objtree=$(objtree)/$(KBUILD_EXTMOD) obj
1230endif
1231
1232export INSTALL_HDR_PATH = $(objtree)/$(hdr-prefix)usr
1233
1234quiet_cmd_headers_install = INSTALL $(INSTALL_HDR_PATH)/include
1235 cmd_headers_install = \
1236 mkdir -p $(INSTALL_HDR_PATH); \
1237 rsync -mrl --include='*/' --include='*\.h' --exclude='*' \
Tai Kuo9cbbfb32021-03-04 21:37:48 +08001238 $(hdr-prefix)usr/include $(INSTALL_HDR_PATH);
Elliot Berman280812b2020-07-24 18:12:48 -07001239
1240PHONY += headers_install
1241headers_install: headers
1242 $(call cmd,headers_install)
1243
1244headers:
1245ifeq ($(KBUILD_EXTMOD),)
1246 $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \
1247 $(error Headers not exportable for the $(SRCARCH) architecture))
1248endif
1249 $(Q)$(MAKE) $(hdr-inst)=$(hdr-prefix)include/uapi
1250 $(Q)$(MAKE) $(hdr-inst)=$(hdr-prefix)arch/$(SRCARCH)/include/uapi
1251
Linus Torvalds1da177e2005-04-16 15:20:36 -07001252ifeq ($(KBUILD_EXTMOD),)
Jens Axboe5e6347b2022-12-22 14:30:11 -07001253core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/ io_uring/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254
Masahiro Yamada23febe32020-06-01 14:56:57 +09001255vmlinux-dirs := $(patsubst %/,%,$(filter %/, \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001256 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
Masahiro Yamada95fb6312020-06-01 14:56:58 +09001257 $(libs-y) $(libs-m)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258
Masahiro Yamada1eaca4b2019-04-27 12:33:37 +09001259vmlinux-alldirs := $(sort $(vmlinux-dirs) Documentation \
Masahiro Yamada23febe32020-06-01 14:56:57 +09001260 $(patsubst %/,%,$(filter %/, $(core-) \
Masahiro Yamada95fb6312020-06-01 14:56:58 +09001261 $(drivers-) $(libs-))))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001262
Masahiro Yamadac99f3912019-08-11 00:53:04 +09001263build-dirs := $(vmlinux-dirs)
Masahiro Yamada76cd3062019-08-11 00:53:05 +09001264clean-dirs := $(vmlinux-alldirs)
Masahiro Yamadac99f3912019-08-11 00:53:04 +09001265
Masahiro Yamada91128262022-08-14 08:09:28 +09001266subdir-modorder := $(addsuffix /modules.order, $(build-dirs))
1267
Sam Ravnborg1f2bfbd2012-05-05 10:18:41 +02001268# Externally visible symbols (used by link-vmlinux.sh)
Masahiro Yamadaf0d50ca2020-06-01 14:56:59 +09001269KBUILD_VMLINUX_OBJS := $(head-y) $(patsubst %/,%/built-in.a, $(core-y))
1270KBUILD_VMLINUX_OBJS += $(addsuffix built-in.a, $(filter %/, $(libs-y)))
1271ifdef CONFIG_MODULES
1272KBUILD_VMLINUX_OBJS += $(patsubst %/, %/lib.a, $(filter %/, $(libs-y)))
1273KBUILD_VMLINUX_LIBS := $(filter-out %/, $(libs-y))
1274else
1275KBUILD_VMLINUX_LIBS := $(patsubst %/,%/lib.a, $(libs-y))
1276endif
1277KBUILD_VMLINUX_OBJS += $(patsubst %/,%/built-in.a, $(drivers-y))
1278
1279export KBUILD_VMLINUX_OBJS KBUILD_VMLINUX_LIBS
Sam Ravnborg95698572012-05-05 10:18:40 +02001280export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
Masahiro Yamada85f0ae72019-09-21 22:18:46 +09001281# used by scripts/Makefile.package
Masahiro Yamada233c7412019-05-16 01:18:54 +09001282export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) LICENSES arch include scripts tools)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001283
Masahiro Yamadad151e972019-01-17 09:10:04 +09001284vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001285
Masahiro Yamada3fdc7d32018-03-16 16:37:15 +09001286# Recurse until adjust_autoksyms.sh is satisfied
1287PHONY += autoksyms_recursive
Nicolas Pitre2441e782016-04-22 15:25:00 -04001288ifdef CONFIG_TRIM_UNUSED_KSYMS
Masahiro Yamada1f50b802018-03-16 16:37:13 +09001289# For the kernel to actually contain only the needed exported symbols,
1290# we have to build modules as well to determine what those symbols are.
1291# (this can be evaluated only once include/config/auto.conf has been included)
Masahiro Yamadafb2d99b2020-05-31 19:11:39 +09001292KBUILD_MODULES := 1
1293
1294autoksyms_recursive: descend modules.order
1295 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \
Masahiro Yamada95d73d52022-06-24 04:11:47 +09001296 "$(MAKE) -f $(srctree)/Makefile autoksyms_recursive"
Masahiro Yamada1f50b802018-03-16 16:37:13 +09001297endif
1298
Masahiro Yamada07a422b2018-03-16 16:37:12 +09001299autoksyms_h := $(if $(CONFIG_TRIM_UNUSED_KSYMS), include/generated/autoksyms.h)
1300
Quentin Perretada445e2020-02-18 09:41:39 +00001301quiet_cmd_autoksyms_h = GEN $@
Quentin Perretfe408222020-03-03 15:44:50 +00001302 cmd_autoksyms_h = mkdir -p $(dir $@); \
1303 $(CONFIG_SHELL) $(srctree)/scripts/gen_autoksyms.sh $@
Quentin Perretada445e2020-02-18 09:41:39 +00001304
Masahiro Yamada07a422b2018-03-16 16:37:12 +09001305$(autoksyms_h):
Quentin Perretada445e2020-02-18 09:41:39 +00001306 $(call cmd,autoksyms_h)
Nicolas Pitre23121ca2016-01-26 21:50:18 -05001307
Nicholas Pigginfbe6e372016-08-24 22:29:21 +10001308ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
1309
1310# Final link of vmlinux with optional arch pass after final link
Cao jin312a3d02017-08-02 10:31:06 +08001311cmd_link-vmlinux = \
Masahiro Yamada3ec8a5b2020-07-02 04:29:36 +09001312 $(CONFIG_SHELL) $< "$(LD)" "$(KBUILD_LDFLAGS)" "$(LDFLAGS_vmlinux)"; \
Nicholas Pigginfbe6e372016-08-24 22:29:21 +10001313 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
Nicolas Pitre2441e782016-04-22 15:25:00 -04001314
Elliot Berman7d5e1de2021-04-07 08:03:11 -07001315ifndef KBUILD_MIXED_TREE
Masahiro Yamada3fdc7d32018-03-16 16:37:15 +09001316vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
Sam Ravnborg1f2bfbd2012-05-05 10:18:41 +02001317 +$(call if_changed,link-vmlinux)
Elliot Berman7d5e1de2021-04-07 08:03:11 -07001318endif
Sam Ravnborg741f98f2007-07-17 10:54:06 +02001319
Masahiro Yamada392885e2018-11-30 10:05:22 +09001320targets := vmlinux
1321
Masahiro Yamada38385f82014-04-28 16:26:18 +09001322# The actual objects are generated when descending,
Linus Torvalds1da177e2005-04-16 15:20:36 -07001323# make sure no implicit rule kicks in
Masahiro Yamadab2c88552020-06-01 14:57:00 +09001324$(sort $(vmlinux-deps) $(subdir-modorder)): descend ;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001325
Masahiro Yamadaba97df42019-01-03 10:16:54 +09001326filechk_kernel.release = \
Will McVickerf0bec7a2020-07-09 15:33:45 -07001327 echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion \
1328 $(srctree) $(BRANCH) $(KMI_GENERATION))"
Michal Marek0d0e7712013-07-11 15:34:51 +02001329
Geert Uytterhoeven83a35e32013-06-28 11:27:31 +02001330# Store (new) KERNELRELEASE string in include/config/kernel.release
Masahiro Yamada24512792019-04-07 19:03:18 +09001331include/config/kernel.release: FORCE
Michal Marek0d0e7712013-07-11 15:34:51 +02001332 $(call filechk,kernel.release)
Sam Ravnborgcb584552006-01-09 21:20:34 +01001333
Masahiro Yamadad8821622018-03-16 16:37:11 +09001334# Additional helpers built in scripts/
1335# Carefully list dependencies so we do not try to build scripts twice
1336# in parallel
1337PHONY += scripts
Masahiro Yamada60df1ae2018-11-29 12:13:24 +09001338scripts: scripts_basic scripts_dtc
Masahiro Yamadad8821622018-03-16 16:37:11 +09001339 $(Q)$(MAKE) $(build)=$(@)
Sam Ravnborgcb584552006-01-09 21:20:34 +01001340
Linus Torvalds1da177e2005-04-16 15:20:36 -07001341# Things we need to do before we recursively start building the kernel
Sam Ravnborg5bb78262005-09-11 22:30:22 +02001342# or the modules are listed in "prepare".
1343# A multi level approach is used. prepareN is processed before prepareN-1.
1344# archprepare is used in arch Makefiles and when processed asm symlink,
1345# version.h and scripts_basic is processed / created.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001346
Masahiro Yamadaa5139fb2019-08-22 13:46:12 +09001347PHONY += prepare archprepare
Sam Ravnborg5bb78262005-09-11 22:30:22 +02001348
Masahiro Yamada36de0772019-08-22 13:46:13 +09001349archprepare: outputmakefile archheaders archscripts scripts include/config/kernel.release \
Masahiro Yamada3044dd02020-05-01 15:01:41 +09001350 asm-generic $(version_h) $(autoksyms_h) include/generated/utsrelease.h \
1351 include/generated/autoconf.h
Sam Ravnborg5bb78262005-09-11 22:30:22 +02001352
Masahiro Yamada65bba042018-11-29 11:58:50 +09001353prepare0: archprepare
Masahiro Yamada60df1ae2018-11-29 12:13:24 +09001354 $(Q)$(MAKE) $(build)=scripts/mod
Sam Ravnborg8d36a622005-09-10 21:05:36 +02001355 $(Q)$(MAKE) $(build)=.
Sam Ravnborg86feeaa2005-09-09 19:28:28 +02001356
Linus Torvalds1da177e2005-04-16 15:20:36 -07001357# All the preparing..
Jiri Olsa33a57ce2020-07-11 23:53:22 +02001358prepare: prepare0 prepare-objtool prepare-resolve_btfids
Josh Poimboeufb9ab5eb2016-02-28 22:22:42 -06001359
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +09001360# Support for using generic headers in asm-generic
Masahiro Yamada7d0e5c22018-12-05 20:28:04 +09001361asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj
1362
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +09001363PHONY += asm-generic uapi-asm-generic
1364asm-generic: uapi-asm-generic
Masahiro Yamada037fc332019-03-17 11:01:09 +09001365 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm \
1366 generic=include/asm-generic
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +09001367uapi-asm-generic:
Masahiro Yamada037fc332019-03-17 11:01:09 +09001368 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm \
1369 generic=include/uapi/asm-generic
Masahiro Yamada2c1f4f12017-10-04 12:56:06 +09001370
Jiri Olsa33a57ce2020-07-11 23:53:22 +02001371PHONY += prepare-objtool prepare-resolve_btfids
Josh Poimboeuf3b27a0c2016-03-03 11:39:30 -06001372prepare-objtool: $(objtool_target)
Masahiro Yamadaef7cfd02018-12-18 14:25:41 +09001373ifeq ($(SKIP_STACK_VALIDATION),1)
Sami Tolvanen195bcf12020-09-25 16:43:53 -07001374ifdef CONFIG_FTRACE_MCOUNT_USE_OBJTOOL
1375 @echo "error: Cannot generate __mcount_loc for CONFIG_DYNAMIC_FTRACE=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1376 @false
1377endif
Masahiro Yamadaef7cfd02018-12-18 14:25:41 +09001378ifdef CONFIG_UNWINDER_ORC
1379 @echo "error: Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1380 @false
1381else
1382 @echo "warning: Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1383endif
1384endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001385
Jiri Olsa33a57ce2020-07-11 23:53:22 +02001386prepare-resolve_btfids: $(resolve_btfids_target)
1387ifeq ($(ERROR_RESOLVE_BTFIDS),1)
1388 @echo "error: Cannot resolve BTF IDs for CONFIG_DEBUG_INFO_BTF, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1389 @false
1390endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001391# Generate some files
1392# ---------------------------------------------------------------------------
1393
1394# KERNELRELEASE can change from a few different places, meaning version.h
1395# needs to be updated, so this check is forced on all builds
1396
1397uts_len := 64
Alex Hongfc31d472019-07-19 16:37:33 +08001398ifneq (,$(BUILD_NUMBER))
1399 UTS_RELEASE=$(KERNELRELEASE)-ab$(BUILD_NUMBER)
1400else
1401 UTS_RELEASE=$(KERNELRELEASE)
1402endif
Sam Ravnborg63104ee2006-07-03 23:30:54 +02001403define filechk_utsrelease.h
Alex Hongfc31d472019-07-19 16:37:33 +08001404 if [ `echo -n "$(UTS_RELEASE)" | wc -c ` -gt $(uts_len) ]; then \
1405 echo '"$(UTS_RELEASE)" exceeds $(uts_len) characters' >&2; \
1406 exit 1; \
1407 fi; \
1408 echo \#define UTS_RELEASE \"$(UTS_RELEASE)\"
Linus Torvalds1da177e2005-04-16 15:20:36 -07001409endef
1410
Sam Ravnborg63104ee2006-07-03 23:30:54 +02001411define filechk_version.h
Sasha Levin950bff22021-02-05 22:50:32 -05001412 if [ $(SUBLEVEL) -gt 255 ]; then \
1413 echo \#define LINUX_VERSION_CODE $(shell \
Masahiro Yamadabb2e41e2021-02-27 23:20:23 +09001414 expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + 255); \
Sasha Levin950bff22021-02-05 22:50:32 -05001415 else \
1416 echo \#define LINUX_VERSION_CODE $(shell \
Masahiro Yamadabb2e41e2021-02-27 23:20:23 +09001417 expr $(VERSION) \* 65536 + $(PATCHLEVEL) \* 256 + $(SUBLEVEL)); \
Sasha Levin950bff22021-02-05 22:50:32 -05001418 fi; \
1419 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + \
1420 ((c) > 255 ? 255 : (c)))'
Sam Ravnborg63104ee2006-07-03 23:30:54 +02001421endef
1422
Masahiro Yamadabb2e41e2021-02-27 23:20:23 +09001423$(version_h): PATCHLEVEL := $(if $(PATCHLEVEL), $(PATCHLEVEL), 0)
1424$(version_h): SUBLEVEL := $(if $(SUBLEVEL), $(SUBLEVEL), 0)
Masahiro Yamada43fee2b2018-07-25 14:16:11 +09001425$(version_h): FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001426 $(call filechk,version.h)
Michal Marek223c24a2014-11-27 16:13:17 +01001427 $(Q)rm -f $(old_version_h)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001428
Sam Ravnborg273b2812009-10-18 00:52:28 +02001429include/generated/utsrelease.h: include/config/kernel.release FORCE
Sam Ravnborg63104ee2006-07-03 23:30:54 +02001430 $(call filechk,utsrelease.h)
1431
Vegard Nossum179efcb2008-12-16 12:33:43 +01001432PHONY += headerdep
1433headerdep:
Peter Foley9663d982011-04-26 17:17:11 -04001434 $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \
1435 $(srctree)/scripts/headerdep.pl -I$(srctree)/include
Vegard Nossum179efcb2008-12-16 12:33:43 +01001436
Masahiro Yamada7ecaf062019-11-07 16:14:41 +09001437# Deprecated. It is no-op now.
David Woodhouse68475352006-06-18 12:02:10 +01001438PHONY += headers_check
Masahiro Yamada7ecaf062019-11-07 16:14:41 +09001439headers_check:
1440 @:
David Woodhouse68475352006-06-18 12:02:10 +01001441
Masahiro Yamadae949f4c2019-06-04 19:13:59 +09001442ifdef CONFIG_HEADERS_INSTALL
Masahiro Yamada59b2bd02019-06-04 19:14:02 +09001443prepare: headers
Masahiro Yamadae949f4c2019-06-04 19:13:59 +09001444endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07001445
Masahiro Yamadabdd77142019-06-04 19:14:01 +09001446PHONY += scripts_unifdef
1447scripts_unifdef: scripts_basic
1448 $(Q)$(MAKE) $(build)=scripts scripts/unifdef
1449
Linus Torvalds1da177e2005-04-16 15:20:36 -07001450# ---------------------------------------------------------------------------
Shuah Khan5a5da782014-08-07 13:07:46 -06001451# Kernel selftest
1452
1453PHONY += kselftest
1454kselftest:
Shuah Khan2bc84522017-09-06 16:44:35 -06001455 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests
Shuah Khan5a5da782014-08-07 13:07:46 -06001456
Shuah Khan17eac6c2019-09-26 16:40:14 -06001457kselftest-%: FORCE
1458 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests $*
Wang Longdcb825a2015-10-08 02:41:18 +00001459
Bamvor Jian Zhang3d6dee72016-01-08 15:27:34 +08001460PHONY += kselftest-merge
1461kselftest-merge:
1462 $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!))
Dan Rue6d3db462019-05-20 10:16:14 -05001463 $(Q)find $(srctree)/tools/testing/selftests -name config | \
1464 xargs $(srctree)/scripts/kconfig/merge_config.sh -m $(objtree)/.config
Masahiro Yamada3e4c6942019-08-21 16:03:48 +09001465 $(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
Bamvor Jian Zhang3d6dee72016-01-08 15:27:34 +08001466
Shuah Khan5a5da782014-08-07 13:07:46 -06001467# ---------------------------------------------------------------------------
Rob Herring37c8a5f2018-01-10 15:19:37 -06001468# Devicetree files
1469
1470ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)
1471dtstree := arch/$(SRCARCH)/boot/dts
1472endif
1473
1474ifneq ($(dtstree),)
1475
Masahiro Yamadaa5139fb2019-08-22 13:46:12 +09001476%.dtb: include/config/kernel.release scripts_dtc
Rob Herring37c8a5f2018-01-10 15:19:37 -06001477 $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
1478
Masahiro Yamadac473a8d2020-02-23 04:04:34 +09001479PHONY += dtbs dtbs_install dtbs_check
Masahiro Yamadab5154bf2020-03-04 12:20:36 +09001480dtbs: include/config/kernel.release scripts_dtc
Rob Herring37c8a5f2018-01-10 15:19:37 -06001481 $(Q)$(MAKE) $(build)=$(dtstree)
1482
Masahiro Yamadab5154bf2020-03-04 12:20:36 +09001483ifneq ($(filter dtbs_check, $(MAKECMDGOALS)),)
Masahiro Yamadae10c4322020-03-04 12:20:37 +09001484export CHECK_DTBS=y
Masahiro Yamadab5154bf2020-03-04 12:20:36 +09001485dtbs: dt_binding_check
1486endif
1487
Masahiro Yamadab5154bf2020-03-04 12:20:36 +09001488dtbs_check: dtbs
Rob Herring4f0e3a52018-09-06 13:26:07 -05001489
Rob Herring37c8a5f2018-01-10 15:19:37 -06001490dtbs_install:
Masahiro Yamada2431f222020-03-07 02:08:51 +09001491 $(Q)$(MAKE) $(dtbinst)=$(dtstree) dst=$(INSTALL_DTBS_PATH)
Rob Herring37c8a5f2018-01-10 15:19:37 -06001492
1493ifdef CONFIG_OF_EARLY_FLATTREE
1494all: dtbs
1495endif
1496
1497endif
1498
1499PHONY += scripts_dtc
1500scripts_dtc: scripts_basic
1501 $(Q)$(MAKE) $(build)=scripts/dtc
1502
Masahiro Yamadae10c4322020-03-04 12:20:37 +09001503ifneq ($(filter dt_binding_check, $(MAKECMDGOALS)),)
1504export CHECK_DT_BINDING=y
1505endif
1506
Masahiro Yamadac473a8d2020-02-23 04:04:34 +09001507PHONY += dt_binding_check
Rob Herring4f0e3a52018-09-06 13:26:07 -05001508dt_binding_check: scripts_dtc
1509 $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings
1510
Rob Herring37c8a5f2018-01-10 15:19:37 -06001511# ---------------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -07001512# Modules
1513
1514ifdef CONFIG_MODULES
1515
Sam Ravnborg070b98b2006-06-25 00:07:55 +02001516# By default, build modules as well
Linus Torvalds1da177e2005-04-16 15:20:36 -07001517
Michal Marek73d13932010-03-10 12:28:58 +01001518all: modules
Linus Torvalds1da177e2005-04-16 15:20:36 -07001519
Masahiro Yamada4b50c8c2020-05-31 17:47:06 +09001520# When we're building modules with modversions, we need to consider
1521# the built-in objects during the descend as well, in order to
1522# make sure the checksums are up to date before we record them.
1523ifdef CONFIG_MODVERSIONS
1524 KBUILD_BUILTIN := 1
1525endif
1526
Masahiro Yamada3fbb43d2014-04-28 16:32:43 +09001527# Build modules
Tejun Heo551559e2007-12-07 21:04:30 +09001528#
Masahiro Yamada3fbb43d2014-04-28 16:32:43 +09001529# A module can be listed more than once in obj-m resulting in
1530# duplicate lines in modules.order files. Those are removed
1531# using awk while concatenating to the final file.
Linus Torvalds1da177e2005-04-16 15:20:36 -07001532
Paul Smith4f193362006-03-05 17:14:10 -05001533PHONY += modules
Elliot Berman7d5e1de2021-04-07 08:03:11 -07001534# if KBUILD_BUILTIN && !KBUILD_MIXED_TREE, depend on vmlinux
Greg Kroah-Hartman49220492023-02-06 12:30:05 +00001535modules: $(if $(KBUILD_BUILTIN), $(if $(KBUILD_MIXED_TREE),,vmlinux)) modules_check modules_prepare
Linus Torvalds1da177e2005-04-16 15:20:36 -07001536
Masahiro Yamada84517912020-05-11 13:21:49 +09001537PHONY += modules_check
1538modules_check: modules.order
1539 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/modules-check.sh $<
Linus Torvalds1da177e2005-04-16 15:20:36 -07001540
Masahiro Yamadab2c88552020-06-01 14:57:00 +09001541cmd_modules_order = $(AWK) '!x[$$0]++' $(real-prereqs) > $@
1542
1543modules.order: $(subdir-modorder) FORCE
1544 $(call if_changed,modules_order)
1545
1546targets += modules.order
Michal Mareka6c36632010-03-08 10:07:12 +01001547
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548# Target to prepare building external modules
Paul Smith4f193362006-03-05 17:14:10 -05001549PHONY += modules_prepare
Masahiro Yamada059bc9fc2018-11-29 12:56:30 +09001550modules_prepare: prepare
Masahiro Yamada596b0472020-09-08 13:27:08 +09001551 $(Q)$(MAKE) $(build)=scripts scripts/module.lds
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552
Masahiro Yamadae3bdda22021-03-31 22:38:03 +09001553modules_install: __modinst_pre
1554PHONY += __modinst_pre
1555__modinst_pre:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 @rm -rf $(MODLIB)/kernel
1557 @rm -f $(MODLIB)/source
1558 @mkdir -p $(MODLIB)/kernel
Masahiro Yamada8e9b4662017-08-20 15:04:11 +09001559 @ln -s $(abspath $(srctree)) $(MODLIB)/source
Linus Torvalds1da177e2005-04-16 15:20:36 -07001560 @if [ ! $(objtree) -ef $(MODLIB)/build ]; then \
1561 rm -f $(MODLIB)/build ; \
Michal Marek7e1c0472014-04-25 17:29:45 +02001562 ln -s $(CURDIR) $(MODLIB)/build ; \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 fi
Masahiro Yamada1bd9a462019-07-17 15:17:50 +09001564 @sed 's:^:kernel/:' modules.order > $(MODLIB)/modules.order
Elliot Berman7d5e1de2021-04-07 08:03:11 -07001565 @cp -f $(mixed-build-prefix)modules.builtin $(MODLIB)/
1566 @cp -f $(or $(mixed-build-prefix),$(objtree)/)modules.builtin.modinfo $(MODLIB)/
Linus Torvalds1da177e2005-04-16 15:20:36 -07001567
Josh Boyerd890f512012-11-05 09:09:24 +10301568ifeq ($(CONFIG_MODULE_SIG), y)
1569PHONY += modules_sign
1570modules_sign:
1571 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modsign
1572endif
1573
Linus Torvalds1da177e2005-04-16 15:20:36 -07001574endif # CONFIG_MODULES
1575
Linus Torvalds1da177e2005-04-16 15:20:36 -07001576###
1577# Cleaning is done on three levels.
1578# make clean Delete most generated files
1579# Leave enough to build external modules
1580# make mrproper Delete the current configuration, and all generated files
1581# make distclean Remove editor backup files, patch leftover files and the like
1582
1583# Directories & files removed with 'make clean'
Masahiro Yamadad0736af2021-03-26 03:54:09 +09001584CLEAN_FILES += include/ksym vmlinux.symvers modules-only.symvers \
Masahiro Yamada3d322852020-08-22 23:56:16 +09001585 modules.builtin modules.builtin.modinfo modules.nsdeps \
Masahiro Yamadab1843022021-02-26 04:39:12 +09001586 compile_commands.json .thinlto-cache
Linus Torvalds1da177e2005-04-16 15:20:36 -07001587
1588# Directories & files removed with 'make mrproper'
Masahiro Yamada0663c682020-05-04 17:08:07 +09001589MRPROPER_FILES += include/config include/generated \
Masahiro Yamada46a63d42019-08-21 16:02:02 +09001590 arch/$(SRCARCH)/include/generated .tmp_objdiff \
Masahiro Yamada0663c682020-05-04 17:08:07 +09001591 debian snap tar-install \
1592 .config .config.old .version \
Masahiro Yamada46457132019-07-15 23:01:49 +09001593 Module.symvers \
David Woodhousefb117942015-07-20 21:16:30 +01001594 signing_key.pem signing_key.priv signing_key.x509 \
1595 x509.genkey extra_certificates signing_key.x509.keyid \
Masahiro Yamada46a63d42019-08-21 16:02:02 +09001596 signing_key.x509.signer vmlinux-gdb.py \
1597 *.spec
Linus Torvalds1da177e2005-04-16 15:20:36 -07001598
Masahiro Yamada46457132019-07-15 23:01:49 +09001599# Directories & files removed with 'make distclean'
Masahiro Yamadab1843022021-02-26 04:39:12 +09001600DISTCLEAN_FILES += tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
Masahiro Yamada46457132019-07-15 23:01:49 +09001601
Linus Torvalds1da177e2005-04-16 15:20:36 -07001602# clean - Delete most, but leave enough to build external modules
1603#
Linus Torvalds1da177e2005-04-16 15:20:36 -07001604clean: rm-files := $(CLEAN_FILES)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001605
Masahiro Yamada76cd3062019-08-11 00:53:05 +09001606PHONY += archclean vmlinuxclean
Linus Torvalds1da177e2005-04-16 15:20:36 -07001607
Pawel Mollbd1ee802012-10-29 11:23:02 +00001608vmlinuxclean:
1609 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
Nicholas Pigginfbe6e372016-08-24 22:29:21 +10001610 $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
Pawel Mollbd1ee802012-10-29 11:23:02 +00001611
Jiri Olsa0945d672021-02-05 13:40:20 +01001612clean: archclean vmlinuxclean resolve_btfids_clean
Linus Torvalds1da177e2005-04-16 15:20:36 -07001613
1614# mrproper - Delete all generated files, including .config
1615#
Linus Torvalds1da177e2005-04-16 15:20:36 -07001616mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -03001617mrproper-dirs := $(addprefix _mrproper_,scripts)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001618
Masahiro Yamadab421b8a2019-01-14 17:29:29 +09001619PHONY += $(mrproper-dirs) mrproper
Linus Torvalds1da177e2005-04-16 15:20:36 -07001620$(mrproper-dirs):
1621 $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
1622
Masahiro Yamadab421b8a2019-01-14 17:29:29 +09001623mrproper: clean $(mrproper-dirs)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624 $(call cmd,rmfiles)
1625
1626# distclean
1627#
Masahiro Yamada46457132019-07-15 23:01:49 +09001628distclean: rm-files := $(wildcard $(DISTCLEAN_FILES))
1629
Paul Smith4f193362006-03-05 17:14:10 -05001630PHONY += distclean
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631
1632distclean: mrproper
Masahiro Yamada46457132019-07-15 23:01:49 +09001633 $(call cmd,rmfiles)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001634 @find $(srctree) $(RCS_FIND_IGNORE) \
Sam Ravnborg070b98b2006-06-25 00:07:55 +02001635 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
Masahiro Yamadaf78271d2017-01-22 23:02:32 +09001636 -o -name '*.bak' -o -name '#*#' -o -name '*%' \
1637 -o -name 'core' \) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001638 -type f -print | xargs rm -f
1639
1640
1641# Packaging of the kernel to various formats
1642# ---------------------------------------------------------------------------
Linus Torvalds1da177e2005-04-16 15:20:36 -07001643
Arnaldo Carvalho de Melobafb6742010-06-07 07:44:25 -03001644%src-pkg: FORCE
Masahiro Yamada000ec952019-08-21 16:02:04 +09001645 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
Zach Brown031ecc62006-06-08 22:12:37 -07001646%pkg: include/config/kernel.release FORCE
Masahiro Yamada000ec952019-08-21 16:02:04 +09001647 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.package $@
Linus Torvalds1da177e2005-04-16 15:20:36 -07001648
1649# Brief documentation of the typical targets used
1650# ---------------------------------------------------------------------------
1651
Segher Boessenkool5dffbe82008-04-06 22:16:07 +02001652boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig)
Konstantin Khlebnikova1e7b7b2014-10-28 17:18:20 +04001653boards := $(sort $(notdir $(boards)))
Segher Boessenkool5dffbe82008-04-06 22:16:07 +02001654board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
1655board-dirs := $(sort $(notdir $(board-dirs:/=)))
Linus Torvalds1da177e2005-04-16 15:20:36 -07001656
Masahiro Yamadafe69b422016-03-13 09:39:55 +09001657PHONY += help
Linus Torvalds1da177e2005-04-16 15:20:36 -07001658help:
1659 @echo 'Cleaning targets:'
Samuel Tardieu5ea084e2006-12-12 19:09:40 +01001660 @echo ' clean - Remove most generated files but keep the config and'
Jesper Juhl5cc8d242006-09-24 14:01:08 +02001661 @echo ' enough build support to build external modules'
Samuel Tardieu5ea084e2006-12-12 19:09:40 +01001662 @echo ' mrproper - Remove all generated files + config + various backup files'
Jesper Juhl5cc8d242006-09-24 14:01:08 +02001663 @echo ' distclean - mrproper + remove editor backup and patch files'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001664 @echo ''
1665 @echo 'Configuration targets:'
1666 @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
1667 @echo ''
1668 @echo 'Other generic targets:'
1669 @echo ' all - Build all targets marked with [*]'
1670 @echo '* vmlinux - Build the bare kernel'
1671 @echo '* modules - Build all modules'
Bodo Eggert9cc5d742005-11-23 20:11:34 +01001672 @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001673 @echo ' dir/ - Build all files in dir and below'
Wang YanQing40ab87a42015-12-11 00:35:19 +08001674 @echo ' dir/file.[ois] - Build specified target only'
Vinícius Tinti433db3e2017-04-24 13:04:58 -07001675 @echo ' dir/file.ll - Build the LLVM assembly file'
1676 @echo ' (requires compiler support for LLVM assembly generation)'
Joe Perches62718972010-01-13 09:31:44 -08001677 @echo ' dir/file.lst - Build specified mixed source/assembly target only'
1678 @echo ' (requires a recent binutils and recent build (System.map))'
Sam Ravnborg155ad602005-07-07 17:56:08 -07001679 @echo ' dir/file.ko - Build module including final link'
Robert P. J. Dayc4d5ee62009-04-24 12:35:23 -04001680 @echo ' modules_prepare - Set up for building external modules'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001681 @echo ' tags/TAGS - Generate tags file for editors'
1682 @echo ' cscope - Generate cscope index'
Jianbin Kangf4ed1002011-01-14 20:07:05 +08001683 @echo ' gtags - Generate GNU GLOBAL index'
Michal Marek3f1d9a62014-07-11 15:57:24 +02001684 @echo ' kernelrelease - Output the release version string (use with make -s)'
1685 @echo ' kernelversion - Output the version stored in Makefile (use with make -s)'
1686 @echo ' image_name - Output the image name (use with make -s)'
Sam Ravnborg2fb9b1b2008-06-21 00:24:17 +02001687 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
Geert Uytterhoeven59df3232007-01-29 13:47:01 +01001688 echo ' (default: $(INSTALL_HDR_PATH))'; \
Sam Ravnborg2fb9b1b2008-06-21 00:24:17 +02001689 echo ''
Randy Dunlap31b8cc82017-05-08 15:55:08 -07001690 @echo 'Static analysers:'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001691 @echo ' checkstack - Generate a list of stack hogs'
Sam Ravnborgaa025e72007-11-14 21:34:55 +01001692 @echo ' versioncheck - Sanity check on version.h usage'
Randy Dunlapec2d9872007-11-04 12:01:55 -08001693 @echo ' includecheck - Check for duplicate included header files'
Adrian Bunk295ac052007-08-24 23:04:56 +02001694 @echo ' export_report - List the usages of all exported symbols'
Nicolas Palix74425ee2010-06-06 17:15:01 +02001695 @echo ' headerdep - Detect inclusion cycles in headers'
Masahiro Yamada7f855fc82017-11-14 18:47:20 +09001696 @echo ' coccicheck - Check with Coccinelle'
Nathan Huckleberry6ad7cbc2020-08-22 23:56:18 +09001697 @echo ' clang-analyzer - Check with clang static analyzer'
1698 @echo ' clang-tidy - Check with clang-tidy'
Nicolas Palix74425ee2010-06-06 17:15:01 +02001699 @echo ''
Matthias Maennich537d1f72019-11-11 14:56:43 +00001700 @echo 'Tools:'
1701 @echo ' nsdeps - Generate missing symbol namespace dependencies'
1702 @echo ''
Randy Dunlap31b8cc82017-05-08 15:55:08 -07001703 @echo 'Kernel selftest:'
Shuah Khane51d8da2020-03-30 12:07:11 -06001704 @echo ' kselftest - Build and run kernel selftest'
1705 @echo ' Build, install, and boot kernel before'
1706 @echo ' running kselftest on it'
1707 @echo ' Run as root for full coverage'
1708 @echo ' kselftest-all - Build kernel selftest'
1709 @echo ' kselftest-install - Build and install kernel selftest'
1710 @echo ' kselftest-clean - Remove all generated kselftest files'
1711 @echo ' kselftest-merge - Merge all the config dependencies of'
1712 @echo ' kselftest to existing .config.'
Shuah Khan5a5da782014-08-07 13:07:46 -06001713 @echo ''
Rob Herring37c8a5f2018-01-10 15:19:37 -06001714 @$(if $(dtstree), \
1715 echo 'Devicetree:'; \
Stephen Boyd7aa8dd912019-08-13 11:38:25 -07001716 echo '* dtbs - Build device tree blobs for enabled boards'; \
1717 echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \
1718 echo ' dt_binding_check - Validate device tree binding documents'; \
1719 echo ' dtbs_check - Validate device tree source files';\
Rob Herring37c8a5f2018-01-10 15:19:37 -06001720 echo '')
1721
Randy Dunlap31b8cc82017-05-08 15:55:08 -07001722 @echo 'Userspace tools targets:'
1723 @echo ' use "make tools/help"'
1724 @echo ' or "cd tools; make help"'
1725 @echo ''
Linus Torvalds1da177e2005-04-16 15:20:36 -07001726 @echo 'Kernel packaging:'
Masahiro Yamada000ec952019-08-21 16:02:04 +09001727 @$(MAKE) -f $(srctree)/scripts/Makefile.package help
Linus Torvalds1da177e2005-04-16 15:20:36 -07001728 @echo ''
1729 @echo 'Documentation targets:'
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -03001730 @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
Linus Torvalds1da177e2005-04-16 15:20:36 -07001731 @echo ''
Andres Salomon01dee182008-04-25 22:34:58 -04001732 @echo 'Architecture specific targets ($(SRCARCH)):'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001733 @$(if $(archhelp),$(archhelp),\
Andres Salomon01dee182008-04-25 22:34:58 -04001734 echo ' No architecture specific help defined for $(SRCARCH)')
Linus Torvalds1da177e2005-04-16 15:20:36 -07001735 @echo ''
1736 @$(if $(boards), \
1737 $(foreach b, $(boards), \
Geert Uytterhoeven42344482019-10-25 13:53:05 +02001738 printf " %-27s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07001739 echo '')
Segher Boessenkool5dffbe82008-04-06 22:16:07 +02001740 @$(if $(board-dirs), \
1741 $(foreach b, $(board-dirs), \
1742 printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
1743 printf " %-16s - Show all of the above\\n" help-boards; \
1744 echo '')
Linus Torvalds1da177e2005-04-16 15:20:36 -07001745
1746 @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
Sam Ravnborg45d506b2006-08-08 21:35:14 +02001747 @echo ' make V=2 [targets] 2 => give reason for rebuild of target'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001748 @echo ' make O=dir [targets] Locate all output files in "dir", including .config'
Geert Uytterhoevena64c0442019-10-25 13:52:32 +02001749 @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK'
1750 @echo ' (sparse by default)'
Dustin Kirkland701842e2006-05-23 15:57:23 -05001751 @echo ' make C=2 [targets] Force check of all c source with $$CHECK'
Ingo Molnaraf07ce32011-06-16 13:26:23 +02001752 @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections'
Masahiro Yamadae27128d2019-09-01 01:25:55 +09001753 @echo ' make W=n [targets] Enable extra build checks, n=1,2,3 where'
Sam Ravnborg28bc20d2011-04-27 22:15:27 +02001754 @echo ' 1: warnings which may be relevant and do not occur too often'
1755 @echo ' 2: warnings which occur quite often but may still be relevant'
1756 @echo ' 3: more obscure warnings, can most likely be ignored'
Michal Mareka6de5532011-04-29 14:45:31 +02001757 @echo ' Multiple levels can be combined with W=12 or W=123'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 @echo ''
1759 @echo 'Execute "make" or "make all" to build all targets marked with [*] '
1760 @echo 'For further info see the ./README file'
1761
1762
Segher Boessenkool5dffbe82008-04-06 22:16:07 +02001763help-board-dirs := $(addprefix help-,$(board-dirs))
1764
1765help-boards: $(help-board-dirs)
1766
Michal Marekfbae4d52014-11-28 13:31:43 +01001767boards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)))
Segher Boessenkool5dffbe82008-04-06 22:16:07 +02001768
1769$(help-board-dirs): help-%:
1770 @echo 'Architecture specific targets ($(SRCARCH) $*):'
1771 @$(if $(boards-per-dir), \
1772 $(foreach b, $(boards-per-dir), \
1773 printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
1774 echo '')
1775
1776
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777# Documentation targets
1778# ---------------------------------------------------------------------------
Jani Nikulae8939222017-10-09 18:26:15 +03001779DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \
1780 linkcheckdocs dochelp refcheckdocs
Jani Nikula22cba312016-05-19 15:14:05 +03001781PHONY += $(DOC_TARGETS)
Masahiro Yamadabc7b752a2019-08-22 02:33:21 +09001782$(DOC_TARGETS):
Mauro Carvalho Chehabcb43fb52017-05-14 11:50:01 -03001783 $(Q)$(MAKE) $(build)=Documentation $@
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784
Masahiro Yamada67274c02019-02-19 18:33:02 +09001785# Misc
1786# ---------------------------------------------------------------------------
1787
1788PHONY += scripts_gdb
Masahiro Yamada7a739ce2019-06-04 19:13:57 +09001789scripts_gdb: prepare0
Masahiro Yamada1e5ff842019-02-19 18:33:04 +09001790 $(Q)$(MAKE) $(build)=scripts/gdb
Masahiro Yamada8d2e5202019-02-19 18:33:05 +09001791 $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
Masahiro Yamada67274c02019-02-19 18:33:02 +09001792
1793ifdef CONFIG_GDB_SCRIPTS
1794all: scripts_gdb
1795endif
1796
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797else # KBUILD_EXTMOD
1798
1799###
1800# External module support.
1801# When building external modules the kernel used as basis is considered
1802# read-only, and no consistency checks are made and the make
1803# system is not used on the basis kernel. If updates are required
1804# in the basis kernel ordinary make commands (without M=...) must
1805# be used.
1806#
1807# The following are the only valid targets when building external
1808# modules.
1809# make M=dir clean Delete all automatically generated files
1810# make M=dir modules Make all modules in specified dir
1811# make M=dir Same as 'make M=dir modules'
1812# make M=dir modules_install
Sam Ravnborg070b98b2006-06-25 00:07:55 +02001813# Install the modules built in the module directory
Linus Torvalds1da177e2005-04-16 15:20:36 -07001814# Assumes install directory is already created
1815
Masahiro Yamada62128042020-09-09 05:55:57 +09001816# We are always building only modules.
1817KBUILD_BUILTIN :=
Linus Torvalds1da177e2005-04-16 15:20:36 -07001818KBUILD_MODULES := 1
Linus Torvalds1da177e2005-04-16 15:20:36 -07001819
Masahiro Yamadac99f3912019-08-11 00:53:04 +09001820build-dirs := $(KBUILD_EXTMOD)
Masahiro Yamada3d322852020-08-22 23:56:16 +09001821$(MODORDER): descend
1822 @:
1823
Masahiro Yamada3d322852020-08-22 23:56:16 +09001824compile_commands.json: $(extmod-prefix)compile_commands.json
1825PHONY += compile_commands.json
1826
Masahiro Yamada76cd3062019-08-11 00:53:05 +09001827clean-dirs := $(KBUILD_EXTMOD)
Masahiro Yamada3d322852020-08-22 23:56:16 +09001828clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers $(KBUILD_EXTMOD)/modules.nsdeps \
Sami Tolvanenba01e932020-03-06 14:14:03 -08001829 $(KBUILD_EXTMOD)/compile_commands.json $(KBUILD_EXTMOD)/.thinlto-cache
Linus Torvalds1da177e2005-04-16 15:20:36 -07001830
Masahiro Yamadafe69b422016-03-13 09:39:55 +09001831PHONY += help
Linus Torvalds1da177e2005-04-16 15:20:36 -07001832help:
1833 @echo ' Building external modules.'
1834 @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target'
1835 @echo ''
1836 @echo ' modules - default target, build the module(s)'
1837 @echo ' modules_install - install the module'
Elliot Berman280812b2020-07-24 18:12:48 -07001838 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'
1839 @echo ' (default: $(abspath $(INSTALL_HDR_PATH)))'
Linus Torvalds1da177e2005-04-16 15:20:36 -07001840 @echo ' clean - remove generated files in module directory only'
1841 @echo ''
Sam Ravnborg06300b22006-01-25 07:13:18 +01001842
Masahiro Yamada596b0472020-09-08 13:27:08 +09001843# no-op for external module builds
1844PHONY += prepare modules_prepare
1845
Linus Torvalds1da177e2005-04-16 15:20:36 -07001846endif # KBUILD_EXTMOD
1847
Masahiro Yamadae3bdda22021-03-31 22:38:03 +09001848# ---------------------------------------------------------------------------
1849# Modules
1850
1851PHONY += modules modules_install
1852
1853ifdef CONFIG_MODULES
1854
1855modules: $(MODORDER)
1856 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1857
1858quiet_cmd_depmod = DEPMOD $(KERNELRELEASE)
1859 cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \
Greg Kroah-Hartman49220492023-02-06 12:30:05 +00001860 $(KERNELRELEASE) $(mixed-build-prefix)
Masahiro Yamadae3bdda22021-03-31 22:38:03 +09001861
1862modules_install:
1863 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1864 $(call cmd,depmod)
1865
1866else # CONFIG_MODULES
1867
1868# Modules not configured
1869# ---------------------------------------------------------------------------
1870
1871modules modules_install:
1872 @echo >&2 '***'
1873 @echo >&2 '*** The present kernel configuration has modules disabled.'
1874 @echo >&2 '*** To use the module feature, please run "make menuconfig" etc.'
1875 @echo >&2 '*** to enable CONFIG_MODULES.'
1876 @echo >&2 '***'
1877 @exit 1
1878
Masahiro Yamada8d2ff5b2022-08-28 11:39:50 +09001879KBUILD_MODULES :=
1880
Masahiro Yamadae3bdda22021-03-31 22:38:03 +09001881endif # CONFIG_MODULES
1882
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001883# Single targets
1884# ---------------------------------------------------------------------------
1885# To build individual files in subdirectories, you can do like this:
1886#
1887# make foo/bar/baz.s
1888#
1889# The supported suffixes for single-target are listed in 'single-targets'
1890#
1891# To build only under specific subdirectories, you can do like this:
1892#
1893# make foo/bar/baz/
1894
1895ifdef single-build
1896
1897# .ko is special because modpost is needed
1898single-ko := $(sort $(filter %.ko, $(MAKECMDGOALS)))
1899single-no-ko := $(sort $(patsubst %.ko,%.mod, $(MAKECMDGOALS)))
1900
1901$(single-ko): single_modpost
1902 @:
1903$(single-no-ko): descend
1904 @:
1905
Masahiro Yamada8d2ff5b2022-08-28 11:39:50 +09001906# Remove MODORDER when done because it is not the real one.
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001907PHONY += single_modpost
Masahiro Yamada596b0472020-09-08 13:27:08 +09001908single_modpost: $(single-no-ko) modules_prepare
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001909 $(Q){ $(foreach m, $(single-ko), echo $(extmod-prefix)$m;) } > $(MODORDER)
1910 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
Masahiro Yamada8d2ff5b2022-08-28 11:39:50 +09001911 $(Q)rm -f $(MODORDER)
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001912
1913export KBUILD_SINGLE_TARGETS := $(addprefix $(extmod-prefix), $(single-no-ko))
1914
1915# trim unrelated directories
1916build-dirs := $(foreach d, $(build-dirs), \
1917 $(if $(filter $(d)/%, $(KBUILD_SINGLE_TARGETS)), $(d)))
1918
1919endif
1920
Masahiro Yamadac99f3912019-08-11 00:53:04 +09001921# Handle descending into subdirectories listed in $(build-dirs)
1922# Preset locale variables to speed up the build process. Limit locale
1923# tweaks to this spot to avoid wrong language settings when running
1924# make menuconfig etc.
1925# Error messages still appears in the original language
1926PHONY += descend $(build-dirs)
1927descend: $(build-dirs)
1928$(build-dirs): prepare
Masahiro Yamadab1fbfcb2019-11-18 13:52:47 +09001929 $(Q)$(MAKE) $(build)=$@ \
Masahiro Yamada20b1be52020-07-08 01:35:08 +09001930 single-build=$(if $(filter-out $@/, $(filter $@/%, $(KBUILD_SINGLE_TARGETS))),1) \
Elliot Berman7d5e1de2021-04-07 08:03:11 -07001931 $(if $(KBUILD_MIXED_TREE),,need-builtin=1) need-modorder=1
Masahiro Yamadac99f3912019-08-11 00:53:04 +09001932
Masahiro Yamada76cd3062019-08-11 00:53:05 +09001933clean-dirs := $(addprefix _clean_, $(clean-dirs))
1934PHONY += $(clean-dirs) clean
1935$(clean-dirs):
1936 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1937
Michal Marek88d7be02010-09-06 12:00:08 +02001938clean: $(clean-dirs)
Michal Marek88d7be02010-09-06 12:00:08 +02001939 $(call cmd,rmfiles)
Kevin Cernekee43f67c92011-05-10 15:47:16 -07001940 @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
Masahiro Yamadaef46d9b2017-11-17 01:49:13 +09001941 \( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \
Rob Herring4f0e3a52018-09-06 13:26:07 -05001942 -o -name '*.ko.*' \
1943 -o -name '*.dtb' -o -name '*.dtb.S' -o -name '*.dt.yaml' \
Deokgyu Yangf7125692021-06-16 15:14:05 +09001944 -o -name '*.dtbo' -o -name '*.dtbo.S' \
Masahiro Yamadaef46d9b2017-11-17 01:49:13 +09001945 -o -name '*.dwo' -o -name '*.lst' \
Masahiro Yamadabbc55bd2019-10-29 21:38:07 +09001946 -o -name '*.su' -o -name '*.mod' \
Michal Marek88d7be02010-09-06 12:00:08 +02001947 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
Masahiro Yamada9a8dfb32018-03-23 22:04:31 +09001948 -o -name '*.lex.c' -o -name '*.tab.[ch]' \
Masahiro Yamada4fa8bc92018-03-23 22:04:37 +09001949 -o -name '*.asn1.[ch]' \
Michal Marek88d7be02010-09-06 12:00:08 +02001950 -o -name '*.symtypes' -o -name 'modules.order' \
Masahiro Yamada8b41fc42019-12-19 17:33:29 +09001951 -o -name '.tmp_*.o.*' \
Emese Revfy6b90bd42016-05-24 00:09:38 +02001952 -o -name '*.c.[012]*.*' \
Vinícius Tinti433db3e2017-04-24 13:04:58 -07001953 -o -name '*.ll' \
Sami Tolvanen93f38312020-03-06 14:19:09 -08001954 -o -name '*.gcno' \
1955 -o -name '*.*.symversions' \) -type f -print | xargs rm -f
Michal Marek88d7be02010-09-06 12:00:08 +02001956
Linus Torvalds1da177e2005-04-16 15:20:36 -07001957# Generate tags for editors
1958# ---------------------------------------------------------------------------
Sam Ravnborga680eed2008-12-03 22:24:13 +01001959quiet_cmd_tags = GEN $@
Masahiro Yamada858805b2019-08-25 22:28:37 +09001960 cmd_tags = $(BASH) $(srctree)/scripts/tags.sh $@
Linus Torvalds1da177e2005-04-16 15:20:36 -07001961
Jianbin Kangf4ed1002011-01-14 20:07:05 +08001962tags TAGS cscope gtags: FORCE
Linus Torvalds1da177e2005-04-16 15:20:36 -07001963 $(call cmd,tags)
1964
Matthias Maennich537d1f72019-11-11 14:56:43 +00001965# Script to generate missing namespace dependencies
1966# ---------------------------------------------------------------------------
1967
1968PHONY += nsdeps
Masahiro Yamadabff9c622019-10-29 21:38:06 +09001969nsdeps: export KBUILD_NSDEPS=1
Matthias Maennich537d1f72019-11-11 14:56:43 +00001970nsdeps: modules
Masahiro Yamadabff9c622019-10-29 21:38:06 +09001971 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/nsdeps
Matthias Maennich537d1f72019-11-11 14:56:43 +00001972
Masahiro Yamada3d322852020-08-22 23:56:16 +09001973# Clang Tooling
1974# ---------------------------------------------------------------------------
1975
1976quiet_cmd_gen_compile_commands = GEN $@
1977 cmd_gen_compile_commands = $(PYTHON3) $< -a $(AR) -o $@ $(filter-out $<, $(real-prereqs))
1978
Nathan Huckleberry6ad7cbc2020-08-22 23:56:18 +09001979$(extmod-prefix)compile_commands.json: scripts/clang-tools/gen_compile_commands.py \
Masahiro Yamada3d322852020-08-22 23:56:16 +09001980 $(if $(KBUILD_EXTMOD),,$(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)) \
1981 $(if $(CONFIG_MODULES), $(MODORDER)) FORCE
1982 $(call if_changed,gen_compile_commands)
1983
1984targets += $(extmod-prefix)compile_commands.json
1985
Nathan Huckleberry6ad7cbc2020-08-22 23:56:18 +09001986PHONY += clang-tidy clang-analyzer
1987
1988ifdef CONFIG_CC_IS_CLANG
1989quiet_cmd_clang_tools = CHECK $<
1990 cmd_clang_tools = $(PYTHON3) $(srctree)/scripts/clang-tools/run-clang-tools.py $@ $<
1991
1992clang-tidy clang-analyzer: $(extmod-prefix)compile_commands.json
1993 $(call cmd,clang_tools)
1994else
1995clang-tidy clang-analyzer:
1996 @echo "$@ requires CC=clang" >&2
1997 @false
1998endif
1999
Linus Torvalds1da177e2005-04-16 15:20:36 -07002000# Scripts to check various things for consistency
2001# ---------------------------------------------------------------------------
2002
Jacob Keller7dfbea42020-10-09 17:18:44 -07002003PHONY += includecheck versioncheck coccicheck export_report
Peter Foley279f3dd2011-04-26 17:15:01 -04002004
Linus Torvalds1da177e2005-04-16 15:20:36 -07002005includecheck:
Peter Foley436f8762011-04-26 17:18:29 -04002006 find $(srctree)/* $(RCS_FIND_IGNORE) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007 -name '*.[hcS]' -type f -print | sort \
Geert Uytterhoeven80007432007-11-05 11:51:44 +01002008 | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009
2010versioncheck:
Peter Foley2ee2d292011-04-26 17:19:28 -04002011 find $(srctree)/* $(RCS_FIND_IGNORE) \
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 -name '*.[hcS]' -type f -print | sort \
Geert Uytterhoeven80007432007-11-05 11:51:44 +01002013 | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014
Nicolas Palix74425ee2010-06-06 17:15:01 +02002015coccicheck:
Masahiro Yamada858805b2019-08-25 22:28:37 +09002016 $(Q)$(BASH) $(srctree)/scripts/$@
Nicolas Palix74425ee2010-06-06 17:15:01 +02002017
Adrian Bunk295ac052007-08-24 23:04:56 +02002018export_report:
2019 $(PERL) $(srctree)/scripts/export_report.pl
2020
Mike Marciniszync398ff02013-06-24 08:48:37 -04002021PHONY += checkstack kernelrelease kernelversion image_name
Jeff Dikee3ccf6e2006-09-27 01:50:37 -07002022
Jeff Dike011e3a92006-12-13 00:34:12 -08002023# UML needs a little special treatment here. It wants to use the host
2024# toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone
2025# else wants $(ARCH), including people doing cross-builds, which means
2026# that $(SUBARCH) doesn't work here.
2027ifeq ($(ARCH), um)
2028CHECKSTACK_ARCH := $(SUBARCH)
2029else
2030CHECKSTACK_ARCH := $(ARCH)
2031endif
Linus Torvalds1da177e2005-04-16 15:20:36 -07002032checkstack:
2033 $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
Masahiro Yamada75dd4742019-07-06 12:07:11 +09002034 $(PERL) $(srctree)/scripts/checkstack.pl $(CHECKSTACK_ARCH)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035
Amerigo Wang7b8ea532010-08-20 05:36:06 -04002036kernelrelease:
Will McVickerf0bec7a2020-07-09 15:33:45 -07002037 @echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion \
2038 $(srctree) $(BRANCH) $(KMI_GENERATION))"
Amerigo Wang01ab1782010-06-28 10:45:21 +08002039
Sam Ravnborgcb584552006-01-09 21:20:34 +01002040kernelversion:
Sam Ravnborg2244cbd2006-01-16 12:12:12 +01002041 @echo $(KERNELVERSION)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002042
Mike Marciniszync398ff02013-06-24 08:48:37 -04002043image_name:
2044 @echo $(KBUILD_IMAGE)
2045
Borislav Petkovea01fa92012-04-11 18:36:18 +02002046# Clear a bunch of variables before executing the submake
Masahiro Yamadaf47a23c2019-02-22 16:40:06 +09002047
2048ifeq ($(quiet),silent_)
2049tools_silent=s
2050endif
2051
Borislav Petkovea01fa92012-04-11 18:36:18 +02002052tools/: FORCE
David Howellsbf351822012-11-05 21:02:08 +00002053 $(Q)mkdir -p $(objtree)/tools
Masahiro Yamada75dd4742019-07-06 12:07:11 +09002054 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/
Borislav Petkovea01fa92012-04-11 18:36:18 +02002055
2056tools/%: FORCE
David Howellsbf351822012-11-05 21:02:08 +00002057 $(Q)mkdir -p $(objtree)/tools
Masahiro Yamada75dd4742019-07-06 12:07:11 +09002058 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(srctree)/tools/ $*
Borislav Petkovea01fa92012-04-11 18:36:18 +02002059
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)