source: src/linux/universal/linux-4.9/Makefile @ 31662

Last change on this file since 31662 was 31662, checked in by brainslayer, 2 months ago

use new squashfs in all kernels

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