Makefile revision 066b7ed9
155922c9dSLinus TorvaldsVERSION = 3
27171511eSLinus TorvaldsPATCHLEVEL = 16
355922c9dSLinus TorvaldsSUBLEVEL = 0
47171511eSLinus TorvaldsEXTRAVERSION = -rc1
538dbfb59SLinus TorvaldsNAME = Shuffling Zombie Juror
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
1315964864SOleg Verych# Do not:
1415964864SOleg Verych# o  use make's built-in rules and variables
15d384e35aSLinus Nilsson#    (this increases performance and avoids hard-to-debug behaviour);
1615964864SOleg Verych# o  print "Entering directory ...";
1715964864SOleg VerychMAKEFLAGS += -rR --no-print-directory
181da177e4SLinus Torvalds
19c051346bSH. Peter Anvin# Avoid funny character set dependencies
2006b5dc64SH. Peter Anvinunexport LC_ALL
21c051346bSH. Peter AnvinLC_COLLATE=C
22c051346bSH. Peter AnvinLC_NUMERIC=C
2307105202SMichal Marekexport LC_COLLATE LC_NUMERIC
24c051346bSH. Peter Anvin
25ab7474eaSBorislav Petkov# Avoid interference with shell env settings
26ab7474eaSBorislav Petkovunexport GREP_OPTIONS
27ab7474eaSBorislav Petkov
281da177e4SLinus Torvalds# We are using a recursive build, so we need to do a little thinking
291da177e4SLinus Torvalds# to get the ordering right.
301da177e4SLinus Torvalds#
311da177e4SLinus Torvalds# Most importantly: sub-Makefiles should only ever modify files in
321da177e4SLinus Torvalds# their own directory. If in some directory we have a dependency on
331da177e4SLinus Torvalds# a file in another dir (which doesn't happen often, but it's often
341da177e4SLinus Torvalds# unavoidable when linking the built-in.o targets which finally
351da177e4SLinus Torvalds# turn into vmlinux), we will call a sub make in that other dir, and
361da177e4SLinus Torvalds# after that we are sure that everything which is in that other dir
371da177e4SLinus Torvalds# is now up to date.
381da177e4SLinus Torvalds#
391da177e4SLinus Torvalds# The only cases where we need to modify files which have global
401da177e4SLinus Torvalds# effects are thus separated out and done before the recursive
411da177e4SLinus Torvalds# descending is started. They are now explicitly listed as the
421da177e4SLinus Torvalds# prepare rule.
431da177e4SLinus Torvalds
44066b7ed9SMichal Marek# Beautify output
45066b7ed9SMichal Marek# ---------------------------------------------------------------------------
46066b7ed9SMichal Marek#
47066b7ed9SMichal Marek# Normally, we echo the whole command before executing it. By making
48066b7ed9SMichal Marek# that echo $($(quiet)$(cmd)), we now have the possibility to set
49066b7ed9SMichal Marek# $(quiet) to choose other forms of output instead, e.g.
50066b7ed9SMichal Marek#
51066b7ed9SMichal Marek#         quiet_cmd_cc_o_c = Compiling $(RELDIR)/$@
52066b7ed9SMichal Marek#         cmd_cc_o_c       = $(CC) $(c_flags) -c -o $@ $<
53066b7ed9SMichal Marek#
54066b7ed9SMichal Marek# If $(quiet) is empty, the whole command will be printed.
55066b7ed9SMichal Marek# If it is set to "quiet_", only the short version will be printed.
56066b7ed9SMichal Marek# If it is set to "silent_", nothing will be printed at all, since
57066b7ed9SMichal Marek# the variable $(silent_cmd_cc_o_c) doesn't exist.
58066b7ed9SMichal Marek#
59066b7ed9SMichal Marek# A simple variant is to prefix commands with $(Q) - that's useful
60066b7ed9SMichal Marek# for commands that shall be hidden in non-verbose mode.
61066b7ed9SMichal Marek#
62066b7ed9SMichal Marek#	$(Q)ln $@ :<
63066b7ed9SMichal Marek#
64066b7ed9SMichal Marek# If KBUILD_VERBOSE equals 0 then the above command will be hidden.
65066b7ed9SMichal Marek# If KBUILD_VERBOSE equals 1 then the above command is displayed.
66066b7ed9SMichal Marek#
671da177e4SLinus Torvalds# To put more focus on warnings, be less verbose as default
681da177e4SLinus Torvalds# Use 'make V=1' to see the full commands
691da177e4SLinus Torvalds
70b8b0618cSCheng Renquanifeq ("$(origin V)", "command line")
71b8b0618cSCheng Renquan  KBUILD_VERBOSE = $(V)
721da177e4SLinus Torvaldsendif
731da177e4SLinus Torvaldsifndef KBUILD_VERBOSE
741da177e4SLinus Torvalds  KBUILD_VERBOSE = 0
751da177e4SLinus Torvaldsendif
761da177e4SLinus Torvalds
77066b7ed9SMichal Marekifeq ($(KBUILD_VERBOSE),1)
78066b7ed9SMichal Marek  quiet =
79066b7ed9SMichal Marek  Q =
80066b7ed9SMichal Marekelse
81066b7ed9SMichal Marek  quiet=quiet_
82066b7ed9SMichal Marek  Q = @
83066b7ed9SMichal Marekendif
84066b7ed9SMichal Marek
85066b7ed9SMichal Marek# If the user is running make -s (silent mode), suppress echoing of
86066b7ed9SMichal Marek# commands
87066b7ed9SMichal Marek
88066b7ed9SMichal Marekifneq ($(filter 4.%,$(MAKE_VERSION)),)	# make-4
89066b7ed9SMichal Marekifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
90066b7ed9SMichal Marek  quiet=silent_
91066b7ed9SMichal Marekendif
92066b7ed9SMichal Marekelse					# make-3.8x
93066b7ed9SMichal Marekifneq ($(filter s% -s%,$(MAKEFLAGS)),)
94066b7ed9SMichal Marek  quiet=silent_
95066b7ed9SMichal Marekendif
96066b7ed9SMichal Marekendif
97066b7ed9SMichal Marek
98066b7ed9SMichal Marekexport quiet Q KBUILD_VERBOSE
99066b7ed9SMichal Marek
1001c7bafe7SRobert P. J. Day# Call a source code checker (by default, "sparse") as part of the
1011c7bafe7SRobert P. J. Day# C compilation.
1021c7bafe7SRobert P. J. Day#
1031c7bafe7SRobert P. J. Day# Use 'make C=1' to enable checking of only re-compiled files.
1041c7bafe7SRobert P. J. Day# Use 'make C=2' to enable checking of *all* source files, regardless
1051c7bafe7SRobert P. J. Day# of whether they are re-compiled or not.
1061c7bafe7SRobert P. J. Day#
1071c7bafe7SRobert P. J. Day# See the file "Documentation/sparse.txt" for more details, including
1081c7bafe7SRobert P. J. Day# where to get the "sparse" utility.
1091da177e4SLinus Torvalds
110b8b0618cSCheng Renquanifeq ("$(origin C)", "command line")
111b8b0618cSCheng Renquan  KBUILD_CHECKSRC = $(C)
1121da177e4SLinus Torvaldsendif
1131da177e4SLinus Torvaldsifndef KBUILD_CHECKSRC
1141da177e4SLinus Torvalds  KBUILD_CHECKSRC = 0
1151da177e4SLinus Torvaldsendif
1161da177e4SLinus Torvalds
1171da177e4SLinus Torvalds# Use make M=dir to specify directory of external module to build
1181da177e4SLinus Torvalds# Old syntax make ... SUBDIRS=$PWD is still supported
1191da177e4SLinus Torvalds# Setting the environment variable KBUILD_EXTMOD take precedence
1201da177e4SLinus Torvaldsifdef SUBDIRS
1211da177e4SLinus Torvalds  KBUILD_EXTMOD ?= $(SUBDIRS)
1221da177e4SLinus Torvaldsendif
1231da177e4SLinus Torvalds
124b8b0618cSCheng Renquanifeq ("$(origin M)", "command line")
125b8b0618cSCheng Renquan  KBUILD_EXTMOD := $(M)
126b8b0618cSCheng Renquanendif
1271da177e4SLinus Torvalds
1281da177e4SLinus Torvalds# kbuild supports saving output files in a separate directory.
1291da177e4SLinus Torvalds# To locate output files in a separate directory two syntaxes are supported.
1301da177e4SLinus Torvalds# In both cases the working directory must be the root of the kernel src.
1311da177e4SLinus Torvalds# 1) O=
1321da177e4SLinus Torvalds# Use "make O=dir/to/store/output/files/"
133070b98bfSSam Ravnborg#
1341da177e4SLinus Torvalds# 2) Set KBUILD_OUTPUT
1351da177e4SLinus Torvalds# Set the environment variable KBUILD_OUTPUT to point to the directory
1361da177e4SLinus Torvalds# where the output files shall be placed.
1371da177e4SLinus Torvalds# export KBUILD_OUTPUT=dir/to/store/output/files/
1381da177e4SLinus Torvalds# make
1391da177e4SLinus Torvalds#
1401da177e4SLinus Torvalds# The O= assignment takes precedence over the KBUILD_OUTPUT environment
1411da177e4SLinus Torvalds# variable.
1421da177e4SLinus Torvalds
1431da177e4SLinus Torvalds
1441da177e4SLinus Torvalds# KBUILD_SRC is set on invocation of make in OBJ directory
1451da177e4SLinus Torvalds# KBUILD_SRC is not intended to be used by the regular user (for now)
1461da177e4SLinus Torvaldsifeq ($(KBUILD_SRC),)
1471da177e4SLinus Torvalds
1481da177e4SLinus Torvalds# OK, Make called in directory where kernel src resides
1491da177e4SLinus Torvalds# Do we want to locate output files in a separate directory?
150b8b0618cSCheng Renquanifeq ("$(origin O)", "command line")
151b8b0618cSCheng Renquan  KBUILD_OUTPUT := $(O)
1521da177e4SLinus Torvaldsendif
1531da177e4SLinus Torvalds
1541da177e4SLinus Torvalds# That's our default target when none is given on the command line
1554f193362SPaul SmithPHONY := _all
1561da177e4SLinus Torvalds_all:
1571da177e4SLinus Torvalds
1581cacc9abSSam Ravnborg# Cancel implicit rules on top Makefile
1591cacc9abSSam Ravnborg$(CURDIR)/Makefile Makefile: ;
1601cacc9abSSam Ravnborg
1611da177e4SLinus Torvaldsifneq ($(KBUILD_OUTPUT),)
1621da177e4SLinus Torvalds# Invoke a second make in the output directory, passing relevant variables
1631da177e4SLinus Torvalds# check that the output directory actually exists
1641da177e4SLinus Torvaldssaved-output := $(KBUILD_OUTPUT)
1651c9e70a5SMasahiro YamadaKBUILD_OUTPUT := $(shell mkdir -p $(KBUILD_OUTPUT) && cd $(KBUILD_OUTPUT) \
1661c9e70a5SMasahiro Yamada								&& /bin/pwd)
1671da177e4SLinus Torvalds$(if $(KBUILD_OUTPUT),, \
1681c9e70a5SMasahiro Yamada     $(error failed to create output directory "$(saved-output)"))
1691da177e4SLinus Torvalds
1700b35786dSMilton MillerPHONY += $(MAKECMDGOALS) sub-make
1710b35786dSMilton Miller
1721cacc9abSSam Ravnborg$(filter-out _all sub-make $(CURDIR)/Makefile, $(MAKECMDGOALS)) _all: sub-make
17316f89098SCharles Keepax	@:
1740b35786dSMilton Miller
175c2e28dc9SMichal Marek# Fake the "Entering directory" message once, so that IDEs/editors are
176c2e28dc9SMichal Marek# able to understand relative filenames.
177066b7ed9SMichal Marek       echodir := @echo
178066b7ed9SMichal Marek quiet_echodir := @echo
179066b7ed9SMichal Mareksilent_echodir := @:
1800b35786dSMilton Millersub-make: FORCE
181066b7ed9SMichal Marek	$($(quiet)echodir) "make[1]: Entering directory \`$(KBUILD_OUTPUT)'"
18223a45e2cSSam Ravnborg	$(if $(KBUILD_VERBOSE:1=),@)$(MAKE) -C $(KBUILD_OUTPUT) \
18323a45e2cSSam Ravnborg	KBUILD_SRC=$(CURDIR) \
1840b35786dSMilton Miller	KBUILD_EXTMOD="$(KBUILD_EXTMOD)" -f $(CURDIR)/Makefile \
1850b35786dSMilton Miller	$(filter-out _all sub-make,$(MAKECMDGOALS))
1861da177e4SLinus Torvalds
1871da177e4SLinus Torvalds# Leave processing to above invocation of make
1881da177e4SLinus Torvaldsskip-makefile := 1
1891da177e4SLinus Torvaldsendif # ifneq ($(KBUILD_OUTPUT),)
1901da177e4SLinus Torvaldsendif # ifeq ($(KBUILD_SRC),)
1911da177e4SLinus Torvalds
1921da177e4SLinus Torvalds# We process the rest of the Makefile if this is the final invocation of make
1931da177e4SLinus Torvaldsifeq ($(skip-makefile),)
1941da177e4SLinus Torvalds
1951da177e4SLinus Torvalds# If building an external module we do not care about the all: rule
1961da177e4SLinus Torvalds# but instead _all depend on modules
1974f193362SPaul SmithPHONY += all
1981da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
1991da177e4SLinus Torvalds_all: all
2001da177e4SLinus Torvaldselse
2011da177e4SLinus Torvalds_all: modules
2021da177e4SLinus Torvaldsendif
2031da177e4SLinus Torvalds
2049da0763bSMichal Marekifeq ($(KBUILD_SRC),)
2059da0763bSMichal Marek        # building in the source tree
2069da0763bSMichal Marek        srctree := .
2079da0763bSMichal Marekelse
2089da0763bSMichal Marek        ifeq ($(KBUILD_SRC)/,$(dir $(CURDIR)))
2099da0763bSMichal Marek                # building in a subdirectory of the source tree
2109da0763bSMichal Marek                srctree := ..
2119da0763bSMichal Marek        else
2129da0763bSMichal Marek                srctree := $(KBUILD_SRC)
2139da0763bSMichal Marek        endif
2149da0763bSMichal Marekendif
2157e1c0477SMichal Marekobjtree		:= .
2161da177e4SLinus Torvaldssrc		:= $(srctree)
2171da177e4SLinus Torvaldsobj		:= $(objtree)
2181da177e4SLinus Torvalds
2190f558c33SMattia DongiliVPATH		:= $(srctree)$(if $(KBUILD_EXTMOD),:$(KBUILD_EXTMOD))
2201da177e4SLinus Torvalds
22111294235SAmerigo Wangexport srctree objtree VPATH
2221da177e4SLinus Torvalds
2231da177e4SLinus Torvalds
2241da177e4SLinus Torvalds# SUBARCH tells the usermode build what the underlying arch is.  That is set
2251da177e4SLinus Torvalds# first, and if a usermode build is happening, the "ARCH=um" on the command
2261da177e4SLinus Torvalds# line overrides the setting of ARCH below.  If a native build is happening,
22738385f8fSMasahiro Yamada# then ARCH is assigned, getting whatever value it gets normally, and
2281da177e4SLinus Torvalds# SUBARCH is subsequently ignored.
2291da177e4SLinus Torvalds
230ffee0de4SDavid WoodhouseSUBARCH := $(shell uname -m | sed -e s/i.86/x86/ -e s/x86_64/x86/ \
231ffee0de4SDavid Woodhouse				  -e s/sun4u/sparc64/ \
2321da177e4SLinus Torvalds				  -e s/arm.*/arm/ -e s/sa110/arm/ \
23339990b5eSLinus Torvalds				  -e s/s390x/s390/ -e s/parisc64/parisc/ \
234236b1957SPaul Mundt				  -e s/ppc.*/powerpc/ -e s/mips.*/mips/ \
235f1b99392SWill Deacon				  -e s/sh[234].*/sh/ -e s/aarch64.*/arm64/ )
2361da177e4SLinus Torvalds
2371da177e4SLinus Torvalds# Cross compiling and selecting different set of gcc/bin-utils
2381da177e4SLinus Torvalds# ---------------------------------------------------------------------------
2391da177e4SLinus Torvalds#
2401da177e4SLinus Torvalds# When performing cross compilation for other architectures ARCH shall be set
2411da177e4SLinus Torvalds# to the target architecture. (See arch/* for the possibilities).
2421da177e4SLinus Torvalds# ARCH can be set during invocation of make:
2431da177e4SLinus Torvalds# make ARCH=ia64
2441da177e4SLinus Torvalds# Another way is to have ARCH set in the environment.
2451da177e4SLinus Torvalds# The default ARCH is the host where make is executed.
2461da177e4SLinus Torvalds
2471da177e4SLinus Torvalds# CROSS_COMPILE specify the prefix used for all executables used
2481da177e4SLinus Torvalds# during compilation. Only gcc and related bin-utils executables
2491da177e4SLinus Torvalds# are prefixed with $(CROSS_COMPILE).
2501da177e4SLinus Torvalds# CROSS_COMPILE can be set on the command line
2511da177e4SLinus Torvalds# make CROSS_COMPILE=ia64-linux-
2521da177e4SLinus Torvalds# Alternatively CROSS_COMPILE can be set in the environment.
25384336466SRoland McGrath# A third alternative is to store a setting in .config so that plain
25484336466SRoland McGrath# "make" in the configured kernel build directory always uses that.
2551da177e4SLinus Torvalds# Default value for CROSS_COMPILE is not to prefix executables
2561da177e4SLinus Torvalds# Note: Some architectures assign CROSS_COMPILE in their arch/*/Makefile
2572331d1a6SSam RavnborgARCH		?= $(SUBARCH)
25884336466SRoland McGrathCROSS_COMPILE	?= $(CONFIG_CROSS_COMPILE:"%"=%)
2591da177e4SLinus Torvalds
2601da177e4SLinus Torvalds# Architecture as present in compile.h
2616752ed90SThomas GleixnerUTS_MACHINE 	:= $(ARCH)
2626752ed90SThomas GleixnerSRCARCH 	:= $(ARCH)
2631da177e4SLinus Torvalds
264d746d647SSam Ravnborg# Additional ARCH settings for x86
265d746d647SSam Ravnborgifeq ($(ARCH),i386)
266d746d647SSam Ravnborg        SRCARCH := x86
267d746d647SSam Ravnborgendif
268d746d647SSam Ravnborgifeq ($(ARCH),x86_64)
269d746d647SSam Ravnborg        SRCARCH := x86
270d746d647SSam Ravnborgendif
27174b469f2SSam Ravnborg
2725e538790SSam Ravnborg# Additional ARCH settings for sparc
273e69f58c0SNamhyung Kimifeq ($(ARCH),sparc32)
274e69f58c0SNamhyung Kim       SRCARCH := sparc
275e69f58c0SNamhyung Kimendif
276a439fe51SSam Ravnborgifeq ($(ARCH),sparc64)
2775e538790SSam Ravnborg       SRCARCH := sparc
278a439fe51SSam Ravnborgendif
2792fb9b1bdSSam Ravnborg
2803cc000b5SPaul Mundt# Additional ARCH settings for sh
2813cc000b5SPaul Mundtifeq ($(ARCH),sh64)
2823cc000b5SPaul Mundt       SRCARCH := sh
2833cc000b5SPaul Mundtendif
2843cc000b5SPaul Mundt
28518aecc2bSChris Metcalf# Additional ARCH settings for tile
2866738d321SChris Metcalfifeq ($(ARCH),tilepro)
2876738d321SChris Metcalf       SRCARCH := tile
2886738d321SChris Metcalfendif
28918aecc2bSChris Metcalfifeq ($(ARCH),tilegx)
29018aecc2bSChris Metcalf       SRCARCH := tile
29118aecc2bSChris Metcalfendif
29218aecc2bSChris Metcalf
2935e538790SSam Ravnborg# Where to locate arch specific headers
2945e538790SSam Ravnborghdr-arch  := $(SRCARCH)
2955e538790SSam Ravnborg
29614cdd3c4SRoman ZippelKCONFIG_CONFIG	?= .config
29741263fc6SBen Gardinerexport KCONFIG_CONFIG
29814cdd3c4SRoman Zippel
2991da177e4SLinus Torvalds# SHELL used by kbuild
3001da177e4SLinus TorvaldsCONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
3011da177e4SLinus Torvalds	  else if [ -x /bin/bash ]; then echo /bin/bash; \
3021da177e4SLinus Torvalds	  else echo sh; fi ; fi)
3031da177e4SLinus Torvalds
304070b98bfSSam RavnborgHOSTCC       = gcc
305070b98bfSSam RavnborgHOSTCXX      = g++
30625583d4bSJosh TriplettHOSTCFLAGS   = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
307070b98bfSSam RavnborgHOSTCXXFLAGS = -O2
3081da177e4SLinus Torvalds
30961163efaSBehan Websterifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
31061163efaSBehan WebsterHOSTCFLAGS  += -Wno-unused-value -Wno-unused-parameter \
31161163efaSBehan Webster		-Wno-missing-field-initializers -fno-delete-null-pointer-checks
31261163efaSBehan Websterendif
31361163efaSBehan Webster
314070b98bfSSam Ravnborg# Decide whether to build built-in, modular, or both.
315070b98bfSSam Ravnborg# Normally, just do built-in.
3161da177e4SLinus Torvalds
3171da177e4SLinus TorvaldsKBUILD_MODULES :=
3181da177e4SLinus TorvaldsKBUILD_BUILTIN := 1
3191da177e4SLinus Torvalds
3203fbb43dfSMasahiro Yamada# If we have only "make modules", don't compile built-in objects.
3213fbb43dfSMasahiro Yamada# When we're building modules with modversions, we need to consider
3223fbb43dfSMasahiro Yamada# the built-in objects during the descend as well, in order to
3233fbb43dfSMasahiro Yamada# make sure the checksums are up to date before we record them.
3241da177e4SLinus Torvalds
3251da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),modules)
3261da177e4SLinus Torvalds  KBUILD_BUILTIN := $(if $(CONFIG_MODVERSIONS),1)
3271da177e4SLinus Torvaldsendif
3281da177e4SLinus Torvalds
3293fbb43dfSMasahiro Yamada# If we have "make <whatever> modules", compile modules
3303fbb43dfSMasahiro Yamada# in addition to whatever we do anyway.
3313fbb43dfSMasahiro Yamada# Just "make" or "make all" shall build modules as well
3321da177e4SLinus Torvalds
3331da177e4SLinus Torvaldsifneq ($(filter all _all modules,$(MAKECMDGOALS)),)
3341da177e4SLinus Torvalds  KBUILD_MODULES := 1
3351da177e4SLinus Torvaldsendif
3361da177e4SLinus Torvalds
3371da177e4SLinus Torvaldsifeq ($(MAKECMDGOALS),)
3381da177e4SLinus Torvalds  KBUILD_MODULES := 1
3391da177e4SLinus Torvaldsendif
3401da177e4SLinus Torvalds
341e579d351SSam Ravnborgexport KBUILD_MODULES KBUILD_BUILTIN
3421da177e4SLinus Torvaldsexport KBUILD_CHECKSRC KBUILD_SRC KBUILD_EXTMOD
3431da177e4SLinus Torvalds
34461163efaSBehan Websterifneq ($(CC),)
34561163efaSBehan Websterifeq ($(shell $(CC) -v 2>&1 | grep -c "clang version"), 1)
34661163efaSBehan WebsterCOMPILER := clang
34761163efaSBehan Websterelse
34861163efaSBehan WebsterCOMPILER := gcc
34961163efaSBehan Websterendif
35061163efaSBehan Websterexport COMPILER
35161163efaSBehan Websterendif
3521da177e4SLinus Torvalds
3531da177e4SLinus Torvalds# Look for make include files relative to root of kernel src
3541da177e4SLinus TorvaldsMAKEFLAGS += --include-dir=$(srctree)
3551da177e4SLinus Torvalds
3561cacc9abSSam Ravnborg# We need some generic definitions (do not try to remake the file).
3571cacc9abSSam Ravnborg$(srctree)/scripts/Kbuild.include: ;
35815964864SOleg Verychinclude $(srctree)/scripts/Kbuild.include
3591da177e4SLinus Torvalds
3601da177e4SLinus Torvalds# Make variables (CC, etc...)
3611da177e4SLinus TorvaldsAS		= $(CROSS_COMPILE)as
3621da177e4SLinus TorvaldsLD		= $(CROSS_COMPILE)ld
3631da177e4SLinus TorvaldsCC		= $(CROSS_COMPILE)gcc
3641da177e4SLinus TorvaldsCPP		= $(CC) -E
3651da177e4SLinus TorvaldsAR		= $(CROSS_COMPILE)ar
3661da177e4SLinus TorvaldsNM		= $(CROSS_COMPILE)nm
3671da177e4SLinus TorvaldsSTRIP		= $(CROSS_COMPILE)strip
3681da177e4SLinus TorvaldsOBJCOPY		= $(CROSS_COMPILE)objcopy
3691da177e4SLinus TorvaldsOBJDUMP		= $(CROSS_COMPILE)objdump
3701da177e4SLinus TorvaldsAWK		= awk
3711da177e4SLinus TorvaldsGENKSYMS	= scripts/genksyms/genksyms
372caa27b66SSam RavnborgINSTALLKERNEL  := installkernel
3731da177e4SLinus TorvaldsDEPMOD		= /sbin/depmod
3741da177e4SLinus TorvaldsPERL		= perl
3751da177e4SLinus TorvaldsCHECK		= sparse
3761da177e4SLinus Torvalds
37780a7d1d9SHannes EderCHECKFLAGS     := -D__linux__ -Dlinux -D__STDC__ -Dunix -D__unix__ \
37880a7d1d9SHannes Eder		  -Wbitwise -Wno-return-void $(CF)
3796588169dSSam RavnborgCFLAGS_MODULE   =
3806588169dSSam RavnborgAFLAGS_MODULE   =
3816588169dSSam RavnborgLDFLAGS_MODULE  =
3821da177e4SLinus TorvaldsCFLAGS_KERNEL	=
3831da177e4SLinus TorvaldsAFLAGS_KERNEL	=
3842521f2c2SPeter OberparleiterCFLAGS_GCOV	= -fprofile-arcs -ftest-coverage
3851da177e4SLinus Torvalds
3861da177e4SLinus Torvalds
387abbf1590SDavid Howells# Use USERINCLUDE when you must reference the UAPI directories only.
388abbf1590SDavid HowellsUSERINCLUDE    := \
389abbf1590SDavid Howells		-I$(srctree)/arch/$(hdr-arch)/include/uapi \
390abbf1590SDavid Howells		-Iarch/$(hdr-arch)/include/generated/uapi \
391abbf1590SDavid Howells		-I$(srctree)/include/uapi \
392abbf1590SDavid Howells		-Iinclude/generated/uapi \
393abbf1590SDavid Howells                -include $(srctree)/include/linux/kconfig.h
394abbf1590SDavid Howells
3951da177e4SLinus Torvalds# Use LINUXINCLUDE when you must reference the include/ directory.
3961da177e4SLinus Torvalds# Needed to be compatible with the O= option
397abbf1590SDavid HowellsLINUXINCLUDE    := \
398abbf1590SDavid Howells		-I$(srctree)/arch/$(hdr-arch)/include \
399abbf1590SDavid Howells		-Iarch/$(hdr-arch)/include/generated \
400abbf1590SDavid Howells		$(if $(KBUILD_SRC), -I$(srctree)/include) \
401abbf1590SDavid Howells		-Iinclude \
402abbf1590SDavid Howells		$(USERINCLUDE)
4031da177e4SLinus Torvalds
404d8672b40SSam RavnborgKBUILD_CPPFLAGS := -D__KERNEL__
4051da177e4SLinus Torvalds
406a0f97e06SSam RavnborgKBUILD_CFLAGS   := -Wall -Wundef -Wstrict-prototypes -Wno-trigraphs \
40794bed2a9SDave Jones		   -fno-strict-aliasing -fno-common \
408a8735821SFloris Kraak		   -Werror-implicit-function-declaration \
409a1c48bb1SGeert Uytterhoeven		   -Wno-format-security
410a1c48bb1SGeert Uytterhoeven
41180c00ba9SSam RavnborgKBUILD_AFLAGS_KERNEL :=
41280c00ba9SSam RavnborgKBUILD_CFLAGS_KERNEL :=
413222d394dSSam RavnborgKBUILD_AFLAGS   := -D__ASSEMBLY__
4146588169dSSam RavnborgKBUILD_AFLAGS_MODULE  := -DMODULE
4156588169dSSam RavnborgKBUILD_CFLAGS_MODULE  := -DMODULE
4166588169dSSam RavnborgKBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds
4171da177e4SLinus Torvalds
418f1d28fb0SRoman Zippel# Read KERNELRELEASE from include/config/kernel.release (if it exists)
419f1d28fb0SRoman ZippelKERNELRELEASE = $(shell cat include/config/kernel.release 2> /dev/null)
420cacd54efSMichal MarekKERNELVERSION = $(VERSION)$(if $(PATCHLEVEL),.$(PATCHLEVEL)$(if $(SUBLEVEL),.$(SUBLEVEL)))$(EXTRAVERSION)
421cb58455cSSam Ravnborg
422070b98bfSSam Ravnborgexport VERSION PATCHLEVEL SUBLEVEL KERNELRELEASE KERNELVERSION
42380ef88d6SSam Ravnborgexport ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
424caa27b66SSam Ravnborgexport CPP AR NM STRIP OBJCOPY OBJDUMP
425caa27b66SSam Ravnborgexport MAKE AWK GENKSYMS INSTALLKERNEL PERL UTS_MACHINE
426070b98bfSSam Ravnborgexport HOSTCXX HOSTCXXFLAGS LDFLAGS_MODULE CHECK CHECKFLAGS
4271da177e4SLinus Torvalds
42806c5040cSSam Ravnborgexport KBUILD_CPPFLAGS NOSTDINC_FLAGS LINUXINCLUDE OBJCOPYFLAGS LDFLAGS
4292521f2c2SPeter Oberparleiterexport KBUILD_CFLAGS CFLAGS_KERNEL CFLAGS_MODULE CFLAGS_GCOV
430222d394dSSam Ravnborgexport KBUILD_AFLAGS AFLAGS_KERNEL AFLAGS_MODULE
4316588169dSSam Ravnborgexport KBUILD_AFLAGS_MODULE KBUILD_CFLAGS_MODULE KBUILD_LDFLAGS_MODULE
43280c00ba9SSam Ravnborgexport KBUILD_AFLAGS_KERNEL KBUILD_CFLAGS_KERNEL
43340df759eSMichal Marekexport KBUILD_ARFLAGS
4341da177e4SLinus Torvalds
4351da177e4SLinus Torvalds# When compiling out-of-tree modules, put MODVERDIR in the module
4361da177e4SLinus Torvalds# tree rather than in the kernel tree. The kernel tree might
4371da177e4SLinus Torvalds# even be read-only.
4381da177e4SLinus Torvaldsexport MODVERDIR := $(if $(KBUILD_EXTMOD),$(firstword $(KBUILD_EXTMOD))/).tmp_versions
4391da177e4SLinus Torvalds
4401da177e4SLinus Torvalds# Files to ignore in find ... statements
4411da177e4SLinus Torvalds
442ae63b2d7SPrarit Bhargavaexport RCS_FIND_IGNORE := \( -name SCCS -o -name BitKeeper -o -name .svn -o    \
443ae63b2d7SPrarit Bhargava			  -name CVS -o -name .pc -o -name .hg -o -name .git \) \
444ae63b2d7SPrarit Bhargava			  -prune -o
445450c6076SJesper Juhlexport RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
446450c6076SJesper Juhl			 --exclude CVS --exclude .pc --exclude .hg --exclude .git
4471da177e4SLinus Torvalds
4481da177e4SLinus Torvalds# ===========================================================================
4491da177e4SLinus Torvalds# Rules shared between *config targets and build targets
4501da177e4SLinus Torvalds
4511da177e4SLinus Torvalds# Basic helpers built in scripts/
4524f193362SPaul SmithPHONY += scripts_basic
4531da177e4SLinus Torvaldsscripts_basic:
4541da177e4SLinus Torvalds	$(Q)$(MAKE) $(build)=scripts/basic
455638adb05SSteven Rostedt	$(Q)rm -f .tmp_quiet_recordmcount
4561da177e4SLinus Torvalds
457cd05e6bdSJan Beulich# To avoid any implicit rule to kick in, define an empty command.
458cd05e6bdSJan Beulichscripts/basic/%: scripts_basic ;
459cd05e6bdSJan Beulich
4604f193362SPaul SmithPHONY += outputmakefile
461fd5f0cd6SJan Beulich# outputmakefile generates a Makefile in the output directory, if using a
462fd5f0cd6SJan Beulich# separate output directory. This allows convenient use of make in the
463fd5f0cd6SJan Beulich# output directory.
4641da177e4SLinus Torvaldsoutputmakefile:
465fd5f0cd6SJan Beulichifneq ($(KBUILD_SRC),)
46692979997SAndi Kleen	$(Q)ln -fsn $(srctree) source
467fd5f0cd6SJan Beulich	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/mkmakefile \
468fd5f0cd6SJan Beulich	    $(srctree) $(objtree) $(VERSION) $(PATCHLEVEL)
469fd5f0cd6SJan Beulichendif
4701da177e4SLinus Torvalds
471d8ecc5cdSSam Ravnborg# Support for using generic headers in asm-generic
472d8ecc5cdSSam RavnborgPHONY += asm-generic
473d8ecc5cdSSam Ravnborgasm-generic:
474d8ecc5cdSSam Ravnborg	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
4753c5994c8SCatalin Marinas	            src=asm obj=arch/$(SRCARCH)/include/generated/asm
4763c5994c8SCatalin Marinas	$(Q)$(MAKE) -f $(srctree)/scripts/Makefile.asm-generic \
4773c5994c8SCatalin Marinas	            src=uapi/asm obj=arch/$(SRCARCH)/include/generated/uapi/asm
478d8ecc5cdSSam Ravnborg
4791da177e4SLinus Torvalds# To make sure we do not include .config for any of the *config targets
4801da177e4SLinus Torvalds# catch them early, and hand them over to scripts/kconfig/Makefile
4811da177e4SLinus Torvalds# It is allowed to specify more targets when calling make, including
4821da177e4SLinus Torvalds# mixing *config targets and build targets.
483070b98bfSSam Ravnborg# For example 'make oldconfig all'.
4841da177e4SLinus Torvalds# Detect when mixed targets is specified, and make a second invocation
4851da177e4SLinus Torvalds# of make so .config is not included in this case either (for *config).
4861da177e4SLinus Torvalds
48710b63956SDavid Howellsversion_h := include/generated/uapi/linux/version.h
488d183e6f5SDavid Howells
4893eb3c740SRoman Zippelno-dot-config-targets := clean mrproper distclean \
490f4ed1009SJianbin Kang			 cscope gtags TAGS tags help %docs check% coccicheck \
491d183e6f5SDavid Howells			 $(version_h) headers_% archheaders archscripts \
4924aed2fd8SLinus Torvalds			 kernelversion %src-pkg
4931da177e4SLinus Torvalds
4941da177e4SLinus Torvaldsconfig-targets := 0
4951da177e4SLinus Torvaldsmixed-targets  := 0
4961da177e4SLinus Torvaldsdot-config     := 1
4971da177e4SLinus Torvalds
4981da177e4SLinus Torvaldsifneq ($(filter $(no-dot-config-targets), $(MAKECMDGOALS)),)
4991da177e4SLinus Torvalds	ifeq ($(filter-out $(no-dot-config-targets), $(MAKECMDGOALS)),)
5001da177e4SLinus Torvalds		dot-config := 0
5011da177e4SLinus Torvalds	endif
5021da177e4SLinus Torvaldsendif
5031da177e4SLinus Torvalds
5041da177e4SLinus Torvaldsifeq ($(KBUILD_EXTMOD),)
5051da177e4SLinus Torvalds        ifneq ($(filter config %config,$(MAKECMDGOALS)),)
5061da177e4SLinus Torvalds                config-targets := 1
5071da177e4SLinus Torvalds                ifneq ($(filter-out config %config,$(MAKECMDGOALS)),)
5081da177e4SLinus Torvalds                        mixed-targets := 1
5091da177e4SLinus Torvalds                endif
5101da177e4SLinus Torvalds        endif
5111da177e4SLinus Torvaldsendif
5121da177e4SLinus Torvalds
5131da177e4SLinus Torvaldsifeq ($(mixed-