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