]> git.ipfire.org Git - thirdparty/kernel/stable.git/blame - Makefile
kbuild: clean up scripts/gcc-version.sh
[thirdparty/kernel/stable.git] / Makefile
CommitLineData
b2441318 1# SPDX-License-Identifier: GPL-2.0
bfeffd15
LT
2VERSION = 5
3PATCHLEVEL = 0
55922c9d 4SUBLEVEL = 0
f17b5f06 5EXTRAVERSION = -rc4
2e6e902d 6NAME = Shy Crocodile
1da177e4
LT
7
8# *DOCUMENTATION*
9# To see a list of typical targets execute "make help"
10# More info can be located in ./README
11# Comments in this file are targeted only to the developer, do not
12# expect to learn how to build the kernel reading this file.
13
ba634ece
MY
14# That's our default target when none is given on the command line
15PHONY := _all
16_all:
17
1da177e4
LT
18# We are using a recursive build, so we need to do a little thinking
19# to get the ordering right.
20#
21# Most importantly: sub-Makefiles should only ever modify files in
22# their own directory. If in some directory we have a dependency on
23# a file in another dir (which doesn't happen often, but it's often
f49821ee 24# unavoidable when linking the built-in.a targets which finally
1da177e4
LT
25# turn into vmlinux), we will call a sub make in that other dir, and
26# after that we are sure that everything which is in that other dir
27# is now up to date.
28#
29# The only cases where we need to modify files which have global
30# effects are thus separated out and done before the recursive
31# descending is started. They are now explicitly listed as the
32# prepare rule.
33
3812b8c5
MY
34ifneq ($(sub-make-done),1)
35
36# Do not use make's built-in rules and variables
37# (this increases performance and avoids hard-to-debug behaviour)
38MAKEFLAGS += -rR
39
b999923c
MY
40# 'MAKEFLAGS += -rR' does not become immediately effective for old
41# GNU Make versions. Cancel implicit rules for this Makefile.
42$(lastword $(MAKEFILE_LIST)): ;
43
3812b8c5
MY
44# Avoid funny character set dependencies
45unexport LC_ALL
46LC_COLLATE=C
47LC_NUMERIC=C
48export LC_COLLATE LC_NUMERIC
49
50# Avoid interference with shell env settings
51unexport GREP_OPTIONS
52
066b7ed9
MM
53# Beautify output
54# ---------------------------------------------------------------------------
55#
56# Normally, we echo the whole command before executing it. By making
57# that echo $($(quiet)$(cmd)), we now have the possibility to set
58# $(quiet) to choose other forms of output instead, e.g.
59#
60# quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
61# cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
62#
63# If $(quiet) is empty, the whole command will be printed.
64# If it is set to "quiet_", only the short version will be printed.
65# If it is set to "silent_", nothing will be printed at all, since
66# the variable $(silent_cmd_cc_o_c) doesn't exist.
67#
68# A simple variant is to prefix commands with $(Q) - that's useful
69# for commands that shall be hidden in non-verbose mode.
70#
71# $(Q)ln $@ :<
72#
73# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
74# If KBUILD_VERBOSE equals 1 then the above command is displayed.
75#
1da177e4
LT
76# To put more focus on warnings, be less verbose as default
77# Use 'make V=1' to see the full commands
78
b8b0618c
CR
79ifeq ("$(origin V)", "command line")
80 KBUILD_VERBOSE = $(V)
1da177e4
LT
81endif
82ifndef KBUILD_VERBOSE
83 KBUILD_VERBOSE = 0
84endif
85
066b7ed9
MM
86ifeq ($(KBUILD_VERBOSE),1)
87 quiet =
88 Q =
89else
90 quiet=quiet_
91 Q = @
92endif
93
94# If the user is running make -s (silent mode), suppress echoing of
95# commands
96
6f0fa58e 97ifneq ($(findstring s,$(filter-out --%,$(MAKEFLAGS))),)
066b7ed9
MM
98 quiet=silent_
99endif
066b7ed9
MM
100
101export quiet Q KBUILD_VERBOSE
102
1da177e4
LT
103# kbuild supports saving output files in a separate directory.
104# To locate output files in a separate directory two syntaxes are supported.
105# In both cases the working directory must be the root of the kernel src.
106# 1) O=
107# Use "make O=dir/to/store/output/files/"
070b98bf 108#
1da177e4
LT
109# 2) Set KBUILD_OUTPUT
110# Set the environment variable KBUILD_OUTPUT to point to the directory
111# where the output files shall be placed.
112# export KBUILD_OUTPUT=dir/to/store/output/files/
113# make
114#
115# The O= assignment takes precedence over the KBUILD_OUTPUT environment
116# variable.
117
c4e6fff1
C
118# KBUILD_SRC is not intended to be used by the regular user (for now),
119# it is set on invocation of make with KBUILD_OUTPUT or O= specified.
1da177e4
LT
120
121# OK, Make called in directory where kernel src resides
122# Do we want to locate output files in a separate directory?
b8b0618c
CR
123ifeq ("$(origin O)", "command line")
124 KBUILD_OUTPUT := $(O)
1da177e4
LT
125endif
126
51193b76
RJ
127ifneq ($(words $(subst :, ,$(CURDIR))), 1)
128 $(error main directory cannot contain spaces nor colons)
129endif
130
1da177e4 131ifneq ($(KBUILD_OUTPUT),)
1da177e4
LT
132# check that the output directory actually exists
133saved-output := $(KBUILD_OUTPUT)
028568d8 134KBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
16f8259c 135 && pwd)
1da177e4 136$(if $(KBUILD_OUTPUT),, \
1c9e70a5 137 $(error failed to create output directory "$(saved-output)"))
1da177e4 138
80463f1b
MY
139# Look for make include files relative to root of kernel src
140#
141# This does not become effective immediately because MAKEFLAGS is re-parsed
142# once after the Makefile is read. It is OK since we are going to invoke
143# 'sub-make' below.
144MAKEFLAGS += --include-dir=$(CURDIR)
145
3812b8c5
MY
146else
147
148# Do not print "Entering directory ..." at all for in-tree build.
149MAKEFLAGS += --no-print-directory
150
151endif # ifneq ($(KBUILD_OUTPUT),)
152
0b35786d
MM
153PHONY += $(MAKECMDGOALS) sub-make
154
1cacc9ab 155$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
16f89098 156 @:
0b35786d 157
c4e6fff1 158# Invoke a second make in the output directory, passing relevant variables
2e8d696b 159sub-make:
3812b8c5
MY
160 $(Q)$(MAKE) sub-make-done=1 \
161 $(if $(KBUILD_OUTPUT),-C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR)) \
aa55c8e2 162 -f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS))
1da177e4 163
3812b8c5 164else # sub-make-done
1da177e4 165# We process the rest of the Makefile if this is the final invocation of make
1da177e4 166
7ff52571
MY
167# Do not print "Entering directory ...",
168# but we want to display it when entering to the output directory
169# so that IDEs/editors are able to understand relative filenames.
170MAKEFLAGS += --no-print-directory
171
aa55c8e2
MY
172# Call a source code checker (by default, "sparse") as part of the
173# C compilation.
174#
175# Use 'make C=1' to enable checking of only re-compiled files.
176# Use 'make C=2' to enable checking of *all* source files, regardless
177# of whether they are re-compiled or not.
178#
036db11c
C
179# See the file "Documentation/dev-tools/sparse.rst" for more details,
180# including where to get the "sparse" utility.
aa55c8e2
MY
181
182ifeq ("$(origin C)", "command line")
183 KBUILD_CHECKSRC = $(C)
184endif
185ifndef KBUILD_CHECKSRC
186 KBUILD_CHECKSRC = 0
187endif
188
189# Use make M=dir to specify directory of external module to build
190# Old syntax make ... SUBDIRS=$PWD is still supported
191# Setting the environment variable KBUILD_EXTMOD take precedence
192ifdef SUBDIRS
0126be38
MY
193 $(warning ================= WARNING ================)
194 $(warning 'SUBDIRS' will be removed after Linux 5.3)
195 $(warning Please use 'M=' or 'KBUILD_EXTMOD' instead)
196 $(warning ==========================================)
aa55c8e2
MY
197 KBUILD_EXTMOD ?= $(SUBDIRS)
198endif
199
200ifeq ("$(origin M)", "command line")
201 KBUILD_EXTMOD := $(M)
202endif
203
9da0763b
MM
204ifeq ($(KBUILD_SRC),)
205 # building in the source tree
206 srctree := .
207else
208 ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
209 # building in a subdirectory of the source tree
210 srctree := ..
211 else
212 srctree := $(KBUILD_SRC)
213 endif
214endif
2c1f4f12
MY
215
216export KBUILD_CHECKSRC KBUILD_EXTMOD KBUILD_SRC
217
7e1c0477 218objtree := .
1da177e4
LT
219src := $(srctree)
220obj := $(objtree)
221
6b12de69 222VPATH := $(srctree)
1da177e4 223
11294235 224export srctree objtree VPATH
1da177e4 225
2c1f4f12
MY
226# To make sure we do not include .config for any of the *config targets
227# catch them early, and hand them over to scripts/kconfig/Makefile
228# It is allowed to specify more targets when calling make, including
229# mixing *config targets and build targets.
230# For example 'make oldconfig all'.
231# Detect when mixed targets is specified, and make a second invocation
232# of make so .config is not included in this case either (for *config).
233
234version_h := include/generated/uapi/linux/version.h
235old_version_h := include/linux/version.h
236
22340a06
MY
237clean-targets := %clean mrproper cleandocs
238no-dot-config-targets := $(clean-targets) \
2c1f4f12
MY
239 cscope gtags TAGS tags help% %docs check% coccicheck \
240 $(version_h) headers_% archheaders archscripts \
63e31a67 241 %asm-generic kernelversion %src-pkg
a29d4d8c
MY
242no-sync-config-targets := $(no-dot-config-targets) install %install \
243 kernelrelease
2c1f4f12 244
d7942413
MY
245config-targets := 0
246mixed-targets := 0
247dot-config := 1
248may-sync-config := 1
2c1f4f12
MY
249
250ifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
251 ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
252 dot-config := 0
253 endif
254endif
255
d7942413
MY
256ifneq ($(filter $(no-sync-config-targets), $(MAKECMDGOALS)),)
257 ifeq ($(filter-out $(no-sync-config-targets), $(MAKECMDGOALS)),)
258 may-sync-config := 0
259 endif
260endif
261
262ifneq ($(KBUILD_EXTMOD),)
263 may-sync-config := 0
264endif
265
2c1f4f12
MY
266ifeq ($(KBUILD_EXTMOD),)
267 ifneq ($(filter config %config,$(MAKECMDGOALS)),)
268 config-targets := 1
269 ifneq ($(words $(MAKECMDGOALS)),1)
270 mixed-targets := 1
271 endif
272 endif
273endif
22340a06
MY
274
275# For "make -j clean all", "make -j mrproper defconfig all", etc.
276ifneq ($(filter $(clean-targets),$(MAKECMDGOALS)),)
277 ifneq ($(filter-out $(clean-targets),$(MAKECMDGOALS)),)
278 mixed-targets := 1
279 endif
280endif
281
2c1f4f12
MY
282# install and modules_install need also be processed one by one
283ifneq ($(filter install,$(MAKECMDGOALS)),)
284 ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
285 mixed-targets := 1
286 endif
287endif
288
289ifeq ($(mixed-targets),1)
290# ===========================================================================
291# We're called with mixed targets (*config and build targets).
292# Handle them one by one.
293
294PHONY += $(MAKECMDGOALS) __build_one_by_one
295
296$(filter-out __build_one_by_one, $(MAKECMDGOALS)): __build_one_by_one
297 @:
298
299__build_one_by_one:
300 $(Q)set -e; \
301 for i in $(MAKECMDGOALS); do \
302 $(MAKE) -f $(srctree)/Makefile $$i; \
303 done
304
305else
306
2c1f4f12
MY
307include scripts/Kbuild.include
308
309# Read KERNELRELEASE from include/config/kernel.release (if it exists)
310KERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
311KERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
312export VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
313
b2d35fa5 314include scripts/subarch.include
1da177e4
LT
315
316# Cross compiling and selecting different set of gcc/bin-utils
317# ---------------------------------------------------------------------------
318#
319# When performing cross compilation for other architectures ARCH shall be set
320# to the target architecture. (See arch/* for the possibilities).
321# ARCH can be set during invocation of make:
322# make ARCH=ia64
323# Another way is to have ARCH set in the environment.
324# The default ARCH is the host where make is executed.
325
326# CROSS_COMPILE specify the prefix used for all executables used
327# during compilation. Only gcc and related bin-utils executables
328# are prefixed with $(CROSS_COMPILE).
329# CROSS_COMPILE can be set on the command line
330# make CROSS_COMPILE=ia64-linux-
331# Alternatively CROSS_COMPILE can be set in the environment.
332# Default value for CROSS_COMPILE is not to prefix executables
333# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
2331d1a6 334ARCH ?= $(SUBARCH)
1da177e4
LT
335
336# Architecture as present in compile.h
6752ed90
TG
337UTS_MACHINE := $(ARCH)
338SRCARCH := $(ARCH)
1da177e4 339
d746d647
SR
340# Additional ARCH settings for x86
341ifeq ($(ARCH),i386)
342 SRCARCH := x86
343endif
344ifeq ($(ARCH),x86_64)
345 SRCARCH := x86
346endif
74b469f2 347
5e538790 348# Additional ARCH settings for sparc
e69f58c0
NK
349ifeq ($(ARCH),sparc32)
350 SRCARCH := sparc
351endif
a439fe51 352ifeq ($(ARCH),sparc64)
5e538790 353 SRCARCH := sparc
a439fe51 354endif
2fb9b1bd 355
3cc000b5
PM
356# Additional ARCH settings for sh
357ifeq ($(ARCH),sh64)
358 SRCARCH := sh
359endif
360
14cdd3c4 361KCONFIG_CONFIG ?= .config
41263fc6 362export KCONFIG_CONFIG
14cdd3c4 363
1da177e4
LT
364# SHELL used by kbuild
365CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
366 else if [ -x /bin/bash ]; then echo /bin/bash; \
367 else echo sh; fi ; fi)
368
6d79a7b4
MY
369HOST_LFS_CFLAGS := $(shell getconf LFS_CFLAGS 2>/dev/null)
370HOST_LFS_LDFLAGS := $(shell getconf LFS_LDFLAGS 2>/dev/null)
371HOST_LFS_LIBS := $(shell getconf LFS_LIBS 2>/dev/null)
d7f14c66 372
070b98bf
SR
373HOSTCC = gcc
374HOSTCXX = g++
96f14fe7 375KBUILD_HOSTCFLAGS := -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 \
f92d19e0
LA
376 -fomit-frame-pointer -std=gnu89 $(HOST_LFS_CFLAGS) \
377 $(HOSTCFLAGS)
378KBUILD_HOSTCXXFLAGS := -O2 $(HOST_LFS_CFLAGS) $(HOSTCXXFLAGS)
379KBUILD_HOSTLDFLAGS := $(HOST_LFS_LDFLAGS) $(HOSTLDFLAGS)
380KBUILD_HOSTLDLIBS := $(HOST_LFS_LIBS) $(HOSTLDLIBS)
1da177e4 381
1da177e4 382# Make variables (CC, etc...)
1da177e4
LT
383AS = $(CROSS_COMPILE)as
384LD = $(CROSS_COMPILE)ld
385CC = $(CROSS_COMPILE)gcc
386CPP = $(CC) -E
387AR = $(CROSS_COMPILE)ar
388NM = $(CROSS_COMPILE)nm
389STRIP = $(CROSS_COMPILE)strip
390OBJCOPY = $(CROSS_COMPILE)objcopy
391OBJDUMP = $(CROSS_COMPILE)objdump
73a4f6db
MY
392LEX = flex
393YACC = bison
1da177e4 394AWK = awk
caa27b66 395INSTALLKERNEL := installkernel
1da177e4 396DEPMOD = /sbin/depmod
1da177e4 397PERL = perl
011bf125 398PYTHON = python
e9781b52
MY
399PYTHON2 = python2
400PYTHON3 = python3
1da177e4
LT
401CHECK = sparse
402
80a7d1d9 403CHECKFLAGS := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
6c49f359 404 -Wbitwise -Wno-return-void -Wno-unknown-attribute $(CF)
b36fad65 405NOSTDINC_FLAGS =
6588169d
SR
406CFLAGS_MODULE =
407AFLAGS_MODULE =
408LDFLAGS_MODULE =
1da177e4
LT
409CFLAGS_KERNEL =
410AFLAGS_KERNEL =
b36fad65 411LDFLAGS_vmlinux =
1da177e4 412
abbf1590
DH
413# Use USERINCLUDE when you must reference the UAPI directories only.
414USERINCLUDE := \
9d022c54
MY
415 -I$(srctree)/arch/$(SRCARCH)/include/uapi \
416 -I$(objtree)/arch/$(SRCARCH)/include/generated/uapi \
abbf1590 417 -I$(srctree)/include/uapi \
3308b285 418 -I$(objtree)/include/generated/uapi \
abbf1590
DH
419 -include $(srctree)/include/linux/kconfig.h
420
1da177e4
LT
421# Use LINUXINCLUDE when you must reference the include/ directory.
422# Needed to be compatible with the O= option
abbf1590 423LINUXINCLUDE := \
9d022c54
MY
424 -I$(srctree)/arch/$(SRCARCH)/include \
425 -I$(objtree)/arch/$(SRCARCH)/include/generated \
abbf1590 426 $(if $(KBUILD_SRC), -I$(srctree)/include) \
f8224f7f
MY
427 -I$(objtree)/include \
428 $(USERINCLUDE)
1da177e4 429
42a92bcc 430KBUILD_AFLAGS := -D__ASSEMBLY__ -fno-PIE
eeb5687a 431KBUILD_CFLAGS := -Wall -Wundef -Werror=strict-prototypes -Wno-trigraphs \
42a92bcc 432 -fno-strict-aliasing -fno-common -fshort-wchar -fno-PIE \
61a0902a 433 -Werror-implicit-function-declaration -Werror=implicit-int \
51b97e35 434 -Wno-format-security \
433dc2eb
MY
435 -std=gnu89
436KBUILD_CPPFLAGS := -D__KERNEL__
80c00ba9
SR
437KBUILD_AFLAGS_KERNEL :=
438KBUILD_CFLAGS_KERNEL :=
6588169d
SR
439KBUILD_AFLAGS_MODULE := -DMODULE
440KBUILD_CFLAGS_MODULE := -DMODULE
441KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
d503ac53 442KBUILD_LDFLAGS :=
433dc2eb 443GCC_PLUGINS_CFLAGS :=
1da177e4 444
96f14fe7 445export ARCH SRCARCH CONFIG_SHELL HOSTCC KBUILD_HOSTCFLAGS CROSS_COMPILE AS LD CC
8377bd2b 446export CPP AR NM STRIP OBJCOPY OBJDUMP KBUILD_HOSTLDFLAGS KBUILD_HOSTLDLIBS
88110713 447export MAKE LEX YACC AWK INSTALLKERNEL PERL PYTHON PYTHON2 PYTHON3 UTS_MACHINE
10844aeb 448export HOSTCXX KBUILD_HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
1da177e4 449
d503ac53 450export KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS KBUILD_LDFLAGS
0e410e15
AK
451export KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE
452export CFLAGS_KASAN CFLAGS_KASAN_NOSANITIZE CFLAGS_UBSAN
222d394d 453export KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
6588169d 454export KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
80c00ba9 455export KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
40df759e 456export KBUILD_ARFLAGS
1da177e4
LT
457
458# When compiling out-of-tree modules, put MODVERDIR in the module
459# tree rather than in the kernel tree. The kernel tree might
460# even be read-only.
461export MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
462
1da177e4
LT
463# Files to ignore in find ... statements
464
ae63b2d7
PB
465export RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o \
466 -name CVS -o -name .pc -o -name .hg -o -name .git \) \
467 -prune -o
450c6076
JJ
468export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
469 --exclude CVS --exclude .pc --exclude .hg --exclude .git
1da177e4
LT
470
471# ===========================================================================
472# Rules shared between *config targets and build targets
473
312a3d09 474# Basic helpers built in scripts/basic/
4f193362 475PHONY += scripts_basic
1da177e4
LT
476scripts_basic:
477 $(Q)$(MAKE) $(build)=scripts/basic
638adb05 478 $(Q)rm -f .tmp_quiet_recordmcount
1da177e4 479
cd05e6bd
JB
480# To avoid any implicit rule to kick in, define an empty command.
481scripts/basic/%: scripts_basic ;
482
4f193362 483PHONY += outputmakefile
fd5f0cd6
JB
484# outputmakefile generates a Makefile in the output directory, if using a
485# separate output directory. This allows convenient use of make in the
486# output directory.
3a51ff34
VK
487# At the same time when output Makefile generated, generate .gitignore to
488# ignore whole output directory
1da177e4 489outputmakefile:
fd5f0cd6 490ifneq ($(KBUILD_SRC),)
92979997 491 $(Q)ln -fsn $(srctree) source
4fd61277 492 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile $(srctree)
3a51ff34 493 $(Q){ echo "# this is build directory, ignore it"; echo "*"; } > .gitignore
fd5f0cd6 494endif
1da177e4 495
99516742 496ifneq ($(shell $(CC) --version 2>&1 | head -n 1 | grep clang),)
ae6b289a 497ifneq ($(CROSS_COMPILE),)
238bcbc4 498CLANG_FLAGS := --target=$(notdir $(CROSS_COMPILE:%-=%))
ad15006c 499GCC_TOOLCHAIN_DIR := $(dir $(shell which $(CROSS_COMPILE)elfedit))
238bcbc4 500CLANG_FLAGS += --prefix=$(GCC_TOOLCHAIN_DIR)
ef8c4ed9 501GCC_TOOLCHAIN := $(realpath $(GCC_TOOLCHAIN_DIR)/..)
ae6b289a
CF
502endif
503ifneq ($(GCC_TOOLCHAIN),)
238bcbc4 504CLANG_FLAGS += --gcc-toolchain=$(GCC_TOOLCHAIN)
ae6b289a 505endif
238bcbc4
MY
506CLANG_FLAGS += -no-integrated-as
507KBUILD_CFLAGS += $(CLANG_FLAGS)
508KBUILD_AFLAGS += $(CLANG_FLAGS)
3bd98050 509export CLANG_FLAGS
ae6b289a
CF
510endif
511
d5028ba8 512RETPOLINE_CFLAGS_GCC := -mindirect-branch=thunk-extern -mindirect-branch-register
2e549b2e 513RETPOLINE_VDSO_CFLAGS_GCC := -mindirect-branch=thunk-inline -mindirect-branch-register
d5028ba8 514RETPOLINE_CFLAGS_CLANG := -mretpoline-external-thunk
2e549b2e 515RETPOLINE_VDSO_CFLAGS_CLANG := -mretpoline
d5028ba8 516RETPOLINE_CFLAGS := $(call cc-option,$(RETPOLINE_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_CFLAGS_CLANG)))
2e549b2e 517RETPOLINE_VDSO_CFLAGS := $(call cc-option,$(RETPOLINE_VDSO_CFLAGS_GCC),$(call cc-option,$(RETPOLINE_VDSO_CFLAGS_CLANG)))
d5028ba8 518export RETPOLINE_CFLAGS
2e549b2e 519export RETPOLINE_VDSO_CFLAGS
d5028ba8 520
315bab4e
MY
521# The expansion should be delayed until arch/$(SRCARCH)/Makefile is included.
522# Some architectures define CROSS_COMPILE in arch/$(SRCARCH)/Makefile.
523# CC_VERSION_TEXT is referenced from Kconfig (so it needs export),
524# and from include/config/auto.conf.cmd to detect the compiler upgrade.
525CC_VERSION_TEXT = $(shell $(CC) --version | head -n 1)
526
1da177e4
LT
527ifeq ($(config-targets),1)
528# ===========================================================================
529# *config targets only - make sure prerequisites are updated, and descend
530# in scripts/kconfig to make the *config target
531
532# Read arch specific Makefile to set KBUILD_DEFCONFIG as needed.
533# KBUILD_DEFCONFIG may point out an alternative default configuration
534# used for 'make defconfig'
a436bb7b 535include arch/$(SRCARCH)/Makefile
315bab4e 536export KBUILD_DEFCONFIG KBUILD_KCONFIG CC_VERSION_TEXT
1da177e4 537
31110ebb 538config: scripts_basic outputmakefile FORCE
31110ebb
SR
539 $(Q)$(MAKE) $(build)=scripts/kconfig $@
540
541%config: scripts_basic outputmakefile FORCE
1da177e4
LT
542 $(Q)$(MAKE) $(build)=scripts/kconfig $@
543
544else
545# ===========================================================================
546# Build targets only - this includes vmlinux, arch specific targets, clean
547# targets and others. In general all targets except *config targets.
548
2c1f4f12
MY
549# If building an external module we do not care about the all: rule
550# but instead _all depend on modules
551PHONY += all
552ifeq ($(KBUILD_EXTMOD),)
553_all: all
554else
555_all: modules
556endif
557
558# Decide whether to build built-in, modular, or both.
559# Normally, just do built-in.
560
561KBUILD_MODULES :=
562KBUILD_BUILTIN := 1
563
564# If we have only "make modules", don't compile built-in objects.
565# When we're building modules with modversions, we need to consider
566# the built-in objects during the descend as well, in order to
567# make sure the checksums are up to date before we record them.
568
569ifeq ($(MAKECMDGOALS),modules)
570 KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
571endif
572
573# If we have "make <whatever> modules", compile modules
574# in addition to whatever we do anyway.
575# Just "make" or "make all" shall build modules as well
576
577ifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
578 KBUILD_MODULES := 1
579endif
580
581ifeq ($(MAKECMDGOALS),)
582 KBUILD_MODULES := 1
583endif
584
585export KBUILD_MODULES KBUILD_BUILTIN
586
1da177e4 587ifeq ($(KBUILD_EXTMOD),)
1da177e4
LT
588# Objects we will link into vmlinux / subdirs we need to visit
589init-y := init/
df85b2d7 590drivers-y := drivers/ sound/ firmware/
1da177e4
LT
591net-y := net/
592libs-y := lib/
593core-y := usr/
37d9fe47 594virt-y := virt/
1da177e4
LT
595endif # KBUILD_EXTMOD
596
597ifeq ($(dot-config),1)
0a16d2e8 598include include/config/auto.conf
315bab4e
MY
599endif
600
601# The all: target is the default when no target is given on the
602# command line.
603# This allow a user to issue only 'make' to build a kernel including modules
604# Defaults to vmlinux, but the arch makefile usually adds further targets
605all: vmlinux
606
607CFLAGS_GCOV := -fprofile-arcs -ftest-coverage \
608 $(call cc-option,-fno-tree-loop-im) \
609 $(call cc-disable-warning,maybe-uninitialized,)
5aadfdeb 610export CFLAGS_GCOV
315bab4e 611
b1f4ff74
PZ
612# The arch Makefiles can override CC_FLAGS_FTRACE. We may also append it later.
613ifdef CONFIG_FUNCTION_TRACER
614 CC_FLAGS_FTRACE := -pg
615endif
616
315bab4e
MY
617# The arch Makefile can set ARCH_{CPP,A,C}FLAGS to override the default
618# values of the respective KBUILD_* variables
619ARCH_CPPFLAGS :=
620ARCH_AFLAGS :=
621ARCH_CFLAGS :=
622include arch/$(SRCARCH)/Makefile
1da177e4 623
315bab4e 624ifeq ($(dot-config),1)
d7942413 625ifeq ($(may-sync-config),1)
315bab4e
MY
626# Read in dependencies to all Kconfig* files, make sure to run syncconfig if
627# changes are detected. This should be included after arch/$(SRCARCH)/Makefile
628# because some architectures define CROSS_COMPILE there.
c955ccaf 629-include include/config/auto.conf.cmd
1da177e4 630
05850719
MY
631$(KCONFIG_CONFIG):
632 @echo >&2 '***'
633 @echo >&2 '*** Configuration file "$@" not found!'
634 @echo >&2 '***'
635 @echo >&2 '*** Please run some configurator (e.g. "make oldconfig" or'
636 @echo >&2 '*** "make menuconfig" or "make xconfig").'
637 @echo >&2 '***'
638 @/bin/false
1da177e4 639
61277981
UM
640# The actual configuration files used during the build are stored in
641# include/generated/ and include/config/. Update them if .config is newer than
642# include/config/auto.conf (which mirrors .config).
9390dff6
MY
643#
644# This exploits the 'multi-target pattern rule' trick.
645# The syncconfig should be executed only once to make all the targets.
646%/auto.conf %/auto.conf.cmd %/tristate.conf: $(KCONFIG_CONFIG)
911a91c3 647 $(Q)$(MAKE) -f $(srctree)/Makefile syncconfig
3041e47e 648else
d7942413
MY
649# External modules and some install targets need include/generated/autoconf.h
650# and include/config/auto.conf but do not care if they are up-to-date.
651# Use auto.conf to trigger the test
9ee4e336
SR
652PHONY += include/config/auto.conf
653
654include/config/auto.conf:
264a2683 655 $(Q)test -e include/generated/autoconf.h -a -e $@ || ( \
5369f550
MM
656 echo >&2; \
657 echo >&2 " ERROR: Kernel configuration is invalid."; \
658 echo >&2 " include/generated/autoconf.h or $@ are missing.";\
659 echo >&2 " Run 'make oldconfig && make prepare' on kernel src to fix it."; \
660 echo >&2 ; \
9ee4e336
SR
661 /bin/false)
662
d7942413 663endif # may-sync-config
9ee4e336 664endif # $(dot-config)
1da177e4 665
a1c48bb1 666KBUILD_CFLAGS += $(call cc-option,-fno-delete-null-pointer-checks,)
ef6000b4 667KBUILD_CFLAGS += $(call cc-disable-warning,frame-address,)
bd664f6b
LT
668KBUILD_CFLAGS += $(call cc-disable-warning, format-truncation)
669KBUILD_CFLAGS += $(call cc-disable-warning, format-overflow)
670KBUILD_CFLAGS += $(call cc-disable-warning, int-in-bool-context)
a1c48bb1 671
1da177e4 672ifdef CONFIG_CC_OPTIMIZE_FOR_SIZE
6748cb3c 673KBUILD_CFLAGS += $(call cc-option,-Oz,-Os)
815eb71e
AB
674else
675KBUILD_CFLAGS += -O2
676endif
1da177e4 677
b303c6df
MY
678ifdef CONFIG_CC_DISABLE_WARN_MAYBE_UNINITIALIZED
679KBUILD_CFLAGS += -Wno-maybe-uninitialized
680endif
a76bcf55 681
69102311
JK
682# Tell gcc to never replace conditional load with a non-conditional one
683KBUILD_CFLAGS += $(call cc-option,--param=allow-store-data-races=0)
684
d677a4d6 685include scripts/Makefile.kcov
6b90bd4b
ER
686include scripts/Makefile.gcc-plugins
687
1873e870
AK
688ifdef CONFIG_READABLE_ASM
689# Disable optimizations that make assembler listings hard to read.
690# reorder blocks reorders the control in the function
691# ipa clone creates specialized cloned functions
692# partial inlining inlines only parts of functions
693KBUILD_CFLAGS += $(call cc-option,-fno-reorder-blocks,) \
694 $(call cc-option,-fno-ipa-cp-clone,) \
695 $(call cc-option,-fno-partial-inlining)
696endif
697
08f67461 698ifneq ($(CONFIG_FRAME_WARN),0)
35bb5b1e
AK
699KBUILD_CFLAGS += $(call cc-option,-Wframe-larger-than=${CONFIG_FRAME_WARN})
700endif
701
2a61f474 702stackp-flags-$(CONFIG_CC_HAS_STACKPROTECTOR_NONE) := -fno-stack-protector
050e9baa
LT
703stackp-flags-$(CONFIG_STACKPROTECTOR) := -fstack-protector
704stackp-flags-$(CONFIG_STACKPROTECTOR_STRONG) := -fstack-protector-strong
2a61f474
MY
705
706KBUILD_CFLAGS += $(stackp-flags-y)
e06b8b98 707
076f421d 708ifdef CONFIG_CC_IS_CLANG
cfe17c9b 709KBUILD_CPPFLAGS += $(call cc-option,-Qunused-arguments,)
cfe17c9b
MY
710KBUILD_CFLAGS += $(call cc-disable-warning, format-invalid-specifier)
711KBUILD_CFLAGS += $(call cc-disable-warning, gnu)
712KBUILD_CFLAGS += $(call cc-disable-warning, address-of-packed-member)
713# Quiet clang warning: comparison of unsigned expression < 0 is always false
714KBUILD_CFLAGS += $(call cc-disable-warning, tautological-compare)
715# CLANG uses a _MergedGlobals as optimization, but this breaks modpost, as the
716# source of a reference will be _MergedGlobals and not on of the whitelisted names.
717# See modpost pattern 2
718KBUILD_CFLAGS += $(call cc-option, -mno-global-merge,)
719KBUILD_CFLAGS += $(call cc-option, -fcatch-undefined-behavior)
cfe17c9b
MY
720else
721
722# These warnings generated too much noise in a regular build.
723# Use make W=1 to enable them (see scripts/Makefile.extrawarn)
9df3e7a7 724KBUILD_CFLAGS += -Wno-unused-but-set-variable
cfe17c9b
MY
725endif
726
0a5f4176 727KBUILD_CFLAGS += $(call cc-disable-warning, unused-const-variable)
1da177e4 728ifdef CONFIG_FRAME_POINTER
a0f97e06 729KBUILD_CFLAGS += -fno-omit-frame-pointer -fno-optimize-sibling-calls
1da177e4 730else
7e9501fd
RV
731# Some targets (ARM with Thumb2, for example), can't be built with frame
732# pointers. For those, we don't have FUNCTION_TRACER automatically
733# select FRAME_POINTER. However, FUNCTION_TRACER adds -pg, and this is
734# incompatible with -fomit-frame-pointer with current GCC, so we don't use
735# -fomit-frame-pointer with FUNCTION_TRACER.
736ifndef CONFIG_FUNCTION_TRACER
a0f97e06 737KBUILD_CFLAGS += -fomit-frame-pointer
1da177e4 738endif
7e9501fd 739endif
1da177e4 740
1e88e415 741DEBUG_CFLAGS := $(call cc-option, -fno-var-tracking-assignments)
2062afb4 742
1da177e4 743ifdef CONFIG_DEBUG_INFO
866ced95 744ifdef CONFIG_DEBUG_INFO_SPLIT
9d937444 745DEBUG_CFLAGS += -gsplit-dwarf
866ced95 746else
1e88e415 747DEBUG_CFLAGS += -g
866ced95 748endif
2288328c 749KBUILD_AFLAGS += -Wa,-gdwarf-2
1da177e4 750endif
bfaf2dd3 751ifdef CONFIG_DEBUG_INFO_DWARF4
9d937444 752DEBUG_CFLAGS += -gdwarf-4
bfaf2dd3 753endif
1da177e4 754
d6f4ceb7 755ifdef CONFIG_DEBUG_INFO_REDUCED
1e88e415 756DEBUG_CFLAGS += $(call cc-option, -femit-struct-debug-baseonly) \
e82c4bb8 757 $(call cc-option,-fno-var-tracking)
d6f4ceb7
AK
758endif
759
1e88e415
MY
760KBUILD_CFLAGS += $(DEBUG_CFLAGS)
761export DEBUG_CFLAGS
762
606576ce 763ifdef CONFIG_FUNCTION_TRACER
07d04081
VG
764ifdef CONFIG_FTRACE_MCOUNT_RECORD
765 # gcc 5 supports generating the mcount tables directly
766 ifeq ($(call cc-option-yn,-mrecord-mcount),y)
767 CC_FLAGS_FTRACE += -mrecord-mcount
768 export CC_USING_RECORD_MCOUNT := 1
769 endif
2f4df001
VG
770 ifdef CONFIG_HAVE_NOP_MCOUNT
771 ifeq ($(call cc-option-yn, -mnop-mcount),y)
772 CC_FLAGS_FTRACE += -mnop-mcount
773 CC_FLAGS_USING += -DCC_USING_NOP_MCOUNT
774 endif
775 endif
07d04081 776endif
a2546fae 777ifdef CONFIG_HAVE_FENTRY
f28bc3c3
VG
778 ifeq ($(call cc-option-yn, -mfentry),y)
779 CC_FLAGS_FTRACE += -mfentry
780 CC_FLAGS_USING += -DCC_USING_FENTRY
781 endif
a2546fae 782endif
f28bc3c3
VG
783export CC_FLAGS_FTRACE
784KBUILD_CFLAGS += $(CC_FLAGS_FTRACE) $(CC_FLAGS_USING)
785KBUILD_AFLAGS += $(CC_FLAGS_USING)
72441cb1 786ifdef CONFIG_DYNAMIC_FTRACE
cf4db259 787 ifdef CONFIG_HAVE_C_RECORDMCOUNT
72441cb1
SR
788 BUILD_C_RECORDMCOUNT := y
789 export BUILD_C_RECORDMCOUNT
790 endif
791endif
16444a8a
ACM
792endif
793
91341d4b
SR
794# We trigger additional mismatches with less inlining
795ifdef CONFIG_DEBUG_SECTION_MISMATCH
796KBUILD_CFLAGS += $(call cc-option, -fno-inline-functions-called-once)
797endif
798
90ad4052 799ifdef CONFIG_LD_DEAD_CODE_DATA_ELIMINATION
e85d1d65
MY
800KBUILD_CFLAGS_KERNEL += -ffunction-sections -fdata-sections
801LDFLAGS_vmlinux += --gc-sections
90ad4052
MY
802endif
803
e8e69931 804# arch Makefile may override CC so keep this after arch Makefile is included
e08d6de4 805NOSTDINC_FLAGS += -nostdinc -isystem $(shell $(CC) -print-file-name=include)
e8e69931 806
1da177e4 807# warn about C99 declaration after statement
a33e7ae2 808KBUILD_CFLAGS += -Wdeclaration-after-statement
1da177e4 809
0bb95f80
KC
810# Variable Length Arrays (VLAs) should not be used anywhere in the kernel
811KBUILD_CFLAGS += $(call cc-option,-Wvla)
812
070b98bf 813# disable pointer signed / unsigned warnings in gcc 4.0
fb073a4b 814KBUILD_CFLAGS += -Wno-pointer-sign
1da177e4 815
217c3e01
SR
816# disable stringop warnings in gcc 8+
817KBUILD_CFLAGS += $(call cc-disable-warning, stringop-truncation)
818
fe8d0a41 819# disable invalid "can't wrap" optimizations for signed / pointers
a137802e 820KBUILD_CFLAGS += $(call cc-option,-fno-strict-overflow)
d0115552 821
87e0d4f0
DB
822# clang sets -fmerge-all-constants by default as optimization, but this
823# is non-conforming behavior for C and in fact breaks the kernel, so we
824# need to disable it here generally.
825KBUILD_CFLAGS += $(call cc-option,-fno-merge-all-constants)
826
827# for gcc -fno-merge-all-constants disables everything, but it is fine
828# to have actual conforming behavior enabled.
829KBUILD_CFLAGS += $(call cc-option,-fmerge-constants)
830
3ce120b1
LT
831# Make sure -fstack-check isn't enabled (like gentoo apparently did)
832KBUILD_CFLAGS += $(call cc-option,-fno-stack-check,)
833
8f7f5c9f
AK
834# conserve stack if available
835KBUILD_CFLAGS += $(call cc-option,-fconserve-stack)
836
fe7c36c7
JT
837# Prohibit date/time macros, which would make the build non-deterministic
838KBUILD_CFLAGS += $(call cc-option,-Werror=date-time)
839
ea8daa7b
DW
840# enforce correct pointer usage
841KBUILD_CFLAGS += $(call cc-option,-Werror=incompatible-pointer-types)
842
c834f0e8
KC
843# Require designated initializers for all marked structures
844KBUILD_CFLAGS += $(call cc-option,-Werror=designated-init)
845
a73619a8
MY
846# change __FILE__ to the relative path from the srctree
847KBUILD_CFLAGS += $(call cc-option,-fmacro-prefix-map=$(srctree)/=)
848
40df759e
MM
849# use the deterministic mode of AR if available
850KBUILD_ARFLAGS := $(call ar-option,D)
851
a436bb7b
MY
852include scripts/Makefile.kasan
853include scripts/Makefile.extrawarn
c6d30853 854include scripts/Makefile.ubsan
a86fe353 855
61754c18
MM
856# Add any arch overrides and user supplied CPPFLAGS, AFLAGS and CFLAGS as the
857# last assignments
858KBUILD_CPPFLAGS += $(ARCH_CPPFLAGS) $(KCPPFLAGS)
859KBUILD_AFLAGS += $(ARCH_AFLAGS) $(KAFLAGS)
860KBUILD_CFLAGS += $(ARCH_CFLAGS) $(KCFLAGS)
52bcc330 861
18991197 862# Use --build-id when available.
0da4fabd 863LDFLAGS_BUILD_ID := $(call ld-option, --build-id)
6588169d 864KBUILD_LDFLAGS_MODULE += $(LDFLAGS_BUILD_ID)
18991197
RM
865LDFLAGS_vmlinux += $(LDFLAGS_BUILD_ID)
866
5d7d18f5 867ifeq ($(CONFIG_STRIP_ASM_SYMS),y)
d79a2719 868LDFLAGS_vmlinux += $(call ld-option, -X,)
5d7d18f5
DH
869endif
870
14516765
LVO
871# insure the checker run with the right endianness
872CHECKFLAGS += $(if $(CONFIG_CPU_BIG_ENDIAN),-mbig-endian,-mlittle-endian)
873
1f2f01b1
LVO
874# the checker needs the correct machine size
875CHECKFLAGS += $(if $(CONFIG_64BIT),-m64,-m32)
876
1da177e4 877# Default kernel image to build when no specific target is given.
070b98bf 878# KBUILD_IMAGE may be overruled on the command line or
1da177e4
LT
879# set in the environment
880# Also any assignments in arch/$(ARCH)/Makefile take precedence over
881# this default value
882export KBUILD_IMAGE ?= vmlinux
883
884#
885# INSTALL_PATH specifies where to place the updated kernel and system map
886# images. Default is /boot, but you can set it to other values
887export INSTALL_PATH ?= /boot
888
f4d4ffc0
JC
889#
890# INSTALL_DTBS_PATH specifies a prefix for relocations required by build roots.
891# Like INSTALL_MOD_PATH, it isn't defined in the Makefile, but can be passed as
892# an argument if needed. Otherwise it defaults to the kernel install path
893#
894export INSTALL_DTBS_PATH ?= $(INSTALL_PATH)/dtbs/$(KERNELRELEASE)
895
1da177e4
LT
896#
897# INSTALL_MOD_PATH specifies a prefix to MODLIB for module directory
898# relocations required by build roots. This is not defined in the
070b98bf 899# makefile but the argument can be passed to make if needed.
1da177e4
LT
900#
901
df9df036 902MODLIB = $(INSTALL_MOD_PATH)/lib/modules/$(KERNELRELEASE)
1da177e4
LT
903export MODLIB
904
ac031f26 905#
3fbb43df
MY
906# INSTALL_MOD_STRIP, if defined, will cause modules to be
907# stripped after they are installed. If INSTALL_MOD_STRIP is '1', then
908# the default option --strip-debug will be used. Otherwise,
909# INSTALL_MOD_STRIP value will be used as the options to the strip command.
2ea03891 910
ac031f26
TT
911ifdef INSTALL_MOD_STRIP
912ifeq ($(INSTALL_MOD_STRIP),1)
2ea03891 913mod_strip_cmd = $(STRIP) --strip-debug
ac031f26 914else
2ea03891 915mod_strip_cmd = $(STRIP) $(INSTALL_MOD_STRIP)
ac031f26
TT
916endif # INSTALL_MOD_STRIP=1
917else
2ea03891 918mod_strip_cmd = true
ac031f26
TT
919endif # INSTALL_MOD_STRIP
920export mod_strip_cmd
921
beb50df3
BJ
922# CONFIG_MODULE_COMPRESS, if defined, will cause module to be compressed
923# after they are installed in agreement with CONFIG_MODULE_COMPRESS_GZIP
924# or CONFIG_MODULE_COMPRESS_XZ.
925
926mod_compress_cmd = true
927ifdef CONFIG_MODULE_COMPRESS
928 ifdef CONFIG_MODULE_COMPRESS_GZIP
3d1450d5 929 mod_compress_cmd = gzip -n -f
beb50df3
BJ
930 endif # CONFIG_MODULE_COMPRESS_GZIP
931 ifdef CONFIG_MODULE_COMPRESS_XZ
3d1450d5 932 mod_compress_cmd = xz -f
beb50df3
BJ
933 endif # CONFIG_MODULE_COMPRESS_XZ
934endif # CONFIG_MODULE_COMPRESS
935export mod_compress_cmd
936
d9d8d7ed 937ifdef CONFIG_MODULE_SIG_ALL
3ee550f1
DW
938$(eval $(call config_filename,MODULE_SIG_KEY))
939
940mod_sign_cmd = scripts/sign-file $(CONFIG_MODULE_SIG_HASH) $(MODULE_SIG_KEY_SRCPREFIX)$(CONFIG_MODULE_SIG_KEY) certs/signing_key.x509
e2a666d5
RR
941else
942mod_sign_cmd = true
943endif
944export mod_sign_cmd
945
9f0c18ae
JP
946ifdef CONFIG_STACK_VALIDATION
947 has_libelf := $(call try-run,\
948 echo "int main() {}" | $(HOSTCC) -xc -o /dev/null -lelf -,1,0)
949 ifeq ($(has_libelf),1)
950 objtool_target := tools/objtool FORCE
951 else
9f0c18ae
JP
952 SKIP_STACK_VALIDATION := 1
953 export SKIP_STACK_VALIDATION
954 endif
955endif
956
e00d8880 957PHONY += prepare0
e2a666d5 958
1da177e4 959ifeq ($(KBUILD_EXTMOD),)
cfc411e7 960core-y += kernel/ certs/ mm/ fs/ ipc/ security/ crypto/ block/
1da177e4
LT
961
962vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
963 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
37d9fe47 964 $(net-y) $(net-m) $(libs-y) $(libs-m) $(virt-y)))
1da177e4
LT
965
966vmlinux-alldirs := $(sort $(vmlinux-dirs) $(patsubst %/,%,$(filter %/, \
37d9fe47 967 $(init-) $(core-) $(drivers-) $(net-) $(libs-) $(virt-))))
1da177e4 968
f49821ee
NP
969init-y := $(patsubst %/, %/built-in.a, $(init-y))
970core-y := $(patsubst %/, %/built-in.a, $(core-y))
971drivers-y := $(patsubst %/, %/built-in.a, $(drivers-y))
972net-y := $(patsubst %/, %/built-in.a, $(net-y))
1da177e4 973libs-y1 := $(patsubst %/, %/lib.a, $(libs-y))
f49821ee
NP
974libs-y2 := $(patsubst %/, %/built-in.a, $(filter-out %.a, $(libs-y)))
975virt-y := $(patsubst %/, %/built-in.a, $(virt-y))
1da177e4 976
1f2bfbd0 977# Externally visible symbols (used by link-vmlinux.sh)
d151e971
MY
978export KBUILD_VMLINUX_OBJS := $(head-y) $(init-y) $(core-y) $(libs-y2) \
979 $(drivers-y) $(net-y) $(virt-y)
3a166fc2 980export KBUILD_VMLINUX_LIBS := $(libs-y1)
95698570 981export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds
1f2bfbd0 982export LDFLAGS_vmlinux
312a3d09 983# used by scripts/package/Makefile
37d9fe47 984export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) arch Documentation include samples scripts tools)
9bb48247 985
d151e971 986vmlinux-deps := $(KBUILD_LDS) $(KBUILD_VMLINUX_OBJS) $(KBUILD_VMLINUX_LIBS)
1da177e4 987
3fdc7d3f
MY
988# Recurse until adjust_autoksyms.sh is satisfied
989PHONY += autoksyms_recursive
990autoksyms_recursive: $(vmlinux-deps)
2441e78b 991ifdef CONFIG_TRIM_UNUSED_KSYMS
ba79d401 992 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/adjust_autoksyms.sh \
86556392 993 "$(MAKE) -f $(srctree)/Makefile vmlinux"
2441e78b 994endif
23121ca2 995
1f50b80a
MY
996# For the kernel to actually contain only the needed exported symbols,
997# we have to build modules as well to determine what those symbols are.
998# (this can be evaluated only once include/config/auto.conf has been included)
999ifdef CONFIG_TRIM_UNUSED_KSYMS
1000 KBUILD_MODULES := 1
1001endif
1002
07a422bb
MY
1003autoksyms_h := $(if $(CONFIG_TRIM_UNUSED_KSYMS), include/generated/autoksyms.h)
1004
1005$(autoksyms_h):
1006 $(Q)mkdir -p $(dir $@)
1007 $(Q)touch $@
23121ca2 1008
fbe6e37d
NP
1009ARCH_POSTLINK := $(wildcard $(srctree)/arch/$(SRCARCH)/Makefile.postlink)
1010
1011# Final link of vmlinux with optional arch pass after final link
312a3d09 1012cmd_link-vmlinux = \
d503ac53 1013 $(CONFIG_SHELL) $< $(LD) $(KBUILD_LDFLAGS) $(LDFLAGS_vmlinux) ; \
fbe6e37d 1014 $(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) $@, true)
2441e78b 1015
3fdc7d3f 1016vmlinux: scripts/link-vmlinux.sh autoksyms_recursive $(vmlinux-deps) FORCE
1f2bfbd0 1017 +$(call if_changed,link-vmlinux)
741f98fe 1018
392885ee
MY
1019targets := vmlinux
1020
3fca1700 1021# Build samples along the rest of the kernel. This needs headers_install.
dd92478a
NP
1022ifdef CONFIG_SAMPLES
1023vmlinux-dirs += samples
3fca1700 1024samples: headers_install
dd92478a
NP
1025endif
1026
38385f8f 1027# The actual objects are generated when descending,
1da177e4 1028# make sure no implicit rule kicks in
1f2bfbd0 1029$(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
1da177e4
LT
1030
1031# Handle descending into subdirectories listed in $(vmlinux-dirs)
1032# Preset locale variables to speed up the build process. Limit locale
1033# tweaks to this spot to avoid wrong language settings when running
1034# make menuconfig etc.
1035# Error messages still appears in the original language
1036
4f193362 1037PHONY += $(vmlinux-dirs)
059bc9fc 1038$(vmlinux-dirs): prepare
f7adc312 1039 $(Q)$(MAKE) $(build)=$@ need-builtin=1
1da177e4 1040
ba97df45 1041filechk_kernel.release = \
0d0e7718 1042 echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
0d0e7718 1043
83a35e36 1044# Store (new) KERNELRELEASE string in include/config/kernel.release
2063945f 1045include/config/kernel.release: $(srctree)/Makefile FORCE
0d0e7718 1046 $(call filechk,kernel.release)
cb58455c 1047
d8821622
MY
1048# Additional helpers built in scripts/
1049# Carefully list dependencies so we do not try to build scripts twice
1050# in parallel
1051PHONY += scripts
60df1aee 1052scripts: scripts_basic scripts_dtc
d8821622 1053 $(Q)$(MAKE) $(build)=$(@)
cb58455c 1054
1da177e4 1055# Things we need to do before we recursively start building the kernel
5bb78269
SR
1056# or the modules are listed in "prepare".
1057# A multi level approach is used. prepareN is processed before prepareN-1.
1058# archprepare is used in arch Makefiles and when processed asm symlink,
1059# version.h and scripts_basic is processed / created.
1da177e4 1060
4f1c1008 1061PHONY += prepare archprepare prepare1 prepare3
5bb78269 1062
86feeaa8 1063# prepare3 is used to check if we are building in a separate output directory,
1da177e4
LT
1064# and if so do:
1065# 1) Check that make has not been executed in the kernel src $(srctree)
f1d28fb0 1066prepare3: include/config/kernel.release
1da177e4 1067ifneq ($(KBUILD_SRC),)
fd54f502 1068 @$(kecho) ' Using $(srctree) as source for kernel'
c955ccaf 1069 $(Q)if [ -f $(srctree)/.config -o -d $(srctree)/include/config ]; then \
5369f550
MM
1070 echo >&2 " $(srctree) is not clean, please run 'make mrproper'"; \
1071 echo >&2 " in the '$(srctree)' directory.";\
1da177e4
LT
1072 /bin/false; \
1073 fi;
1da177e4
LT
1074endif
1075
4f1c1008
MY
1076prepare1: prepare3 outputmakefile asm-generic $(version_h) $(autoksyms_h) \
1077 include/generated/utsrelease.h
7bb9d092 1078 $(cmd_crmodverdir)
1da177e4 1079
668c35f6 1080archprepare: archheaders archscripts prepare1 scripts
5bb78269 1081
65bba042 1082prepare0: archprepare
60df1aee 1083 $(Q)$(MAKE) $(build)=scripts/mod
8d36a623 1084 $(Q)$(MAKE) $(build)=.
86feeaa8 1085
1da177e4 1086# All the preparing..
b9ab5ebb
JP
1087prepare: prepare0 prepare-objtool
1088
2c1f4f12 1089# Support for using generic headers in asm-generic
7d0e5c20
MY
1090asm-generic := -f $(srctree)/scripts/Makefile.asm-generic obj
1091
2c1f4f12
MY
1092PHONY += asm-generic uapi-asm-generic
1093asm-generic: uapi-asm-generic
7d0e5c20 1094 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/asm
2c1f4f12 1095uapi-asm-generic:
7d0e5c20 1096 $(Q)$(MAKE) $(asm-generic)=arch/$(SRCARCH)/include/generated/uapi/asm
2c1f4f12 1097
b9ab5ebb 1098PHONY += prepare-objtool
3b27a0c8 1099prepare-objtool: $(objtool_target)
ef7cfd00
MY
1100ifeq ($(SKIP_STACK_VALIDATION),1)
1101ifdef CONFIG_UNWINDER_ORC
1102 @echo "error: Cannot generate ORC metadata for CONFIG_UNWINDER_ORC=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1103 @false
1104else
1105 @echo "warning: Cannot use CONFIG_STACK_VALIDATION=y, please install libelf-dev, libelf-devel or elfutils-libelf-devel" >&2
1106endif
1107endif
1da177e4 1108
1da177e4
LT
1109# Generate some files
1110# ---------------------------------------------------------------------------
1111
1112# KERNELRELEASE can change from a few different places, meaning version.h
1113# needs to be updated, so this check is forced on all builds
1114
1115uts_len := 64
63104eec
SR
1116define filechk_utsrelease.h
1117 if [ `echo -n "$(KERNELRELEASE)" | wc -c ` -gt $(uts_len) ]; then \
1118 echo '"$(KERNELRELEASE)" exceeds $(uts_len) characters' >&2; \
1119 exit 1; \
1120 fi; \
ad774086 1121 echo \#define UTS_RELEASE \"$(KERNELRELEASE)\"
63104eec 1122endef
1da177e4
LT
1123
1124define filechk_version.h
ad774086 1125 echo \#define LINUX_VERSION_CODE $(shell \
450c6076 1126 expr $(VERSION) \* 65536 + 0$(PATCHLEVEL) \* 256 + 0$(SUBLEVEL)); \
ad774086 1127 echo '#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))'
1da177e4
LT
1128endef
1129
43fee2b2 1130$(version_h): FORCE
1da177e4 1131 $(call filechk,version.h)
223c24a7 1132 $(Q)rm -f $(old_version_h)
1da177e4 1133
273b281f 1134include/generated/utsrelease.h: include/config/kernel.release FORCE
63104eec
SR
1135 $(call filechk,utsrelease.h)
1136
179efcb4
VN
1137PHONY += headerdep
1138headerdep:
9663d989
PF
1139 $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \
1140 $(srctree)/scripts/headerdep.pl -I$(srctree)/include
179efcb4 1141
8d730cfb
DW
1142# ---------------------------------------------------------------------------
1143# Kernel headers
8d730cfb 1144
e6883b18
SR
1145#Default location for installed headers
1146export INSTALL_HDR_PATH = $(objtree)/usr
6d716275 1147
9d022c54
MY
1148# If we do an all arch process set dst to include/arch-$(SRCARCH)
1149hdr-dst = $(if $(KBUILD_HEADERS), dst=include/arch-$(SRCARCH), dst=include)
e6883b18 1150
f7de64b7 1151PHONY += archheaders archscripts
6520fe55 1152
e6883b18 1153PHONY += __headers
a9d9a400 1154__headers: $(version_h) scripts_basic uapi-asm-generic archheaders archscripts
e1b702cf 1155 $(Q)$(MAKE) $(build)=scripts build_unifdef
e6883b18
SR
1156
1157PHONY += headers_install_all
2fb9b1bd
SR
1158headers_install_all:
1159 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh install
6d716275 1160
8d730cfb 1161PHONY += headers_install
e6883b18 1162headers_install: __headers
9d022c54 1163 $(if $(wildcard $(srctree)/arch/$(SRCARCH)/include/uapi/asm/Kbuild),, \
10b63956 1164 $(error Headers not exportable for the $(SRCARCH) architecture))
a8ff49a1 1165 $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include
9d022c54 1166 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi $(hdr-dst)
8d730cfb 1167
1f85712e
MF
1168PHONY += headers_check_all
1169headers_check_all: headers_install_all
2fb9b1bd 1170 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/headers.sh check
1f85712e 1171
68475359
DW
1172PHONY += headers_check
1173headers_check: headers_install
a8ff49a1 1174 $(Q)$(MAKE) $(hdr-inst)=include/uapi dst=include HDRCHECK=1
9d022c54 1175 $(Q)$(MAKE) $(hdr-inst)=arch/$(SRCARCH)/include/uapi $(hdr-dst) HDRCHECK=1
68475359 1176
257edce6
MY
1177ifdef CONFIG_HEADERS_CHECK
1178all: headers_check
1179endif
1180
5a5da78b
SK
1181# ---------------------------------------------------------------------------
1182# Kernel selftest
1183
1184PHONY += kselftest
1185kselftest:
2bc84526 1186 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests run_tests
5a5da78b 1187
801d2e9f 1188PHONY += kselftest-clean
dcb825a9 1189kselftest-clean:
2bc84526 1190 $(Q)$(MAKE) -C $(srctree)/tools/testing/selftests clean
dcb825a9 1191
3d6dee7a
BJZ
1192PHONY += kselftest-merge
1193kselftest-merge:
1194 $(if $(wildcard $(objtree)/.config),, $(error No .config exists, config your kernel first!))
1195 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh \
1196 -m $(objtree)/.config \
1197 $(srctree)/tools/testing/selftests/*/config
1198 +$(Q)$(MAKE) -f $(srctree)/Makefile olddefconfig
1199
37c8a5fa
RH
1200# ---------------------------------------------------------------------------
1201# Devicetree files
1202
1203ifneq ($(wildcard $(srctree)/arch/$(SRCARCH)/boot/dts/),)
1204dtstree := arch/$(SRCARCH)/boot/dts
1205endif
1206
1207ifneq ($(dtstree),)
1208
1209%.dtb: prepare3 scripts_dtc
1210 $(Q)$(MAKE) $(build)=$(dtstree) $(dtstree)/$@
1211
4f0e3a57
RH
1212PHONY += dtbs dtbs_install dt_binding_check
1213dtbs dtbs_check: prepare3 scripts_dtc
37c8a5fa
RH
1214 $(Q)$(MAKE) $(build)=$(dtstree)
1215
4f0e3a57
RH
1216dtbs_check: export CHECK_DTBS=1
1217dtbs_check: dt_binding_check
1218
37c8a5fa
RH
1219dtbs_install:
1220 $(Q)$(MAKE) $(dtbinst)=$(dtstree)
1221
1222ifdef CONFIG_OF_EARLY_FLATTREE
1223all: dtbs
1224endif
1225
1226endif
1227
1228PHONY += scripts_dtc
1229scripts_dtc: scripts_basic
1230 $(Q)$(MAKE) $(build)=scripts/dtc
1231
4f0e3a57
RH
1232dt_binding_check: scripts_dtc
1233 $(Q)$(MAKE) $(build)=Documentation/devicetree/bindings
1234
1da177e4
LT
1235# ---------------------------------------------------------------------------
1236# Modules
1237
1238ifdef CONFIG_MODULES
1239
070b98bf 1240# By default, build modules as well
1da177e4 1241
73d1393e 1242all: modules
1da177e4 1243
3fbb43df 1244# Build modules
551559e1 1245#
3fbb43df
MY
1246# A module can be listed more than once in obj-m resulting in
1247# duplicate lines in modules.order files. Those are removed
1248# using awk while concatenating to the final file.
1da177e4 1249
4f193362 1250PHONY += modules
2da30e70 1251modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
551559e1 1252 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
fd54f502 1253 @$(kecho) ' Building modules, stage 2.';
b805aa0e 1254 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1da177e4 1255
a6c36632
MM
1256modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
1257 $(Q)$(AWK) '!x[$$0]++' $^ > $(objtree)/modules.builtin
1258
2063945f 1259%/modules.builtin: include/config/auto.conf include/config/tristate.conf
a6c36632
MM
1260 $(Q)$(MAKE) $(modbuiltin)=$*
1261
1da177e4
LT
1262
1263# Target to prepare building external modules
4f193362 1264PHONY += modules_prepare
059bc9fc 1265modules_prepare: prepare
1da177e4
LT
1266
1267# Target to install modules
4f193362 1268PHONY += modules_install
1da177e4
LT
1269modules_install: _modinst_ _modinst_post
1270
4f193362 1271PHONY += _modinst_
2da30e70 1272_modinst_:
1da177e4
LT
1273 @rm -rf $(MODLIB)/kernel
1274 @rm -f $(MODLIB)/source
1275 @mkdir -p $(MODLIB)/kernel
8e9b4667 1276 @ln -s $(abspath $(srctree)) $(MODLIB)/source
1da177e4
LT
1277 @if [ ! $(objtree) -ef $(MODLIB)/build ]; then \
1278 rm -f $(MODLIB)/build ; \
7e1c0477 1279 ln -s $(CURDIR) $(MODLIB)/build ; \
1da177e4 1280 fi
551559e1 1281 @cp -f $(objtree)/modules.order $(MODLIB)/
bc081dd6 1282 @cp -f $(objtree)/modules.builtin $(MODLIB)/
b805aa0e 1283 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1da177e4 1284
50a8ec31 1285# This depmod is only for convenience to give the initial
1da177e4
LT
1286# boot a modules.dep even before / is mounted read-write. However the
1287# boot script depmod is the master version.
4f193362 1288PHONY += _modinst_post
6d128e1e 1289_modinst_post: _modinst_
50a8ec31 1290 $(call cmd,depmod)
1da177e4 1291
d890f510
JB
1292ifeq ($(CONFIG_MODULE_SIG), y)
1293PHONY += modules_sign
1294modules_sign:
1295 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modsign
1296endif
1297
1da177e4
LT
1298else # CONFIG_MODULES
1299
1300# Modules not configured
1301# ---------------------------------------------------------------------------
1302
612e47ce
MY
1303PHONY += modules modules_install
1304modules modules_install:
5369f550
MM
1305 @echo >&2
1306 @echo >&2 "The present kernel configuration has modules disabled."
1307 @echo >&2 "Type 'make config' and enable loadable module support."
1308 @echo >&2 "Then build a kernel with module support enabled."
1309 @echo >&2
1da177e4
LT
1310 @exit 1
1311
1312endif # CONFIG_MODULES
1313
1da177e4
LT
1314###
1315# Cleaning is done on three levels.
1316# make clean Delete most generated files
1317# Leave enough to build external modules
1318# make mrproper Delete the current configuration, and all generated files
1319# make distclean Remove editor backup files, patch leftover files and the like
1320
1321# Directories & files removed with 'make clean'
fbfa9be9 1322CLEAN_DIRS += $(MODVERDIR) include/ksym
1da177e4
LT
1323
1324# Directories & files removed with 'make mrproper'
d8ecc5cd 1325MRPROPER_DIRS += include/config usr/include include/generated \
3fbb43df 1326 arch/*/include/generated .tmp_objdiff
278ae604 1327MRPROPER_FILES += .config .config.old .version \
d5b71936 1328 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
fb117949
DW
1329 signing_key.pem signing_key.priv signing_key.x509 \
1330 x509.genkey extra_certificates signing_key.x509.keyid \
3ee7b3fa 1331 signing_key.x509.signer vmlinux-gdb.py
1da177e4
LT
1332
1333# clean - Delete most, but leave enough to build external modules
1334#
1335clean: rm-dirs := $(CLEAN_DIRS)
1336clean: rm-files := $(CLEAN_FILES)
fb68d4be 1337clean-dirs := $(addprefix _clean_, . $(vmlinux-alldirs) Documentation samples)
1da177e4 1338
bd1ee804 1339PHONY += $(clean-dirs) clean archclean vmlinuxclean
1da177e4
LT
1340$(clean-dirs):
1341 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1342
bd1ee804
PM
1343vmlinuxclean:
1344 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/link-vmlinux.sh clean
fbe6e37d 1345 $(Q)$(if $(ARCH_POSTLINK), $(MAKE) -f $(ARCH_POSTLINK) clean)
bd1ee804
PM
1346
1347clean: archclean vmlinuxclean
1da177e4
LT
1348
1349# mrproper - Delete all generated files, including .config
1350#
1351mrproper: rm-dirs := $(wildcard $(MRPROPER_DIRS))
1352mrproper: rm-files := $(wildcard $(MRPROPER_FILES))
cb43fb57 1353mrproper-dirs := $(addprefix _mrproper_,scripts)
1da177e4 1354
b421b8a6 1355PHONY += $(mrproper-dirs) mrproper
1da177e4
LT
1356$(mrproper-dirs):
1357 $(Q)$(MAKE) $(clean)=$(patsubst _mrproper_%,%,$@)
1358
b421b8a6 1359mrproper: clean $(mrproper-dirs)
1da177e4
LT
1360 $(call cmd,rmdirs)
1361 $(call cmd,rmfiles)
1362
1363# distclean
1364#
4f193362 1365PHONY += distclean
1da177e4
LT
1366
1367distclean: mrproper
1368 @find $(srctree) $(RCS_FIND_IGNORE) \
070b98bf 1369 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
f78271df
MY
1370 -o -name '*.bak' -o -name '#*#' -o -name '*%' \
1371 -o -name 'core' \) \
1da177e4
LT
1372 -type f -print | xargs rm -f
1373
1374
1375# Packaging of the kernel to various formats
1376# ---------------------------------------------------------------------------
c79624c1 1377package-dir := scripts/package
1da177e4 1378
bafb6747
ACM
1379%src-pkg: FORCE
1380 $(Q)$(MAKE) $(build)=$(package-dir) $@
031ecc6d 1381%pkg: include/config/kernel.release FORCE
6c2133e1 1382 $(Q)$(MAKE) $(build)=$(package-dir) $@
1da177e4
LT
1383
1384
1385# Brief documentation of the typical targets used
1386# ---------------------------------------------------------------------------
1387
5dffbe81 1388boards := $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*_defconfig)
a1e7b7bb 1389boards := $(sort $(notdir $(boards)))
5dffbe81
SB
1390board-dirs := $(dir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/*/*_defconfig))
1391board-dirs := $(sort $(notdir $(board-dirs:/=)))
1da177e4 1392
fe69b420 1393PHONY += help
1da177e4
LT
1394help:
1395 @echo 'Cleaning targets:'
5ea084ef 1396 @echo ' clean - Remove most generated files but keep the config and'
5cc8d246 1397 @echo ' enough build support to build external modules'
5ea084ef 1398 @echo ' mrproper - Remove all generated files + config + various backup files'
5cc8d246 1399 @echo ' distclean - mrproper + remove editor backup and patch files'
1da177e4
LT
1400 @echo ''
1401 @echo 'Configuration targets:'
1402 @$(MAKE) -f $(srctree)/scripts/kconfig/Makefile help
1403 @echo ''
1404 @echo 'Other generic targets:'
1405 @echo ' all - Build all targets marked with [*]'
1406 @echo '* vmlinux - Build the bare kernel'
1407 @echo '* modules - Build all modules'
9cc5d74c 1408 @echo ' modules_install - Install all modules to INSTALL_MOD_PATH (default: /)'
1da177e4 1409 @echo ' dir/ - Build all files in dir and below'
40ab87a4 1410 @echo ' dir/file.[ois] - Build specified target only'
433db3e2
VT
1411 @echo ' dir/file.ll - Build the LLVM assembly file'
1412 @echo ' (requires compiler support for LLVM assembly generation)'
62718979
JP
1413 @echo ' dir/file.lst - Build specified mixed source/assembly target only'
1414 @echo ' (requires a recent binutils and recent build (System.map))'
155ad605 1415 @echo ' dir/file.ko - Build module including final link'
c4d5ee67 1416 @echo ' modules_prepare - Set up for building external modules'
1da177e4
LT
1417 @echo ' tags/TAGS - Generate tags file for editors'
1418 @echo ' cscope - Generate cscope index'
f4ed1009 1419 @echo ' gtags - Generate GNU GLOBAL index'
3f1d9a6c
MM
1420 @echo ' kernelrelease - Output the release version string (use with make -s)'
1421 @echo ' kernelversion - Output the version stored in Makefile (use with make -s)'
1422 @echo ' image_name - Output the image name (use with make -s)'
2fb9b1bd 1423 @echo ' headers_install - Install sanitised kernel headers to INSTALL_HDR_PATH'; \
59df3230 1424 echo ' (default: $(INSTALL_HDR_PATH))'; \
2fb9b1bd 1425 echo ''
31b8cc80 1426 @echo 'Static analysers:'
1da177e4
LT
1427 @echo ' checkstack - Generate a list of stack hogs'
1428 @echo ' namespacecheck - Name space analysis on compiled kernel'
aa025e7d 1429 @echo ' versioncheck - Sanity check on version.h usage'
ec2d987f 1430 @echo ' includecheck - Check for duplicate included header files'
295ac051 1431 @echo ' export_report - List the usages of all exported symbols'
179efcb4 1432 @echo ' headers_check - Sanity check on exported headers'
74425eee 1433 @echo ' headerdep - Detect inclusion cycles in headers'
7f855fc8 1434 @echo ' coccicheck - Check with Coccinelle'
74425eee 1435 @echo ''
31b8cc80 1436 @echo 'Kernel selftest:'
5a5da78b
SK
1437 @echo ' kselftest - Build and run kernel selftest (run as root)'
1438 @echo ' Build, install, and boot kernel before'
1439 @echo ' running kselftest on it'
dcb825a9 1440 @echo ' kselftest-clean - Remove all generated kselftest files'
bbfe63b6 1441 @echo ' kselftest-merge - Merge all the config dependencies of kselftest to existing'
3d6dee7a 1442 @echo ' .config.'
5a5da78b 1443 @echo ''
37c8a5fa
RH
1444 @$(if $(dtstree), \
1445 echo 'Devicetree:'; \
1446 echo '* dtbs - Build device tree blobs for enabled boards'; \
1447 echo ' dtbs_install - Install dtbs to $(INSTALL_DTBS_PATH)'; \
1448 echo '')
1449
31b8cc80
RD
1450 @echo 'Userspace tools targets:'
1451 @echo ' use "make tools/help"'
1452 @echo ' or "cd tools; make help"'
1453 @echo ''
1da177e4 1454 @echo 'Kernel packaging:'
6c2133e1 1455 @$(MAKE) $(build)=$(package-dir) help
1da177e4
LT
1456 @echo ''
1457 @echo 'Documentation targets:'
cb43fb57 1458 @$(MAKE) -f $(srctree)/Documentation/Makefile dochelp
1da177e4 1459 @echo ''
01dee188 1460 @echo 'Architecture specific targets ($(SRCARCH)):'
1da177e4 1461 @$(if $(archhelp),$(archhelp),\
01dee188 1462 echo ' No architecture specific help defined for $(SRCARCH)')
1da177e4
LT
1463 @echo ''
1464 @$(if $(boards), \
1465 $(foreach b, $(boards), \
1466 printf " %-24s - Build for %s\\n" $(b) $(subst _defconfig,,$(b));) \
1467 echo '')
5dffbe81
SB
1468 @$(if $(board-dirs), \
1469 $(foreach b, $(board-dirs), \
1470 printf " %-16s - Show %s-specific targets\\n" help-$(b) $(b);) \
1471 printf " %-16s - Show all of the above\\n" help-boards; \
1472 echo '')
1da177e4
LT
1473
1474 @echo ' make V=0|1 [targets] 0 => quiet build (default), 1 => verbose build'
45d506bd 1475 @echo ' make V=2 [targets] 2 => give reason for rebuild of target'
1da177e4 1476 @echo ' make O=dir [targets] Locate all output files in "dir", including .config'
9ba26a72 1477 @echo ' make C=1 [targets] Check re-compiled c source with $$CHECK (sparse by default)'
701842e3 1478 @echo ' make C=2 [targets] Force check of all c source with $$CHECK'
af07ce3e 1479 @echo ' make RECORDMCOUNT_WARN=1 [targets] Warn about ignored mcount sections'
28bc20dc
SR
1480 @echo ' make W=n [targets] Enable extra gcc checks, n=1,2,3 where'
1481 @echo ' 1: warnings which may be relevant and do not occur too often'
1482 @echo ' 2: warnings which occur quite often but may still be relevant'
1483 @echo ' 3: more obscure warnings, can most likely be ignored'
a6de553d 1484 @echo ' Multiple levels can be combined with W=12 or W=123'
1da177e4
LT
1485 @echo ''
1486 @echo 'Execute "make" or "make all" to build all targets marked with [*] '
1487 @echo 'For further info see the ./README file'
1488
1489
5dffbe81
SB
1490help-board-dirs := $(addprefix help-,$(board-dirs))
1491
1492help-boards: $(help-board-dirs)
1493
fbae4d58 1494boards-per-dir = $(sort $(notdir $(wildcard $(srctree)/arch/$(SRCARCH)/configs/$*/*_defconfig)))
5dffbe81
SB
1495
1496$(help-board-dirs): help-%:
1497 @echo 'Architecture specific targets ($(SRCARCH) $*):'
1498 @$(if $(boards-per-dir), \
1499 $(foreach b, $(boards-per-dir), \
1500 printf " %-24s - Build for %s\\n" $*/$(b) $(subst _defconfig,,$(b));) \
1501 echo '')
1502
1503
1da177e4
LT
1504# Documentation targets
1505# ---------------------------------------------------------------------------
e8939222
JN
1506DOC_TARGETS := xmldocs latexdocs pdfdocs htmldocs epubdocs cleandocs \
1507 linkcheckdocs dochelp refcheckdocs
22cba31b
JN
1508PHONY += $(DOC_TARGETS)
1509$(DOC_TARGETS): scripts_basic FORCE
cb43fb57 1510 $(Q)$(MAKE) $(build)=Documentation $@
1da177e4 1511
67274c08
MY
1512# Misc
1513# ---------------------------------------------------------------------------
1514
1515PHONY += scripts_gdb
1516scripts_gdb: prepare
1e5ff84f 1517 $(Q)$(MAKE) $(build)=scripts/gdb
8d2e5200 1518 $(Q)ln -fsn $(abspath $(srctree)/scripts/gdb/vmlinux-gdb.py)
67274c08
MY
1519
1520ifdef CONFIG_GDB_SCRIPTS
1521all: scripts_gdb
1522endif
1523
1da177e4
LT
1524else # KBUILD_EXTMOD
1525
1526###
1527# External module support.
1528# When building external modules the kernel used as basis is considered
1529# read-only, and no consistency checks are made and the make
1530# system is not used on the basis kernel. If updates are required
1531# in the basis kernel ordinary make commands (without M=...) must
1532# be used.
1533#
1534# The following are the only valid targets when building external
1535# modules.
1536# make M=dir clean Delete all automatically generated files
1537# make M=dir modules Make all modules in specified dir
1538# make M=dir Same as 'make M=dir modules'
1539# make M=dir modules_install
070b98bf 1540# Install the modules built in the module directory
1da177e4
LT
1541# Assumes install directory is already created
1542
1543# We are always building modules
1544KBUILD_MODULES := 1
1da177e4 1545
4f193362 1546PHONY += $(objtree)/Module.symvers
1da177e4
LT
1547$(objtree)/Module.symvers:
1548 @test -e $(objtree)/Module.symvers || ( \
1549 echo; \
1550 echo " WARNING: Symbol version dump $(objtree)/Module.symvers"; \
1551 echo " is missing; modules will have no dependencies and modversions."; \
1552 echo )
1553
1554module-dirs := $(addprefix _module_,$(KBUILD_EXTMOD))
4f193362 1555PHONY += $(module-dirs) modules
e07db28e 1556$(module-dirs): prepare $(objtree)/Module.symvers
1da177e4
LT
1557 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
1558
1559modules: $(module-dirs)
fd54f502 1560 @$(kecho) ' Building modules, stage 2.';
b805aa0e 1561 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
1da177e4 1562
4f193362 1563PHONY += modules_install
a67dc21a 1564modules_install: _emodinst_ _emodinst_post
e6304663 1565
4f193362
PS
1566install-dir := $(if $(INSTALL_MOD_DIR),$(INSTALL_MOD_DIR),extra)
1567PHONY += _emodinst_
a67dc21a 1568_emodinst_:
a67dc21a 1569 $(Q)mkdir -p $(MODLIB)/$(install-dir)
b805aa0e 1570 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modinst
1da177e4 1571
4f193362 1572PHONY += _emodinst_post
a67dc21a
SR
1573_emodinst_post: _emodinst_
1574 $(call cmd,depmod)
1575
1da177e4
LT
1576clean-dirs := $(addprefix _clean_,$(KBUILD_EXTMOD))
1577
4f193362 1578PHONY += $(clean-dirs) clean
1da177e4
LT
1579$(clean-dirs):
1580 $(Q)$(MAKE) $(clean)=$(patsubst _clean_%,%,$@)
1581
1582clean: rm-dirs := $(MODVERDIR)
88d7be03 1583clean: rm-files := $(KBUILD_EXTMOD)/Module.symvers
1da177e4 1584
fe69b420 1585PHONY += help
1da177e4
LT
1586help:
1587 @echo ' Building external modules.'
1588 @echo ' Syntax: make -C path/to/kernel/src M=$$PWD target'
1589 @echo ''
1590 @echo ' modules - default target, build the module(s)'
1591 @echo ' modules_install - install the module'
1592 @echo ' clean - remove generated files in module directory only'
1593 @echo ''
06300b21 1594
059bc9fc 1595PHONY += prepare
e07db28e
MY
1596prepare:
1597 $(cmd_crmodverdir)
1da177e4
LT
1598endif # KBUILD_EXTMOD
1599
88d7be03
MM
1600clean: $(clean-dirs)
1601 $(call cmd,rmdirs)
1602 $(call cmd,rmfiles)
43f67c98 1603 @find $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD), .) $(RCS_FIND_IGNORE) \
ef46d9b3 1604 \( -name '*.[aios]' -o -name '*.ko' -o -name '.*.cmd' \
4f0e3a57
RH
1605 -o -name '*.ko.*' \
1606 -o -name '*.dtb' -o -name '*.dtb.S' -o -name '*.dt.yaml' \
ef46d9b3 1607 -o -name '*.dwo' -o -name '*.lst' \
d523b255 1608 -o -name '*.su' \
88d7be03 1609 -o -name '.*.d' -o -name '.*.tmp' -o -name '*.mod.c' \
9a8dfb39 1610 -o -name '*.lex.c' -o -name '*.tab.[ch]' \
4fa8bc94 1611 -o -name '*.asn1.[ch]' \
88d7be03
MM
1612 -o -name '*.symtypes' -o -name 'modules.order' \
1613 -o -name modules.builtin -o -name '.tmp_*.o.*' \
6b90bd4b 1614 -o -name '*.c.[012]*.*' \
433db3e2 1615 -o -name '*.ll' \
88d7be03
MM
1616 -o -name '*.gcno' \) -type f -print | xargs rm -f
1617
1da177e4
LT
1618# Generate tags for editors
1619# ---------------------------------------------------------------------------
a680eedc
SR
1620quiet_cmd_tags = GEN $@
1621 cmd_tags = $(CONFIG_SHELL) $(srctree)/scripts/tags.sh $@
1da177e4 1622
f4ed1009 1623tags TAGS cscope gtags: FORCE
1da177e4
LT
1624 $(call cmd,tags)
1625
1da177e4
LT
1626# Scripts to check various things for consistency
1627# ---------------------------------------------------------------------------
1628
279f3dd3
PF
1629PHONY += includecheck versioncheck coccicheck namespacecheck export_report
1630
1da177e4 1631includecheck:
436f876c 1632 find $(srctree)/* $(RCS_FIND_IGNORE) \
1da177e4 1633 -name '*.[hcS]' -type f -print | sort \
80007434 1634 | xargs $(PERL) -w $(srctree)/scripts/checkincludes.pl
1da177e4
LT
1635
1636versioncheck:
2ee2d292 1637 find $(srctree)/* $(RCS_FIND_IGNORE) \
1da177e4 1638 -name '*.[hcS]' -type f -print | sort \
80007434 1639 | xargs $(PERL) -w $(srctree)/scripts/checkversion.pl
1da177e4 1640
74425eee
NP
1641coccicheck:
1642 $(Q)$(CONFIG_SHELL) $(srctree)/scripts/$@
1643
1da177e4
LT
1644namespacecheck:
1645 $(PERL) $(srctree)/scripts/namespace.pl
1646
295ac051
AB
1647export_report:
1648 $(PERL) $(srctree)/scripts/export_report.pl
1649
c398ff00 1650PHONY += checkstack kernelrelease kernelversion image_name
e3ccf6e3 1651
011e3a9a
JD
1652# UML needs a little special treatment here. It wants to use the host
1653# toolchain, so needs $(SUBARCH) passed to checkstack.pl. Everyone
1654# else wants $(ARCH), including people doing cross-builds, which means
1655# that $(SUBARCH) doesn't work here.
1656ifeq ($(ARCH), um)
1657CHECKSTACK_ARCH := $(SUBARCH)
1658else
1659CHECKSTACK_ARCH := $(ARCH)
1660endif
1da177e4
LT
1661checkstack:
1662 $(OBJDUMP) -d vmlinux $$(find . -name '*.ko') | \
011e3a9a 1663 $(PERL) $(src)/scripts/checkstack.pl $(CHECKSTACK_ARCH)
1da177e4 1664
7b8ea53d
AW
1665kernelrelease:
1666 @echo "$(KERNELVERSION)$$($(CONFIG_SHELL) $(srctree)/scripts/setlocalversion $(srctree))"
01ab1788 1667
cb58455c 1668kernelversion:
2244cbd8 1669 @echo $(KERNELVERSION)
1da177e4 1670
c398ff00
MM
1671image_name:
1672 @echo $(KBUILD_IMAGE)
1673
ea01fa9f 1674# Clear a bunch of variables before executing the submake
f47a23ce
MY
1675
1676ifeq ($(quiet),silent_)
1677tools_silent=s
1678endif
1679
ea01fa9f 1680tools/: FORCE
bf35182f 1681 $(Q)mkdir -p $(objtree)/tools
8e9b4667 1682 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(src)/tools/
ea01fa9f
BP
1683
1684tools/%: FORCE
bf35182f 1685 $(Q)mkdir -p $(objtree)/tools
8e9b4667 1686 $(Q)$(MAKE) LDFLAGS= MAKEFLAGS="$(tools_silent) $(filter --j% -j,$(MAKEFLAGS))" O=$(abspath $(objtree)) subdir=tools -C $(src)/tools/ $*
ea01fa9f 1687
06300b21
SR
1688# Single targets
1689# ---------------------------------------------------------------------------
bc2546a6 1690# Single targets are compatible with:
e1b8513d 1691# - build with mixed source and output
bc2546a6
SR
1692# - build with separate output dir 'make O=...'
1693# - external modules
1694#
1695# target-dir => where to store outputfile
1696# build-dir => directory in kernel source tree to use
1697
6b12de69
MY
1698build-target = $(if $(KBUILD_EXTMOD), $(KBUILD_EXTMOD)/)$@
1699build-dir = $(patsubst %/,%,$(dir $(build-target)))
1700
1701%.i: prepare FORCE
1702 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
1703%.ll: prepare FORCE
1704 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
1705%.lst: prepare FORCE
1706 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
1707%.o: prepare FORCE
1708 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
1709%.s: prepare FORCE
1710 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
1711%.symtypes: prepare FORCE
1712 $(Q)$(MAKE) $(build)=$(build-dir) $(build-target)
1713%.ko: %.o
1714 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
06300b21 1715
bc2546a6 1716# Modules
6d3c94e4
MY
1717PHONY += /
1718/: ./
1719
8e2faea8 1720# Make sure the latest headers are built for Documentation
ddea05fa 1721Documentation/ samples/: headers_install
059bc9fc 1722%/: prepare FORCE
648ad9b1 1723 $(Q)$(MAKE) KBUILD_MODULES=1 $(build)=$(build-dir)
06300b21 1724
38385f8f 1725# FIXME Should go into a make.lib or something
1da177e4
LT
1726# ===========================================================================
1727
1728quiet_cmd_rmdirs = $(if $(wildcard $(rm-dirs)),CLEAN $(wildcard $(rm-dirs)))
1729 cmd_rmdirs = rm -rf $(rm-dirs)
1730
1731quiet_cmd_rmfiles = $(if $(wildcard $(rm-files)),CLEAN $(wildcard $(rm-files)))
1732 cmd_rmfiles = rm -f $(rm-files)
1733
bc3c26fe 1734# Run depmod only if we have System.map and depmod is executable
50a8ec31 1735quiet_cmd_depmod = DEPMOD $(KERNELRELEASE)
569658dd 1736 cmd_depmod = $(CONFIG_SHELL) $(srctree)/scripts/depmod.sh $(DEPMOD) \
5a144a1a 1737 $(KERNELRELEASE)
50a8ec31 1738
7bb9d092 1739# Create temporary dir for module support files
ab19f879
SR
1740# clean it up only when building all modules
1741cmd_crmodverdir = $(Q)mkdir -p $(MODVERDIR) \
1742 $(if $(KBUILD_MODULES),; rm -f $(MODVERDIR)/*)
1da177e4 1743
392885ee
MY
1744# read saved command lines for existing targets
1745existing-targets := $(wildcard $(sort $(targets)))
1da177e4 1746
b999923c 1747-include $(foreach f,$(existing-targets),$(dir $(f)).$(notdir $(f)).cmd)
1da177e4 1748
25815cf5
MY
1749endif # ifeq ($(config-targets),1)
1750endif # ifeq ($(mixed-targets),1)
3812b8c5 1751endif # sub-make-done
1da177e4 1752
4f193362 1753PHONY += FORCE
1da177e4 1754FORCE:
4f193362 1755
bd412d81 1756# Declare the contents of the PHONY variable as phony. We keep that
fe8d0a41 1757# information in a variable so we can use it in if_changed and friends.
4f193362 1758.PHONY: $(PHONY)