Makefile revision 51193b76
1c517d838SLinus TorvaldsVERSION = 4
2f55532a0SLinus TorvaldsPATCHLEVEL = 6
355922c9dSLinus TorvaldsSUBLEVEL = 0
4f55532a0SLinus TorvaldsEXTRAVERSION = -rc1
525cb62b7SLinus TorvaldsNAME = Blurry Fish Butt
61da177e4SLinus Torvalds
71da177e4SLinus Torvalds# *DOCUMENTATION*
81da177e4SLinus Torvalds# To see a list of typical targets execute "make help"
91da177e4SLinus Torvalds# More info can be located in ./README
101da177e4SLinus Torvalds# Comments in this file are targeted only to the developer, do not
111da177e4SLinus Torvalds# expect to learn how to build the kernel reading this file.
121da177e4SLinus Torvalds
13a436bb7bSMasahiro Yamada# o Do not use make's built-in rules and variables
14a436bb7bSMasahiro Yamada#   (this increases performance and avoids hard-to-debug behaviour);
15a436bb7bSMasahiro Yamada# o Look for make include files relative to root of kernel src
16a436bb7bSMasahiro YamadaMAKEFLAGS += -rR --include-dir=$(CURDIR)
171da177e4SLinus Torvalds
18c051346bSH. Peter Anvin# Avoid funny character set dependencies
1906b5dc64SH. Peter Anvinunexport LC_ALL
20c051346bSH. Peter AnvinLC_COLLATE=C
21c051346bSH. Peter AnvinLC_NUMERIC=C
2207105202SMichal Marekexport LC_COLLATE LC_NUMERIC
23c051346bSH. Peter Anvin
24ab7474eaSBorislav Petkov# Avoid interference with shell env settings
25ab7474eaSBorislav Petkovunexport GREP_OPTIONS
26ab7474eaSBorislav Petkov
271da177e4SLinus Torvalds# We are using a recursive build, so we need to do a little thinking
281da177e4SLinus Torvalds# to get the ordering right.
291da177e4SLinus Torvalds#
301da177e4SLinus Torvalds# Most importantly: sub-Makefiles should only ever modify files in
311da177e4SLinus Torvalds# their own directory. If in some directory we have a dependency on
321da177e4SLinus Torvalds# a file in another dir (which doesn't happen often, but it's often
331da177e4SLinus Torvalds# unavoidable when linking the built-in.o targets which finally
341da177e4SLinus Torvalds# turn into vmlinux), we will call a sub make in that other dir, and
351da177e4SLinus Torvalds# after that we are sure that everything which is in that other dir
361da177e4SLinus Torvalds# is now up to date.
371da177e4SLinus Torvalds#
381da177e4SLinus Torvalds# The only cases where we need to modify files which have global
391da177e4SLinus Torvalds# effects are thus separated out and done before the recursive
401da177e4SLinus Torvalds# descending is started. They are now explicitly listed as the
411da177e4SLinus Torvalds# prepare rule.
421da177e4SLinus Torvalds
43066b7ed9SMichal Marek# Beautify output
44066b7ed9SMichal Marek# ---------------------------------------------------------------------------
45066b7ed9SMichal Marek#
46066b7ed9SMichal Marek# Normally, we echo the whole command before executing it. By making
47066b7ed9SMichal Marek# that echo $($(quiet)$(cmd)), we now have the possibility to set
48066b7ed9SMichal Marek# $(quiet) to choose other forms of output instead, e.g.
49066b7ed9SMichal Marek#
50066b7ed9SMichal Marek#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
51066b7ed9SMichal Marek#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
52066b7ed9SMichal Marek#
53066b7ed9SMichal Marek# If $(quiet) is empty, the whole command will be printed.
54066b7ed9SMichal Marek# If it is set to "quiet_", only the short version will be printed.
55066b7ed9SMichal Marek# If it is set to "silent_", nothing will be printed at all, since
56066b7ed9SMichal Marek# the variable $(silent_cmd_cc_o_c) doesn't exist.
57066b7ed9SMichal Marek#
58066b7ed9SMichal Marek# A simple variant is to prefix commands with $(Q) - that's useful
59066b7ed9SMichal Marek# for commands that shall be hidden in non-verbose mode.
60066b7ed9SMichal Marek#
61066b7ed9SMichal Marek#	$(Q)ln $@ :<
62066b7ed9SMichal Marek#
63066b7ed9SMichal Marek# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
64066b7ed9SMichal Marek# If KBUILD_VERBOSE equals 1 then the above command is displayed.
65066b7ed9SMichal Marek#
661da177e4SLinus Torvalds# To put more focus on warnings, be less verbose as default
671da177e4SLinus Torvalds# Use 'make V=1' to see the full commands
681da177e4SLinus Torvalds
69b8b0618cSCheng Renquanifeq ("$(origin V)", "command line")
70b8b0618cSCheng Renquan  KBUILD_VERBOSE = $(V)
711da177e4SLinus Torvaldsendif
721da177e4SLinus Torvaldsifndef KBUILD_VERBOSE
731da177e4SLinus Torvalds  KBUILD_VERBOSE = 0
741da177e4SLinus Torvaldsendif
751da177e4SLinus Torvalds
76066b7ed9SMichal Marekifeq ($(KBUILD_VERBOSE),1)
77066b7ed9SMichal Marek  quiet =
78066b7ed9SMichal Marek  Q =
79066b7ed9SMichal Marekelse
80066b7ed9SMichal Marek  quiet=quiet_
81066b7ed9SMichal Marek  Q = @
82066b7ed9SMichal Marekendif
83066b7ed9SMichal Marek
84066b7ed9SMichal Marek# If the user is running make -s (silent mode), suppress echoing of
85066b7ed9SMichal Marek# commands
86066b7ed9SMichal Marek
87066b7ed9SMichal Marekifneq ($(filter 4.%,$(MAKE_VERSION)),)	# make-4
88066b7ed9SMichal Marekifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
89066b7ed9SMichal Marek  quiet=silent_
90066b7ed9SMichal Marekendif
91066b7ed9SMichal Marekelse					# make-3.8x
92066b7ed9SMichal Marekifneq ($(filter s% -s%,$(MAKEFLAGS)),)
93066b7ed9SMichal Marek  quiet=silent_
94066b7ed9SMichal Marekendif
95066b7ed9SMichal Marekendif
96066b7ed9SMichal Marek
97066b7ed9SMichal Marekexport quiet Q KBUILD_VERBOSE
98066b7ed9SMichal Marek
991da177e4SLinus Torvalds# kbuild supports saving output files in a separate directory.
1001da177e4SLinus Torvalds# To locate output files in a separate directory two syntaxes are supported.
1011da177e4SLinus Torvalds# In both cases the working directory must be the root of the kernel src.
1021da177e4SLinus Torvalds# 1) O=
1031da177e4SLinus Torvalds# Use "make O=dir/to/store/output/files/"
104070b98bfSSam Ravnborg#
1051da177e4SLinus Torvalds# 2) Set KBUILD_OUTPUT
1061da177e4SLinus Torvalds# Set the environment variable KBUILD_OUTPUT to point to the directory
1071da177e4SLinus Torvalds# where the output files shall be placed.
1081da177e4SLinus Torvalds# export KBUILD_OUTPUT=dir/to/store/output/files/
1091da177e4SLinus Torvalds# make
1101da177e4SLinus Torvalds#
1111da177e4SLinus Torvalds# The O= assignment takes precedence over the KBUILD_OUTPUT environment
1121da177e4SLinus Torvalds# variable.
1131da177e4SLinus Torvalds
1141da177e4SLinus Torvalds# KBUILD_SRC is set on invocation of make in OBJ directory
1151da177e4SLinus Torvalds# KBUILD_SRC is not intended to be used by the regular user (for now)
1161da177e4SLinus Torvaldsifeq ($(KBUILD_SRC),)
1171da177e4SLinus Torvalds
1181da177e4SLinus Torvalds# OK, Make called in directory where kernel src resides
1191da177e4SLinus Torvalds# Do we want to locate output files in a separate directory?
120b8b0618cSCheng Renquanifeq ("$(origin O)", "command line")
121b8b0618cSCheng Renquan  KBUILD_OUTPUT := $(O)
1221da177e4SLinus Torvaldsendif
1231da177e4SLinus Torvalds
1241da177e4SLinus Torvalds# That's our default target when none is given on the command line
1254f193362SPaul SmithPHONY := _all
1261da177e4SLinus Torvalds_all:
1271da177e4SLinus Torvalds
1281cacc9abSSam Ravnborg# Cancel implicit rules on top Makefile
1291cacc9abSSam Ravnborg$(CURDIR)/Makefile Makefile: ;
1301cacc9abSSam Ravnborg
13151193b76SRobert Jarzmikifneq ($(words $(subst :, ,$(CURDIR))), 1)
13251193b76SRobert Jarzmik  $(error main directory cannot contain spaces nor colons)
13351193b76SRobert Jarzmikendif
13451193b76SRobert Jarzmik
1351da177e4SLinus Torvaldsifneq ($(KBUILD_OUTPUT),)
1361da177e4SLinus Torvalds# Invoke a second make in the output directory, passing relevant variables
1371da177e4SLinus Torvalds# check that the output directory actually exists
1381da177e4SLinus Torvaldssaved-output := $(KBUILD_OUTPUT)
1391c9e70a5SMasahiro YamadaKBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
1401c9e70a5SMasahiro Yamada								&& /bin/pwd)
1411da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
1421c9e70a5SMasahiro Yamada     $(error failed to create output directory "$(saved-output)"))
1431da177e4SLinus Torvalds
1440b35786dSMilton MillerPHONY += $(MAKECMDGOALS) sub-make
1450b35786dSMilton Miller
1461cacc9abSSam Ravnborg$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
14716f89098SCharles Keepax	@:
1480b35786dSMilton Miller
1492e8d696bSMasahiro Yamadasub-make:
150745a2543SMasahiro Yamada	$(Q)$(MAKE) -C $(KBUILD_OUTPUT) KBUILD_SRC=$(CURDIR) \
151aa55c8e2SMasahiro Yamada	-f $(CURDIR)/Makefile $(filter-out _all sub-make,$(MAKECMDGOALS))
1521da177e4SLinus Torvalds
1531da177e4SLinus Torvalds# Leave processing to above invocation of make
1541da177e4SLinus Torvaldsskip-makefile := 1
1551da177e4SLinus Torvaldsendif # ifneq ($(KBUILD_OUTPUT),)
1561da177e4SLinus Torvaldsendif # ifeq ($(KBUILD_SRC),)
1571da177e4SLinus Torvalds
1581da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
1591da177e4SLinus Torvaldsifeq ($(skip-makefile),)
1601da177e4SLinus Torvalds
1617ff52571SMasahiro Yamada# Do not print "Entering directory ...",
1627ff52571SMasahiro Yamada# but we want to display it when entering to the output directory
1637ff52571SMasahiro Yamada# so that IDEs/editors are able to understand relative filenames.
1647ff52571SMasahiro YamadaMAKEFLAGS += --no-print-directory
1657ff52571SMasahiro Yamada
166aa55c8e2SMasahiro Yamada# Call a source code checker (by default, "sparse") as part of the
167aa55c8e2SMasahiro Yamada# C compilation.
168aa55c8e2SMasahiro Yamada#
169aa55c8e2SMasahiro Yamada# Use 'make C=1' to enable checking of only re-compiled files.
170aa55c8e2SMasahiro Yamada# Use 'make C=2' to enable checking of *all* source files, regardless
171aa55c8e2SMasahiro Yamada# of whether they are re-compiled or not.
172aa55c8e2SMasahiro Yamada#
173aa55c8e2SMasahiro Yamada# See the file "Documentation/sparse.txt" for more details, including
174aa55c8e2SMasahiro Yamada# where to get the "sparse" utility.
175aa55c8e2SMasahiro Yamada
176aa55c8e2SMasahiro Yamadaifeq ("$(origin C)", "command line")
177aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = $(C)
178aa55c8e2SMasahiro Yamadaendif
179aa55c8e2SMasahiro Yamadaifndef KBUILD_CHECKSRC
180aa55c8e2SMasahiro Yamada  KBUILD_CHECKSRC = 0
181aa55c8e2SMasahiro Yamadaendif
182aa55c8e2SMasahiro Yamada
183aa55c8e2SMasahiro Yamada# Use make M=dir to specify directory of external module to build
184aa55c8e2SMasahiro Yamada# Old syntax make ... SUBDIRS=$PWD is still supported
185aa55c8e2SMasahiro Yamada# Setting the environment variable KBUILD_EXTMOD take precedence
186aa55c8e2SMasahiro Yamadaifdef SUBDIRS
187aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD ?= $(SUBDIRS)
188aa55c8e2SMasahiro Yamadaendif
189aa55c8e2SMasahiro Yamada
190aa55c8e2SMasahiro Yamadaifeq ("$(origin M)", "command line")
191aa55c8e2SMasahiro Yamada  KBUILD_EXTMOD := $(M)
192aa55c8e2SMasahiro Yamadaendif
193aa55c8e2SMasahiro Yamada
1941da177e4SLinus Torvalds# If building an external module we do not care about the all: rule
1951da177e4SLinus Torvalds# but instead _all depend on modules
1964f193362SPaul SmithPHONY += all
1971da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
1981da177e4SLinus Torvalds_all: all
1991da177e4SLinus Torvaldselse
2001da177e4SLinus Torvalds_all: modules
2011da177e4SLinus Torvaldsendif
2021da177e4SLinus Torvalds
2039da0763bSMichal Marekifeq ($(KBUILD_SRC),)
2049da0763bSMichal Marek        # building in the source tree
2059da0763bSMichal Marek        srctree := .
2069da0763bSMichal Marekelse
2079da0763bSMichal Marek        ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
2089da0763bSMichal Marek                # building in a subdirectory of the source tree
2099da0763bSMichal Marek                srctree := ..
2109da0763bSMichal Marek        else
2119da0763bSMichal Marek                srctree := $(KBUILD_SRC)
2129da0763bSMichal Marek        endif
2139da0763bSMichal Marekendif
2147e1c0477SMichal Marekobjtree		:= .
2151da177e4SLinus Torvaldssrc		:= $(srctree)
2161da177e4SLinus Torvaldsobj		:= $(objtree)
2171da177e4SLinus Torvalds
2180f558c33SMattia DongiliVPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
2191da177e4SLinus Torvalds
22011294235SAmerigo Wangexport srctree objtree VPATH
2211da177e4SLinus Torvalds
2221da177e4SLinus Torvalds# SUBARCH tells the usermode build what the underlying arch is.  That is set
2231da177e4SLinus Torvalds# first, and if a usermode build is happening, the "ARCH=um" on the command
2241da177e4SLinus Torvalds# line overrides the setting of ARCH below.  If a native build is happening,
22538385f8fSMasahiro Yamada# then ARCH is assigned, getting whatever value it gets normally, and
2261da177e4SLinus Torvalds# SUBARCH is subsequently ignored.
2271da177e4SLinus Torvalds
228ffee0de4SDavid WoodhouseSUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
229ffee0de4SDavid Woodhouse				  -e s/sun4u/sparc64/ \
2301da177e4SLinus Torvalds				  -e s/arm.*/arm/ -e s/sa110/arm/ \
23139990b5eSLinus Torvalds				  -e s/s390x/s390/ -e s/parisc64/parisc/ \
232236b1957SPaul Mundt				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
233f1b99392SWill Deacon				  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
2341da177e4SLinus Torvalds
2351da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
2361da177e4SLinus Torvalds# ---------------------------------------------------------------------------
2371da177e4SLinus Torvalds#
2381da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
2391da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
2401da177e4SLinus Torvalds# ARCH can be set during invocation of make:
2411da177e4SLinus Torvalds# make ARCH=ia64
2421da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
2431da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
2441da177e4SLinus Torvalds
2451da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
2461da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
2471da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
2481da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
2491da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
2501da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
25184336466SRoland McGrath# A third alternative is to store a setting in .config so that plain
25284336466SRoland McGrath# "make" in the configured kernel build directory always uses that.
2531da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
2541da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
2552331d1a6SSam RavnborgARCH		?= $(SUBARCH)
25684336466SRoland McGrathCROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)
2571da177e4SLinus Torvalds
2581da177e4SLinus Torvalds# Architecture as present in compile.h
2596752ed90SThomas GleixnerUTS_MACHINE 	:= $(ARCH)
2606752ed90SThomas GleixnerSRCARCH 	:= $(ARCH)
2611da177e4SLinus Torvalds
262d746d647SSam Ravnborg# Additional ARCH settings for x86
263d746d647SSam Ravnborgifeq ($(ARCH),i386)
264d746d647SSam Ravnborg        SRCARCH := x86
265d746d647SSam Ravnborgendif
266d746d647SSam Ravnborgifeq ($(ARCH),x86_64)
267d746d647SSam Ravnborg        SRCARCH := x86
268d746d647SSam Ravnborgendif
26974b469f2SSam Ravnborg
2705e538790SSam Ravnborg# Additional ARCH settings for sparc
271e69f58c0SNamhyung Kimifeq ($(ARCH),sparc32)
272e69f58c0SNamhyung Kim       SRCARCH := sparc
273e69f58c0SNamhyung Kimendif
274a439fe51SSam Ravnborgifeq ($(ARCH),sparc64)
2755e538790SSam Ravnborg       SRCARCH := sparc
276a439fe51SSam Ravnborgendif
2772fb9b1bdSSam Ravnborg
2783cc000b5SPaul Mundt# Additional ARCH settings for sh
2793cc000b5SPaul Mundtifeq ($(ARCH),sh64)
2803cc000b5SPaul Mundt       SRCARCH := sh
2813cc000b5SPaul Mundtendif
2823cc000b5SPaul Mundt
28318aecc2bSChris Metcalf# Additional ARCH settings for tile
2846738d321SChris Metcalfifeq ($(ARCH),tilepro)
2856738d321SChris Metcalf       SRCARCH := tile
2866738d321SChris Metcalfendif
28718aecc2bSChris Metcalfifeq ($(ARCH),tilegx)
28818aecc2bSChris Metcalf       SRCARCH := tile
28918aecc2bSChris Metcalfendif
29018aecc2bSChris Metcalf
2915e538790SSam Ravnborg# Where to locate arch specific headers
2925e538790SSam Ravnborghdr-arch  := $(SRCARCH)
2935e538790SSam Ravnborg
29414cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
29541263fc6SBen Gardinerexport KCONFIG_CONFIG
29614cdd3c4SRoman Zippel
2971da177e4SLinus Torvalds# SHELL used by kbuild
2981da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
2991da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
3001da177e4SLinus Torvalds	  else echo sh; fi ; fi)
3011da177e4SLinus Torvalds
302070b98bfSSam RavnborgHOSTCC       = gcc
303070b98bfSSam RavnborgHOSTCXX      = g++
30451b97e35SKirill A. ShutemovHOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer -std=gnu89
305070b98bfSSam RavnborgHOSTCXXFLAGS = -O2
3061da177e4SLinus Torvalds
30761163efaSBehan Websterifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
30861163efaSBehan WebsterHOSTCFLAGS  += -Wno-unused-value -Wno-unused-parameter \
30961163efaSBehan Webster		-Wno-missing-field-initializers -fno-delete-null-pointer-checks
31061163efaSBehan Websterendif
31161163efaSBehan Webster
312070b98bfSSam Ravnborg# Decide whether to build built-in, modular, or both.
313070b98bfSSam Ravnborg# Normally, just do built-in.
3141da177e4SLinus Torvalds
3151da177e4SLinus TorvaldsKBUILD_MODULES :=
3161da177e4SLinus TorvaldsKBUILD_BUILTIN := 1
3171da177e4SLinus Torvalds
3183fbb43dfSMasahiro Yamada# If we have only "make modules", don't compile built-in objects.
3193fbb43dfSMasahiro Yamada# When we're building modules with modversions, we need to consider
3203fbb43dfSMasahiro Yamada# the built-in objects during the descend as well, in order to
3213fbb43dfSMasahiro Yamada# make sure the checksums are up to date before we record them.
3221da177e4SLinus Torvalds
3231da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),modules)
3241da177e4SLinus Torvalds  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
3251da177e4SLinus Torvaldsendif
3261da177e4SLinus Torvalds
3273fbb43dfSMasahiro Yamada# If we have "make <whatever> modules", compile modules
3283fbb43dfSMasahiro Yamada# in addition to whatever we do anyway.
3293fbb43dfSMasahiro Yamada# Just "make" or "make all" shall build modules as well
3301da177e4SLinus Torvalds
3311da177e4SLinus Torvaldsifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
3321da177e4SLinus Torvalds  KBUILD_MODULES := 1
3331da177e4SLinus Torvaldsendif
3341da177e4SLinus Torvalds
3351da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),)
3361da177e4SLinus Torvalds  KBUILD_MODULES := 1
3371da177e4SLinus Torvaldsendif
3381da177e4SLinus Torvalds
339e579d351SSam Ravnborgexport KBUILD_MODULES KBUILD_BUILTIN
3401da177e4SLinus Torvaldsexport KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
3411da177e4SLinus Torvalds
3421cacc9abSSam Ravnborg# We need some generic definitions (do not try to remake the file).
343a436bb7bSMasahiro Yamadascripts/Kbuild.include: ;
344a436bb7bSMasahiro Yamadainclude scripts/Kbuild.include
3451da177e4SLinus Torvalds
3461da177e4SLinus Torvalds# Make variables (CC, etc...)
3471da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
3481da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
3491da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
3501da177e4SLinus TorvaldsCPP		= $(CC) -E
3511da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
3521da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
3531da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
3541da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
3551da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
3561da177e4SLinus TorvaldsAWK		= awk
3571da177e4SLinus TorvaldsGENKSYMS	= scripts/genksyms/genksyms
358caa27b66SSam RavnborgINSTALLKERNEL  := installkernel
3591da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
3601da177e4SLinus TorvaldsPERL		= perl
361011bf125SMasahiro YamadaPYTHON		= python
3621da177e4SLinus TorvaldsCHECK		= sparse
3631da177e4SLinus Torvalds
36480a7d1d9SHannes EderCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
36580a7d1d9SHannes Eder		  -Wbitwise -Wno-return-void $(CF)
3666588169dSSam RavnborgCFLAGS_MODULE   =
3676588169dSSam RavnborgAFLAGS_MODULE   =
3686588169dSSam RavnborgLDFLAGS_MODULE  =
3691da177e4SLinus TorvaldsCFLAGS_KERNEL	=
3701da177e4SLinus TorvaldsAFLAGS_KERNEL	=
3712521f2c2SPeter OberparleiterCFLAGS_GCOV	= -fprofile-arcs -ftest-coverage
3725c9a8750SDmitry VyukovCFLAGS_KCOV	= -fsanitize-coverage=trace-pc
3731da177e4SLinus Torvalds
3741da177e4SLinus Torvalds
375abbf1590SDavid Howells# Use USERINCLUDE when you must reference the UAPI directories only.
376abbf1590SDavid HowellsUSERINCLUDE    := \
377abbf1590SDavid Howells		-I$(srctree)/arch/$(hdr-arch)/include/uapi \
378abbf1590SDavid Howells		-Iarch/$(hdr-arch)/include/generated/uapi \
379abbf1590SDavid Howells		-I$(srctree)/include/uapi \
380abbf1590SDavid Howells		-Iinclude/generated/uapi \
381abbf1590SDavid Howells                -include $(srctree)/include/linux/kconfig.h
382abbf1590SDavid Howells
3831da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
3841da177e4SLinus Torvalds# Needed to be compatible with the O= option
385abbf1590SDavid HowellsLINUXINCLUDE    := \
386abbf1590SDavid Howells		-I$(srctree)/arch/$(hdr-arch)/include \
38790ac086bSMichal Marek		-Iarch/$(hdr-arch)/include/generated/uapi \
388abbf1590SDavid Howells		-Iarch/$(hdr-arch)/include/generated \
389abbf1590SDavid Howells		$(if $(KBUILD_SRC), -I$(srctree)/include) \
390abbf1590SDavid Howells		-Iinclude \
391abbf1590SDavid Howells		$(USERINCLUDE)
3921da177e4SLinus Torvalds
393d8672b40SSam RavnborgKBUILD_CPPFLAGS := -D__KERNEL__
3941da177e4SLinus Torvalds
395a0f97e06SSam RavnborgKBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
39694bed2a9SDave Jones		   -fno-strict-aliasing -fno-common \
397a8735821SFloris Kraak		   -Werror-implicit-function-declaration \
39851b97e35SKirill A. Shutemov		   -Wno-format-security \
39951b97e35SKirill A. Shutemov		   -std=gnu89
400a1c48bb1SGeert Uytterhoeven
40180c00ba9SSam RavnborgKBUILD_AFLAGS_KERNEL :=
40280c00ba9SSam RavnborgKBUILD_CFLAGS_KERNEL :=
403222d394dSSam RavnborgKBUILD_AFLAGS   := -D__ASSEMBLY__
4046588169dSSam RavnborgKBUILD_AFLAGS_MODULE  := -DMODULE
4056588169dSSam RavnborgKBUILD_CFLAGS_MODULE  := -DMODULE
4066588169dSSam RavnborgKBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
4071da177e4SLinus Torvalds
408f1d28fb0SRoman Zippel# Read KERNELRELEASE from include/config/kernel.release (if it exists)
409f1d28fb0SRoman ZippelKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
410cacd54efSMichal MarekKERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
411cb58455cSSam Ravnborg
412070b98bfSSam Ravnborgexport VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
41380ef88d6SSam Ravnborgexport ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
414caa27b66SSam Ravnborgexport CPP AR NM STRIP OBJCOPY OBJDUMP
415011bf125SMasahiro Yamadaexport MAKE AWK GENKSYMS INSTALLKERNEL PERL PYTHON UTS_MACHINE
416070b98bfSSam Ravnborgexport HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
4171da177e4SLinus Torvalds
41806c5040cSSam Ravnborgexport KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
4195c9a8750SDmitry Vyukovexport KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV CFLAGS_KCOV CFLAGS_KASAN CFLAGS_UBSAN
420222d394dSSam Ravnborgexport KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
4216588169dSSam Ravnborgexport KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
42280c00ba9SSam Ravnborgexport KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
42340df759eSMichal Marekexport KBUILD_ARFLAGS
4241da177e4SLinus Torvalds
4251da177e4SLinus Torvalds# When compiling out-of-tree modules, put MODVERDIR in the module
4261da177e4SLinus Torvalds# tree rather than in the kernel tree. The kernel tree might
4271da177e4SLinus Torvalds# even be read-only.
4281da177e4SLinus Torvaldsexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
4291da177e4SLinus Torvalds
4301da177e4SLinus Torvalds# Files to ignore in find ... statements
4311da177e4SLinus Torvalds
432ae63b2d7SPrarit Bhargavaexport RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o    \
433ae63b2d7SPrarit Bhargava			  -name CVS -o -name .pc -o -name .hg -o -name .git \) \
434ae63b2d7SPrarit Bhargava			  -prune -o
435450c6076SJesper Juhlexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
436450c6076SJesper Juhl			 --exclude CVS --exclude .pc --exclude .hg --exclude .git
4371da177e4SLinus Torvalds
4381da177e4SLinus Torvalds# ===========================================================================
4391da177e4SLinus Torvalds# Rules shared between *config targets and build targets
4401da177e4SLinus Torvalds
4411da177e4SLinus Torvalds# Basic helpers built in scripts/
4424f193362SPaul SmithPHONY += scripts_basic
4431da177e4SLinus Torvaldsscripts_basic:
4441da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/basic
445638adb05SSteven Rostedt	$(Q)rm -f .tmp_quiet_recordmcount
4461da177e4SLinus Torvalds
447cd05e6bdSJan Beulich# To avoid any implicit rule to kick in, define an empty command.
448cd05e6bdSJan Beulichscripts/basic/%: scripts_basic ;
449cd05e6bdSJan Beulich
4504f193362SPaul SmithPHONY += outputmakefile
451fd5f0cd6SJan Beulich# outputmakefile generates a Makefile in the output directory, if using a
452fd5f0cd6SJan Beulich# separate output directory. This allows convenient use of make in the
453fd5f0cd6SJan Beulich# output directory.
4541da177e4SLinus Torvaldsoutputmakefile:
455fd5f0cd6SJan Beulichifneq ($(KBUILD_SRC),)
45692979997SAndi Kleen	$(Q)ln -fsn $(srctree) source
457fd5f0cd6SJan Beulich	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
458fd5f0cd6SJan Beulich	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
459fd5f0cd6SJan Beulichendif
4601da177e4SLinus Torvalds
461d8ecc5cdSSam Ravnborg# Support for using generic headers in asm-generic
462d8ecc5cdSSam RavnborgPHONY += asm-generic
463d8ecc5cdSSam Ravnborgasm-generic:
464d8ecc5cdSSam Ravnborg	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
4653c5994c8SCatalin Marinas	            src=asm obj=arch/$(SRCARCH)/include/generated/asm
4663c5994c8SCatalin Marinas	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
4673c5994c8SCatalin Marinas	            src=uapi/asm obj=arch/$(SRCARCH)/include/generated/uapi/asm
468d8ecc5cdSSam Ravnborg
4691da177e4SLinus Torvalds# To make sure we do not include .config for any of the *config targets
4701da177e4SLinus Torvalds# catch them early, and hand them over to scripts/kconfig/Makefile
4711da177e4SLinus Torvalds# It is allowed to specify more targets when calling make, including
4721da177e4SLinus Torvalds# mixing *config targets and build targets.
473070b98bfSSam Ravnborg# For example 'make oldconfig all'.
4741da177e4SLinus Torvalds# Detect when mixed targets is specified, and make a second invocation
4751da177e4SLinus Torvalds# of make so .config is not included in this case either (for *config).
4761da177e4SLinus Torvalds
47710b63956SDavid Howellsversion_h := include/generated/uapi/linux/version.h
478223c24a7SMichal Marekold_version_h := include/linux/version.h
479d183e6f5SDavid Howells
4803eb3c740SRoman Zippelno-dot-config-targets := clean mrproper distclean \
481fbae4d58SMichal Marek			 cscope gtags TAGS tags help% %docs check% coccicheck \
482d183e6f5SDavid Howells			 $(version_h) headers_% archheaders archscripts \
4834aed2fd8SLinus Torvalds			 kernelversion %src-pkg
4841da177e4SLinus Torvalds
4851da177e4SLinus Torvaldsconfig-targets := 0
4861da177e4SLinus Torvaldsmixed-targets  := 0
4871da177e4SLinus Torvaldsdot-config     := 1
4881da177e4SLinus Torvalds
4891da177e4SLinus Torvaldsifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
4901da177e4SLinus Torvalds	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
4911da177e4SLinus Torvalds		dot-config := 0
4921da177e4SLinus Torvalds	endif
4931da177e4SLinus Torvaldsendif
4941da177e4SLinus Torvalds
4951da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
4961da177e4SLinus Torvalds        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
4971da177e4SLinus Torvalds                config-targets := 1
498d0d38cd9SMasahiro Yamada                ifneq ($(words $(MAKECMDGOALS)),1)
4991da177e4SLinus Torvalds                        mixed-targets := 1
5001da177e4SLinus Torvalds                endif
5011da177e4SLinus Torvalds        endif
5021da177e4SLinus Torvaldsendif
503a85a41edSMichal Marek# install and module_install need also be processed one by one
504a85a41edSMichal Marekifneq ($(filter install,$(MAKECMDGOALS)),)
505a85a41edSMichal Marek        ifneq ($(filter modules_install,$(MAKECMDGOALS)),)
506a85a41edSMichal Marek	        mixed-targets := 1
507a85a41edSMichal Marek        endif
508